📄 gpio.c
字号:
#include <pic.h>
#include "..\inc\include.h"
#include "..\lib\GPIO.h"
volatile uchar KeyValue; //
volatile uchar KeyEvent; //
static void Delay(uchar t)
{
uchar i;
int j;
i = t;
while(i--){
j = 1000;
while(j--);
}
}
void Port_Init(void)
{
#if defined(_16F737) || defined(_16F747) || defined(_16F767) || defined(_16F777)
ADCON1 |= 0x0F; //pins config as digital IO instead of anolog input pins
#endif
//---Port A---
//---Port B---
RBPU = 0; //PORTB Pull-up
TRISB |= 0xF0; //RB4~7 input
TRISB &= 0xF0; //RB0~3 output
TRISB0 = 0; //LED(RB0) output
LED = 0;
//---Port C---
TRISC6 = 0; //RC6/TxD output
//---Port D---
}
void KeyScan(void)
{
Delay(20); //延时消抖
if((!KEY_DEC) || (!KEY_INC) || (!KEY_POWER)){ //按下按键
//LED2 = !LED2;
LED = OFF; //按键时LED闪烁一下(开始)
KeyValue = (uchar)((!KEY_DEC<<2) | (!KEY_INC<<1) | (!KEY_POWER<<0));
KeyEvent = KEY_PRESSED;
}
else if(KeyValue & 0x07) { //松开按键
//LED3 = !LED3;
KeyValue = KeyValue; //按键值不变,留待处理
KeyEvent = KEY_RELEASED;
} else { //误触发
KeyValue = 0;
KeyEvent = KEY_IDLE;
}
PORTB = PORTB;
RBIF = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -