#pragma SMALL DB OE #include sbit redlight = P0^0; sbit yellowlight = P0^1; sbit greenlight = P0^2; sbit door = P0^3; sbit daynight = P0^4; void SendSerial(char c) { /* initialize..set values for TMOD, TH1 and TCON */ TMOD = 0x20; /* configure timer for the correct baud rate */ TH1 = 0xe6; /* 1200 bps for 12 MHz clock */ TCON = 0x00; /* Set timer to not running */ /* set the Tx interrupt in SCON to indicate sending data */ SCON = 0x50; /* Set Serial IO to and normal mode */ /* start timer */ TR1 = 1; /* write character to SBUF */ SBUF = c; /* wait for completion of sent data */ while( (SCON & 0x02) == 0){} } /* Delay function */ void delay() { int i, j; for (i=0; i<1000; i++) for (j=0; j<50; j++) i=i+0; } /* Main function which will blink LED */ void main (void) { redlight=0; while(1) { delay(); /* These are the test lights */ if (door == 0) { greenlight=0; } else { greenlight=1; } if (daynight == 1) { yellowlight=0; } else { yellowlight=1; } if (door == 0) /* door closed */ { SendSerial('x'); } else { /* door open */ if (daynight == 1) /* daytime */ SendSerial('y'); else /* nighttime */ SendSerial('z'); } } }