The program is written in embedded C using Keiluvision 4.

NEC Protocol :

NEC IR protocol encodes the keys using a 32bit frame format as shown below.

Each bit is transmitted using the pulse distance as shown:
Logical '0': A 562.5µs pulse burst followed by a 562.5µs space, with a total transmit time of 1.125ms
Logical '1': A 562.5µs pulse burst followed by a 1.6875ms space, with a total transmit time of 2.25ms

When a key is pressed on the remote controller, the message transmitted consists of the following, in order:

AddressComplement of AddressCommandComplement of Command
LSB-MSB(0-7)LSB-MSB(8-15)LSB-MSB(16-23)LSB-MSB(24-31)
  1. A 9ms leading pulse burst (16 times the pulse burst length used for a logical data bit)
  2. A 4.5ms space
  3. The 8-bit address for the receiving device
  4. The 8-bit logical inverse of the address
  5. The 8-bit command
  6. The 8-bit logical inverse of the command
  7. A final 562.5µs pulse burst to signify the end of message transmission.

Steps to Decode the NEC Protocol :

By using an external interrupt, we measure Time gap between two negative transitions. 

If it is 13.5ms it is considered as start of frame.

 If it is 2.25ms it is considered as logic 1

 If it is 1.125ms it is considered as logic 0

AC Remote Protocol (VOLTAS) :

The AC remote transmits all of its parameters whenever a key is pressed. The Logic values and widths are same as NEC protocol. The frame is 67 Bits in size. Each message sent starts with a start condition (similar to NEC protocol).The message also contains 8 bits  at the end representing a checksum. Note that the data transmitted is MSB to LSB but the codes are in binary reversed order.

The decoding steps are similar to that of NEC protocol.

ModeON/OFFFan speedSleep
LSB-MSB(1-3)4LSB-MSB(5-6)8
TemperatureSleepChecksum and other bits
LSB-MSB(9-13)12LSB-MSB(13-67)

RC-5 Protocol :

The RC5 code uses the bi phase modulation technique which means that every bit consists of 2 parts .A bit is always a high/low or a low/high transition. Logic zero is transmitted as a burst(train of pulses) followed by a space. Logic One is transmitted as a space followed by a burst. Hence by detecting a Low to High transition, it is decoded as a logic 0. And a High to low transition is decoded as a logic 1.

 It  uses a 14 bit frame as follows:

The bits are transmitted from MSB to LSB. each high and low levels are of equal length =[1.728ms/2]=0.864ms.

AGC control bitToggle bit  addressCommand
1-234-89-14

Steps to Decode the RC-5 Protocol 

1.     When a first pulse is detected that is when a button is pressed on the remote control  a train of pulses are detected by the receiver, for the very first bit detected  that is at the start of the AGC bit the receiver output goes to zero.

2.      We could observe the direction of the changing at the middle of the bit that is 0.5 bit(1st agc bit) + 2bits(2nd agc bit + check bit) +5 bits ( address bits) +0.25bit (to ensure that we are correctly now present at the command bit) =7.75 bits =13.392ms. (+or - 0.1ms is ok).

3. as each bit is of two states(a high & a low)  It means that the second half of the bit is actually the same meaning of the bit to be transmitted, If you want to measure the correct logic level directly from the Receiver Output, you should measure at the first half of the bit and need not to measure the whole bit length of 1.728ms.

4.     Now starts your command bits with 0.25 of the bit already skipped in step2.

5.     Hence now we are exactly at the middle of the “half  bit” (our first command bit) .

6.     We can scan for 0.25 bit length and find whether low or high if the very first scan gives us  high that means necessarily the other half (0.5 bit) of the bit should be low so as per rules : high to low  means a “1”  And vice- versa for a “0”. Store  this  scanned  bit & remember this  is  a MSB bit so left shift this bit in a register. Remember one need not to decode whole 1.728ms bit length. As now say  scanning decoding & shifting took  around  0.5 of  bit length (it changes from controller to controller depending on machine cycles to execute a task ).

7.     Still  0.25 bit of already decoded bit is remaining hence spend 0.25 + another 0.25 bit 1.728ms*0.5=1.296ms  bit time to enter exactly at the  mid half of the next command  bit. Again scan,decode & right shift in the same register used to right shift the first bit-this is second command bit. Repeat steps 6 & 7 till all 6 command bits are recovered. 

Note that the TSOP 1838 sensor is active LOW