#include <reg52.h>
sbit key1=P3^0;//定义按键位置 sbit key2=P3^1; sbit key3=P3^2; sbit key4=P3^3;
unsigned char const dofly[]={0xf9,0xb0,0x92,0x80};// code table 1358 //////////////////////////////////////////////////////// void delay(unsigned int cnt) { while(--cnt); } /////////////////////////////////////////////////////// main() {
P2=0x00;//数码管全亮 while(1) { if(!key1) //按下相应的按键,数码管显示相应的码值 P0=0xf9;//数码管显示"1" if(!key2) P0=0xa4;//2 if(!key3) P0=0xb0;//3 if(!key4) P0=0x99;//4
} }//如果有干扰请加去抖程序 //红外接收头部分用黑色物质遮光,防止干扰按键
|