《51单片机键盘、闪烁灯、点阵程序.doc》由会员分享,可在线阅读,更多相关《51单片机键盘、闪烁灯、点阵程序.doc(9页珍藏版)》请在金锄头文库上搜索。
1、51单片机键盘、点阵程序点阵程序#include unsigned char tabx=0xf7,0xf7,0x80,0xf7,0xf7,0xff,0xff,0xff, 0xf7,0xf7,0x80,0xf7,0xf7,0xff,0xff,0xff, 0xf7,0xf7,0x80,0xf7,0xf7,0xff,0xff,0xff, 0xff,0xf7,0xf7,0x80,0xf7,0xf7,0xff,0xff, 0xff,0xff,0xf7,0xf7,0x80,0xf7,0xf7,0xff, 0xff,0xff,0xf7,0xf7,0x80,0xf7,0xf7,0xff, 0xff,0xff,
2、0xff,0xf7,0xf7,0x80,0xf7,0xf7 ; unsigned char taby=0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f, 0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f, 0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f, 0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f, 0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f, 0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f, 0xf
3、e,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f;unsigned char i,j,k;unsigned int a,b; void delay(unsigned int z ) for(a=z;a0;a-) for(b=110;b0;b-); void display() while(1) P1=tabyi; P0= tabxj; delay(5); P0=0X00; P1=0XFF; i+; if(i=56) i=0; j+; if(j%16)=0) delay(10); if(j%56)=0) delay(500); if(j=56) delay(200); j
4、=0; void main() while(1) display(); delay(5); 键盘程序#includereg51.hsbit key1 = P37;sbit key2 = P36;sbit key3 = P35;sbit key4 = P34;sbit key5 = P33;sbit key6 = P32;sbit led1 = P20;sbit led2 = P21;sbit led3 = P22;sbit led4 = P23;#define uchar unsigned char uchar i;void main(void) while(1) if (key1=0) le
5、d1=0; led2=1; if (key2=0) led1=1; led2=0; if (key3=0) led3=0; led4=0; if (key4=0) led3=1; led4=1; if (key5=0) led1=0; led2=0; led3=0; led4=0; if (key6=0) led1=1; led2=1; led3=1; led4=1; 闪烁灯#includesbit P1_0=P10; void delay02s(void) unsigned char i,j,k; for(i=20;i0;i-) for(j=20;j0;j-) for(k=248;k0;k-); void main(void) while(1) P1_0=0; delay02s(); P1_0=1; delay02s(); 流水灯#include #include unsigned char a,b,k,j;sbit beep=P23;void delay10ms() for(a=100;a0;a-) for(b=225;b0;b-); void main() k=0xfe; while(1) delay10ms(); beep=0; delay10ms(); beep=1; j=_crol_(k,1); k=j; P1=j;