Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

help needed in AT89C4051

Status
Not open for further replies.

vinash

Member level 2
Joined
Nov 3, 2005
Messages
45
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,999
doc0524 code

Hi,
I am a new comer to the field of microcontrollers and doing some simple projects to get familiar with microcontrollers. Currently i am embarking on using the AT89C4051 as an ADC . I am actually trying to use the application notes provided by the following website:
h**p://www.atmel.com/dyn/resources/prod_documents/DOC0524.PDF
It would be very useful if someone were to help me with the coding (C-program) for the application. I have tried a few times but have failed. Your help would be greaatly appreciated.
I have done the conections for the ADC conversion and had connected the positive voltage of the signal to Pin 1.1. and i wrote a very simple program, that would be able to output voltage reading on the LEDs,.
The program is of as follows:

#include<AT89x051.h>

char a[10]={0x03,0x13,0x23,0x33,0x43,0x53,0x63,0x73,0x83,0x93}; /* The numbering from 0-9*/


void main(void)

{int j, adc_data;
while(1){

P1_1=adc_data;
P1=a[adc_data%10];
for(j=0;j<30000;j++);

}
}


I do always get a zero on my LED display, no matter how i changed the voltage input, Could someone please help.I am struggling with this for a few days. Thank you
 

tofinhk

Member level 1
Joined
Apr 6, 2004
Messages
36
Helped
6
Reputation
12
Reaction score
1
Trophy points
1,288
Activity points
380
I wonder what data you stored in adc_data and also the schematic you are using.
If you use the whole P1 (8 pins) to control the LED, where you get the adc_data?
Also, what is the meaning of P1_1=adc_data?
 

    vinash

    points: 2
    Helpful Answer Positive Rating

vinash

Member level 2
Joined
Nov 3, 2005
Messages
45
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,999
I have connected the 8.2K resistor to the ground directly instead of connecting it to the 30Pf capacitor as shown in the schmetic diagram ( in the website given). I have done this so that whenever the power is on, it would straight light the leds rather than it needing to toggle if i had connected according to the schmetic given.

P1_1= adc_data,
What i'm trying to do is assign the 8 bit data received from the voltage supply ( from pin 1.1) to the address adc_data.

P1=[adc_data%10];
I am trying to output the data that is stored in address adc_data to the LED connections.

This is all i am trying to do.I hope you would be able to solve my problem. Thank you.
 

tofinhk

Member level 1
Joined
Apr 6, 2004
Messages
36
Helped
6
Reputation
12
Reaction score
1
Trophy points
1,288
Activity points
380
vinash said:
...
P1_1= adc_data,
What i'm trying to do is assign the 8 bit data received from the voltage supply ( from pin 1.1) to the address adc_data.

P1=[adc_data%10];
I am trying to output the data that is stored in address adc_data to the LED connections.
...
If you are trying to assign 8bit data to adc_data, isn't it adc_data=xxx???

if you are using the circuit provided in your document, seems that some pins in P1 is already used for your ADC, how you can connect the LED by P1?
 

    vinash

    points: 2
    Helpful Answer Positive Rating

vinash

Member level 2
Joined
Nov 3, 2005
Messages
45
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,999
Hi,
Thanks for the help, actually i'm quite confused on how to read an input ( for example how to read the voltage input from P1.1) I have read in the datasheet and they had stated that in order to use a port as input, just write 1s to them. It would be great if you are able to help me in this.I am also not sure how to capture the data that is obtained from P1.1.
 

leekk8

Full Member level 5
Joined
Sep 6, 2005
Messages
309
Helped
35
Reputation
70
Reaction score
18
Trophy points
1,298
Location
Malaysia
Activity points
3,817
To make a port to be input port, write 1s to the port. You can also set a single pin to be high to make the pin to be input pin. I've done this well in AT89C51.

Anyway, I have a question, if the Port 1 is used as output port, and I want to send all 1s to 8 LEDs using Port 1, can the controller do it? Or it will make the Port 1 as input port? I'm using AT89C51.
 

    vinash

    points: 2
    Helpful Answer Positive Rating

vinash

Member level 2
Joined
Nov 3, 2005
Messages
45
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,999
Hi Lekka,
If thats the case, so say, i am giving a command such as
P1=0x03, Does it mean that i am automatically using P1.0 and P1.1 as inputs and the rest of the pins as output?
 

leekk8

Full Member level 5
Joined
Sep 6, 2005
Messages
309
Helped
35
Reputation
70
Reaction score
18
Trophy points
1,298
Location
Malaysia
Activity points
3,817
I'm not sure how to program it in C. I'm using assembly language and assembler Asem51.

To make the Port 1 as input port, the code is
MOV P1,#FFH

To make a single pin (eg Pin 1.1) as input pin, the code is
SETB P1.1

The idea is, you set the particular port or single pin high, the port or pin will be input port or input pin. Without doing this, you can't receive data using them.
 

tofinhk

Member level 1
Joined
Apr 6, 2004
Messages
36
Helped
6
Reputation
12
Reaction score
1
Trophy points
1,288
Activity points
380
I don't really know how this schematic works as an ADC, so I can't answer you how to get the data.
For the input, vinash you should be right. You may just try in your circuit.
As you said you can't display in LED, I wonder what code you wrote for controlling your LED. Do you mind posting it for us?
 

    vinash

    points: 2
    Helpful Answer Positive Rating

vinash

Member level 2
Joined
Nov 3, 2005
Messages
45
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,999
HI Tofinkh,
The program that i had written is below:

I have also uploaded the file, please do have a look and please do let me know if you find any mistake, thanks a lot, i do greatly appreciate your help

#include<AT89x051.h>

char a[10]={0x07,0x17,0x27,0x37,0x47,0x57,0x67,0x77,0x87,0x97};
char b[10]={0x0F,0x1F,0x2F,0x3F,0x4F,0x5F,0x6F,0x7F,0x8F,0x9F};
void delay(int count);
void main(void)

{
unsigned char adc_data;

P1=0x03; // setting P1.0 and P1.1 as inputs and the rest of the P1 as output
while(1){
P1_1=adc_data; // read the data (from the voltage input) from P1.1 and store it in adc_data
delay(5);
P1=P1&0x03; // set P1 again such that P1.0 and P1.1 are inputs and the other P1 ports sre output
P1=a[adc_data%10]; // find the remainder of the data obtained e.g if it is 0x15, the remainder is 1 thus P1& 0x03=1
// and a[1]=1 and thus 1 would be displayed
delay(5);
}
}


void delay (int count)
{
int j;
for(j=0;j< count;j++){
continue;
}
}
 

tofinhk

Member level 1
Joined
Apr 6, 2004
Messages
36
Helped
6
Reputation
12
Reaction score
1
Trophy points
1,288
Activity points
380
hi,

you better check how the ADC works in your document first. if you wanna put the value from P1.1 and store it in adc_data, it should be
adc_data = P1_1;

for driving the 7 segment LED, you have to enable the LED before sending out the value, the P1.2 and P1.3 in the schematic, enable one LED at once. Please have a look on its datasheet also.
 

    vinash

    points: 2
    Helpful Answer Positive Rating

vinash

Member level 2
Joined
Nov 3, 2005
Messages
45
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,999
HI, I had modified the code, and the new code is of as follows: and as you had mentioned about P1.2 and P1.3 having been switched low whenever the led of interest is used. I had done that and also currently i am just using one led to test and for that i had kept P1.3 always low and P1.2 always high so that only one led is used. But i still dont get any figures on the LED. hope you would be able to help. Thank you.

#include<AT89x051.h>

char a[10]={0x07,0x17,0x27,0x37,0x47,0x57,0x67,0x77,0x87,0x97};
char b[10]={0x0F,0x1F,0x2F,0x3F,0x4F,0x5F,0x6F,0x7F,0x8F,0x9F};
void delay(int count);
void main(void)

{
unsigned char adc_data,z;

P1=0x03; // setting P1.0 and P1.1 as inputs and the rest of the P1 as output
while(1){
P3_7=0;
P1=P1&0x03; // set P1 again such that P1.0 and P1.1 are inputs and the other P1 ports sre output
adc_data=P1_1; // read the data (from the voltage input) from P1.1 and store it in adc_data
z=P1&0x03;
z=a[adc_data%10];
delay(5);
P1=P1&0x03;
P1=a[adc_data]; // find the remainder of the data obtained e.g if it is 0x15, the remainder is 1 thus P1& 0x03=1
// and a[1]=1 and thus 1 would be displayed
delay(5);

}
}


void delay (int count)
{
int j;
for(j=0;j< count;j++){
continue;
}
}
 

tofinhk

Member level 1
Joined
Apr 6, 2004
Messages
36
Helped
6
Reputation
12
Reaction score
1
Trophy points
1,288
Activity points
380
vinash, as AT89C4051 does not have a "real" ADC, the ADC in your application note is made by a comparator and some simple RC circuit. You have to read the document before you want to get the analog value. It should not be done by simply typing adc_data=P1_1.
Please check carefully about your application note first. HTH
 

vinash

Member level 2
Joined
Nov 3, 2005
Messages
45
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,999
Hi Tofinhk,
Thank you for your kindly aadvice, would try to do something about it. But anyway, really appreciate for the help you had rendered
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top