日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 單片機 > 單片機
[導讀]//***************精典按鍵處理程序*********************\\\\//單片機型號STC12C5204AD //按鍵輸入口:P2^0,P2^1 //輸出端口:P2^2#include #define null 0x00 #define bit_0 0x01 #define bit_1 0x02 #define

//***************精典按鍵處理程序*********************\

//單片機型號STC12C5204AD
//按鍵輸入口:P2^0,P2^1
//輸出端口:P2^2

#include


#define null 0x00
#define bit_0 0x01
#define bit_1 0x02
#define bit_2 0x04
#define bit_3 0x08
#define bit_4 0x10
#define bit_5 0x20
#define bit_6 0x40
#define bit_7 0x80
#define uchar unsigned char
#define suchar static unsigned char
#define uint unsigned int
#define suint static unsigned int
#define cuchar const unsigned char

#define uchar unsigned char
sbit OUT_LIGHT = P2^2; //定義背光驅(qū)動口

bit LOCK=0;
char keybitbuf;


//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
typedef struct // 按鍵處理用
{ uchar timebuf[8];
uchar hadpresskey;
} PressKey;
PressKey presskey;

#define WAITCIRCLETIMENUM 10// 20 //等待延時次數(shù)

/*按鍵檢測*/
char lookForKey(PressKey *b,uchar *a,uchar BITNUM)
{ uchar m,n;
n=BITNUM,m=0;
while (!(n&1)) { m+=1;n=n>>1;}
if (b->hadpresskey&(*a)&BITNUM)
{ b->hadpresskey&=~BITNUM;
return(BITNUM);
}
else { if (*a&BITNUM)
{ b->timebuf[m]=0;
b->hadpresskey&=~BITNUM;
}
else { if (b->timebuf[m]>=WAITCIRCLETIMENUM )
{ b->hadpresskey|=BITNUM;
b->timebuf[m]=0;
}
else {b->timebuf[m]++; }
}
}
return(0);
}

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//程序的調(diào)用
void main()
{
while(1)
{
keybitbuf=P2; //P2表示單片機的P2口
if (lookForKey(&presskey,&keybitbuf,0x02)) {OUT_LIGHT=~OUT_LIGHT;} //0X02表示P2.1口,0X01表示P2.0,0X04表示P2.2 ,0X08表示P2.3,0X10表示P2.4
if (lookForKey(&presskey,&keybitbuf,0x01)) {OUT_LIGHT=~OUT_LIGHT; ;}
if (lookForKey(&presskey,&keybitbuf,0x20)) { ;}
}
}

本站聲明: 本文章由作者或相關(guān)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉