Microcontroller › 8051 › wiegand protocol › tis is work i have done
tis is work i have done yet…..
is not for showing card no. Itz just about displaying 26 bits it recieved
#include<reg51.h>
sbit rs=P1^4;
sbit lcde=P1^5;
sbit d4=P1^0;
sbit d5=P1^1;
sbit d6=P1^2;
sbit d7=P1^3;
int i=0;
int arr[26];
code const unsigned char slo[]=”CARD NUMBER”;
unsigned char xch(unsigned char);
void datatr(unsigned char);
void lcdinit();
void dispslogan(unsigned char *);
void send_command(unsigned char);
void senddata(unsigned char );
void delay();
void next_line();
void clr_lcd();
/*FUNCTION FOR SWAPPING LSBYTE AND MSBYTE OF THE DATA*/
unsigned char xch(unsigned char data1)
{
unsigned char temp,temp1;
temp=data1;
data1=data1>>4;
temp1=data1;
data1=temp;
data1=data1<<4;
data1=data1|temp1;
return(data1);
}
/*FUNCTION FOR 4BIT DATA TRANSFER ON LCD PINS IN 4-BIT MODE*/
void datatr(unsigned char data1)
{
d4=data1&0x01;
data1=data1>>1;
d5=data1&0x01;
data1=data1>>1;
d6=data1&0x01;
data1=data1>>1;
d7=data1&0x01;
}
/*INITIALIZATION OF LCD*/
void lcdinit()
{
clr_lcd(); //FUNCTION SET
send_command(0x28);
delay();
send_command(0x28);
delay();
send_command(0x28);
delay();
send_command(0x06); //ENTRY MODE
delay();
send_command(0x0c); //DISPLAY ON/OFF
delay();
clr_lcd();
}
/*FUNCTION FOR DISPLAYING DATA ON THE LCD*/
void dispslogan(unsigned char *p)
{
unsigned char data1;
while(*p)
{
data1=*p;
senddata(data1);
p++;
}
}
/*FUNCTION FOR SENDING LCD COMMANDS*/
void send_command(unsigned char data1)
{
unsigned char data2;
rs=0;
delay();
lcde=1;
delay();
data2=xch(data1);
datatr(data2);
lcde=0;
delay();
lcde=1;
datatr(data1);
delay();
lcde=0;
delay();
rs=1;
}
/*FUNCTION FOR WRITING DATA ON THE LCD*/
void senddata(unsigned char data1)
{
unsigned char data2;
rs=1;
delay();
lcde=1;
delay();
data2=xch(data1);
datatr(data2);
lcde=0;
delay();
lcde=1;
datatr(data1);
delay();
lcde=0;
delay();
rs=0;
}
/*delay for 20 micro second*/
void delay()
{
unsigned char i,j;
for(i=0;i<100;i++)
{
for(j=0;j<20;j++)
{
}
}
}
/*COMMAND FOR BRINGING LCD CURSOR ON SECOND LINE*/
void next_line()
{
send_command(0xc0);
delay();
}
/*COMMAND FOR CLEARING LCD AND BRINGING LCD CURSOR ON FIRST LINE*/
void clr_lcd()
{
send_command(0x01);
delay();
send_command(0x02);
delay();
}
/*EXTERNAL INTERRUPT 0 FOR DATA1*/
void exdata1() interrupt 0 //INT0……P3.2
{
arr=1;
i++;
IE0 = 0;
}
/*EXTERNAL INTERRUPT 1 FOR DATA0*/
void exdata0() interrupt 2 //INT1……P3.3
{
arr=0;
i++;
IE1=0;
}
//main function
int main()
{
lcdinit();
IE=0x85; // INTERRUPT ENABLE REGISTER ENABLING EXTERNAL INTERRUPT 0 , EXTERNAL INTERRUPT 1
IT0=1; // EDGE TRIGGERING……TCON.O
IT1=1; // EDGE TRIGGERING……TCON.1
IE=0x85; // INTERRUPT ENABLE REGISTER ENABLING EXTERNAL INTERRUPT 0 , EXTERNAL INTERRUPT 1
//IE0=0;
//IE1=0;
dispslogan(slo);
if(i==26) // AS CARD CONTAINS 26 BITS
{
clr_lcd();
for(i=1;i<=25;i++)
{
senddata(arr);
delay();
}
}
if(i >= 26 )
{
EA = 0;
}
}
plz help yar