完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
设计图如下,
由于已经硬件实现,无法更改,现附上程序,求高手挑错。 //--------------------------------------- // AD0809 by maomaochong // Date: 2011/8/31 // time: 15:54 // Function: ADDA-ADDC connect to P2.0-P2.2 to choose AD channel //--------------------------------------- #include "reg51.h" ***it ST_ALE=P3^0; //START and ALE both connect to P3.0 ***it EOC=P3^1; //EOC connect to P3.1 ***it OE=P3^2; //OE conect to P3.2 ***it CLK=P3^3; //CLK connect to P3.3 unsigned char CHANNEL; //AD channel variable unsigned char LED[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; //common cathode LED code unsigned char CHECK[4]={0xFE,0xFD,0xFB,0xF7}; //choose LED channel void delay(unsigned char time) { unsigned char i,j; for(i=time;i>0;i--) for(j=250;j>0;j--) ; } void display() { unsigned long temp; unsigned char DATA,digit[4]; unsigned int k,l; DATA=P1; //save AD data temp=DATA; //the temporary variable temp=temp*1000/51; //AD formula:D=A*5/255 digit[0]=temp/1000; //the thousands place digit[1]=temp%1000/100; //the hundreds place digit[2]=temp%1000%100/10; //the tens place digit[3]=temp%1000%100%10; //the ones place DATA=P2; //save P2 for(k=0;k<1000;k++) { /* lighten each LED and equal the below for loop P1=LED[digit[0]]+0x80; P2_4=0; P2_4=1; P1=LED[digit[1]]; P2_5=0; P2_5=1; P1=LED[digit[2]]; P2_6=0; P2_6=1; P1=LED[digit[3]]; P2_7=0; P2_7=1; */ for(l=0;l<4;l++) { P2=P2|0x0F; //avoid LED residual P0=LED[digit[l]]+0x80*(l==0); //LED code P2=DATA&CHECK[l]; //choose LED channel } } P2=DATA; //restore P2 } void main() { ST_ALE=0; //START and ALE default OE=0; //OE default TMOD=0x02; //T0 operate in mode 2 EA=1; //all interrupt enable ET0=1; //T0 interrupt enable TR0=1; //T0 run while(1) { ST_ALE=1; //lock the AD channel address ST_ALE=0; //AD run while(EOC==0); //wait until AD over OE=1; //enable to transmit AD data display(); //view the AD result and diaplay LED } } void T1_TIME() interrupt 1 using 0 { CLK=~CLK; //CLK 500 kHz } 具体问题为数码管显示数值和滑动变阻器显示数值不同,求解。若需要源设计,请发邮件到994504828@qq.com。新手小白一个,请大神指教! |
|
相关推荐
1个回答
|
|
回帖奖励 +2 分积分
不错的文件,值得收藏
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
2024年上海海思MCU开发者体验官招募,手机/MatePad大奖等你拿!
955 浏览 0 评论
【xG24 Matter开发套件试用体验】蓝牙控制板载LED
829 浏览 0 评论
978 浏览 0 评论
电赛:mspm0l1306的开发板可以烧录程序,但是程序运行不了,怎么解决这个问题?
1038 浏览 1 评论
【xG24 Matter开发套件试用体验】Silicon Labs 基于 EFR32MG24 Explorer Kit 开发板 开箱试用体验
823 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
10514 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-8-6 02:13 , Processed in 0.609666 second(s), Total 74, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号