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.

problem interfacing 89c2051

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
micro 8051 + 89 c2051 + datasheet

Hi friends,
I am doing project named Auto Measurement of Current from power supply for one of my application.
I am amplifying the analog output using an OP-Amp OP07,the amplified output is given to ADC,there i am converting to digital,this digital value i am taking at one of the Port of microcontroller(89c2051).I want to get this value using serial communication.for that i have connected the microcontroller to max233.

my problem is no value is displayed in the hyperterminal.
can any body tell me what problem do i have?
The code i have used is

#include<reg52.h>
#include<stdio.h>


sbit adc_port=P1;
sbit rd = P3^0;
sbit wr = P3^1;
sbit CS=P1^2;
sbit intr=P1^3;

void conv();
void read();
void transmit(unsigned char);


unsigned char adc_val;

void main()
{
TMOD=0x20;
TH1=-3;
SCON=0x50;
TR1=1;
TI=1;
while(1)
{
conv();
read();
P3=adc_val;
}
}
void conv()
{
CS=0;
wr=0;
wr=1;
CS=1;
while(intr);
}

void read()
{
CS=0;
rd=0;
adc_val=adc_port;
rd=1;
CS=1;
}

void transmit(unsigned char data1)
{
SBUF=data1;
while(!TI);
TI=0;
}


thanks in advance.
 

header file at89c2051 download

Hi viswanath;

I dont see the transmit function being called anywhere in your program. Dont make TI=1 at the start. make EA =1. First display in the LCD and check if u r getting the outout.

HOW to appraoch?
First convert the ADC value. store in a variable. move the variabe data to SBUF and transmit as u r doing. Also keep this transmit routine in the while(1) infinite loop.

Are u using any interrupt in while(intr);

there are more possiblilties like matching the baudrate of the hyperterminal and cross checking hte serial cable that u r using. I will talk of this issues for u once u confirm that do u get output in LCD.
 

89c2051 india

hi shiv,
thanx 4 replying.

di i need to write the interrupt function for this....
and what abt PCON and TCON registers,do i need to use these registers.
 

at89c2051 hyperterminal problem

there is no need for any knid of interrupt. after conversion just call the transmit function. see if the hyperterminal is also set for the 9600 baud rate and 8 data bits and 1 stop bit and flow control none.

Added after 33 seconds:

there is no need for any knid of interrupt. after conversion just call the transmit function. see if the hyperterminal is also set for the 9600 baud rate and 8 data bits and 1 stop bit and flow control none.
if u r using KEIL IDE then u can check in the simulator itself.
 

ok sir,

Why do serial communication doesn't need interrupt and in what type applications we will use interrupt concept for serial communication.

Could you please clarify me the above two queries.

thanks.
 

The basic general purpose controller which have UART have internal pins RI and TI that takes cares of the interrupt. Other interrupts will be handled by the controller by the priority assigned.
Even though UART in 8051 in full duplex we use them as half duplex by monitoring TI and RI pins.
Without these interrupt serial comm, does not work.

please send me your mob. number if teh doubt is not clarified. I will call u if u r within karnataka
 

hi shiv,

i got success in serial communication.
The problem which i am facing nw is with ADC.
according to the datasheet for 5V with 2.5 as Vref/2 the output binary should be FF(11111111),but i am getting reverse for 0V input i am getting FF as output and for 5V input i am getting 00000000 as output.

could you have any idea where the problem mighht be?

actuallly the input to the ADC is in the range 0-4.3V.
Vref/2 which i have used in the circuit is 2.5volts,is it correct r hw do we calculate the vref voltage..

my mob is 09963517504.
send me ur's.

thanks,
viswanath.
 

Check the Vref documentation of the manual.

Some times register to which we need to move the Vref value may be configured negatively.

If Vref selection is through hardware we need to refer the document.

If possible send the data sheet of the ADC u r using. Is It ADC0808 or any other company. I will download the data sheet and see myself.
 

Hi,
I am using ADC0804 n i have attached the datasheet.

Added after 2 minutes:

sory,
some problem is coming when attaching,
plz download it from the website,i am using ADC 0804 from national semiconductors
 

Regarding ADC I think You need to check the reference voltage point ..because there will also be Negative reference..
Why Vref /2? Are you using any potential divider o f/2 at reference point?
I hope the Analog input you are giving is also Positive...
Is there any conversion Logic selection which can be control through software?
What is the ADC logic?
Successive approximation? R2R ladder logic?
I think I am asking question to you but that would infact may help you.
Please cofirm the voltage exactly at pins of controller..
 

Hi shiv,
ADC is 8 bit parllel Successive Approximation type.
 

hi shiv,
now my circuit is ok with ADC.
I am not able to read converted data from the microcontroller in the PC.

i am sending my code,plz tell me where i am doing mistake,


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

sbit MYDATA=P1;
sbit rd=P3^0;
sbit wr=P3^1;
sbit cs=P1^2;
sbit intr=P1^3;

unsigned char receive();
void transmit(unsigned char);
unsigned char chr;
unsigned char result;

void main()
{
unsigned char value;
SCON=0X50;
TMOD=0X20;
TH1=-3;
TR1=1;
TI=1;
MYDATA=0XFF;
intr=1;
rd=1;
wr=1;
while(1)
{
wr=0;
wr=1;
while(intr==1)
rd=0;
value=MYDATA;
rd=1;
transmit(value);
}
}

void transmit(unsigned char data1)
{
SBUF=data1;
while(!TI);
TI=0;
}






thanks,
visu
 

write the interrupt routine and then execute
 

Hi,
You are not converting the data sent in 'data1' to the transmit routine, which is a 'binary' hex number into an 'ASCII' Hex number to print it out on hyperterminal in a readable form, hyperterminal will try to print whatever character is the ASCII code in 'data1' (if it is printable) for the code sent to it.

Try something like :-


void transmit(unsigned char data1)
{
unsigned char cChar[6]; //Make the string limits longer than 6 if required.
int i;

sprintf(cChar, "%02x\n\r\0", (unsigned int)data1);
//May not need the (unsigned char) cast, some compilers don't.

//Use "%02i\n\r\0" if you want it in decimal this will print each new value on a
//new line. Should then print something like 7f for a value of #7f. If you use the
//"%#05x\n\r\0" you should get 0x07f printed out.
//include more math routines if you want to convert value to a voltage directly.
//you could then make the format string more fancy including adding "Volts" etc.
//before the line feed & carriage return character.

for(i = 0; i < 5; i++) //Make the character count longer if required.
{
SBUF=cChar;
while(!TI);
TI=0;
}
}

You will also need to include the header file <stdio.h> for this to work.

I hope this helps.

Best regards
Bob.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top