單片機(jī)C語言編程:.H文件與.C文件的關(guān)系!
/*如下為鍵盤驅(qū)動的頭文檔*/#ifndef _KEY_H_ //防重復(fù)引用,如果沒有定義過_KEY_H_,則編譯下句#define _KEY_H_ //此符號唯一, 表示只要引用過一次,即#i nclude,則定義符號_KEY_H_/////////////////////////////////////////////////////////////////char keyhit( void ); //擊鍵否unsigned char Keyscan( void ); //取鍵值////////////////////////////////////////////////////////////////#endif
二、盡量使用宏定義#define
#define KEYNUM 65//按鍵數(shù)量,用于Keycode[KEYNUM]#define LINENUM 8//鍵盤行數(shù)#define ROWNUM 8//鍵盤列數(shù)
static unsigned char sts;//按鍵狀態(tài)變量static unsigned char Nowkeycode;//此時(shí)的鍵碼static unsigned char Prekeycode;//上一次的鍵碼static unsigned char Keydowntime;//矩形鍵盤按下去抖時(shí)間變量static unsigned char Keyuptime;//矩形鍵盤釋放去抖時(shí)間變量static unsigned char Onoffdowntime;//關(guān)機(jī)鍵按下去抖時(shí)間變量static unsigned char Onoffuptime;//關(guān)機(jī)鍵釋放去抖時(shí)間變量static unsigned char onoff_10ms; //判斷關(guān)機(jī)鍵中斷次數(shù)變量,累計(jì)150次大約為3S,因?yàn)榍昂筮M(jìn)了兩個10ms中斷
const unsigned char a=1;//定義a=1,編譯器不允許修改a的值作用:保護(hù)不希望被修改的參數(shù)const unsigned char Key_code[KEYNUM]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,0x40,0x41};//鍵碼const unsigned char Line_out[LINENUM]={0xFE,0xFD,0xFB,0xf7,0xEF,0xDF,0xBF,0x7F};//行輸出編碼const unsigned char Row_in[ROWNUM]={0xFE,0xFD,0xFB,0xf7,0xEF,0xDF,0xBF,0x7F};//列輸入編碼
static int i=0;int main(void){...while (1){if (i)dosomething();}}/* Interrupt service routine. */void ISR_2(void){i=1;}
【1】沙子的逆襲——從二氧化硅到芯片
【2】大佬故事:初中開始學(xué)編程,大學(xué)畢業(yè)后直接進(jìn)微軟...
【3】漫畫科普:芯片是如何設(shè)計(jì)出來的
【4】你常用哪種軟件畫原理圖和PCB
【5】PCB大神的那些專屬技巧和風(fēng)騷走位
免責(zé)聲明:本文內(nèi)容由21ic獲得授權(quán)后發(fā)布,版權(quán)歸原作者所有,本平臺僅提供信息存儲服務(wù)。文章僅代表作者個人觀點(diǎn),不代表本平臺立場,如有問題,請聯(lián)系我們,謝謝!