原创 键盘驱动

2007-4-19 18:47 2801 5 5 分类: MCU/ 嵌入式

 


超逼真PDF下载版:


                            pdf


即时复制版(这里没英文注释,想要注释版请下载上面文件):


#include<reg52.h><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />


#include<intrins.h>


 


#define display  P1


#define keyboardCode  P2


#define uint  unsigned int


#define uchar unsigned char


 


uchar code initialKeyboardCode[] = { 0xef, 0xdf, 0xbf, 0x<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />7f };                   //Set the initial keyboard code.


uchar code getKeyboardCode[] = { 0xee, 0xed, 0xeb, 0xe7, 0xde, 0xdd, 0xdb, 0xd7,  //When the keyboard pressed


0xbe, 0xbd, 0xbb, 0xb7, 0x7e, 0x7d, 0x7b, 0x77 }; // down ,the mcu will get one of them.


uchar code theActionCode[] = { 0xf7, 0xf4, 0xf1, 0xf0, 0xf8, 0xf5, 0xf2, 0xf0,  //The display code, you can rewrite


0xf9, 0xf6, 0xf3, 0xf0, 0xf8, 0xf5, 0xf2, 0xf0 }; // them if you want . But the code you rewrite must correspondence


// with the ”getkeyboardCode”.


 


void KeyboardScan(void)


{


    uchar sender = 0x00;


    uchar counterOne = 0x00;


       uchar counterTwo = 0x00;


 


       for(counterOne=0x00; counterOne<4; counterOne++)


       {


              keyboardCode = initialKeyboardCode[counterOne]; //Load the initialKeyboardCode


              sender = keyboardCode;                          //Get the keyboardCode when the keyboard press down


            //perhaps a delay here.


                     for(counterTwo=0x00; counterTwo<16; counterTwo++)


                     {


                            if(sender==getKeyboardCode[counterTwo]) //When a geyKeyboardCode equal to the sender ,


                            {                                    


                                   display = theActionCode[counterTwo];//Then load the display code from the theActioncode


                    //You can write you control functions here too.


                }                          


                     }                                                    


        }   


}


 


//The test main function.


void main(void)


{


    display = 0x00;


       while(1)


       {


              KeyboardScan();


       }


}


 


文章评论0条评论)

登录后参与讨论
我要评论
0
5
关闭 站长推荐上一条 /2 下一条