alvinmuji
Newbie level 3
Hi, any idea how to interface ADC0804 with 8051? I conenct the ADC0804 D7-D0 (Pin Pin 11 – Pin 18) to the 8051 P2.7 - P2.0 (Pin 28 – Pin 21). However, its not giving me the expected result. then I tried on ADC0804 chip itself and it does work with LED indication. but when interface with 8051, it just couldn't work. this is the code I used, can anyone advice? Thanks in advance!
Code:
#include <ds89c4xx.h>
sbit adc_port = P2; //ADC port
sbit rd = P0^2; //Read signal P0.2
sbit wr = P0^1; //Write signal P0.1
sbit cs = P0^3; //Chip Select P0.3 (((pin5 of pull up)))
sbit intr = P0^0; //INTR signal P0.0
sbit mybit = P0^7; //high/low compare value result
void conv(); //Start of conversion function
void read(); //Read ADC function
unsigned char adc_data;
void main() {
while (1) { //Forever loop
conv(); //Start conversion
read(); //Read ADC
if (adc_data <= 0X40) //Send the read and compare if value is less than 40 in hex, 64 in decimal. More than 50cm away <1.25V { mybit=1 ; // set P0.7 high } else { mybit=0 ; // set P0.7 low }
} }
void conv() {
cs = 0; //Make CS low
wr = 0; //Make WR low
wr = 1; //Make WR high (start conversion)
cs = 1; //Make CS high
while (intr); //Wait for INTR to go low
}
void read() {
cs = 0; //Make CS low
rd = 0; //Make RD low
adc_data = adc_port; //Read data from ADC0804 port
rd = 1; //Make RD high
cs = 1; //Make CS high
}