Friday, 24 June 2016

8051 Assembly Program for ADC0804

ADC0804 Pin-out and Typical Connections

As shown in the typical circuit, ADC0804 can be interfaced with any microcontroller. You need a minimum of 11 pins to interface ADC0804, eight for data pins and 3 for control pins. As shown in the typical circuit the chip select pin can be made low if you are not using the microcontroller port for any other peripheral (multiplexing).
center

ADC0804 Pin Diagram

There is a universal rule to find out how to use an IC. All you need is the datasheet of the IC you are working with and take a look at the timing diagram of the IC which shows how to send the data, which signal to assert and at what time the signal should be made high or low etc.
Note: Keep this in mind that whenever you are working with an IC and you want to know how to communicate with that IC, then simply look into the timing diagram of that IC from its datasheet. It gives you complete information that you need regarding the communication of IC.
center

Start Conversion Timing Diagram

center

End of Conversion Timing Diagram

The above timing diagrams are from ADC0804 datasheet. The first diagram (FIGURE 10A) shows how to start a conversion. Also you can see which signals are to be asserted and at what time to start a conversion. So looking into the timing diagram FIGURE 10A. We note down the steps or say the order in which signals are to be asserted to start a conversion of ADC. As we have decided to make Chip select pin as low so we need not to bother about the CS signal in the timing diagram. Below steps are for starting an ADC conversion. I am also including CS signal to give you a clear picture. While programming we will not use this signal.
  1. Make chip select (CS) signal low.
  2. Make write (WR) signal low.
  3. Make chip select (CS) high.
  4. Wait for INTR pin to go low (means conversion ends).
Once the conversion in ADC is done, the data is available in the output latch of the ADC. Looking at the FIGURE 10B which shows the timing diagram of how to read the converted value from the output latch of the ADC. Data of the new conversion is only avalable for reading after ADC0804 made INTR pin low or say when the conversion is over. Below are the stepts to read output from the ADC0804.
  1. Make chip select (CS) pin low.
  2. Make read (RD) signal low.
  3. Read the data from port where ADC is connected.
  4. Make read (RD) signal high.
  5. Make chip select (CS) high.
  1. rd equ P1.0  ;Read signal P1.0
  2. wr equ P1.1  ;Write signal P1.1
  3. cs equ P1.2  ;Chip Select P1.2
  4. intr equ P1.3  ;INTR signal P1.3
  5.  
  6. adc_port equ P2  ;ADC data pins P2
  7. adc_val equ 30H  ;ADC read value stored here
  8.  
  9. org 0H
  10. start:  ;Start of Program
  11. acall conv  ;Start ADC conversion
  12. acall read  ;Read converted value
  13. mov P3,adc_val  ;Move the value to Port 3
  14. sjmp start  ;Do it again
  15.  
  16. conv:  ;Start of Conversion
  17. clr cs  ;Make CS low
  18. clr wr  ;Make WR Low
  19. nop
  20. setb wr  ;Make WR High
  21. setb cs  ;Make CS high
  22. wait:
  23. jb intr,wait  ;Wait for INTR signal
  24. ret  ;Conversion done
  25.  
  26. read:  ;Read ADC value
  27. clr cs  ;Make CS Low
  28. clr rd  ;Make RD Low
  29. mov a,adc_port  ;Read the converted value
  30. mov adc_val,a  ;Store it in local variable
  31. setb rd  ;Make RD High
  32. setb cs  ;Make CS High
  33. ret  ;Reading done

8051 C program for ADC0804

  1. #include <REGX51.H>
  2. #define adc_port P2 //ADC Port
  3. #define rd P1_0 //Read signal P1.0
  4. #define wr P1_1 //Write signal P1.1
  5. #define cs P1_2 //Chip Select P1.2
  6. #define intr P1_3 //INTR signal P1.3
  7.  
  8. void conv(); //Start of conversion function
  9. void read(); //Read ADC function
  10.  
  11. unsigned char adc_val;
  12.  
  13. void main() {
  14. while (1) { //Forever loop
  15. conv(); //Start conversion
  16. read(); //Read ADC
  17. P3 = adc_val; //Send the read value to P3
  18. }
  19. }
  20.  
  21. void conv() {
  22. cs = 0; //Make CS low
  23. wr = 0; //Make WR low
  24. wr = 1; //Make WR high
  25. cs = 1; //Make CS high
  26. while (intr); //Wait for INTR to go low
  27. }
  28.  
  29. void read() {
  30. cs = 0; //Make CS low
  31. rd = 0; //Make RD low
  32. adc_val = adc_port; //Read ADC port
  33. rd = 1; //Make RD high
  34. cs = 1; //Make CS high
  35. }