In this tutorial we will learn how to interface the ADC0804 (Analog to Digital Converter) with the 8051 microcontroller (89c51,89c52). 8051 microcontrollers are very old and do not have a built-in analog to digital converter, unlike their newer rivals (Arduino, Pic microcontroller and many more). So we cannot directly measure any analog value (voltage, temperature present in atmosphere) with 8051 microcontrollers. So to measure an analog quantity with 8051 microcontroller we need an external device which can measure the analog quantity and pass it to the 8051 microcontroller. Since 8051 series microcontrollers work with digital data, the external device must convert the analog data to digital before passing it to the 8051 microcontroller. Analog-to-digital converters are used for this purpose.
ADC0804 Analog to Digital Converter
ADC0804 is an analog to digital converter popular among DIY circuit makers. It measures the analog quantity and generates digital reading of the measured analog quantity. Operating and interfacing the adc0804 with microcontrollers is a difficult task. The Adc0804 operations (start of analog voltage conversion into digital, conversion stop, data output) must be controlled by an external controller. In our case, the 89c51 microcontroller will control all operations of the adc0804. The Adc0804 has dedicated pins to control its operations from an external unit. Adc0804 has 8-bit resolution, means it can output a maximum value of 255, the minimum is 0 . To know more about adc0804, its working principle, pinout and interface with microcontrollers below is a good tutorial for you.
Adc0804 Pinout and operation
DIY project
The project circuit is not very complex if you followed the tutorials above. First insert LCD 16×2, 89c51 and ADC0804 into your breadboard. Make simple connections. Apply 5 volts to pins 40 and 31 of the 89c51 microcontroller. Ground pin 20. Connect the Crystal (11.0592) to pins 18 and 19 of the microcontroller in parallel to two 33pF capacitors. Connect the reset button to pin 9 of the 89c51 microcontroller. Connect port 3 pin 0 to cs (chip select) of ADC0804, port 3 pin 1 to wr pin of ADC0804, port 3 pin 2 to rd pin of ADC0804, port 3 pin 3 to intr pin of ADC0804. Port-3 pin-5 of 8051 to RS pin of 16×2 LCD, Port-3 pin-6 of 8051 to EN pin of 16×2 LCD, Make RW pin of 16×2 LCD ground.
Apply 1.28 volts to the vref/2 pin of the ADC0804. This is the reference voltage for ADC0804. This is the voltage at which the step size of the ADC0804 will be set to 10 mv. The LM35 output voltage varies by 10 mV per °C change in temperature. Consequently, both the LM35 and ADC0804 are now working with 10 mv shift. when there is a 10 mv change in temperature, the output increases/decreases by 1.
To learn more about the operation of the Lm35 temperature sensor, pinout and formula for calculating the temperature, follow the tutorial below.
Coming to the code first, I have included the reg51.h header file, you must include this header file in all your projects where you are using 8051 (89c51,89c52) microcontroller. Then the three-pin ports 5 and 6 are set to RS (Register Select) and EN (Enable) to be used to control the LCD. If you don't know how to use 16×2 LCD, first do a short tutorial on
Pins 0, 1, 2 and 3 of port 3 are used as cs(chip select) wr(write) rd(read) intr(interrupt) to control the ADC0804. The project code is given below and each instruction is well explained.
Download the project files and the code (c,HEX) compiled in keil uvision 4. If you have a problem with any instruction or part of the code, just leave a comment below. Please give us your feedback on the Project.