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.

help in interfacing AD0804 to 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
ad0804

Hi,
I am trying to interface AD0804 to AT89C4051 microcontroller, is there any schmetics or any websites where i would be able to get some reference> Thank you.
 

at89c4051

Hi Vinash,

I've notice you struggle to get some ADC with AT89C4051.
First with default comparator and RC external.

Then you tried with MCP3208 suitable for 4051 due to few connecting lines using SPI bit bang since 4051 has no default SPI interface.

Now you try with ADC0804 (a memory mapped peripheral with much more connecting lines than SPI interface).

In genuine data sheet it's a small asssembler program wrote in 8048 assembler. You can use it as a guide for a C program.

Alternatively you can try this design : https://www.iguanalabs.com/adc2051.htm
Be aware that on that page you won't find any software (you have to pay for CD), but in my opinion are enough hints to build it yourself.
 

mcp3208 connect 8051

HI,
I've interfaced AT89C4051 with ad0804, and my source code is of as follows:

// Interfacing ADC0804 with AT89C4051,
// defination of pins are as follows:



#include<AT89x051.h>


sbit WRITE=P3^0; // defining the WR and INTR pins
sbit INTR=P3^1;

unsigned int a[10]={0x40,0x60,0x44,0x64,0x50,0x68,0x4C,0x6C,0x50,0x70};
scanled();
void delay(void);
unsigned int advalue,value;
void main(void){
P1=0xFF;
P3=0xFF;

while(1) {

WRITE=0;
WRITE=1;
while(INTR==1);
advalue=P1;
value=advalue*5/256;
scanled();

}
}

scanled()
{
P3=a[value%10];

}


I do get readings, but it is not real time, whenver i change the voltage inout, i have to switch of the main power off and on before the led reflects the voltage input, It would be very helpful, if you were to help me on how to do it realtime, that is, i need not switch the mains off, and whenver i change the voltage input, it automatically reflects in the LED. I hope you would be able to help me. Thank you.
 

at89c4051 adc

If you've used P3^0 and P3^1 as control line why inside scanled() did you used P3 for driving LEDs ?

scanled()
{
P3=a[value%10];
}

I didn't figure out why did you multiplied by 5 and then divided by 256 the ADC results ?
Since P1 cannot get a value greater than 255, what do you think about the value of "value" variable prior to be used in scanled() after "advalue*5/256" ?
It's casting required after "advalue*5/256" performed ?
 

ad0804

Hi,
I am using P3 to drive LEDS because i am using AT89C4051 and it has only 20 pins, thus i dont have enough pins.

I didn't figure out why did you multiplied by 5 and then divided by 256 the ADC results ?
Since P1 cannot get a value greater than 255, what do you think about the value of "value" variable prior to be used in scanled() after "advalue*5/256" ?
It's casting required after "advalue*5/256" performed?

As for this, i am doing this, because, i am using it to display values between 0-5V, thus "advalue*5/256* is used as an conversion formula.

That is all. Please do correct me if i am wrong, thank you.
 

at89c4051 spi

As I've told you the SPI interface (MCP3208 ADC) it's more suitable for your design.

In order to be helped by other members you must to provide more details regarding your design.
How do you expect that someone will figure out how did you connect the LED to port P3 ?
Do you use 7 LEDs directly tied to P3 (obvious through current limiter resistors) ?
Or did you use a BCD 7 segment convertor (which requires only 4 lines, rather than 7) ?
Look at the unsigned int a[10]={0x40,0x60,0x44,0x64,0x50,0x68,0x4C,0x6C,0x50,0x70};
First why unsigned int and not unsigned char ? Since are not declared as constant, will be stored in RAM, thus waste of space for "int".
If an element of the array will be sent to P3, then according to your declaration
P3^7 = 0
P3^6 = 1
P3^1 = 0
P3^0 = 0
are constant regardless of element 0, 1, 2, ...9, thus you'll waste 4 lines.
Nevertheless that you don't have control of P3^6 which is tied hardware internal to comparator output.

No back to hardware. You can't use P3^0 and P3^1 as control lines (/WR and /INTR) and LED display.
Bear in mind that once a conversion was started, another raising pulse on /WR line (WRITE=0; WRITE=1; ) will start another conversion, even if the previous conversion wasn't finished.
Thus, if you tied on P3^0 to /WR and LED display as well, you must be sure that the LED signal will not overide the /WR signal.

The best solution is to use P1 for both reading ADC (input) and writing LED (output) (wiring them parallel on the "bus").
But you have to use the /RD signal which is actually hardware tied to GND (I bet it's so, otherwise you aren't able to read the data conversion).
Obvious the /CS could be kept tied to GND (like present) or tied to P3 as well.
During display procedure the /RD signal must be high and will only goes low for a short time during reading of ADC conversion results when /INTR goes low.
Because the read cycle is short you can not even see the display LED flickering (as a matter of fact the same data read from ADC will be delivered immediately to the display on same port).
Thus you can set P3 as bellow:
P3^0 = /CS
P3^1 = /WR
P3^2 = /INTR you can use /INT0 feature of 8051 rather than polling for EOC (while(INTR==1);)
P3^4 = /RD

Funny enough if you set the ADC0804 running in continuos mode (/WR and /INTR tied together, and /CS = 0, /RD = 0) you don't even need a micro.
You need only 3 things:
1. 2 diodes, one resistor and a switch to start the conversion on /WR pin
2. A buffer to drive the LEDs
3. Finnaly a smart brain to make the display conversion (if 0xFF means for you +5V as full scale, then 0x80 means 2,5V)
You must admit that you need the brain to see data on LED.
Just a joke.
 

mcp3208 c

check the books " 8051 uC" by scott mackenzie and "8051 uC and embedded systems" by mazidi
 

mcp3208 adc embedded c code

afti_khan said:
check the books " 8051 uC" by scott mackenzie and "8051 uC and embedded systems" by mazidi

Afti_Khan, would you be so kind and post some links to the ebooks (I'm not expecting to advice Vinash to buy them or turn over pages in a library). If you can point out the pages that cover Vinash's needs it would be more than wonderful and a real help. I'm confident that Mackenzie's ebook link could be found easily in the forum. How about Mazidi ? Maybe you can ask nice Tico70 to finish scanning the book. As you can see Tico70 said "this a retribution for all the good information that I had gotten from ELEKTRODA "

BTW, I'll donate you 50 points if you can point out my mistake in my previous above post dated 16 Dec 2005 10:43
Cross my finger I'll do it.
 

connect mcp3208 to 8051

HI Silvio,
Thanks for your help, i have managed to make a real time ADC. I had made some errors in the LED part. Anyway thank you again for yor help. You had earlier mentioned
The best solution is to use P1 for both reading ADC (input) and writing LED (output) (wiring them parallel on the "bus").
.
I was wondering how you do that. Do you just connect P1 to both the LED as well as the reading the ADC converter? than whenever you give a command to P1,(whether you use it for reading ADC or writing LED) wouldn it effect the LED?
I hope you would be able to clarify my doudts on this. Thank you.
 

adc0804 led flicker

Hi Vinash,

Bear in mind that time required to read results of conversion is very short.
Nevertheless, the data you read is immediately displayed on same P1. Thus you wont see any effect on LED.
My mistake which I'm talking about above is that during a read of ADC0804, the convertor wouldn't be able to sink the LED current and appropiate VIL max meat at P1.
You're already familiar with connecting two devices that share the same bus.
When one is enabled (CS) other must be disabled to avoid conflict.
Since LED don't behaves as such common devices, you must to provide a way to disable them during short reading cycle of ADC0804.
Assuming you have LEDs with common anode then a small PNP transistor able to source the required current will drive the LEDs.
The transistor will be biased through a resistor by P3^7 which is driven low during display and high during short ADC reading cycle.
Obvious the colector of transistor is tied to the common anode of LED and emitor goes toward +5v.

Hope I've succeeded to clarify your doubts.
 

how connect mcp3208 to 8051

Thank you Silvio, well i've got another query, i hope you would be able to help me, instead of using parallel transmission for reading the ADC input(using the whole of P1), can i use serial transmission? than i can save on the pins?Please do kindly advise. Thank you.
 

at89c4051 led

Hi Vinash,

According to your first attempt using MPC3208 with SPI interface.
As i've told you before, since AT89C4051 has no hardware SPI interface you must use "bit bang" method of using general-purpose I/O lines to emulate a serial port.
You need only 4 wires : CS, CK, DOut, Din
Read this : **broken link removed**


Then all you need is to read mainly the pages 15 - 16 of
**broken link removed**

However if you want to use RX and TX lines of AT89C4051 you can use AD7823 and set the 8051 to operate in mode 0.
Page 10 of Analog AD7823
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top