Program to Detect the Object Using IR Sensor(1)

Embed Size (px)

Citation preview

  • 8/2/2019 Program to Detect the Object Using IR Sensor(1)

    1/5

    Program to detect the object using IR sensor

    #include

    #include

    xdata char *sel174;

    xdata char *lcdsel; //pointer declaration

    xdata char *sensor;

    unsigned char array[12] ={"NOT DETECTED"};

    unsigned char array1[8] = {"DETECTED"};

    unsigned char i;

    void delay() // Delay declaration/

    {int i,j;

    for(i=0;i

  • 8/2/2019 Program to Detect the Object Using IR Sensor(1)

    2/5

    void main()

    {

    int s;

    sel174 = 0xffc3; /* Address alloted to give Command to the LCD */

    lcdsel = 0xffc4; /* Address alloted to give data to the LCD */

    sensor=0xffc5; /* Address alloted to the Sensor */

    while(1)

    {

    s=*sensor;

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

    cmd_check();*lcdsel = 0x38; /* To select both lines of the LCD */

    cmd_check();

    *lcdsel = 0x06; /* Entry mode */

    cmd_check();

    *lcdsel = 0x01; /* Clear Display */

    cmd_check();

    *lcdsel = 0x0c; /* Display ON Cursor OFF */

    cmd_check();

    *lcdsel = 0x80; /* Starting address of top row of LCD*/

    if(s==0)

    {

    for (i=0;i

  • 8/2/2019 Program to Detect the Object Using IR Sensor(1)

    3/5

    {

    data_check();

    *lcdsel = array1[i];

    delay1(); //Long delay

    }

    }

    }

    }

    Program to detect the object using IR sensor and count it

    #include

    #include

    xdata char *sel174; //pointer declaration

    xdata char *lcdsel;

    xdata char *sensor;

    unsigned char array[14] ={"N0.OF PERSONS:"};

    unsigned char i;

    void delay() /* Short Delay */

    {

    int i,j;

    for(i=0;i

  • 8/2/2019 Program to Detect the Object Using IR Sensor(1)

    4/5

    delay();

    *sel174 = 0x00;

    }

    void data_check() /* Indicating Data to the LCD */

    {

    delay();

    *sel174 = 0x01;

    }

    void main()

    {int s,count=0,temp=0,t1,t2;

    sel174 = 0xffc3; /* Address alloted to give Command to the LCD */

    lcdsel = 0xffc4; /* Address alloted to give data to the LCD */

    sensor=0xffc5; /* Address alloted to the Sensor */

    cmd_check();

    *lcdsel = 0x38; /* To select both lines of the LCD */

    cmd_check();

    *lcdsel = 0x06; /* Entry mode */cmd_check();

    *lcdsel = 0x01; /* Clear Display */

    cmd_check();

    *lcdsel = 0x0c; /* Display ON Cursor OFF */

    cmd_check();

    *lcdsel = 0x80; /* Starting address of top row of LCD*/

    for (i=0;i

  • 8/2/2019 Program to Detect the Object Using IR Sensor(1)

    5/5

    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; //specifying address locationdata_check();

    *lcdsel=t1+48; // 48- to convert to ASCII

    data_check();

    *lcdsel=t2+48;

    delay1();

    }

    }