標題: 51單片機獨立按鍵C程序 [打印本頁]
作者: test20190611 時間: 2019-6-11 11:15
標題: 51單片機獨立按鍵C程序
#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
}
}//如果有干擾請加去抖程序
//紅外接收頭部分用黑色物質遮光,防止干擾按鍵
| 歡迎光臨 (http://m.raoushi.com/bbs/) |
Powered by Discuz! X3.1 |