完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
单片机HC6800系列,出现问题按键无反应,数码管不单亮0,求大神帮忙找问题,0错误0警告代码如下:
#include ***it KEY1=P1^0; ***it KEY2=P1^1; ***it KEY3=P1^2; ***it KEY4=P1^3; /////P2第三位接138输入口,P0接数码管,P1接键盘扫描 unsigned char LED[16]={0x3f,0x06,0x5B,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; unsigned char LEDBuff[6]={0xff,0xff,0xff,0xff,0xff,0xff}; bit stopwatchRefresh=1; bit stopwatchRunning=0; unsigned char T0RH=0; unsigned char T0RL=0; unsigned char Decimalpart=0; unsigned int Integerpart=0; unsigned char KeySta[4]={1,1,1,1}; void Configtimer0(unsigned char ms) //输入的时间应当小于工作模式的时间65ms { unsigned long tmp; tmp=65536-12000000*ms/12/1000; tmp=tmp+0; //此处设置补偿,使计算更精准 T0RH=(unsigned char )(tmp>>8); T0RL=(unsigned char )tmp; TMOD&=0xf0; TMOD|=0x01; TH0=T0RH; TL0=T0RL; ET0=1; TR0=1; } void stopwatchDisplay() { unsigned char i; unsigned buf[4]; LEDBuff[0]=LED[Decimalpart%10]; LEDBuff[1]=LED[Decimalpart/10&10]; buf[0]=Integerpart%10; buf[1]=Integerpart/10%10; buf[2]=Integerpart/100%10; buf[3]=Integerpart/1000%10; for (i=3;i>=1;i--) { if (buf[i]==0) LEDBuff[i+2] = 0xff; else break; } for (;i>=0;i--) {LEDBuff[i+2]=LED[buf[i]];} LEDBuff[2]|=0x7f; } void LEDScan() { static unsigned char i=0; P0=0xff; P2=(P2&0xf8) | i; P0=LEDBuff[i]; if(i<5) i++; else i=0; } void KeyScan() { unsigned char i; static unsigned char keybuf[4]= {0xff,0xff,0xff,0xff}; keybuf[0] = (keybuf[0]<<1) |KEY1; keybuf[1] = (keybuf[1]<<1) |KEY2; keybuf[2] = (keybuf[2]<<1) |KEY3; keybuf[3] = (keybuf[3]<<1) |KEY4; for (i=0;i<4;i++) { if (keybuf[i]==0x00) { KeySta[i]=0; } else if (keybuf[i]==0xff) { KeySta[i]=1; } } } void StopwatchReset() { stopwatchRunning = 0; Decimalpart=0; Integerpart=0; stopwatchRefresh=1; } void StopwatchAction() { if(stopwatchRunning) stopwatchRunning=0; else stopwatchRunning=1; } void KeyDriver() { unsigned char i ; unsigned char backup[4]={1,1,1,1}; for (i=0;i<4;i++) { if (backup[i]!=KeySta[i]) { if (backup[i]!=0) { if(i==1) StopwatchReset(); else if(i==2) StopwatchAction(); } backup[i]=KeySta[i]; } } } void stopwatchCount() { if(stopwatchRunning==1) { Decimalpart++; if(Decimalpart>=100) { Decimalpart=0; Integerpart++; if(Integerpart>=10000) { Integerpart=0; } } } stopwatchRefresh=1; } void main() { EA=1; ConfigTimer0(2); P1=0xff; while(1) { if(stopwatchRefresh==1) { stopwatchRefresh=0; stopwatchDisplay(); } KeyDriver(); } } void interrupttimer0() interrupt 1 { unsigned char time10ms=0; TH0=T0RH; TL0=T0RL; LEDScan(); KeyScan(); time10ms++; if (time10ms>=5) { time10ms=0; stopwatchCount(); } } |
|
相关推荐
2 个讨论
|
|
hobbye501 发表于 2017-3-15 11:50 排除了!花了4~6个小时,2处错误,中断缺个静态,还有就是stopwatchDisplay()函数里面for语句不能检测0,如果检测0程序就死,原因不明。修改后 void stopwatchDisplay() { unsigned char i; unsigned buf[4]; LEDBuff[0]=LED[Decimalpart%10]; LEDBuff[1]=LED[Decimalpart/10&10]; buf[0]=Integerpart%10; buf[1]=Integerpart/10%10; buf[2]=Integerpart/100%10; buf[3]=Integerpart/1000%10; for (i=4;i>=2;i--) { if(buf[i-1]==0) LEDBuff[i+1]=0x00; else break; } for (;i>=1;i--) LEDBuff[i+1]=LED[buf[i-1]]; LEDBuff[2]|=0x80; } |
|
|
|
|
|
飞凌嵌入式ElfBoard EL 1板卡-i2c与从设备通讯编程示例之i2c-tools工具使用
652 浏览 0 评论
stc15f2k60s2利用串口传输字模存储到eeprom并进行点阵显示
696 浏览 1 评论
1264 浏览 0 评论
588 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-串口通讯编程示例之串口编写程序
1190 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11598 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-3 08:18 , Processed in 0.586526 second(s), Total 49, Slave 38 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号