Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[General] How to interface ADC0804 with 8051?

Status
Not open for further replies.

alvinmuji

Newbie level 3
Newbie level 3
Joined
May 28, 2014
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
22
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
}
 

Hi,

Your program has 2 Errors :

1) You can't use this : sbit adc_port = P2; . This is not correct. sbit only defines a bit not a full port(or full byte).
check this : https://www.keil.com/support/man/docs/c51/c51_le_sbit.htm

2) Because P2 is your input port , You should write 0xFF in P2 before you start read operation.if you don't connect P2 to any other peripheral and it's only used as a input port, you need to write 0xff only once,but if you use P2 as Input/output port,you need to write 0xFF before every read operation.

and also i assume that you used Pull-Up resistors on your P0 Port (that you used to send commands to ADC). Correct?

Good Luck!
 
CS is an active low input to activate ADC0804. so CS must be grounded always...

try this


Code C - [expand]
1
2
3
4
sbit RD=P2^0;
sbit WR=P2^1;
sbit INTR=P2^2;
sfr MYDATA=P1;



in main function


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
MYDATA=0xFF;
RD=1;
WR=1;
 INTR=1;
 
while(1)
{
  WR=0;
 WR=1;
while(INTR==1)
 RD=0;
 value=MYDATA;
  convert(value);
   display(value);   //in lcd
    RD=1;
}

 
Last edited by a moderator:

Hello Memarian,

Thanks for your reply and pointing out out error. I did the changes and find that my ADC0804 (D7-D0) is always '1111 1111' as P2 is tied to the adc0804 (D7-D0)... and yup! I used Pull-Up resistors on the P0 Port !
Code:
#include <ds89c4xx.h> 

sbit rd = P0^2; //Read signal P0.2
sbit wr = P0^1; //Write signal P0.1
sbit cs = P0^3; //Chip Select P0.3
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() {

P2 = 0XFF;	 //set P2 as input
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 = P2; //Read data from ADC0804 port
rd = 1; //Make RD high
cs = 1; //Make CS high
}
 

Thanks for your reply and pointing out out error. I did the changes and find that my ADC0804 (D7-D0) is always '1111 1111' as P2 is tied to the adc0804 (D7-D0)... and yup! I used Pull-Up resistors on the P0 Port !
Code:
#include <ds89c4xx.h> 

sbit rd = P0^2; //Read signal P0.2
sbit wr = P0^1; //Write signal P0.1
sbit cs = P0^3; //Chip Select P0.3
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() {

P2 = 0XFF;	 //set P2 as input
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 = P2; //Read data from ADC0804 port
rd = 1; //Make RD high
cs = 1; //Make CS high
}

Hi,

Your program has 2 Errors :

1) You can't use this : sbit adc_port = P2; . This is not correct. sbit only defines a bit not a full port(or full byte).
check this : https://www.keil.com/support/man/docs/c51/c51_le_sbit.htm

2) Because P2 is your input port , You should write 0xFF in P2 before you start read operation.if you don't connect P2 to any other peripheral and it's only used as a input port, you need to write 0xff only once,but if you use P2 as Input/output port,you need to write 0xFF before every read operation.

and also i assume that you used Pull-Up resistors on your P0 Port (that you used to send commands to ADC). Correct?

Good Luck!
 

Hi,
Can you post your schematic (circuit)?

It seems that your program is ok,but for some reason maybe there is some faults somewhere else.

BTW : what is your microcontroller clock? DS89c4xx are not normal 8051! Normal 8051 has machine cycle=Clock/12 , but in DS89c4xx usually machine cycle=1 Clock ! if your microcontroller clock is too high, your timing will have some problems. (For example after enabling Read, you must wait between 125 ... 200 ns for valid data).
 
Last edited:

In many datasheet had testing diagram such as initial command .

More error bits rate, More tolelance not noise.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top