Sunteți pe pagina 1din 5

Program to detect the object using IR sensor #include<reg51.h> #include<stdio.

h> xdata char *sel174; xdata char *lcdsel; xdata char *sensor;

//pointer declaration

unsigned char array[12] ={"NOT DETECTED"}; unsigned char array1[8] = {"DETECTED"}; unsigned char i; void delay() { int i,j; for(i=0;i<0xf;i++) for(j=0;j<0xff;j++); } void delay1() { int i,j; for(i=0;i<0xff;i++) for(j=0;j<0xff;j++); } void cmd_check() { delay(); *sel174 = 0x00; } void data_check() { delay(); *sel174 = 0x01; } //Indicating Data to the LCD // Delay declaration/

//long delay declaration

// Indicating Command to the LCD

//function call

void main() { int s; sel174 = 0xffc3; lcdsel = 0xffc4; sensor=0xffc5; while(1) { s=*sensor;

/* Address alloted to give Command to the LCD */ /* Address alloted to give data to the LCD */ /* Address alloted to the Sensor */

s = ((s&0x20)>>0x05); cmd_check(); *lcdsel = 0x38; cmd_check(); *lcdsel = 0x06; cmd_check(); *lcdsel = 0x01; cmd_check(); *lcdsel = 0x0c; cmd_check(); *lcdsel = 0x80; if(s==0) { for (i=0;i<12;i++) { data_check(); *lcdsel = array[i]; delay1(); } } else { cmd_check(); *lcdsel = 0x80; for (i=0;i<8;i++)

/* To select both lines of the LCD */ /* Entry mode */ /* Clear Display */ /* Display ON Cursor OFF */ /* Starting address of top row of LCD*/

/* To display message1 */

/* Starting address of top row of LCD*/ /* To display message2 */

{ data_check(); *lcdsel = array1[i]; delay1(); //Long delay } } } }

Program to detect the object using IR sensor and count it

#include<reg51.h> #include<stdio.h> xdata char *sel174; xdata char *lcdsel; xdata char *sensor; //pointer declaration

unsigned char array[14] ={"N0.OF PERSONS:"}; unsigned char i; void delay() { int i,j; for(i=0;i<0xf;i++) for(j=0;j<0xff;j++); } void delay1() { int i,j; for(i=0;i<0xff;i++) for(j=0;j<0xff;j++); } void cmd_check() { /* Short Delay */

/* Long Delay */

/* Indicating Command to the LCD */

delay(); *sel174 = 0x00; } void data_check() { delay(); *sel174 = 0x01; } /* Indicating Data to the LCD */

void main() { int s,count=0,temp=0,t1,t2; sel174 = 0xffc3; lcdsel = 0xffc4; sensor=0xffc5; cmd_check(); *lcdsel = 0x38; cmd_check(); *lcdsel = 0x06; cmd_check(); *lcdsel = 0x01; cmd_check(); *lcdsel = 0x0c; cmd_check(); *lcdsel = 0x80; /* To select both lines of the LCD */ /* Entry mode */ /* Clear Display */ /* Display ON Cursor OFF */ /* Starting address of top row of LCD*/ /* Address alloted to give Command to the LCD */ /* Address alloted to give data to the LCD */ /* Address alloted to the Sensor */

for (i=0;i<14;i++) /* To display message */ { data_check(); *lcdsel = array[i]; } while(1) {

s=*sensor; s = ((s&0x20)>>0x05);

/* To select the 6th bit and moving to lsb */

if(s^temp==0x01 && s==1) /* To detect the 1 0 transition of sensor register*/ { delay1(); count=count+1; } temp=s; t1=count/10; t2=count%10; cmd_check(); *lcdsel=0x8E; data_check(); *lcdsel=t1+48; data_check(); *lcdsel=t2+48; delay1(); } }

//specifying address location // 48- to convert to ASCII

S-ar putea să vă placă și