# define uint unsigned int
Void delayms (uint XMS);
Void keyscan ();
Void main ()
{
While (1)
{
Keyscan ();
}
}
Void keyscan ()
{
P0=0 xf0;
If (P0==0 xe0-0xfc)
{
Delayms (10);
If (P0==0 xe0-0xfc)
{
P0=0 x0f;
If (P0==0 x07)
{
P1=0 x18;
The P2=0 x1a;
while(! P0);
}
If (P0==0 x0b)
{
P1=0 x11;
The P2=0 x13;
while(! P0);
}
If (P0==0 x0d)
{
P1=0 x19;
The P2=0 x0b;
while(! P0);
}
If (P0==0 x0e)
{
P1=0 x01;
The P2=0 x08;
while(! P0);
}
}
}
If (P0==0 xd0)
{
Delayms (10);
If (P0==0 xd0)
{
P0=0 x0f;
If (P0==0 x07)
{
P1=0 x11;
The P2=0 x1a;
while(! P0);
}
If (P0==0 x0b)
{
P1=0 x01;
The P2=0 x08;
while(! P0);
}
If (P0==0 x0d)
{
P1=0 x09;
The P2=0 x18;
while(! P0);
}
}
}
}
Void delayms (uint XMS)
{
Uint I, j;
For (I=XMS; i> 0; I -)
For (j=110; J> 0; J -);
}
CodePudding user response:
In general, matrix keyboard to provide a low level signal, low pull IO,If (P0==0 xe0-0xfc)
{
P0=0 x0f;
If (P0==0 x07)
Don't know what are you change P0 level, you should see procedure is P0 as key input, the program do you use the fixed level, key natural role, don't know you don't pull up resistors P0 answered