定时器外部中断红外通讯问题

void UartIRInit(void)
{
/*----set INTP3-----------------------------------------------------------*/
PIF3 = 0;
PM3.1 = 1;
EGP = 0x00; //EGP3=0
EGN = 0x08; //EPN3=1
PMK3 = 0; //enable interrupt
PPR3 = 1; //low priority
/*---set TMH1-------------------------------------------------------------*/
TMHMD1 = 0;
TMHMD1 = 0x30;//00110000
CMP01 = 103; //8000000/64/104=1201.92
TMMKH1 = 0; //enble interrupt
TMPRH1 = 0; //high priority
/*---set TMH0-------------------------------------------------------------*/
TMHMD0 = 0;
PM3.2 = 0;
P3.2 = 0;
CMP00 = 104;//8000000/(104+1) = 76.190K
TMHMD0 = 0x01;//enable output
TMMKH0 = 1; //disable interrupt
/*--------byte set--------------------------------------------------------*/
//RXIR=0;
//TXIR
UartIR.Monit500ms = 0;
UartIR.Monit5s = 0;
UartIR.Lapse30ms = 0;
FUartIR_RStart = 0;
FUartIR_REnd = 0;
FUartIR_Treat = 0;
FUartIR_Ting = 0;
}
__interrupt void IntP3(void)
{
CMP01 = 51;
TMHE1 = 1;
PMK3 = 1;
IRB = 0;//infrade buf
IRBits = 0;
IRParity = 0;
}
__interrupt void IntTMH1(void)
{
TMHE1 = 0;
CMP01 = 103;
TMHE1 = 1;
if (FUartIR_Ting == 1)
{
if (IRBits < 9) //data bit
{
if ((IRB&0x01) == 0x0)
TMHE0 = 1;
else
{
IRParity++; //even parity
TMHE0 = 0;
P3.2 = 0;
}
IRB >>= 1;
IRBits++;
}
else if (IRBits == 9) //parity bit
{
if (IRParity.0 == 0)
{
TMHE0 = 1;//even 1 bits,even parity is 0
}
else
{
TMHE0 = 0;
P3.2 = 0;
}
IRBits++;
}
else if (IRBits == 10)//stop bit
{
TMHE0 = 0;
P3.2 = 0;
IRBits++;
}
else if (IRBits == 11)
{
TMHE1 = 0;//end the transmit
#ifndef __IR30MS
if (UartIR.FENum != 0)
{
UartIR.FENum--;
IRB = 0xfe;
IRBits = 1; //start bit
IRParity = 0;
CMP01 = 103;
TMHE1 = 1;
TMHE0 = 1;
}
else if (UartIR.DataNum < (UartIR.Buf[9]+12))
{
IRB = UartIR.Buf[UartIR.DataNum++];
IRBits = 1;//start bit
IRParity = 0;
CMP01 = 103;
TMHE1 = 1;
TMHE0 = 1;//start bit
}
else
{
FUartIR_Ting = 0;
FUartIR_RStart = 0;
PIF3 = 0;
PMK3 = 0;//enable P5 interrupt
TMHE1 = 0;//stop TMH1
}
#endif
}
}
/*-----receive state------------------------------------------------------*/
else
{
if (IRBits == 0) //the first judge is 0.416ms
{
if (P3.1 == 1)//start bit is error
{
PMK3 = 0;
TMHE1 = 0;//end the receive
}
else
{
IRBits = 1;//++;
}
}
else if (IRBits < 9)//data bits
{
IRB >>= 1;
if (P3.1 == 1)
{
IRB |= 0x80;
IRParity++;
}
IRBits++;
}
else if (IRBits == 9) //parity bit
{
if (((P3.1==0)&&(IRParity.0==0)) ||
((P3.1==1)&&(IRParity.0==1))) //even check right
{
IRBits++;
}
else
{
PMK3 = 0;
TMHE1 = 0; //stop receive
IRBits = 0;
}
}
else//end bit
{
PMK3 = 0;//enable receive last byte
TMHE1 = 0;//because priority of TMH1 higher than P5
if (P3.1 == 1)//stop bit
{
UartIR.Monit500ms = 0;
UartIR.Monit5s = 0;
if (FUartIR_RStart == 0)
{
if (IRB == 0x68)
{
FUartCom = 1;
UartIR.Buf[0] = 0x68;
UartIR.DataNum = 1;
FUartIR_RStart = 1;
}
}
else
{
if (UartIR.DataNum < MAXNUM_UART)
{
UartIR.Buf[UartIR.DataNum] = IRB;
if (UartIR.DataNum == 7)
{
if (IRB != 0x68)
FUartIR_RStart = 0;
}
else if (UartIR.DataNum >= (UartIR.Buf[9]+11))
{
if (IRB == 0x16)
{
PMK3 = 1; //end the receive
FUartIR_REnd = 1;
}
FUartIR_RStart = 0;
}
UartIR.DataNum++;
}
else
FUartIR_RStart = 0;
}
}
}
}
}这个是源代码,问题从这里来,有空请帮看看,红外确实没有做过。
回复
有奖活动 | |
---|---|
分享开发笔记,赚取电动螺丝刀(便携轻巧与无刷电机两款可选) | |
看《关键跃升》,聊聊工作心法、动力、能力、沟通与协作,从五个方面深入交流你的工作心得 | |
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
我要给自己挣一部逻辑分析仪 | |
用知识换取送给亲朋的礼物,做个浪漫的开发者 | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 |
打赏帖 | |
---|---|
Buck电路工作在CCM模式下电感电流的计算公式是什么?被打赏5分 | |
buck电路工作原理被打赏5分 | |
基于MSPM0L1306的MODBUS-RTU协议通讯实验被打赏100分 | |
我想要一部加热台+多合一调试工具被打赏18分 | |
每周了解几个硬件知识+485硬件知识分享被打赏10分 | |
【换取手持数字示波器】树莓派PICO调试器官方固件本地化部署实践被打赏24分 | |
【换取手持数字示波器】分享一个KEIL无法识别CMSIS-DAP调试器的解决办法被打赏20分 | |
【换取手持数字示波器】分享一个自制的ArduinoNano扩展板底板被打赏23分 | |
【换取手持示波器】树莓派PICOW网页烟花被打赏18分 | |
【换取手持示波器】树莓派PICO逻辑分析仪被打赏16分 |