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