sensor reading problem

Discussion in 'Embedded Systems and Microcontrollers' started by sahar, Oct 23, 2008.

Thread Status:
Not open for further replies.
  1. sahar

    Thread Starter New Member

    Oct 23, 2008
    4
    0
    hi
    every one
    i'm doing a project to control light intensity within a room at89c51 interfacing with adc0808.i have used 3 light sensors with pin 26,27,28 of adc.this system always send the reading 255 whether sensors are connected or not.i cant understand the problem.plz help me to solve the problem.i follow the code mentioned below.is any problem in my code or i will check my circuit.

    #include<reg51.h>
    void se(unsigned char x);
    void con(unsigned char value);
    void ms(unsigned int value);

    sbit clock=P3^2;
    sbit ALE=P3^6;
    sbit OE=P3^5;
    sbit SC=P3^3;
    sbit EOC=P3^4;

    sbit Addr_A=P1^0;
    sbit Addr_B=P1^1;
    sbit Addr_C=P1^2;

    sbit Relay1=P1^3;
    sbit Relay2=P1^4;
    sbit Relay3=P1^5;
    sbit Relay4=P1^6;
    sbit Relay5=P1^7;

    unsigned char lux;
    unsigned char array[]={'0','1','2','3','4','5','6','7','8','9'};

    void timer0() interrupt 1
    {
    clock=~clock;
    }
    void serial0() interrupt 4
    {
    if(RI==1)
    {
    se('P');
    RI=0;
    lux=SBUF;
    switch(lux)
    {
    case ('a'):
    Relay1=1;
    se('a');
    break;

    case ('A'):
    Relay1=0;
    se('A');
    break;

    case ('b'):
    Relay2=1;
    se('b');
    break;

    case ('B'):
    Relay2=0;
    se('B');
    break;

    case ('c'):
    Relay3=1;
    se('c');
    break;

    case ('C'):
    Relay3=0;
    se('C');
    break;

    case ('d'):
    Relay4=1;
    se('d');
    break;

    case ('D'):
    Relay4=0;
    se('D');
    break;

    case ('e'):
    Relay5=1;
    se('e');
    break;

    case ('E'):
    Relay5=0;
    se('E');
    break;

    default :
    se('N');
    }
    RI=0;
    }
    }

    void main(void)
    {
    unsigned char value;

    P2=0xFF;
    EOC=1;
    ALE=0;
    OE=0;
    SC=0;

    TMOD=0x22;
    TH1=0xFD;
    SCON=0x50;
    EA=1;
    ES=1;
    // IE=0x92;
    TR1=1;
    TI=0;
    RI=0;

    // get data from adc
    while(1)
    {
    //use channel 0
    ms(30000);
    se('X');
    se('O');
    se('P');
    Addr_A=0;
    Addr_B=0;
    Addr_C=0;
    ms(255);
    ALE=1;
    ms(255);
    SC=1;
    ms(255);
    ALE=0;
    SC=0;
    while(EOC==1);
    while(EOC==0);
    OE=1;
    ms(255);
    value=P2;
    OE=0;
    con(value);
    se('X');
    //use channel 1
    ms(30000);
    se('y');
    Addr_A=1;
    Addr_B=0;
    Addr_C=0;
    ms(255);
    ALE=1;
    ms(255);
    SC=1;
    ms(255);
    ALE=0;
    SC=0;
    while(EOC==1);
    while(EOC==0);
    OE=1;
    ms(255);
    value=P2;
    OE=0;
    con(value);
    se('Y');
    //use channel 2
    ms(30000);
    se('z');
    Addr_A=0;
    Addr_B=1;
    Addr_C=0;
    ms(255);
    ALE=1;
    ms(255);
    SC=1;
    ms(255);
    ALE=0;
    SC=0;
    while(EOC==1);
    while(EOC==0);
    OE=1;
    ms(255);
    value=P2;
    OE=0;
    con(value);
    se('Z');
    }
    }
    void ms(unsigned int value)
    {
    unsigned int x,y;
    for(x=0;x<value;x++);
    for(y=0;y<1275;y++);
    }
    void con(unsigned char value)
    {
    unsigned char x,d1,d2,d3;
    x=value/10;
    d1=value%10;
    d2=x%10;
    d3=x/10;
    se(array[d3]);
    ms(255);
    se(array[d2]);
    ms(255);
    se(array[d1]);
    ms(255);
    }
    void se(unsigned char x)
    {
    SBUF=x;
    while(TI==0);
    TI=0;
    }

    thanks in advance
     
Loading...
Thread Status:
Not open for further replies.