Infrared decoder
Posted: Mon Nov 03, 2008 8:15 pm
This program uses a micro controller PIC16F877 running at 4MHz to decode infra red signals from a remote control using Philips RC5 protocol. It can be used to test any remote controls and to switch 8 devices using an RC5 remote control. The address and command decimal values are show on a 16x4 LCD display. Keys 1 to 8 of remote control are used to control individually 8 bits of PORTD, switching on/off any AC or DC devices using e.g. an 8 relay board. The Standby key is used to switch on/off all 8 outputs. There are also 8 push to make switches to toggle manually the state of any output. By pressing switch 1 and 2 at the same time, will switch on/off all outputs. The state of outputs is show on the LCD display. Bit 6 and 7 of PORTB are used to select the address mode to the output control; 00=TV, 01=VCR, 10=SAT, 11=Hi-Fi.
The main flowchart set the LCD display on PORTA, initializes ports, read the state of bit 6 and 7 to variable β€modeβ€, enable RB0/INT interrupt and starts a loop.
A transition of 1 to 0 on RB0/INT pin, will call β€startβ€ macro, just used to set a variable and call β€ir_decβ€ macro. Inside β€ir_decβ€ macro, some delays to read RB0 near the end of S1 bit, beginning and second half of S2 bit. If they are β€010β€, the signal comes from a valid RC5 remote control. More delays to skip toggle bit, not used here, and start to read the 5 bits address and 6 bits command to β€adrβ€ and β€cmdβ€ variables. Along β€ir_decβ€ macro, 14 pulses of about 300us each are generated on RE0 pin to show on a oscilloscope the reading points of initial bits, and each address/command bits - always on second half. After a successful IR decoding, β€ir_decβ€ macro calls the β€outputβ€ macro. Inside β€outputβ€ macro the display shows address and command values in decimal, compares β€adrβ€ and β€modeβ€ variables to validate the device mode used, and send β€cmdβ€ variable value to PORTD, displaying the output state in binary.
A blinking LED on RE1 pin show the activity of all non RC5 remote controls.
The main loop also calls β€sw_keyβ€ macro to read PORTC switches to control manually PORTD outputs.
an exemple how to build ir receiver e-block:
The main flowchart set the LCD display on PORTA, initializes ports, read the state of bit 6 and 7 to variable β€modeβ€, enable RB0/INT interrupt and starts a loop.
A transition of 1 to 0 on RB0/INT pin, will call β€startβ€ macro, just used to set a variable and call β€ir_decβ€ macro. Inside β€ir_decβ€ macro, some delays to read RB0 near the end of S1 bit, beginning and second half of S2 bit. If they are β€010β€, the signal comes from a valid RC5 remote control. More delays to skip toggle bit, not used here, and start to read the 5 bits address and 6 bits command to β€adrβ€ and β€cmdβ€ variables. Along β€ir_decβ€ macro, 14 pulses of about 300us each are generated on RE0 pin to show on a oscilloscope the reading points of initial bits, and each address/command bits - always on second half. After a successful IR decoding, β€ir_decβ€ macro calls the β€outputβ€ macro. Inside β€outputβ€ macro the display shows address and command values in decimal, compares β€adrβ€ and β€modeβ€ variables to validate the device mode used, and send β€cmdβ€ variable value to PORTD, displaying the output state in binary.
A blinking LED on RE1 pin show the activity of all non RC5 remote controls.
The main loop also calls β€sw_keyβ€ macro to read PORTC switches to control manually PORTD outputs.
an exemple how to build ir receiver e-block: