#include “reg52.h”
float shuju;
unsigned char sj;
unsigned int gata;
unsigned char gw,sw,bw;
unsigned char kk,tdao;
//4联共阳数码管,最高位显现通道号,其他三位为电压值
unsigned char code shuzi[]={
0xC0,0xF9,0xA4,0xB0,0x99,
0x92,0x82,0xF8,0x80,0x90};
unsigned char code duanxuan[]={0x0f,0x8f,0x4f,0xcf,0x2f,0xaf,0x6f,0xff};
sbit START=P3^1; //ALE也衔接P3.1
sbit OE=P3^3;
sbit EOC=P3^2;
sbit clock=P3^0;
void delay()
{
unsigned char i;
for(i=200;i>0;i–);
}
//timer init
void Timer()
{
TMOD=0x21;
TH0=0x3c;//20ms
TL0=0xb0;
TH1=0xff;//100khz
TL1=0xfd;
}
void AD_zh()
{
START=0; //ADC0809的发动信号
START=1;
START=0;
while(EOC==0);//等候转化完毕
OE=1; //输出转化数据
sj=P1; //P1口接纳数据
shuju=sj;//转化为浮点型
shuju=(shuju/51.0)*100.00;//转化成百位数据;
gata=shuju;//转化为整型
bw=gata/100;//别离百位
sw=(gata/10)%10;//别离十位
gw=gata%10;//别离个位
}
//timer0/counter0 interrupt
void timer0(void) interrupt 1 //T0用于发生秒信号
{
TH0=0x3c;
TL0=0xb0;
kk++;
if(kk==20)
{
kk=0;
tdao++; //用于转化通道,丈量各个通道数据
if(tdao==8)
{
tdao=0;
}
}
}
void timer1(void) interrupt 3
{
clock=~clock; //定时器发生ADC0809所需的时钟信号
}
void display()
{
P0=shuzi[gw]; //个位
P2=0xf8&duanxuan[tdao];
delay();
P0=shuzi[sw];//十位
P2=0xf4&duanxuan[tdao];
delay();
P0=shuzi[bw]&0x7f; //电压百位
P2=0xf2&duanxuan[tdao];
delay();
P0=shuzi[tdao+1]; //通道从1~8,每秒换一个通道
P2=0xf1&duanxuan[tdao];
delay();
}
//the main fun
void main(void)
{
uchar i;
Timer();
TR0=1;
ET0=1;
TR1=1;
ET1=1;
EA=1;
while(1)
{
AD_zh();
for(i=0;i<10;i++) //下降改写速度,使显现安稳
{
display();//显现程序
}
}
}
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/fangan/biancheng/261159.html