单片机独立键盘的使用,烧录后,按键没反应,换键重新烧录还是不行,程序如下:
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit key_S2 = P3^0;
sbit key_S3 = P3^1;
sbit DU = P2^6;
sbit WE = P2^7;
uchar code tabel[]= {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F,};
uchar num = 0;
void delay(uint z)
{
uint x,y;
for(x = z; x>0; x–)
for(y=114; y>0; y–);
}
void main()
{
WE = 1;
P0 = 0xfd;
WE = 0;
while(1)
{
if(key_S2 == 0)
{
delay(20);
if(key_S2 == 0)
{
if(num <=9)
num = num+1;
while(!key_S2);
}
}
if(key_S3 == 0)
{
delay(20);
if(key_S3 == 0)
{
if(num>0)
num = num-1;
while(!key_S3);
}
}
}
DU = 1;
P0 = tabel[num];
DU = 0;
}
烧录后,按键没反应,换键重新烧录还是不行