ADC 0808 Interfacing With 8051 Microcontroller
Port 2 ( Pins 2.4 to 2.7) is being used to write data on the LCD. Also, P1.0 pin is used as RS (Register Select for LCD) and P1.1 pin is used as E (Enable pin for LCD).
Any 16x2 LCD can be used here which has HD44780U controller in it. For example, JHD162A LCD can be used with this code easily.
A crystal of 11.0592 MHz is used here. You can use any crystal value from 3 to 24MHz with 8051. As we know that 8051 micro controller has an architecture which executes an instruction in 12 CPU cycles [1], hence this 11.0592Mhz crystal makes this 8051 run at 0.92 MIPS (Million of instructions per second).
In the above circuit, 8 bit data bus of ADC0808 is attached with 8051 on Port 0. And control signals of ADC0808 are attached on Port 2 of 8051 microcontroller. LCD is attached on Port 1, LCD is used here just to show the output value of ADC.
ADC0808 has 8 input channels. You can use any channel for ADC purposes in the code. A potentiometer (i-e variable 10k resistor) is attached on IN1 of ADC0808 just to demonstrate how to use this code. Input voltage at IN1 is read in the code and displayed on the LCD. Since, ADC0808 gives an output of 8bit value, so a voltage value of 0v at IN1 will mean ADC value of 0 and a voltage of 5v at IN1 pin means ADC value of 255. In the above figure, it is clear that a voltage of 2.5v is applied on IN1 pin and ADC value of 127 (i-e half of 255) is displayed on the LCD correctly.
A crystal of 12MHz value is used in this circuit, which makes this 8051 (i-e AT89C51) run at a speed of 1MIPS (Million of instructions per second). You can use any other value of crystal ( From 3 to 24 MHz value only) with 8051 as well.
Any 16x2 LCD can be used here which has HD44780U controller in it. For example, JHD162A LCD can be used with this code easily.
A crystal of 11.0592 MHz is used here. You can use any crystal value from 3 to 24MHz with 8051. As we know that 8051 micro controller has an architecture which executes an instruction in 12 CPU cycles [1], hence this 11.0592Mhz crystal makes this 8051 run at 0.92 MIPS (Million of instructions per second).
ADC0808 Interfacing Diagram |
In the above circuit, 8 bit data bus of ADC0808 is attached with 8051 on Port 0. And control signals of ADC0808 are attached on Port 2 of 8051 microcontroller. LCD is attached on Port 1, LCD is used here just to show the output value of ADC.
ADC0808 has 8 input channels. You can use any channel for ADC purposes in the code. A potentiometer (i-e variable 10k resistor) is attached on IN1 of ADC0808 just to demonstrate how to use this code. Input voltage at IN1 is read in the code and displayed on the LCD. Since, ADC0808 gives an output of 8bit value, so a voltage value of 0v at IN1 will mean ADC value of 0 and a voltage of 5v at IN1 pin means ADC value of 255. In the above figure, it is clear that a voltage of 2.5v is applied on IN1 pin and ADC value of 127 (i-e half of 255) is displayed on the LCD correctly.
A crystal of 12MHz value is used in this circuit, which makes this 8051 (i-e AT89C51) run at a speed of 1MIPS (Million of instructions per second). You can use any other value of crystal ( From 3 to 24 MHz value only) with 8051 as well.
In the main function, firstly pins attached with ADC0808 are initialized using InitADC(); statement, then LCD is initialized using InitLCD() function. Then "Starting..." is displayed on the LCD for one second. After that LCD screen is cleared.
In the while(1) loop, ADC_Value = ReadADC(AN1); statement reads value from IN1 pin of ADC0808 and assigns this value to ADC_Value variable. Next 3 statements are converting ADC_Value in to digits, which will be displayed on the LCD screen. After that, LCD screen is cleared and ADC value is displayed on the LCD.
In the main function, firstly pins attached with ADC0808 are initialized using InitADC(); statement, then LCD is initialized using InitLCD() function. Then "Starting..." is displayed on the LCD for one second. After that LCD screen is cleared.
In the while(1) loop, ADC_Value = ReadADC(AN1); statement reads value from IN1 pin of ADC0808 and assigns this value to ADC_Value variable. Next 3 statements are converting ADC_Value in to digits, which will be displayed on the LCD screen. After that, LCD screen is cleared and ADC value is displayed on the LCD.
In the while(1) loop, ADC_Value = ReadADC(AN1); statement reads value from IN1 pin of ADC0808 and assigns this value to ADC_Value variable. Next 3 statements are converting ADC_Value in to digits, which will be displayed on the LCD screen. After that, LCD screen is cleared and ADC value is displayed on the LCD.
In the main function, firstly pins attached with ADC0808 are initialized using InitADC(); statement, then LCD is initialized using InitLCD() function. Then "Starting..." is displayed on the LCD for one second. After that LCD screen is cleared.
In the while(1) loop, ADC_Value = ReadADC(AN1); statement reads value from IN1 pin of ADC0808 and assigns this value to ADC_Value variable. Next 3 statements are converting ADC_Value in to digits, which will be displayed on the LCD screen. After that, LCD screen is cleared and ADC value is displayed on the LCD.
In the InitADC() function shown above, pins attached to ADC0808 are initialized properly. Also, data bus attached with Port 0 is initialized as well.
ReadADC() function (shown above) returns 8 bit ADC value. This value is read from a channel, which is the input argument to ReadADC() function. Channel can have a value of AN0 for IN0 pin of ADC0808 or AN1 for IN1 pin etc. For example, to read voltage value at IN7 pin of ADC0808, you can use the statement ReadADC(AN7);.
Please Comment Your Views.
Proteus Simulation And Source Code Click Here
Comments
Post a Comment