//程序头函数
#include <reg52.h>
//宏定义
#define uint unsigned int
#define uchar unsigned char
#define Data_ADC0809 P1
//ADC0809
sbit ST=P3^3;
sbit EOC=P3^4;
sbit OE=P3^2;
//显示数组 0-9 - F
uchar Data_[]={ 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,
0x8e,0xc0};
sbit Wei1 = P2^7;
sbit Wei2 = P2^6;
sbit Wei3 = P2^5;
sbit Wei4 = P2^4;
//函数声明
extern uchar ADC0809();
void Display();
void delay(uint t);
uint temp=0;
uint sum=0;
//显示模式
uchar p;
void main() //主函数
{
while(1)
{
//读取AD值
for(p=0;p<50;p++)
{
sum=sum+ADC0809();
Display();
}
temp=sum/50;
sum=0;
for(p=0;p<30;p++)
Display();
}
}
//ADC0809读取信息
uchar ADC0809()
{
uchar temp_=0x00;
//初始化高阻太
OE=0;
//转化初始化
ST=0;
//开始转换
ST=1;
ST=0;
//外部中断等待AD转换结束
while(EOC==0)
//读取转换的AD值
OE=1;
temp_=Data_ADC0809;
OE=0;
return temp_;
}
//延时
void delay(uint t)
{
uint i,j;
for(i=0;i<t;i++)
for(j=0;j<10;j++);
}
//显示 X表示状态 Data表示数据
void Display()
{
P0=0xff;
Wei1=0;
delay(10);
Wei1=1;
P0=~Data_[temp/100];
Wei2=0;
delay(10);
Wei2=1;
P0=~Data_[temp%100/10];
Wei3=0;
delay(10);
Wei3=1;
P0=~Data_[temp%100%10];
Wei4=0;
delay(10);
Wei4=1;
}