This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Temperature sensor from Analogue to Digital

I am currently doing a mini-project on temperature sensor using 8051 micro-controller.

The 8051 micro-controller will receive 8bit temperature data from Analogue-to-Digital Converter which is connected to a temperature sensor(eg. LM35)

I have a problem in translating the 8bit data from ADC to a temperature reading (eg. 38 celcius)in keil. I hope to understand the structure or the procedure in carrying out this step. Thank you!

Parents
  • Below is the C prog. I notice that the problem is lies with "OPORT = instr;"
    because it suppose to move what is in instr into OPORT which is in Xdata at location 0000h but it did not.

    #include <reg51.h>

    void delay5ms(void);
    void delay1ms(void);

    void lcdWriteInstrReg(char instr);
    void lcdInit(void);
    void lcdClrScr(void);

    char xdata OPORT _at_ 0x0000;

    sbit pinRW = P3^3;
    sbit pinRS = P3^4;
    sbit pinE = P3^5;

    void main(void)
    {

    lcdInit();
    while(1);
    }//end main

    void lcdWriteInstrReg(char instr)
    {

    OPORT = instr; //o/p to D0-D7
    pinRW = 0; //write
    pinRS = 0; //RS=0 for instr Reg
    pinE = 0;
    pinE = 1;
    pinE = 0;
    }


    void lcdInit(void)
    {
    delay5ms();
    delay5ms();
    delay5ms();
    delay5ms();
    lcdWriteInstrReg(0x38);
    delayms();
    lcdWriteInstrReg(0x38);
    delay1ms();
    lcdWriteInstrReg(0x38);
    delay1ms();
    lcdWriteInstrReg(0x06);
    delay1ms();
    lcdWriteInstrReg(0x0f);
    delay1ms();
    lcdClrScr();
    }

    void lcdClrScr(void)
    {
    lcdWriteInstrReg(0x01);
    delay1ms();
    delay1ms();
    }

Reply
  • Below is the C prog. I notice that the problem is lies with "OPORT = instr;"
    because it suppose to move what is in instr into OPORT which is in Xdata at location 0000h but it did not.

    #include <reg51.h>

    void delay5ms(void);
    void delay1ms(void);

    void lcdWriteInstrReg(char instr);
    void lcdInit(void);
    void lcdClrScr(void);

    char xdata OPORT _at_ 0x0000;

    sbit pinRW = P3^3;
    sbit pinRS = P3^4;
    sbit pinE = P3^5;

    void main(void)
    {

    lcdInit();
    while(1);
    }//end main

    void lcdWriteInstrReg(char instr)
    {

    OPORT = instr; //o/p to D0-D7
    pinRW = 0; //write
    pinRS = 0; //RS=0 for instr Reg
    pinE = 0;
    pinE = 1;
    pinE = 0;
    }


    void lcdInit(void)
    {
    delay5ms();
    delay5ms();
    delay5ms();
    delay5ms();
    lcdWriteInstrReg(0x38);
    delayms();
    lcdWriteInstrReg(0x38);
    delay1ms();
    lcdWriteInstrReg(0x38);
    delay1ms();
    lcdWriteInstrReg(0x06);
    delay1ms();
    lcdWriteInstrReg(0x0f);
    delay1ms();
    lcdClrScr();
    }

    void lcdClrScr(void)
    {
    lcdWriteInstrReg(0x01);
    delay1ms();
    delay1ms();
    }

Children