# Making an animated relay in proteus work using pic16f877A

#### trinetra31

Jul 12, 2012
1
Hi all,
I am trying to make an animated relay work to switch on the bulb in my circuit. When a input is given to the pic16f877A, it is to make the relay on the bulb. I have fixed everything correctly( according to me...). But i can't make the relay work when i execute (F12). The lcd included works well though. Pls help. I will include the coding and the picture of the circuit. Also what do the blue and red square lights that appear in the proteus simulation.
Pls do help me.
Thanks
S.Trinetra
Code:
#include<htc.h>
#include <pic.h>

__CONFIG ( 0x3F32 );

#define data                PORTD     //Pins to the LCD D0-D7
#define rs          RC2       //rs of LCD
#define rw          RC0       //rw of LCD
#define en          RC3       //e of LCD
#define in          RE0       //input for RFID

// The above pins can be changed according to whicheva u choose

void initialize();
void busy();
void display(unsigned char one[], unsigned char two[]);
void command(unsigned char var);
void send_data(unsigned char var);
void string(unsigned char *var);

unsigned char text1[]={"RFID PROJECT"};
unsigned char text3[]={"CARD ACCEPTED"};
unsigned char text4[]={"CARD REJECTED"};
unsigned char text5[]={"                "};
//Additional text can be placed above. and can be called according to how
//u the calling in the code

void main(void)
{
int i, d;
TRISC=0x00;
TRISD=0X00;
TRISE=0x01;
initialize();
display(text1, text2);
while(1)
{
if (in==1)
{
RC1=1;
display(text3, text5);
busy();

}
else
{
RC1=0;
display(text4, text5);
busy();

}
}
}

void initialize()
{
data=0x38; rs=0; rw=0; en=1; en=0; busy();
data=0x0E; rs=0; rw=0; en=1; en=0; busy();
data=0x01; rs=0; rw=0; en=1; en=0; busy();
data=0x06; rs=0; rw=0; en=1; en=0; busy();
}

void busy()
{
unsigned char i,j;
for(i=0;i<50;i++)
for(j=0;j<255;j++);
}

void command(unsigned char var)
{
data=var; rs=0; rw=0;  en=1; en=0;busy();
}

void send_data(unsigned char var)
{
rs=1;rw=0;  en=1; data=var;  en=0; busy();
}

void string(unsigned char *var)
{
while(*var)
send_data(*var++);
}

void display(unsigned char one[], unsigned char two[])
{
command(0x80);
string(one);
command(0xC0);
string(two);
busy();
}

p.s
relay is set to 5V. It is still not working.
Do u notice the power terminal connected to one part of the relay and diode. Must have a certain value? I can't seem to insert any value.
Do u think that there is something wrong with the code in Mplab?
Must ac source and bulb be connected to the transistor and ground?

#### Attachments

• pic16f877a.jpg
148 KB · Views: 5,490

#### rparthiban69

Aug 17, 2012
1
try again

In proteus simultion not having a RFID card simulation and otherwise use emergency switch type( push button ).

Try this configure bit also
__CONFIG(HS & PWRTEN & BOREN & LVPEN & WDTDIS & DUNPROT & DEBUGDIS);

#### Harald Kapp

##### Moderator
Moderator
Nov 17, 2011
12,730
Does the logic level at RC1 change? If yes, then it is a simulation problem. I can't help with proteus but e.g. SPICE does have a problem with floating nets. Maybe proteus too? So just for the simulation you could connect the lamp circuit at one point to GND of the digital circuit (but don't do this in the real circuit).
It may also be required to connect a voltage source (e.g. 5V) to the power terminal unless proteus recognizes this as an implicit power source, but I doubt it.

Is this a problem only of the simulation or is this a problem in the real circuit (but correct in the simulation)?
RC1 has a 10k series resistor to Q1 which gives a base current of at best 440µA (assuming 5V output at RC1 and 0.6V for Vbe of Q1). The 2N3903 (I think this is the transistor, the schematic is a bit hard to read there) has a max. DC current gain of 150. That makes for a collector current of 66mA. Is that enough for the relay?

Replies
9
Views
342
Replies
13
Views
558
Replies
26
Views
1K
Replies
3
Views
850
Replies
1
Views
309