Delay
void Delay(unsigned int z)
{
int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
Key(独立键盘)
#include <REGX52.H>
#include "Delay.h"
unsigned char Key()
{
unsigned char KeyNum=0;
if(P3_4==0){
Delay(20);while(P3_4==0);Delay(20);KeyNum=1;}
if(P3_5==0){
Delay(20);while(P3_5==0);Delay(20);KeyNum=2;}
if(P3_6==0){
Delay(20);while(P3_6==0);Delay(20);KeyNum=3;}
if(P3_7==0){
Delay(20);while(P3_7==0);Delay(20);KeyNum=4;}
return KeyNum;
}
//char 型为八位能够更好的移植
MatrixKey(矩阵键盘)(无脑法)
#include <REGX52.H>
#include "Delay.h"
unsigned char MatrixKey