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: 10
Last edited:

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
524
Trophy points
1,393
Activity points
0
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.
 

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
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: 16
  • RELAY.pdf
    25 KB · Views: 7

Gorgon

Full Member level 6
Joined
Nov 10, 2005
Messages
345
Helped
75
Reputation
150
Reaction score
67
Trophy points
1,308
Location
Norway
Activity points
3,652
The crystal has no load capacitors (15pF). And it could be that your clock is not ticking.
 

paulfjujo

Advanced Member level 4
Joined
Jun 9, 2008
Messages
1,442
Helped
290
Reputation
580
Reaction score
276
Trophy points
1,363
Location
France 01800
Activity points
10,141
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)
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
48,516
Helped
14,271
Reputation
28,805
Reaction score
12,974
Trophy points
1,393
Location
Bochum, Germany
Activity points
280,594
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

Top