You are on page 1of 3

#include<reg51.

h> void command(unsigned char); void display(unsigned char); void msdelay(unsigned int); sfr ldata = 0x80; sbit rs = P2^5; sbit rw = P2^6; sbit en = P2^7; sbit rx = P3^0; sbit tx = P3^1; sbit d1= P3^2; sbit d2= P3^3; sbit d3 =P3^4; sbit d4 = P3^5; sbit d5 = P3^6; void disparray(unsigned char d[]); void comdarray(unsigned char d[]); unsigned char z; unsigned char code bcomm[]={0x38,0x0e,0x06,0x01,0x80,0x00}; unsigned char code lnct[]={"LNCT INDORE~"}; unsigned char code lnct1[]={"RED DETECTED~"}; unsigned char code lnct2[]={"GREEN DETECTED~"}; unsigned char code lnct3[]={"BLUE DETECTED~"}; void main(void) { d1=d2=d3=d4=d5=0; comdarray(bcomm); msdelay(5); disparray(lnct); msdelay(250); command(0x01); msdelay(50); command(0x82); msdelay(5); TMOD=0X20; TH1=-3; SCON=0X50; TR1=1; while(1) { while(RI==0); z=SBUF; RI=0; if(z=='R') { d1=1;

disparray(lnct1); msdelay(250); command(0x01); } if(z=='G') { d2=1; disparray(lnct2); msdelay(250); command(0x01); } if(z=='B') { d3=1; disparray(lnct3); msdelay(250); command(0x01); } } } void disparray(unsigned char d[]) { unsigned char x=0; while(d[x]!='~') { display(d[x]); x++; } } void comdarray(unsigned char d[]) { unsigned char x=0; while(d[x]!=0x00) { command(d[x]); x++; } } void command(unsigned char valu) { ldata =valu; rs =0; rw =0; en =1; msdelay(1); en =0; return; } void display(unsigned char valu) { ldata =valu;

rs =1; rw =0; en =1; msdelay(1); en =0; return; } void msdelay(unsigned int value) { unsigned int i,j; for(i=0;i<value;i++) for(j=0;j<1275;j++); }