利用动态扫描和定时器1在数码管上显示出从765432开始以110秒的速度往下递减直至765398并保

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

利用动态扫描和定时器1在数码管上显示出从765432开始以1/10秒的速度往下递减直至765398并保持显示此数,与此同时利用定时器0以500MS速度进行流水灯从上至下移动,当数码管上数减到停止时,实验板上流水灯也停止然后全部开始闪烁,3秒后(用T0定时)流水灯全部关闭、数码管上显示出“HELLO”。到此保持住。Proteus仿真图:#includereg52.h#includeintrins.h#defineuintunsignedint#defineucharunsignedcharvoiddelayms(uint);//延时子程序voidinit();//初始化子程序voiddisplay(uintsix,uintfive,uintfour,uintthree,uinttwo,uintone);//显示子程序ucharcodetable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0X76,0X79,0X38,0X38,0X3F,0};uinttemp,bai,shi,ge;ucharx,y,flag,led,flag1;voidmain(){init();while(1){if(flag1==0)display(7,6,5,bai,shi,ge);elsedisplay(16,17,18,19,20,21);}}voidinit(){temp=432;x=y=0;flag=0;flag1=0;led=0xfe;P3=led;EA=1;TMOD=0x11;TH0=(65536-50000)/256;TL0=(65536-50000)%256;ET0=1;TR0=1;TH1=(65536-50000)/256;TL1=(65536-50000)%256;ET1=1;TR1=1;}voiddelayms(uintms){uintx,y;for(x=ms;x0;x--)for(y=110;y0;y--);}voiddisplay(uintsix,uintfive,uintfour,uintthree,uinttwo,uintone){P2=table[six];P1=0xfe;delayms(1);P1=0xff;P2=table[five];P1=0xfd;delayms(1);P1=0xff;P2=table[four];P1=0xfb;delayms(1);P1=0xff;P2=table[three];P1=0xf7;delayms(1);P1=0xff;P2=table[two];P1=0xef;delayms(1);P1=0xff;P2=table[one];P1=0xdf;delayms(1);P1=0xff;}voidtimer0()interrupt1{TH0=(65536-50000)/256;TL0=(65536-50000)%256;x++;if(flag==0&&x==10){x=0;led=_crol_(led,1);P3=led;}if(flag==2){if(x%2==0)P3=~P3;if(x==60){TR0=0;P3=0xff;flag1=1;}}}voidtimer1()interrupt3{TH1=(65536-50000)/256;TL1=(65536-50000)%256;y++;if(y==2){y=0;temp--;if(temp=398){bai=temp/100;shi=temp%100/10;ge=temp%10;}elseflag=1;if(flag==1){P3=0xff;TR0=0;TH0=(65536-50000)/256;TL0=(65536-50000)%256;TR0=1;x=0;flag=2;TR1=0;}}}

1 / 4
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功