Hello, in my project work I want to read serially received data continuously and compare it with stored ID in MCU I am using 8051. If the ID match then Green LED will glow, for ID mismatch Orange LED. If no ID found Red LED should glow. In this I am getting problem,when valid Id received it is indicated by Green LED but if we stop sending ID i.e. logically NO DATA in SBUF the Red LED should glow ; it doesn't happen its showing Green Led on...how to solve this one?
Here is code
/* /Program to interface RFID with 8051 microcontroller (AT89C51) Program receiving character/Tag ID serially and security alarm system baud rate 9600, no parity, crystal freq 11.0579 Mhz*/
#include <REGX51.H> sbit s10 = P1^0; sbit s11 = P1^1; sbit s12 = P1^2; sbit s13 = P1^3;
void green_led_on() { SBUF='*'; s12=1; s13=1; s10=0; s11=0; }
void red_led_on() { s10=1; s11=1; }
void main( ) { char recID; P2=0x00; P1=0x00; P0=0x00; TMOD=0x20; TH1=0xfD; TR1=1; SCON=0x50; IE=0x90; RI=1; while(1) { if (RI=='1') { recID=SBUF; RI = 0; if(recID==55) { green_led_on(); }
else if(recID==10) { green_led_on(); }
else if(recID==74) { green_led_on(); }
else if(recID==104) { green_led_on(); }
else { red_led_on(); } } } }
Does your program have four valid codes that should result in "green"? Or does it require you to send the four character in proper sequence like a pin code?
By the way - you don't seem to like software comments much. How would a reader know what is controlled by your 4 bitmapped signals?
And your "green" function plays with four signals while the "red" function only plays with two. So what about the two signals that is only handled in green_led_on()? When will they ever get another state?