Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

What's wrong with my code?

Status
Not open for further replies.

theredkid

Newbie level 5
Joined
Apr 21, 2011
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,353
Hello,

Could you maybe check my following ccs c code used to control a relay driver for turning on/off leds. Unfortunately does not work.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <18F452.h> 
#define Fosc 16000000 //Baudrate 
#use delay(clock=Fosc,crystal=4000000) 
 
#fuses H4,PROTECT,BROWNOUT,PUT,NOWDT,NODEBUG,NOWDT,NOCPD,CCP2C1,STVREN,NOLVP 
void OneSC() 
{ 
delay_ms(1000); 
} 
 
void main() 
{ 
unsigned char a; 
set_tris_b(0x00); 
output_b(0x01); 
 
while(1) 
{ 
OneSC(); 
 
for(a=1;a<6;a++) 
{ 
output_b(0x03);  
delay_ms(250); //  
output_b(0x01); // 
delay_ms(250); // 
} 
 
OneSC(); 
 
output_b(0x05); 
Delay_ms(6000); 
output_b(0x01); 
OneSC(); 
 
output_b(0x09); 
Delay_ms(3000); 
output_b(0x01); 
} 
}

 

Attachments

  • relay.pdf
    25.5 KB · Views: 80
Last edited:

Please post the full circuit showing connections with PIC. If you have Proteus then draw circuit in Proteus and zip and post the file. Also post the complete CCS C project files.
 

OK here comes the connection with PIC. The ports with black arrows in PIC and RELAY are connected to each other.
 

Attachments

  • PIC .pdf
    23.6 KB · Views: 79
  • RELAY.pdf
    25 KB · Views: 52

The crystal has no load capacitors (15pF). And it could be that your clock is not ticking.
 

hello,

I didn't see your code, but the hardware has allready a problem...

What is the relay coil resistance value ?

because from 15V trough R8=100 ohms to get 12V ..
it means maxi current is 30mA
and to drive 6 relays ...
+ 6 leds with about 5mA each => allready consume near 30mA!!
How to drive the relay with 12V
.. check 12V with all relay ON.

there is something wrong !

remove R8 and ZD1 and use a 7812 (12V 1A) regulator (with radiator)
 

The newly posted PIC schematic still doesn't show clearly where the three serial interface lines are connected. But apparently to PORT D. The code is however operating port B.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top