The IR-200S IR-Dongle is programmed by sending a Control Byte via the UART Controller. For proper operation, the UART must be programmed as 8-bit data word, no parity and 1 stop bit. To correctly initialize the IR-200S, you should first RESET, and then PROGRAM to 9600 baud, then go to NORMAL operation.
Note: The SPACE state means "1" programmed, the MARK state means "0".
| Function | Operation |
|---|---|
| Power Off | Keep both RTS & DTR at MARK state for 100 msec |
| Reset | Sequence:
|
| Normal | Keep both RTS & DTR at SPACE state for normal operation |
| Programming | Sequence:
|
| BIT7 | 6 | 5 | 4 | 3 | 2 | 1 | BIT0 |
| 0 | 0 | 0 | PW | B3 | B2 | B1 | B0 |
Where
| PW: | IrDA pulse select 1 = 1.6 us output pulse ( preferred setting ) 0 = 3/16 bit time pulse |
||||||||||||||||||||||||||||||||||||
| B3..B0: | Baud rate select (values other than below are undefined)
|
void delay(int count)
{
while(count-- > 0) outp(0x80,0);
}
void IR_reset()
{
outp(comport+4,0x03); /* normal operation */
delay(10000);
outp(comport+4,0x02); /* -DTR low -> reset PIC */
delay(200);
outp(comport+4,0x03); /* back to normal operation */
delay(20);
}
IR_ctlbyte(char ctlbyte)
{
outp(comport+4,0x01); /* -RTS low -> send control byte */
delay(10);
outp(comport,ctlbyte);
delay(2000);
outp(comport+4,0x03); /* back to normal operation */
}
void setbaud(int baud)
{
outp(comport+3,0x83); /* LCR, select DLAB */
outp(comport+0,baud); /* DLAB LSB */
outp(comport+1,0x00); /* DLAB MSB, always be 0 */
outp(comport+3,0x03); /* LCR, NP-1S-8D format */
outp(comport+2,0x00); /* FCR */
outp(comport+1,0x00); /* IER */
}
int baud_div[] = {1,2,3,6,12}; /* UART DLAB divider */
char ctlbyte[]={0x10,0x11,0x12,0x13,0x14};
/*
see control byte information above for control byte definition
Control byte BaudRate
0x10 115200bps
0x11 57600 bps
0x12 38400 bps
0x13 19200 bps
0x14 9600 bps
*/
void main(void)
{
/* Reset IR-200S IR_Dongle & Set UART to 115.2K baud */
IR_reset();
setbaud(baud_div[4]);
IR_ctlbyte(ctlbyte[0]);
setbaud(baud_div[ctlbyte]);
inp(comport);
}