sop板
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

155 lines
1.9 KiB

#include "bsp_key.h"
#include "bsp_config_delay.h"
U8 bsp_key_init(void)
{
D_stdIO_P3(BITN6);
D_stdIO_P1(BITN7);
D_stdIO_P0(BITN6);
D_stdIO_P4(BITN3);
D_HighR_P1(BITN0);
D_HighR_P0(BITN7);
D_HighR_P1(BITN3);
D_HighR_P2(BITN0);
KR1 = KR2 = KR3 = KR4 = 1;
KC1 = KC2 = KC3 = KC4 = 1;
return 0;
}
void scan_row(U8 r)
{
KR1 = 0;
KR2 = 0;
KR3 = 0;
KR4 = 0;
switch(r){
case 1:
KR1 = 1;break;
case 2:
KR2 = 1;break;
case 3:
KR3 = 1;break;
case 4:
KR4 = 1;break;
default:
break;
}
}
U8 scan_col(U8 c)
{
if(c == 1)
{
if(KC1 == 1)
{
delayInMs(10);
if(KC1 == 1)
{
while(KC1 == 1);
return 1;
}
}
}
else if(c == 2){
if(KC2 == 1)
{
delayInMs(10);
if(KC2 == 1)
{
while(KC2 == 1);
return 1;
}
}
}
else if(c == 3){
if(KC3 == 1)
{
delayInMs(10);
if(KC3 == 1)
{
while(KC3 == 1);
return 1;
}
}
}
else if(c == 4){
if(KC4 == 1)
{
delayInMs(10);
if(KC4 == 1)
{
while(KC4 == 1);
return 1;
}
}
}
return 0;
}
U8 bsp_key_scan(void)
{
U8 key = BSP_KEY_NUM_MAX;
//扫描第1行
scan_row(1);
if(scan_col(1) > 0){
return 0;
}
if(scan_col(2) > 0){
return 1;
}
if(scan_col(3) > 0){
return 2;
}
if(scan_col(4) > 0){
return 3;
}
// //扫描第2行
// scan_row(2);
// if(scan_col(1) > 0){
// key = 4;
// }
// if(scan_col(2) > 0){
// key = 5;
// }
// if(scan_col(3) > 0){
// key = 6;
// }
// if(scan_col(4) > 0){
// key = 7;
// }
// //扫描第3行
// scan_row(3);
// if(scan_col(1) > 0){
// key = 8;
// }
// if(scan_col(2) > 0){
// key = 9;
// }
// if(scan_col(3) > 0){
// key = 10;
// }
// if(scan_col(4) > 0){
// key = 11;
// }
// //扫描第4行
// scan_row(4);
// if(scan_col(1) > 0){
// key = 12;
// }
// if(scan_col(2) > 0){
// key = 13;
// }
// if(scan_col(KC3) > 0){
// key = 14;
// }
// if(scan_col(KC4) > 0){
// key = 15;
// }
return key;
}