数码管移位显示
#include<reg51.h>
typedef unsigned int u16;
typedef unsigned char u8;
//管腳定義
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
u8 KeyValue;
u8 keystate;
u8 code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//顯示0~F的值
u8 display[8];
//延時
void delay(u16 i)
{while(i--);
}void juzhen()
{u8 a=0; P1=0x0f;if(P1!=0x0f){delay(1);P1=0x0f;if(P1!=0x0f){ keystate=1;switch(P1){case 0x07:KeyValue=0;break;case 0x0b: //00001011KeyValue=1;break;case 0x0d: //00001101KeyValue=2;break;case 0x0e:KeyValue=3;break;}P1=0xf0;switch(P1){case 0x70:KeyValue=KeyValue;break;case 0xb0: //00001011KeyValue=KeyValue+4;break;case 0xd0: //00001101KeyValue=KeyValue+8;break;case 0xe0:KeyValue=KeyValue+12;break;}while((a<50)&&(P1=0xf0)) //檢測按鍵松手檢測{delay(1000);a++;} }}
}
void display1()
{u8 i;for(i=0;i<8;i++){switch(i){case 0:LSA=0;LSB=0;LSC=0;break;case 1:LSA=1;LSB=0;LSC=0;break;case 2:LSA=0;LSB=1;LSC=0;break;case 3:LSA=1;LSB=1;LSC=0;break;case 4:LSA=0;LSB=0;LSC=1;break;case(5):LSA=1;LSB=0;LSC=1;break;case(6):LSA=0;LSB=1;LSC=1;break;case(7):LSA=1;LSB=1;LSC=1;break;}P0=display[i];delay(100);P0=0x00;}
}void main()
{while(1){juzhen();if(keystate==1){display[7]=display[6];display[6]=display[5];display[5]=display[4];display[4]=display[3];display[3]=display[2];display[2]=display[1];display[1]=display[0];display[0]=smgduan[KeyValue];keystate=0;}delay(100);display1();}
}
轉載于:https://www.cnblogs.com/tanghaojie/p/11093549.html
總結
- 上一篇: 设计模式整理之简单工厂
- 下一篇: 3-无重复字符的最长子串(中等)