/*定义变量声明类型*/
#define u32 unsigned long
#define u16 unsigned int
#define u8 unsigned char
/*--------------以上为芯片底层定义正常情况下不可更改----------------------------*/
/*--------------以下为应用层定义按用户需求更改----------------------------------*/
/*芯片管脚映射*/
#define IO_SEGA IO_2 //
#define IO_K3 IO_2 //
#define IO_LED4 IO_2 //
#define IO_SEGB IO_3 //
#define IO_LED3 IO_3 //
#define IO_K2 IO_3 //
#define IO_K1 IO_4 //
#define IO_SEGF IO_5 //
#define IO_K5 IO_5 //
#define IO_LED5 IO_5 //
#define IO_SEGC IO_6 //
#define IO_LED2 IO_6 //
#define IO_SEGD IO_7 //
#define IO_LED1 IO_7 //
#define IO_SEGP IO_8 //
#define IO_BUZ IO_9 //
#define IO_COM3 IO_10 //
#define IO_COM1 IO_11 //
#define IO_COM2 IO_12 //
#define IO_SEGG IO_13 //
#define IO_K4 IO_13 //
#define IO_LED6 IO_13 //
#define IO_SEGE IO_14 //
#define IO_LED7 IO_14 //
#define IO_RELAY IO_15 //
#define IO_DATA IO_3
/*变量定义*/
//for key
volatile bit f_data_r_ok,f_fl;
volatile u8 u8_data_r_byte,u8_data_r_bit,u8_rl_cnt,u8_rh_cnt,u8_data_r,u8_data_r_step;
volatile u8 u8_data1,u8_data2,u8_data_r[2];
/*主程序*/
void main(void)
{
while(1)
{
if(f_data_r_ok)
{
u8_data1 = u8_data_r[0];
u8_data2 = u8_data_r[1];
f_data_r_ok = 0;
}
}
}
//中断服务函数
void interrupt Timer1_Isr(void)
{
if(TMR2IF)
{
TMR2IF = 0;
f_100us = 1;
if(f_data_r_ok==0)
{
if(DATA(IO_DATA))
{
u8_rh_cnt++;
if(u8_rh_cnt>=18)
{
u8_data_r_step = 0;
}
if(f_fl==0)
{
if(u8_data_r_step==1)
{
u8_data_r_step = 2;
u8_data_r_bit = 0;
u8_data_r_byte = 0;
}
else if(u8_data_r_step==2)
{
u8_data_r >>= 1;
if(u8_rh_cnt>u8_rl_cnt)
{
u8_data_r |= 0x80;
}
u8_data_r_bit++;
if(u8_data_r_bit>=8)
{
u8_data_r_bit = 0;
u8_data_r[u8_data_r_byte] = u8_data_r_bit;
u8_data_r_byte++;
if(u8_data_r_byte>=2)
{
f_data_r_ok = 1;
u8_data_r_step = 0;
}
}
}
u8_rh_cnt = 0;
u8_rl_cnt = 0;
}
f_fl = 1;
}
else
{
u8_rl_cnt++;
if(u8_rl_cnt>=18)
{
u8_data_r_step = 1;
}
f_fl = 0;
}
}
}
}