C51单片机通过ADC0809八路采集温度四位数码管循环显示
时间: 2023-07-03 20:27:43 浏览: 90
好的,我了解了你的问题。下面是一个C51单片机通过ADC0809八路采集温度并在四位数码管上循环显示的简单代码:
```
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit CS=P1^0; //ADC0809片选控制端
sbit CLK=P1^1; //ADC0809时钟控制端
sbit INTR=P1^2; //ADC0809转换完成中断输出端
sbit DOUT=P1^3; //ADC0809数据输出端
sbit DIG1=P2^4; //第一位数码管
sbit DIG2=P2^5; //第二位数码管
sbit DIG3=P2^6; //第三位数码管
sbit DIG4=P2^7; //第四位数码管
uchar code seg[]={ //数码管段码表
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x00
};
void delay(uint i){ //延时函数
while(i--);
}
void display(uchar dat){ //数码管显示函数
uchar i;
DIG1=0;DIG2=0;DIG3=0;DIG4=0; //清除所有数码管
for(i=0;i<4;i++){
switch(i){ //选择要显示的数码管
case 0:DIG1=1;break;
case 1:DIG2=1;break;
case 2:DIG3=1;break;
case 3:DIG4=1;break;
}
P0=seg[dat%10]; //选择要显示的数字
dat/=10;
delay(10); //延时10ms
}
}
void ADC0809(){ //ADC0809采集函数
uchar i,adval;
for(i=0;i<8;i++){
CS=0; //片选ADC0809
CLK=0; //清零时钟线
_nop_(); //空操作
_nop_();
_nop_();
CLK=1; //置高时钟线
adval<<=1; //左移一位
if(DOUT==1)adval|=0x01; //读取数据
CS=1; //取消片选ADC0809
}
display(adval); //显示采集的温度值
}
void main(){
while(1){
ADC0809(); //采集温度并显示
}
}
```
这个代码中,我们通过C51单片机控制ADC0809芯片进行八路采集,然后将采集到的温度值通过四位数码管循环显示。其中,采集函数使用了8个时钟周期来完成一次采集,每个时钟周期为12us,因此采集频率为1.25kHz。数码管显示函数每次延时10ms,因此数码管的刷新频率为100Hz,可以保证显示的稳定性。