打印

关于红外接收的程序

[复制链接]
1331|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
xsgy123|  楼主 | 2012-9-17 17:57 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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

/*-----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;
}
}
}
}
}
请教下列几个问题,第一是校验位,偶校验,但不清楚确认的方法;第二是不知道发送时数值从哪里来;第三是觉得发送和接收的波特率和时钟频率不大对,不知怎么确认;第四是不知道0和1怎么判断的?请指导!

相关帖子

沙发
火箭球迷| | 2012-9-17 18:08 | 只看该作者
第四是不知道0和1怎么判断的?
根据高低电平时间长短来区分0和1的,具体多长多短,自己两端定义好就行

使用特权

评论回复
板凳
baidudz| | 2012-9-17 18:16 | 只看该作者
第二是不知道发送时数值从哪里来
程序大略看了下,没见发射部分的程序,

使用特权

评论回复
地板
renyunling18| | 2012-9-17 20:41 | 只看该作者
:L应该是程序没有贴完整把

使用特权

评论回复
5
summerlover| | 2012-9-17 22:19 | 只看该作者
程序看着很乱,没头没尾的

使用特权

评论回复
6
秋天落叶| | 2012-9-17 22:54 | 只看该作者
程序太长了

使用特权

评论回复
7
yybj| | 2012-9-18 18:05 | 只看该作者
大致看了下,感觉程序没贴全

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

229

主题

2603

帖子

1

粉丝