style: code format

This commit is contained in:
IOsetting 2022-02-09 14:49:48 +08:00
parent 1dc7666b27
commit 3d22dac649

View File

@ -23,8 +23,6 @@
#include "fw_hal.h" #include "fw_hal.h"
#include <string.h> #include <string.h>
#define MAIN_Fosc 24000000L
#define Timer0_Reload (65536UL -(MAIN_Fosc / 1000)) //Timer 0 frequency 1000Hz
#define KeyIO P0 #define KeyIO P0
__BIT B_1ms; // 1ms flag __BIT B_1ms; // 1ms flag
@ -53,7 +51,6 @@ void USB_Init(void);
void KeyScan(void); void KeyScan(void);
void SendKeyStatus(void); void SendKeyStatus(void);
void main() void main()
{ {
uint8_t i; uint8_t i;
@ -378,7 +375,7 @@ void SendKeyStatus(void)
if(KeyCode) // if key pressed if(KeyCode) // if key pressed
{ {
// 4*4 key matrixmax 3 keys pressed simultaneously // allow 3 keys pressed simultaneously
if(KeyCount(KeyCode) > 3) if(KeyCount(KeyCode) > 3)
{ {
return; // too many keys return; // too many keys
@ -462,19 +459,13 @@ P02 ---- K08 ---- K09 ---- K10 ---- K11 ----
P03 ---- K12 ---- K13 ---- K14 ---- K15 ---- P03 ---- K12 ---- K13 ---- K14 ---- K15 ----
| | | | | | | |
******************************************************/ ******************************************************/
void IO_KeyDelay(void)
{
uint8_t i;
i = 5;
while(--i);
}
void KeyScan(void) void KeyScan(void)
{ {
uint8_t temp; uint8_t temp;
KeyIO = 0x0F; KeyIO = 0x0F;
IO_KeyDelay(); SYS_DelayUs(1);
if ((KeyIO & 0x0F) == 0x0F) // no key pressed if ((KeyIO & 0x0F) == 0x0F) // no key pressed
{ {
NewKeyCode = 0; NewKeyCode = 0;
@ -483,27 +474,26 @@ void KeyScan(void)
{ {
// scan first line // scan first line
KeyIO = (uint8_t)~0x10; KeyIO = (uint8_t)~0x10;
IO_KeyDelay(); SYS_DelayUs(1);
// save 4 keys status // save 4 keys status
temp = KeyIO & 0x0F; temp = KeyIO & 0x0F;
// second line // second line
KeyIO = (uint8_t)~0x20; KeyIO = (uint8_t)~0x20;
IO_KeyDelay(); SYS_DelayUs(1);
// save 4 keys status
temp |= KeyIO << 4; temp |= KeyIO << 4;
// save current key status // save current key status
NewKeyCode = (~temp) & 0xFF; NewKeyCode = (~temp) & 0xFF;
// scan third line // third line
KeyIO = (uint8_t)~0x40; KeyIO = (uint8_t)~0x40;
IO_KeyDelay(); SYS_DelayUs(1);
temp = KeyIO & 0x0F; temp = KeyIO & 0x0F;
// scan 4th line // 4th line
KeyIO = (uint8_t)~0x80; KeyIO = (uint8_t)~0x80;
IO_KeyDelay(); SYS_DelayUs(1);
temp |= KeyIO << 4; temp |= KeyIO << 4;
// save all 16 keys' status in 2 bytes, 1 indicates key pressed // save all 16 keys' status in 2 bytes, 1 indicates key pressed