完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include
***it ADDR0 = P1^0; ***it ADDR1 = P1^1; ***it ADDR2 = P1^2; ***it ADDR3 = P1^3; ***it ENLED = P1^4; ***it LED2 = P0^0; ***it LED3 = P0^1; ***it LED4 = P0^2; ***it LED5 = P0^3; ***it LED6 = P0^4; ***it LED7 = P0^5; ***it LED8 = P0^6; ***it LED9 = P0^7; ***it KEY1 = P2^4; ***it KEY14 = P2^5; ***it KEY8 = P2^7; ***it KEY15 = P2^6; ***it IN1=P2^4; ***it IN2=P2^5; ***it IN3=P2^6; ***it IN4=P2^7; ***it OUT1=P2^3; ***it OUT2=P2^2; ***it OUT3=P2^1; ***it OUT4=P2^0; unsigned char code a[]={ 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90, }; unsigned char b[6]={0x00,0x00,0x00,0x00,0x00,0x00 }; unsigned char cnt =0; void main() { bit T =0; unsigned char keyout = 0; unsigned int j=0; static signed long i ; static signed long i0 = 2000; static signed long i1 = 1500; static signed long i2 = 1200; static signed long i3 = 1000; static signed long i4 = 800; static signed long i5 = 500; static signed long i6 = 200; static signed long i7 = 100; static signed long i8 = 2000; ENLED = 0; ADDR3 = 1; ADDR2 = 1; ADDR1 = 1; ADDR0 = 0; while(1) { switch(keyout) { case 0 :OUT4 = 1;OUT3 = 1;OUT2 = 1;OUT1 = 0;break; case 1 :OUT4 = 1;OUT3 = 1;OUT1 = 1;OUT2 = 0;break; case 2 :OUT4 = 1;OUT2 = 1;OUT1 = 1;OUT3 = 0;break; case 3 :OUT3 = 1;OUT3 = 1;OUT1 = 1;OUT4 = 0;break; default:break; } keyout++; keyout = keyout&0x03; //让OUT轮流为零 if(OUT4==0&&IN3==0) { T=1; } //按下KEY15,进入调节模式 if(T==1) //调节模式 { if(OUT4==0&&IN2==0) { T=0; P0=0xFF; break; } //按下KEY14,退出调节模式. EA = 1; TMOD = 0x01; TH0 = 0xFC; TL0 = 0x67; ET0 = 1; TR0 = 1; for(j=0;j<=600;j++); //延时,防止按键不可控.可用其他方式优化. if(OUT2==0&&IN4==0) { cnt=cnt+1; if(cnt==8) { cnt=0; } } if(OUT4==0&&IN4==0) { cnt=cnt-1; if(cnt==-1) { cnt=7; } } //按左键被调节的灯左移一个,按右键被调节的灯右移一个. switch(cnt) { case 0:i=i0;break; case 1:i=i1;break; case 2:i=i2;break; case 3:i=i3;break; case 4:i=i4;break; case 5:i=i5;break; case 6:i=i6;break; case 7:i=i7;break; default:break; } //调节哪个灯的延时,就将哪个灯的延时赋值给i. if(OUT1==0&&IN4==0) { i=i+1; } if(OUT2==0&&IN1==0) { i=i+10; } if(OUT2==0&&IN2==0) { i=i+100; } if(OUT2==0&&IN3==0) { i=i+1000; } if(OUT1==0&&IN2==0) { i=i+10000; } if(i>=1000000) { i=0; } //调节灯的延时 if(OUT3==0&&IN4==0) { i=i-1; } if(OUT3==0&&IN1==0) { i=i-10; } if(OUT3==0&&IN2==0) { i=i-100; } if(OUT3==0&&IN3==0) { i=i-1000; } if(OUT1==0&&IN3==0) { i=i-10000; } if(i<=-1) { i=999999; } //调节灯的延时 switch(cnt) { case 0:i0=i;break; case 1:i1=i;break; case 2:i2=i;break; case 3:i3=i;break; case 4:i4=i;break; case 5:i5=i;break; case 6:i6=i;break; case 7:i7=i;break; default:break; } //将调节好的延时赋值回去 b[0] = a[i%10]; b[1] = a[i/10%10]; b[2] = a[i/100%10]; b[3] = a[i/1000%10]; b[4] = a[i/10000%10]; b[5] = a[i/100000%10]; //将数字在数码管上体现出来 } if(OUT1==0&&IN1==0) { LED2=0; for(i=0;i<=i0;i++); LED2 = 1; LED3 = 0; for(i=0;i<=i1;i++); LED3 =1; LED4 = 0; for(i=0;i<=i2;i++); LED4 = 1; LED5 = 0; for(i=0;i<=i3;i++); LED5 = 1; LED6 = 0; for(i=0;i<=i4;i++); LED6 = 1; LED7 = 0; for(i=0;i<=i5;i++); LED7 = 1; LED8 = 0; for(i=0;i<=i6;i++); LED8 = 1; LED9 = 0; for(i=0;i<=i7;i++); LED9 = 1; for(i=0;i<=i8;i++); } //按下KEY1发射 } } void TnterruptTimer() interrupt 1 { static unsigned char k=0; TH0 = 0xFC; TL0 = 0X67; P0 = 0xFF; switch(k) { case 0:ADDR2=0;ADDR1=0;ADDR0=0;k++;P0=b[0];break; case 1:ADDR2=0;ADDR1=0;ADDR0=1;k++;P0=b[1];break; case 2:ADDR2=0;ADDR1=1;ADDR0=0;k++;P0=b[2];break; case 3:ADDR2=0;ADDR1=1;ADDR0=1;k++;P0=b[3];break; case 4:ADDR2=1;ADDR1=0;ADDR0=0;k++;P0=b[4];break; case 5:ADDR2=1;ADDR1=0;ADDR0=1;k++;P0=b[5];break; case 6:ADDR2=1;ADDR1=1;ADDR0=0;k=0;P0=~(0x01< }//动态刷新数码管 } |
|
相关推荐
1个回答
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-LCD显示图片编程示例之介绍mmap
72 浏览 0 评论
《DNESP32S3使用指南-IDF版_V1.6》第二章 常用的C语言知识点
509 浏览 0 评论
【RA-Eco-RA2E1-48PIN-V1.0开发板试用】(第三篇)ADC采集+PWM输出
546 浏览 0 评论
《DNK210使用指南 -CanMV版 V1.0》第四十五章 人脸识别实验
545 浏览 0 评论
1008 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11763 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 14:40 , Processed in 0.814135 second(s), Total 72, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号