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.

Reading from adc0804....

Status
Not open for further replies.

yviswanathbe

Full Member level 4
Joined
Jun 14, 2007
Messages
221
Helped
10
Reputation
20
Reaction score
6
Trophy points
1,298
Activity points
3,066
Hi,
i am interfacing ADC0804 to AT89S8252.
My circuit is working fine but i am not able read the converted value in the PC.
Every time i am getting the same value even when i am changing analog input.
Can anybody please help what might be the problem?
I am attaching my code here?
Thanks in advance.....


#include<stdio.h>
#include<reg51.h>

sbit MYDATA=P2;
sbit rd=P3^7;
sbit wr=P3^6;
sbit intr=P3^3;

unsigned char value;
void pause(int);
void delay1ms();
void delay();
void transmit(unsigned char);

void main(void)
{
SCON=0X50;
TMOD=0X20;
TH1=0XFD;
TR1=1;
MYDATA=0XFF;
intr=1;
pause(5);
while(1)
{
delay();
wr=0;
delay();
wr=1;
while(intr==1);
delay();
rd=0;
delay();
value=MYDATA;
rd=1;
transmit(value);
void transmit(unsigned char value)
{
TI=0;
SBUF=value;
while(!TI);
//TI=0;
//flag = 1;
}
void pause(int k)
{
int j;
for(j=0;j<=k;j++)
{
delay1ms();
}
}
void delay1ms()
{
int i;
for(i=0;i<=500;i++) // 15
{
;
}
}
void delay()
{
int k,l;
for(k=0;k<40;k++)
for(l=0;l<80;l++);
}




Thanks,
viswanath
 

Hi viswanath,
I am surprised your code actually compiles in the form listed. I would have expected that you would need a pair of closing braces inserted at the end of your measurement loop, just above the the start of your transmit function. This way it will go around your measurement loop forever and send the data out of the serial port after each measurement has completed. As it stands I think it it will crash the micro after the first pass and never take a reading after the first one because the program is no longer active, hence no change in your readings.

Try something like this code snippet

void main(void)
{
// Insert all your code here as below but change the bits as I have shown it below

while(1)
{
delay();
wr=0;
delay();
wr=1;
while(intr==1);
delay();
rd=0;
delay();
value=MYDATA;
rd=1;
transmit(value);
} //This brace will close the while loop
} //This brace will close the main function
//Insert the rest of your functions here, they look as if they will work OK but could
// be optimised a bit!

I hope this helps.

Regards
Bob.
 

Hi,
Also, you have to correct the declaration of 'MYDATA' variable from
' sbit MYDATA=P2; ' to an SFR variable declaration. Follow the conventions of your compiler for the declarations.

Regards,
Laktronics
 

How can we read o/p of adc through p89v51rd2fn.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top