EV1527解码,我也贡献一个,抗干扰,自适应, 经测试比买的解码成功率高,具体多少没计算,通过示波器看到; /* 中断处理函数 、每次中断查询一下电平; 手册16个CLK(一个数据位)的时间是 最大4.24ms(4240us)/16= 265us; 最小230us/16=14us; 分频时间是4us; ; 同步头高电平至少4个时钟;识别同步头分2步 第一步高电平时间大于等于40us,小于265*4*1.2 = 1060*1.2=1270us; 第二步 低电平时间是高电平时间的31倍,留20%余量26倍-36倍之间; 计算电平时间 (高电平时间 + 低电平时间) / 32 ; 数据宽时间要在这个数值的 正负20% 之间 */ INTERRUPT_HANDLER(EXTI_PORTA_IRQHandler, 3) { static U16 data_h_time; // static U16 data_l_time; // static U16 bit_time_min; static U16 bit_time_max; static U8 decode_KEY; static U32 decode_ID; U16 temp; static U8 ev1527_rx_last; U16 ev1527_new_time; disableInterrupts(); ev1527_new_time = (uint16_t)TIM2->CNTRH << 8; ev1527_new_time |= (uint16_t)(TIM2->CNTRL); if(EV1527_RX) //接收编码高电平 { if(ev1527_rx_last==0) //上次是低电平,有跳变 { EV1527_COUNT_CLEAR; if(ev1527_decode_state>sync_h) { str_ev1527_data.l_data[str_ev1527_data.l_data_write] = ev1527_new_time; str_ev1527_data.l_data_write = (str_ev1527_data.l_data_write + 1) % EV1527_DATA_TIME_NUM; switch(ev1527_decode_state) { case sync_l:{ temp = str_ev1527_data.l_data[str_ev1527_data.l_data_read] / str_ev1527_data.h_data[str_ev1527_data.h_data_read]; if((temp >= SYNC_RATIO_MIN) && (temp <= SYNC_RATIO_MAX)) { temp = str_ev1527_data.l_data[str_ev1527_data.l_data_read] + str_ev1527_data.h_data[str_ev1527_data.h_data_read]; str_ev1527_data.h_data_read = (str_ev1527_data.h_data_read + 1) % EV1527_DATA_TIME_NUM; str_ev1527_data.l_data_read = (str_ev1527_data.l_data_read + 1) % EV1527_DATA_TIME_NUM; bit_time_min = temp / 9; bit_time_max = temp / 7; decode_ID = 0; decode_KEY = 0; data_h_time = 0; data_l_time = 0; ev1527_decode_state = chipid_0l; } else { ev1527_decode_state = sync_h; } }break; case chipid_0l: case chipid_1l: case chipid_2l: case chipid_3l: case chipid_4l: case chipid_5l: case chipid_6l: case chipid_7l: case chipid_8l: case chipid_9l: case chipid_10l: case chipid_11l: case chipid_12l: case chipid_13l: case chipid_14l: case chipid_15l: case chipid_16l: case chipid_17l: case chipid_18l: case chipid_19l: { data_h_time += str_ev1527_data.h_data[str_ev1527_data.h_data_read]; data_l_time += str_ev1527_data.l_data[str_ev1527_data.l_data_read]; str_ev1527_data.l_data_read = (str_ev1527_data.l_data_read + 1) % EV1527_DATA_TIME_NUM; str_ev1527_data.h_data_read = (str_ev1527_data.h_data_read + 1) % EV1527_DATA_TIME_NUM; temp = data_h_time + data_l_time; if(temp >= bit_time_min) { if(temp <= bit_time_max) { if(data_h_time > data_l_time) { decode_ID |= 0x01; } decode_ID <<= 1; ev1527_decode_state++; data_h_time = 0; data_l_time = 0; } else { ev1527_decode_state = sync_h; } } }break; case data_0l: case data_1l: case data_2l: case data_3l: { data_h_time += str_ev1527_data.h_data[str_ev1527_data.h_data_read]; data_l_time += str_ev1527_data.l_data[str_ev1527_data.l_data_read]; str_ev1527_data.l_data_read = (str_ev1527_data.l_data_read + 1) % EV1527_DATA_TIME_NUM; str_ev1527_data.h_data_read = (str_ev1527_data.h_data_read + 1) % EV1527_DATA_TIME_NUM; temp = data_h_time + data_l_time; if(temp >= bit_time_min) { if(temp <= bit_time_max) { if(data_h_time > data_l_time) { decode_KEY |= 0x08; } if(ev1527_decode_state == data_3l) { ev1527_chip_ID = decode_ID; ev1527_chip_key = decode_KEY; ev1527_new_sms = 1; LED_ON(LED_01); ev1527_decode_state = sync_h; } else { decode_KEY >>= 1; ev1527_decode_state++; } data_h_time = 0; data_l_time = 0; } else { ev1527_decode_state = sync_h; } } }break; } } } ev1527_rx_last = 1; } else //接收编码低电平 { if(ev1527_rx_last) //上次是高电平,有跳变 { EV1527_COUNT_CLEAR; if(ev1527_decode_state == sync_h) { if((ev1527_new_time >= SYNC_H_TIME_MIN) && (ev1527_new_time <= SYNC_H_TIME_MAX)) { str_ev1527_data.l_data_read = str_ev1527_data.l_data_write=0; str_ev1527_data.h_data_read = str_ev1527_data.h_data_write=0; str_ev1527_data.h_data[str_ev1527_data.h_data_write] = ev1527_new_time; str_ev1527_data.h_data_write = (str_ev1527_data.h_data_write + 1) % EV1527_DATA_TIME_NUM; ev1527_decode_state = sync_l; } } else { str_ev1527_data.h_data[str_ev1527_data.h_data_write] = ev1527_new_time; str_ev1527_data.h_data_write = (str_ev1527_data.h_data_write + 1) % EV1527_DATA_TIME_NUM; } } ev1527_rx_last = 0; } enableInterrupts(); }
最新回复 [0]