板子是stc89c52
代码是我自己写的
可就是出不来,没用,求指教
- #include<reg51.h>
- typedef unsigned int u16;
- #define GPIO_DIG P0
- #define GPIO_KEY P1
- sbit LSA=P2^2;
- sbit LSB=P2^3;
- sbit LSC=P2^4;
- sbit beep=P1^5;
- sbit led=P2^0;
- unsigned char code DIG_CODE[17]={
- 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
- unsigned char KeyValue;
- unsigned char KeyState;
- unsigned char DisplayData[8];
- unsigned char password[8]={1,2,3,4,5,6,7,8};
- void Delay10ms();
- void KeyDown();
- void DigDisplay();
- void bijiao();
- void zhengque();
- void cuowu();
- ////////////////////////////////////////
- void main(void)
- {
- int i;
- KeyState=0;
- for(i=0;i<8;i++)
- {
- KeyDown();
- if(KeyState==1)
- {
- DisplayData[7]=DisplayData[6];
- DisplayData[6]=DisplayData[5];
- DisplayData[5]=DisplayData[4];
- DisplayData[4]=DisplayData[3];
- DisplayData[3]=DisplayData[2];
- DisplayData[2]=DisplayData[1];
- DisplayData[1]=DisplayData[0];
- DisplayData[0]=DIG_CODE[KeyValue];
- KeyState=0;
- }
- DigDisplay();
- }
- KeyDown();
- if(KeyState==1)
- {
- if(KeyValue==16)
- bijiao();
- }
- }
- ////////////////////////////////////////
- //·ù÷
- void delay(u16 i)
- {
- while(i--);
- }
- void shengyin()
- {
- int num=0;
- EA=1;
- ET0=1;
- TMOD=0x01;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- TR0=1;
-
-
- beep=~beep;
- delay(50);
- if(num==10)
- beep=1;
- }
- void timer0() interrupt 1 //50ms
- {
- int num;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- num++;
- }
- ////////////////////////////////////////
- //
- void bijiao()
- {
- int i,a=0;
- for(i=0;i<8;i++)
- {
- if(DisplayData[i]== password[i])
- { a=a+1; }
- else
- { a=a; }
- }
- if(a==8)
- { zhengque(); }
- else
- { cuowu(); }
- }
- void zhengque()
- {
- DisplayData[0]=~0x3f; // "o"
- DisplayData[1]=~0x73; // "p"
- DisplayData[2]=~0x79; // "E"
- DisplayData[3]=~0x54; // "n"
- DigDisplay();
- }
- void cuowu()
- {
- DisplayData[2]=~0x79; // "E"
- DisplayData[3]=~0x50; // "r"
- DisplayData[4]=~0x50; // "r"
- DigDisplay();
- shengyin();
- led=1;
- }
-
- //
- void DigDisplay()
- {
- unsigned char i;
- unsigned int j;
- 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;
- }
- GPIO_DIG=DisplayData[i];
- j=10;
- while(j--);
- GPIO_DIG=0x00;
- }
- }
- //////////////////////////////////////
- //ì°ü
- void KeyDown(void)
- {
- unsigned int a=0;
- GPIO_KEY=0x0f;
- if(GPIO_KEY!=0x0f)
- {
- Delay10ms();
- a++;
- a=0;
- if(GPIO_KEY!=0x0f)
- {
- KeyState=1;
- GPIO_KEY=0X0F;
- Delay10ms();
- switch(GPIO_KEY)
- {
- case(0X07): KeyValue=0;break;
- case(0X0b): KeyValue=1;break;
- case(0X0d): KeyValue=2;break;
- case(0X0e): KeyValue=3;break;
- default: KeyValue=17;
- }
- GPIO_KEY=0XF0;
- Delay10ms();
- switch(GPIO_KEY)
- {
- case(0X70): KeyValue=KeyValue;break;
- case(0Xb0): KeyValue=KeyValue+4;break;
- case(0Xd0): KeyValue=KeyValue+8;break;
- case(0Xe0): KeyValue=KeyValue+12;break;
- default: KeyValue=17;
- }
- while((a<500)&&(GPIO_KEY!=0xf0))
- {
- Delay10ms();
- a++;
- }
- a=0;
- }
- }
- }
- ///////////////////////////////
- //±10ms
- void Delay10ms(void)
- {
- unsigned char a,b,c;
- for(c=1;c>0;c--)
- for(b=38;b>0;b--)
- for(a=130;a>0;a--);
- }
复制代码 |