完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
以下这段程序时间走的比实际的快很多,不像是误差造成的。如在while(1)主循环里面随便加条语句后就正常了,不知道是什么原因.......求解!
----------------------------------------------------------------- #include ***it ADDR0 = P1^0; ***it ADDR1 = P1^1; ***it ADDR2 = P1^2; unsigned char code LedChar[] = {0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71}; unsigned char LedBuff[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; unsigned int cnt = 0; unsigned long sec = 0; void main() { EA = 1; TMOD = 0x01; TH0 = 0xFC; TL0 = 0x67; TR0 = 1; ET0 = 1; while(1) { if(cnt >= 1000) { cnt = 0; sec++; LedBuff[0] = LedChar[sec%10]; LedBuff[1] = LedChar[sec/10%10]; LedBuff[2] = LedChar[sec/100%10]; LedBuff[3] = LedChar[sec/1000%10]; LedBuff[4] = LedChar[sec/10000%10]; LedBuff[5] = LedChar[sec/100000%10]; } **如果在这个位置随便加条语句后就正常了** } } void Interrupttimer0() interrupt 1 { static unsigned char i = 0; TH0 = 0xFC; TL0 = 0x67; cnt++; P0 = 0x00; switch(i) { case 0: ADDR0 = 1; ADDR1 = 1; ADDR2 = 1; i++; P0 = LedBuff[0]; break; case 1: ADDR0 = 1; ADDR1 = 1; ADDR2 = 0; i++; P0 = LedBuff[1]; break; case 2: ADDR0 = 1; ADDR1 = 0; ADDR2 = 1; i++; P0 = LedBuff[2]; break; case 3: ADDR0 = 1; ADDR1 = 0; ADDR2 = 0; i++; P0 = LedBuff[3]; break; case 4: ADDR0 = 0; ADDR1 = 1; ADDR2 = 1; i++; P0 = LedBuff[4]; break; case 5: ADDR0 = 0; ADDR1 = 1; ADDR2 = 0; i=0; P0 = LedBuff[5]; break; default : break; } } |
|
相关推荐
8个回答
|
|
|
|
|
|
对啊,我的晶振是11.0592 |
|
|
|
|
|
|
|
|
|
|
|
本人初学,就是看那教程来的,试了就是很奇怪。。 |
|
|
|
|
|
|
|
不错的文档,值得收藏
|
|
|
|
先看看你使用的晶振频率,STC有个计算表,算一下时间,或者就是用keil测试运行那条语句实际运行时间
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
409 浏览 0 评论
【xG24 Matter开发套件试用体验】10-Bluetooth示例1
469 浏览 0 评论
697 浏览 0 评论
【xG24 Matter开发套件试用体验】power specification电源规格参数配置
512 浏览 0 评论
475 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
10813 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-8-22 13:44 , Processed in 0.752996 second(s), Total 86, Slave 68 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191