1、temp=temp;P1=temp;temp=1;delay(1000);void move_left_only(void) temp=0x01;temp1;void move_left_hold(void) temp=0xfe;void main() while(1) move_left_hold();move_mid_side();move_right_hlod();move_left_only();move_right_only();数码管 #include char data_duan=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90;
2、/09 char data_wei=0xff,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0x00; /0xff全关,之后为第一个数码管到第八个数码管 /char data_wei_add=0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00;for(j=0;j100;j+);void show_number_only(void) int i;P2=data_wei1; /P2为位选 for(i=0;i10;i+) P0=data_duani; /P0为段选 /*数码管动态显示子程序*/ void move_show1(void)
3、for(i=1;2;P2=data_weii;delay(1);void move_show2(void) 3;void move_show3(void) 4;void move_show4(void) 5;void move_show5(void) 6;void move_show6(void) void move_show7(void) 8;void move_show8(void) 9;/*数码管动态显示,实现数码管由18在八个数码管上一次显示*/ void move_show_hold(void) int temp,i;temp=1000;for(i=temp;i-) move_sho
4、w1();temp=600;move_show2();temp=400;move_show3();temp=200;move_show4();move_show5();move_show6();temp=100;move_show7();move_show8();void show_all(void) /将所有的位选端口打开,变化段选,显示整体变化19 P2=data_wei9;int main(void) while(1) / show_number_only();/move_show_hold(); / show_all();独立按键 #include sbit key1=P30; sbi
5、t d2=P10;int temp,number=0;j-) ;d2=1;key1=1;if(key1=0) delay(100);number+;if(number=7) temp=tempelse number=0;矩阵按键 #includechar data_duan=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x80,0xc6, 0xc0,0x86,0x8e,;/09 char data_wei=0xff,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0x00;int number=0
6、;/void move_show1(void) / / int i;/ for(i=1;i+) / P2=data_weii; / P0=data_duani; / delay(1);/ / /void move_show2(void) / P0=data_duani;void scan_key(void) int temp;P1=0xfe;temp=P1;temp=temp&0xf0;while(temp!=0xf0) switch(temp) case 0xe0:number=12;break;case 0xd0:number=13;case 0xb0:number=14;case 0x7
7、0:number=15;P1=0xfd;number=8;number=9;number=10;number=11;P1=0xfb;number=4;number=5;number=6;number=7;P1=0xf7;number=1;number=2;number=3;/ return number;int main(void) / int num=0;/ num=scan_key(num);scan_key();P0=data_duannumber;定时器中断 #include int number=0,time=0;/ TMOD=0x01;/设置工作方式定时器0 / TH0=(6553
8、6-50000)/256; /给计数器装初值 / TL0=(65535-50000)%256;/ EA=1; /开总中断 / ET0=1; /定时器T0中断允许 / TR0=1; /启动定时器0 TMOD=0x10;/设置工作方式定时器1 TH1=(65536-50000)/256; /给计数器装初值 TL1=(65535-50000)%256;EA=1; /开总中断 ET1=1; /定时器T1中断允许 TR1=1; /启动定时器1 if(number=20) P2=data_wei2;P0=data_duan4;if(time=40) P2=data_wei0;time=0;void ext
9、er3() interrupt 3 time+;/void exter1() interrupt 1 / time+;/ number+;时钟 #include variable) ;void alarm_show_s(void) int sign2;for(sign2=1;sign2sign2+) /数码管动态显示 S1=second%10;P2=data_weisign2;P0=data_duanS1;for(sign2=2;sign2+) S2=second/10;P0=data_duanS2;for(sign2=3;P0=0xbf;for(sign2=4;M1=minute%10;P0=data_duanM1;for(sign2=5;M2=minute/10;P0=data_duanM2;for(sign2=6;P2=data_wei
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1