Microcontroller C language programming: ADC0809 digital-to-analog conversion and display

Publisher:知音学友Latest update time:2013-11-07 Source: 21icKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/* Name: ADC0809 digital-to-analog conversion and display

Description: ADC0809 sampling channel 3 input

Analog quantity, the converted result is displayed on the digital tube.

*/

#include

#define uchar unsigned char

#define uint unsigned int

//Digital tube segment code for each digit (common cathode)

uchar code DSY_CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};


sbit CLK=P1^3; //clock signal

sbit ST=P1^2; //Start signal


sbit EOC=P1^1; //Conversion end signal

sbit OE=P1^0; //output enable

//Delay

void DelayMS(uint ms)

{

uchar i;

while(ms--) for(i=0;i<120;i++);

}

// Display the conversion result

void Display_Result(uchar d)

{

P2=0xf7; The 4th digital tube displays the unit digit

P0=DSY_CODE[d%10];


DelayMS(5);

P2=0xfb; The third digital tube displays the tens digit

P0=DSY_CODE[d%100/10];

DelayMS(5);

P2=0xfd; The second digital tube displays the hundreds digit

P0=DSY_CODE[d/100];

DelayMS(5);

            }[page]

//Main program

void main()

{

TMOD=0x02; //T1 working mode 2

TH0=0x14;

TL0=0x00;

IE=0x82;

TR0=1;

P1=0x3f; //Select channel 3 (0111) of ADC0809 (P1.4~P1.6)

while(1)

{

ST=0;ST=1;ST=0; //Start A/D conversion

while(EOC==0); //Wait for the conversion to complete

OE=1;

Display_Result(P3);

OE=0;

}


 }

//T0 timer interrupt provides clock signal to ADC0808

void Timer0_INT() interrupt 1

{

CLK=~CLK;

}

Microcontroller C language programming: ADC0809 digital-to-analog conversion and display

Keywords:MCU Reference address:Microcontroller C language programming: ADC0809 digital-to-analog conversion and display

Previous article:Electronic System Thermal Management Solutions
Next article:Microcontroller C language programming: using ADC0808 to control PWM output

Latest Microcontroller 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号