EDN首页   博客首页

日志档案

发表于 2007-4-19 18:47:21

7

标签: 键盘驱动  键盘扫描  

键盘驱动

 

超逼真PDF下载版:

                            pdf

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

#include<reg52.h>

#include<intrins.h>

 

#define display  P1

#define keyboardCode  P2

#define uint  unsigned int

#define uchar unsigned char

 

uchar code initialKeyboardCode[] = { 0xef, 0xdf, 0xbf, 0x7f };                   //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();

       }

}

 

系统分类: 单片机   |   用户分类: 单片机开发   |   来源: 原创   |   【推荐给朋友】   |   【添加到收藏夹】

    阅读(719)    回复(2)  

投一票您将和博主都有获奖机会!

最新评论

  • 545

    2007-4-24 11:40:47

    好呀,真不错,多谢了。

  • goop

    2007-4-24 11:42:07

    你好呀。