遥控器主要是通过解码来控制红外模块,从而完成小车的行走
#include "apue.h"
#include "uart.h"
void
main()
{
TMOD = 0x20;
// timer1, auto-load
TH1 = TL1 = 0xFF;
PCON = 0x80;
// 57600bps on 11.0592M
SCON = 0x50;
// UART, REN
IE = 0x91;
// EA, ES, EX0
TR1 = 1;
// start
while
(1);
}
void
int0_IR() interrupt 0
{
size_t
lowTime, highTime;
EX0 = 0;
memset
(UARTBuf, 0, SLEN);
/* detect leader code pluse */
TH2 = TL2 = 0;
// Clear timer
TR2 = 1;
// run timer
while
(IR == 0);
// until MCU detect high level
TR2 = 0;
// stop timer
UARTBuf[0] = TH2;
// store timer value
UARTBuf[1] = TL2;
TH2 = TL2 = 0;
TR2 = 1;
while
(IR == 1);
TR2 =0;
UARTBuf[2] = TH2;
UARTBuf[3] = TL2;
UARTBuf[SLEN - 1] = 0x7e;
// end of data
UARTSend();
// send data to PC over RS232
delayms(1000);
// delay 1 second
EX0 = 1;
}
}