1481509156 发表于 2024-8-21 20:01 用示波器看下定时时间对不对, 简单一些用那种8路输入的逻辑分析仪也可以的 |
你这个是无解的. 放弃吧, 遥控分固定码和滚动码. 看波形, 你这每一帧都不一样的. 是滚动码, 不懂它的滚动算法, 是不能解码的 |
xmcolong 发表于 2024-8-21 19:00 我这配置有问题吗?我这边IO脚收到波形,然后也能进入中断(在中断点灯和定时器判断为1时关灯,灯是闪烁的),但解码部分解不出来 |
我用100us 都可以的, 50us也是没有问题的 |
xmcolong 发表于 2024-8-21 02:02 那个注释是错误的,我这里定时器1是定时50us检测一次的 |
if(INTFbits.T1IF) // 定时器0中断 132 = 1MS ................................................................................................................. 定时时间太长了, 改us的! |
fj51hei 发表于 2024-8-20 16:59 是的,电平脉宽高一样,是由低电平时长部分决定0/1 |
coody_sz 发表于 2024-8-20 15:31 这个只是脉宽不同吧? |
xiaobendan001 发表于 2024-8-20 08:30 大佬,我按照如下模式写了解码,没生效,帮忙看下哪里的问题 void main(void) { GPIO_INIT(); DISI(); // 禁用所有未屏蔽的中断 //AWUCON = 0X80; //0010 0000 // TMR0 = 0; // 加载0x00到TMR0(初始定时器寄存器) //T0MD = 0X01; // 将precaler0赋给Timer0, precaler0分割率= 1:8,时钟源为指令时钟 //INTE = 0X01; // 使能定时器0中断&PABIE状态变化中断 //;启用Timer0和全局中断位 //PCON1 = C_TMR0_En; // 启用Timer0 ENI(); while(1) { CLRWDT(); RX_SHUT=0; CLRWDT(); Timer1_INIT(); soft_decodetask(); } } void isr(void) __interrupt(0) { if(INTFbits.T1IF) // 定时器0中断 132 = 1MS { if(RFDecodeOK == 0) { if(!RX_DATA) { IR_Time_L++; IR_Time_H=0; if(JumpFlag && IR_Time_L > 4) { JumpFlag=0; } } else { IR_Time_H++; if(!JumpFlag && IR_Time_H > 4) { JumpFlag=1; soft_decode(); IR_Time_L=0; IR_Time_H=0; } } } INTF= (unsigned char)~(C_INT_TMR1); // 清除T0IF标志位 } } /******************************定时器配置*************************************************/ void Timer1_INIT(void) { TMRH = 0; TMR1 = 50; //50us T1CR1 = 0x03; T1CR2 = C_TMR1_ClkSrc_Inst | C_PS1_Div4; INTE = 0x08; } /******************************中断*************************************************/ void soft_decode() //解码 { static unsigned char RxBitCnt = 0; //接收数据位 static unsigned long RxData = 0; //数据缓冲 if(IR_State==0) { if((IR_Time_L >= 19) && (IR_Time < 25)) { IR_State=1; RxData=0; RxBitCnt=0; } else { IR_State=0; } } else if(IR_State==1 && RxBitCnt < 32) { if((IR_Time_L > 6) && (IR_Time_L < 9)) { RxData = RxData<<1; RxBitCnt++; } else if((IR_Time_L > 11) && (IR_Time_L < 14)) { RxData = RxData<<1; RxData |=1; RxBitCnt++; } else { RxBitCnt=0; IR_State=0; } if(IR_cnt>=32) { RxBitCnt=0; IR_State=0; RxUserCode = RxData >> 24; if(RxUserCode == K1_NUM1) { RFDecodeOK = 1; RX_flag = 1; } else if(RxUserCode == K1_NUM2) { RFDecodeOK = 1; RX_flag = 2; } else if(RxUserCode == K2_NUM1) { RFDecodeOK = 1; RX_flag = 3; } else if(RxUserCode == K2_NUM2) { RFDecodeOK = 1; RX_flag = 4; } } } } void soft_decodetask(void) { static unsigned int RxTimerCnt = 0; if(RFDecodeOK) { RFDecodeOK = 0; if(RX_flag==1){LED123=0;} if(RX_flag==2){LED123=1;} if(RX_flag==3){LED123=0;} if(RX_flag==4){LED123=1;} } if(RFDecodeOK) { RxTimerCnt++; if(RxTimerCnt >= 2000) { RxTimerCnt=0; RFDecodeOK=0; } } } |
coody_sz 发表于 2024-8-20 15:31 大哥,帮忙看下我这程序为啥不生效 |
coody_sz 发表于 2024-8-20 15:31 void main(void) { GPIO_INIT(); DISI(); // 禁用所有未屏蔽的中断 //AWUCON = 0X80; //0010 0000 // TMR0 = 0; // 加载0x00到TMR0(初始定时器寄存器) //T0MD = 0X01; // 将precaler0赋给Timer0, precaler0分割率= 1:8,时钟源为指令时钟 //INTE = 0X01; // 使能定时器0中断&PABIE状态变化中断 //;启用Timer0和全局中断位 //PCON1 = C_TMR0_En; // 启用Timer0 ENI(); while(1) { CLRWDT(); RX_SHUT=0; CLRWDT(); Timer1_INIT(); soft_decodetask(); } } void isr(void) __interrupt(0) { if(INTFbits.T1IF) // 定时器0中断 132 = 1MS { if(RFDecodeOK == 0) { if(!RX_DATA) { IR_Time_L++; IR_Time_H=0; if(JumpFlag && IR_Time_L > 4) { JumpFlag=0; } } else { IR_Time_H++; if(!JumpFlag && IR_Time_H > 4) { JumpFlag=1; soft_decode(); IR_Time_L=0; IR_Time_H=0; } } } INTF= (unsigned char)~(C_INT_TMR1); // 清除T0IF标志位 } } /******************************定时器配置*************************************************/ void Timer1_INIT(void) { TMRH = 0; TMR1 = 50; //50us T1CR1 = 0x03; T1CR2 = C_TMR1_ClkSrc_Inst | C_PS1_Div4; INTE = 0x08; } /******************************中断*************************************************/ void soft_decode() //解码 { static unsigned char RxBitCnt = 0; //接收数据位 static unsigned long RxData = 0; //数据缓冲 if(IR_State==0) { if((IR_Time_L >= 19) && (IR_Time < 25)) { IR_State=1; RxData=0; RxBitCnt=0; } else { IR_State=0; } } else if(IR_State==1 && RxBitCnt < 32) { if((IR_Time_L > 6) && (IR_Time_L < 9)) { RxData = RxData<<1; RxBitCnt++; } else if((IR_Time_L > 11) && (IR_Time_L < 14)) { RxData = RxData<<1; RxData |=1; RxBitCnt++; } else { RxBitCnt=0; IR_State=0; } if(IR_cnt>=32) { RxBitCnt=0; IR_State=0; RxUserCode = RxData >> 24; if(RxUserCode == K1_NUM1) { RFDecodeOK = 1; RX_flag = 1; } else if(RxUserCode == K1_NUM2) { RFDecodeOK = 1; RX_flag = 2; } else if(RxUserCode == K2_NUM1) { RFDecodeOK = 1; RX_flag = 3; } else if(RxUserCode == K2_NUM2) { RFDecodeOK = 1; RX_flag = 4; } } } } void soft_decodetask(void) { static unsigned int RxTimerCnt = 0; if(RFDecodeOK) { RFDecodeOK = 0; if(RX_flag==1){LED123=0;} if(RX_flag==2){LED123=1;} if(RX_flag==3){LED123=0;} if(RX_flag==4){LED123=1;} } if(RFDecodeOK) { RxTimerCnt++; if(RxTimerCnt >= 2000) { RxTimerCnt=0; RFDecodeOK=0; } } } |
不归零码吧?测量高低电平,判断在一定范围内,然后计算占空比,确定0或1。 315、433无线遥控我喜欢用曼彻斯特编码(归零码),归零码更适合幅度键控类无线遥控,距离更远,自适应解码,恢复时钟方便。 |
测量周期,长短不同 |