关于ADC0809和单片机的C语言,求括号内的问题
发布网友
发布时间:2024-03-06 23:53
我来回答
共2个回答
热心网友
时间:2024-12-12 07:29
unsigned char code dispbitcode[]={ 0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f};(定义8个数码管的位控制字)
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,0x00};(定义数码管的段码)
unsigned char dispbuf[8]={10,10,10,10,10,0,0,0};(定义显示初始值
unsigned char dispcount;
sbit ST=P3^0;
sbit OE=P3^1;
sbit EOC=P3^2;
unsigned char channel=0xbc;//IN3(具体是什么看硬件,这不是地址,只是控制位)
unsigned char getdata;
void main(void)
{
TMOD=0x01;
TH0=(65536-4000)/256;
TL0=(65536-4000)%256;
TR0=1;
ET0=1;
EA=1;
P3=channel;(TMOD=1定义定时器0工作于模式1,EA=1开中断,P3赋值应该是启动0809开启IN3通道的AD转换)
while(1)
{
ST=0;
ST=1;
ST=0;
while(EOC==0);
OE=1;
getdata=P0;
OE=0;
dispbuf[2]=getdata/100;
getdata=getdata%10;
dispbuf[1]=getdata/10;
dispbuf[0]=getdata%10;
}
}
void t0(void) interrupt 1 using 0
{
TH0=(65536-4000)/256;
TL0=(65536-4000)%256;
P1=dispcode[dispbuf[dispcount]];
P2=dispbitcode[dispcount];
dispcount++;
if(dispcount==8)
{
dispcount=0;
}
热心网友
时间:2024-12-12 07:29
直接用带AD的芯片不就好了,这么麻烦