12MHZ
#include "reg52.h"
typedef unsigned int u16
typedef unsigned char u8
#define KEY_MATRIX_PORTP1
#define SMG_A_DP_PORTP0
u8 gsmg_code[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}
void delay_10us(u16 ten_us)
{
while(ten_us--)
}
u8 key_matrix_ranks_scan(void)
{
u8 key_value=0
KEY_MATRIX_PORT=0xf7
if(KEY_MATRIX_PORT!=0xf7)
{
delay_10us(1000)
switch(KEY_MATRIX_PORT)
{
case 0x77: key_value=1break
case 0xb7: key_value=5break
case 0xd7: key_value=9break
case 0xe7: key_value=13break
}
}
while(KEY_MATRIX_PORT!=0xf7)
KEY_MATRIX_PORT=0xfb
if(KEY_MATRIX_PORT!=0xfb)
{
delay_10us(1000)
switch(KEY_MATRIX_PORT)
{
case 0x7b: key_value=2break
case 0xbb: key_value=6break
case 0xdb: key_value=10break
case 0xeb: key_value=14break
}
}
while(KEY_MATRIX_PORT!=0xfb)
KEY_MATRIX_PORT=0xfd
if(KEY_MATRIX_PORT!=0xfd)
{
delay_10us(1000)
switch(KEY_MATRIX_PORT)
{
case 0x7d: key_value=3break
case 0xbd: key_value=7break
case 0xdd: key_value=11break
case 0xed: key_value=15break
}
}
while(KEY_MATRIX_PORT!=0xfd)
KEY_MATRIX_PORT=0xfe
if(KEY_MATRIX_PORT!=0xfe)
{
delay_10us(1000)
switch(KEY_MATRIX_PORT)
{
case 0x7e: key_value=4break
case 0xbe: key_value=8break
case 0xde: key_value=12break
case 0xee: key_value=16break
}
}
while(KEY_MATRIX_PORT!=0xfe)
return key_value
}
u8 key_matrix_flip_scan(void)
{
static u8 key_value=0
KEY_MATRIX_PORT=0x0f
if(KEY_MATRIX_PORT!=0x0f)
{
delay_10us(1000)
if(KEY_MATRIX_PORT!=0x0f)
{
KEY_MATRIX_PORT=0x0f
switch(KEY_MATRIX_PORT)
{
case 0x07: key_value=1break
case 0x0b: key_value=2break
case 0x0d: key_value=3break
case 0x0e: key_value=4break
}
KEY_MATRIX_PORT=0xf0
switch(KEY_MATRIX_PORT)
{
case 0x70: key_value=key_valuebreak
case 0xb0: key_value=key_value+4break
case 0xd0: key_value=key_value+8break
case 0xe0: key_value=key_value+12break
}
while(KEY_MATRIX_PORT!=0xf0)
}
}
else
key_value=0
return key_value
}
void main()
{
u8 key=0
while(1)
{
key=key_matrix_ranks_scan()
if(key!=0)
SMG_A_DP_PORT=gsmg_code[key-1]
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)