WIRELESS WAITER AND BILL CALL SYSTEM CODES
/* WIRELESS WAITER AND BILL CALL SYSTEM */
#include <REGX52.H>
sbit rcv=P2^4; //show work process only
sbit snd=P2^5; //show work process only
sbit process1=P1^0;
sbit process2=P1^1;
sbit null=P1^2;
void msdelay(unsigned int time)
{
int i,j;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
unsigned char serrx() //receiving function
{
unsigned char x; //for storing received frame
rcv=1;
msdelay(200); // WAIT UNTILL RI FLAG SETS INDICATING FRAME RECEIVED
x=SBUF; // PLACING THE DATA RECEIVED IN A VARIABLE X
RI=0; // CLEARING RI FLAG ROR NEXT RECEIVE OPERATION
msdelay(100);
rcv=0;
return(x); //return received frame data
}
void sertx(unsigned char x) //TRANSMITTING CHARACTER FUNCTION
{
SBUF=x; //PLACE CHARACTER TO SEND IN SBUF REGISTER
snd=1;
while (TI==0); //WAIT TILL TI FLAG SETS INDICATING DATA SENT
TI=0; // CLEAR TI FLAG FOR NEXT TRANSMIT OPERATION
msdelay(100);
snd=0;
}
void ex0_ISR (void) interrupt 0 //interrupt for answering table 1
{
ledt1w=0;
ledt1b=0;
sertx('I'); //answer table 1
}
void ex1_ISR (void) interrupt 2 using 2//interrupt for answering table 2
{
ledt2w=0;
ledt2b=0;
sertx('J'); //answer table 2
}
void main () // MAIN FUNCTION
{
unsigned char y;
EA = 1; // Enable Global Interrupt Flag
EX0 = 1; // Enable EX0 Interrupt
IT0 = 1; // Configure external interrupt 0 for falling edge on /INT0 (P3.2)
EX1 = 1; // Enable EX1 Interrupt
IT1 = 1; // Configure external interrupt 1 for falling edge on /INT2 (P3.3)
P2=0x00;
P1=0x00;
TMOD=0x20; // SETTING BAUD RATE
TH1=0xFD; // TO 9600
SCON=0x50; // BAUD
TR1=1;
while(1)
{ msdelay(50);
if((!ledt1w)&&(!ledt1b))
{ sertx('A'); //call table 1
msdelay(200);
y=serrx(); //receive request or answer from table 1
if(y=='D') //if table 1 calls waiter
{
ledt1w=1;
}
if(y=='E') //if table 1 calls bill
{
ledt1b=1;
}
if(y=='C') //if table 1 calls nothing
{
process1=1;
msdelay(200);
process1=0;
}
else
{
null=1;
msdelay(100);
null=0;
}
}
if((!ledt2w)&&(!ledt2b))
{
sertx('B'); //call table 2
msdelay(100);
y=serrx(); //receive request or answer from table 2
if(y=='G') //if table 2 calls waiter
{
ledt2w=1;
}
if(y=='H') //if table 2 calls bill
{
ledt2b=1;
}
if(y=='F') //if table 2 calls nothing
{
process2=1;
msdelay(100);
process2=0;
}
else
{
null=1;
msdelay(100);
null=0;
}
}
}
}