一、仿真原理图:
二、部分代码:
按键采集
uint8_t KeyScan(void)
{
uint8_t value = 0x00;
KeyPort->ODR = 0x00;
KeyPort->ODR = 0xf7;
if((KeyPort->IDR & 0xf0) != 0xf0)
{
HAL_Delay(50);
if((KeyPort->IDR & 0xf0) != 0xf0)
{
value = (KeyPort->IDR & 0xf7);
}
}
KeyPort->ODR = 0x00;
KeyPort->ODR = 0xfb;
if((KeyPort->IDR & 0xf0) != 0xf0)
{
HAL_Delay(50);
if((KeyPort->IDR & 0xf0) != 0xf0)
{
value = (KeyPort->IDR & 0xfb);
}
}
KeyPort->ODR = 0x00;
KeyPort->ODR = 0xfd;
if((KeyPort->IDR & 0xf0) != 0xf0)
{
HAL_Delay(50);
if((KeyPort->IDR & 0xf0) != 0xf0)
{
value = (KeyPort->IDR & 0xfd);
}
}
KeyPort->ODR = 0x00;