资源描述:
《很_实习总结_总结汇报_应用文书 - 很》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、#include#include#defineucharunsignedchar#defineuintunsignedintuchartemp,temp1;voiddelayms(uintms){uinti,j;for(i=ms;i>0;i--)for(j=110;j>0;j--);}voidmain(){TCON=0x00;EX0=1;EX1=1;PX1=1;EA=1;P0=0;temp=0x01;while(1){P0=temp;temp=_crol_(temp,1);delay
2、ms(300);}}voidint0_serve()interrupt0{P0=0xff;delayms(5000);}voidint1_serve()interrupt2{temp1=P0;P0=0;delayms(5000);P0=temp1;}第三个:#include#defineucharunsignedchar#defineuintunsignedintucharcodeduanma[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,//共阳数码管段
3、码值0-F0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};ucharcodeweima[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//位码voiddelayms(uintms){uinti,j;for(i=ms;i>0;i--)for(j=110;j>0;j--);}voidmain(){while(1){P0=duanma[2];P1=0;P1=weima[0];delayms(1);P0=duanma[0];P1=0;P1=weima[1];dela
4、yms(1);P0=duanma[1];P1=0;P1=weima[2];delayms(1);P0=duanma[4];P1=0;P1=weima[3];delayms(1);}}发挥部分:#include#defineucharunsignedchar#defineuintunsignedint#definekey_time15//按键去抖动延时的时间voidinit();voidkeyscan();voiddisplay();voiddisplay1(ucharshi,ucharge);voidde
5、layms(uintms);sbitkey_1=P3^2;ucharcodeduanma[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,//共阳数码管段码值0-F0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};ucharcodeweima[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//位码ucharnum1,shi,ge;ucharnum=14;uintKeyTimeCnt1=0;//按键去抖动延时计数器
6、ucharKeyLock1=0;//按键触发后自锁的变量标志voidmain(){init();while(1){keyscan();display();shi=num/10;ge=num%10;display1(shi,ge);if(num1==20){num1=0;num--;if(num==0){TR0=0;}}}}voidT0_timer()interrupt1{TH0=(65536-45872)/256;TL0=(65536-45872)%256;num1++;}voidinit(){TMOD=0x01;TH0=
7、(65536-45872)/256;TL0=(65536-45872)%256;TR0=0;ET0=1;EA=1;}voidkeyscan(){if(key_1==1)//IO是高电平,说明按键没有被按下,这时要及时清零一些标志位{KeyLock1=0;//按键自锁标志清零KeyTimeCnt1=0;//按键去抖动延时计数器清零,此行非常巧妙。}elseif(KeyLock1==0)//有按键按下,且是第一次被按下{KeyTimeCnt1++;if(KeyTimeCnt1>key_time1){KeyTimeCnt1=0;
8、KeyLock1=1;//自锁按键置位,避免一直触发TR0=1;}}}voiddisplay(){P0=duanma[2];P1=0;P1=weima[0];delayms(1);P0=duanma[0];P1=0;P1=weima[1];delayms(1);}voiddisplay1(ucharsh