完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
kingst 51开发板,自制红绿灯程序,在中断调用LedShow 和在主程序调用LedShow,效果不同,为什么?
STC59C52 --------------------------- 请大家帮我看看,下面的程序,在中断调用LedShow 和在主程序调用LedShow,效果不同,为什么? 在中断调用时:LED和发光二极管目测下,一闪一闪的。 在主程序调用时: 发光正常. 是因为调用LedShow时,LedShow 没有执行完毕,而产生新的中断吗? 我是菜鸟,庆大侠赐教 #include ***it ADDR0 = P1^0; ***it ADDR1 = P1^1; ***it ADDR2 = P1^2; ***it ADDR3 = P1^3; ***it ENLED = P1^4; void Configertimer0(unsigned int ms); static unsigned char timer = 0; static unsigned char LedBuff[]= { 0xFF,0xFF,0xFF }; unsigned char code LedChar[] = { 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8, 0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e }; static unsigned char T0TH = 0; static unsigned char T0TL = 0; static unsigned int counter = 0; void LedShow(); void main() { unsigned char color = 0; EA = 1; ENLED = 0; ConfigerTimer0(1); while(1) { if(timer == 0) { switch(color) { case 0: timer = 9; color = 1; LedBuff[2] = 0x3F; break; case 1: timer = 15; color = 2; LedBuff[2] = 0xE7; break; case 2: timer = 5; color = 0; LedBuff[2] = 0xFC; break; default:break; } } LedBuff[0] = LedChar[timer%10]; LedBuff[1] = LedChar[timer/10]; LedShow(); }; } void ConfigerTimer0(unsigned int ms) { unsigned long tmp; tmp = 11059200/12; tmp = (tmp*ms)/1000; T0TH =(unsigned char)(tmp>>8); T0TL =(unsigned char)tmp; TMOD &= 0xF0; TMOD |= 0x01; ET0 = 1; TR0 = 1; } void LedShow() { static unsigned char i = 0; P0 = 0xFF; switch(i) { case 0: ADDR2 = 0;ADDR1 = 0;ADDR0 = 0; i++; P0 = LedBuff[0]; break; case 1: ADDR2 = 0;ADDR1 = 0;ADDR0 = 1; i++; P0 = LedBuff[1]; break; case 2: ADDR2 = 1;ADDR1 = 1;ADDR0 = 0; i=0;P0 = LedBuff[2]; break; default: break; } } void InterruptTimer0() interrupt 1 { TH0 = T0TH; TL0 = T0TL; counter++; if(counter>=20) { counter = 0; timer--; } } |
|
相关推荐
1个回答
|
|
|
顶下自己的问题
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
435 浏览 0 评论
464 浏览 0 评论
450 浏览 0 评论
806 浏览 0 评论
RT-Thread与英飞凌(infineon)合作得板子PSOC 6 板子学习
748 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
17012 浏览 31 评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-12 08:36 , Processed in 0.568823 second(s), Total 42, Slave 34 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
3457