pushbuttonproc.c

来自「在WinAVR下的ST7565圖形點陣的驅動程序」· C语言 代码 · 共 77 行

C
77
字号
//包含所需头文件
#include "config.h"


uint8 ScanKeyBoard(void)
{
    uint8 Scan_Out=0x20, Scan_In, i;    
    
    PB_SCAN_PORT &= ~PB_SCAN_MASK;
    NOP();
    Scan_In = PB_READ_PORT & PB_READ_MASK;
    if(Scan_In == PB_READ_MASK)     // 没有按键按下
        return NO_VALUE;

    for(i=0; i<3; i++)
    {
        PB_SCAN_PORT |= PB_SCAN_MASK;
        PB_SCAN_PORT &= ~Scan_Out;
        NOP();
        Scan_In = PB_READ_PORT & PB_READ_MASK;
        if(Scan_In != PB_READ_MASK)     
        {
            return (~PB_READ_PORT & (PB_SCAN_MASK|PB_READ_MASK));
        }
        Scan_Out <<= 1;
    }
    return NO_VALUE;
}


void GetPushButtonValue(void)
{
    static uint8 KeyTemp, PreKeyValue;
    static uint16 KeyTimer;

    KeyTemp = ScanKeyBoard();

    if(KeyTemp == NO_VALUE)
    {
        PreKeyValue = NO_VALUE;
    }
    else
    {
        if(KeyTemp == PreKeyValue)
        {
            KeyTimer ++;
            if(KeyTimer == 0x02)
            {
                KeyValue = KeyTemp;
                SysFlag.KeyValid = 1;
            }
        }
        else
        {
            KeyTimer = 0;
            PreKeyValue = KeyTemp;
        }
    }
}


void PushButton_Proc(void)
{
    if(SysFlag.KeyValid)
    {
        SysFlag.KeyValid = 0;
        switch(KeyValue)
        {
            case S1_VALUE:
                NOP();
                break;

            default:break;
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?