Application of analog-to-digital conversion ADC0804 (including source code and circuit)

Publisher:MysticalDreamerLatest update time:2011-07-17 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

[Experimental requirements]

The analog quantity between 0 and 5V is input from the analog channel of ADC0804, converted into digital quantity by ADC0804 and sent to the microcontroller. After being processed by the microcontroller, it is displayed in decimal on the digital tube.

[Purpose of the experiment]

Learn how to use a single-chip microcomputer to control the ADC0804 chip for digital-to-analog conversion, and master the principle of dynamic scanning display of digital tubes.

Dynamic scanning: Take the six-digit digital tube displaying 123456 as an example: first let the first digital tube display 1, and the rest are all dark. 1 is on for a few milliseconds and then goes out. Then immediately let the second digital tube display 2, and the rest are all dark. 2 is also on for a few milliseconds. This is how the sixth digital tube is lit, and then it comes back to display 1. This cycle continues at a very fast speed. Since the visual retention time of the human eye is about 20 milliseconds, it is not possible to feel that there are dark digital tubes. What we see is that six digital tubes are displaying the value of 123456 at the same time. If we slow down this process a little bit, we will see that the first digital tube displays 1, then moves to the second and then displays 2... That is to say, only one digital tube is lit at any time. This is the principle of dynamic scanning display of digital tubes.

ADC0804: ADC0804 is an 8-bit full MOS medium-speed A/D converter. It is a successive approximation A/D converter with a three-state data output latch on the chip, which can be directly interfaced with a single-chip microcomputer. Single-channel input, the conversion time is about 100us. The conversion timing of ADC0804 is: when CS=0, A/D conversion is allowed. When WR changes from low to high, A/D starts to convert, and a total of 66-73 clock cycles are required for one conversion. When CS and WR are valid at the same time, A/D conversion is started, and the INTR signal (low level is valid) is generated at the end of the conversion, which can be used for query or interrupt signal. The data results can be read under the control of CS and RD. The INTR signal is not used in this experiment.

[Hardware Circuit]

[source code]

//Twist the potentiometer next to AD, and the first three digits of the digital tube will display a value between 0 and 255. This is the conversion of analog signals into digital signals, i.e. analog-to-digital conversion.

#include

#include

#define uint unsigned int

#define uchar unsigned char

sbit adrd=P3^7; //IO port definition

sbit adwr=P3^6;

sbit diola=P2^5;

sbit dula=P2^6;

sbit wela=P2^7;

unsigned char j,k,adval;

void delay(unsigned char i) //delay program

{

for(j=i;j>0;j--)

for(k=125;k>0;k--);

}

uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, //digital tube code

0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};

void display(uchar bai_c,uchar sh_c,uchar g_c) //display program

{

P0=table[bai_c]; //Display hundreds

dula=1;

dula=0;

P0=0xfe;

wela=1;

wela=0;

delay(5);

dula=0;

P0=table[sh_c]; //Display tens digit

dula=1;

dula=0;

wela=0;

P0=0xfd;

wela=1;

wela=0;

delay(5);

P0=table[g_c]; //Display the units digit

dula=1;

dula=0;

P0=0xfb;

wela=1;

wela=0;

delay(5);

}

void main() // Main program

{

uchar a,A1,A2,A2t,A3;

while(1)

{

wela=1;

P0=0; //Enable ADCS

adwr=0; //AD write (you can write anything, mainly to start AD conversion)

_nop_();

adwr=1;

P0=0xff; //turn off ADCS

delay(10);

wela=0; //Close the latch end of the AD chip select signal latch to prevent the AD chip select from changing when operating the digital tube

for(a=20;a>0;a--) //It should be noted that the time interval between writing and reading ADC0804 must be long enough, otherwise the data cannot be read out

{ //The reason for putting the display part here is to increase the time interval between writing and reading

display(A1,A2,A3);

} //Send to display to everyone.

wela=1; //Reopen the latch end with AD chip select signal latch

P1=0xff; //Write the full value before reading P1

P0=0; //Enable ADCS

adrd=0; //AD read enable

adval=P1; //AD data read and assigned to P1 port

adrd=1;

P0=0xff; //turn off ADCS

adwr=0;

P1=adval; //Send the AD value to eight LEDs for display at the same time

A1=adval/100; //separate hundreds, tens, and ones

A2t=adval%100;

A2=A2t/10;

A3=A2t%10;

};

}

Reference address:Application of analog-to-digital conversion ADC0804 (including source code and circuit)

Previous article:Overvoltage output protection circuit
Next article:Application of voltage divider model in analog circuit

Latest Industrial Control Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号