以AT89C51单片机为核心,ADC0808为AD转换器,采用中断方式,对0~5V的模拟电压进行循环采集,采集的数据送LED数码管显示,并存入内存,超过5V界限指示灯闪烁...

首先,你需要连接ADC0808和AT89C51单片机。然后,你可以使用AT89C51的中断功能来控制ADC0808进行模拟电压采集。

具体来说,你可以设置一个定时器中断,每隔一段时间就会触发中断。在中断服务子程序中,你可以调用ADC0808的采集函数,将模拟电压转换为数字值。然后,你可以使用AT89C51的数据总线将数字值传送到LED数码管,实现显示。同时,你还可以使用AT89C51的存储器将数据存储到内存中。

如果模拟电压超过了5V的界限,你可以在中断服务子程序中使用AT89C51的输出端口控制指示灯进行闪烁。

总的来说,这是一个使用AT89C51单片机和ADC0808进行模拟电压采集

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,这里提供一个简单的基于51单片机AD采集电压并显示在数码管上的代码示例,供参考: ``` #include <reg52.h> #include <intrins.h> #define uint unsigned int #define uchar unsigned char sbit DSPORT=P2^2; //数码管数据口 sbit DS1=P0^0; //数码管第一位 sbit DS2=P0^1; //数码管第二位 sbit DS3=P0^2; //数码管第三位 sbit DS4=P0^3; //数码管第四位 sbit CS=P2^1; //ADC芯片片选信号 sbit CLK=P2^0; //ADC芯片时钟信号 sbit DIN=P2^3; //ADC芯片数据输入信号 void delay(uint xms) //延时函数 { uint i,j; for(i=xms;i>0;i--) for(j=110;j>0;j--); } uchar code table[] = { //数码管显示表 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71 }; void Dsplay(uchar num) //数码管显示函数 { switch(num) { case 1: DSPORT=0; DS1=0; DS2=0; DS3=0; DS4=1; break; case 2: DSPORT=0; DS1=0; DS2=0; DS3=1; DS4=0; break; case 3: DSPORT=0; DS1=0; DS2=0; DS3=1; DS4=1; break; case 4: DSPORT=0; DS1=0; DS2=1; DS3=0; DS4=0; break; case 5: DSPORT=0; DS1=0; DS2=1; DS3=0; DS4=1; break; case 6: DSPORT=0; DS1=0; DS2=1; DS3=1; DS4=0; break; case 7: DSPORT=0; DS1=0; DS2=1; DS3=1; DS4=1; break; case 8: DSPORT=0; DS1=1; DS2=0; DS3=0; DS4=0; break; case 9: DSPORT=0; DS1=1; DS2=0; DS3=0; DS4=1; break; case 10: DSPORT=0; DS1=1; DS2=0; DS3=1; DS4=0; break; case 11: DSPORT=0; DS1=1; DS2=0; DS3=1; DS4=1; break; case 12: DSPORT=0; DS1=1; DS2=1; DS3=0; DS4=0; break; case 13: DSPORT=0; DS1=1; DS2=1; DS3=0; DS4=1; break; case 14: DSPORT=0; DS1=1; DS2=1; DS3=1; DS4=0; break; case 15: DSPORT=0; DS1=1; DS2=1; DS3=1; DS4=1; break; case 16: DSPORT=1; DS1=0; DS2=0; DS3=0; DS4=0; break; default: break; } } uchar ADConvert() //ADC采集函数 { uchar i,dat=0; CS=0; CLK=0; DIN=1; for(i=0;i<8;i++) { CLK=0; _nop_(); dat<<=1; if(DOUT) dat++; CLK=1; _nop_(); } CS=1; return dat; } void main() { uchar num=0; uint vol=0; while(1) { vol=ADConvert(); //采集电压值 vol=vol*5000/256; //转换为实际电压值,假设ADC参考电压5V num=vol/1000; //将电压值拆分成四位数 Dsplay(num+1); //显示千位数 delay(5); num=(vol%1000)/100; Dsplay(num+1); //显示百位数 delay(5); num=(vol%100)/10; Dsplay(num+1); //显示十位数 delay(5); num=vol%10; Dsplay(num+1); //显示个位数 delay(5); } } ``` 需要注意的是,这段代码仅供参考,具体实现时需要根据自己的硬件实际情况进行修改。同时,需要注意电压转换的精度和参考电压的设置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值