en.radzio.dxp.pl

Decoding remote control RC5 infrared signal
This article show how to decode RC5 signal using 16-bit Timer1 and INT0 external interrupt input in ATtiny2313 Atmel AVR device.


For decoding RC5 signal I prepared two interrupt handlers. First for INT0 external interrupt, which are triggered by first falling edge of RC5 signal (remember that receiver gives inverted signal). This handler prepare Timer1 to work by loading proper value to its register, and selects clock source as prescaled by 8 clock signal. Except this all registers used by second handler are cleared.Each frame bit are sampled twice, one in each half of bit. Thanks this we have safety that proper decoding RC5 frame and protect against disturbation.

Demo application
Demonstation apllication receive RC5 signal and display on LCD Address, Command and Toggle bit from received RC5 frame. Demo movie :

Source code of main.asm file is shown below:

;------------------------------------------------------------------------------
; RC5 demo application
; http://avr-mcu.dxp.pl
; (c) Radoslaw Kwiecien
;------------------------------------------------------------------------------
.include "tn2313def.inc"
;------------------------------------------------------------------------------
; CPU frequency must be defined correctly
;------------------------------------------------------------------------------
#define F_CPU 8000000
;------------------------------------------------------------------------------
; Code segment
;------------------------------------------------------------------------------
.cseg
;------------------------------------------------------------------------------
; Include source files
;------------------------------------------------------------------------------
#include "vectors.asm"
#include "hd44780.asm"
#include "wait.asm"
#include "rc5.asm"
;------------------------------------------------------------------------------
; Constants definitions
;------------------------------------------------------------------------------
AddressTxt: .db "Address: ",0,0
CommandTxt: .db "Command: ",0,0
WaitingTxt: .db "Waiting for RC5",0
;------------------------------------------------------------------------------
; Program code
;------------------------------------------------------------------------------
ProgramEntryPoint:
  ldi   r16,LOW(RAMEND)            ; init stack
  out   SPL, r16                   ;
  rcall LCD_Init                   ; init LCD
  ldi   r16,0                      ; go to 0,0
  rcall LCD_SetAddressDD           ;
  ldi   ZL,LOW(WaitingTXT << 1)    ;
  ldi   ZH,HIGH(WaitingTXT << 1)   ; Display text
  rcall LCD_WriteString            ;
  rcall RC5Init                    ; init RC5
;------------------------------------------------------------------------------
; Main program loop
;------------------------------------------------------------------------------
MainLoop:

  rcall WaitForRC5                 ; wait for RC5 code

  ldi   r16,0                      ;
  rcall LCD_SetAddressDD           ; go to 0,0

  ldi   ZL,LOW(AddressTXT << 1)    ;
  ldi   ZH,HIGH(AddressTXT << 1)   ; display text "Address:"
  rcall LCD_WriteString            ;

  ldi   r16,9                      ;
  rcall LCD_SetAddressDD           ; go to 9,0

  lds   r16,RC5Address             ;
  rcall LCD_WriteHex8              ; display received RC5 address (hex)

  ldi   r16,0x40                   ;
  rcall LCD_SetAddressDD           ; go to 0,1

  ldi   ZL,LOW(CommandTXT << 1)    ;
  ldi   ZH,HIGH(CommandTXT << 1)   ; display text "Command:"
  rcall LCD_WriteString            ;

  ldi   r16,0x49                   ;
  rcall LCD_SetAddressDD           ; go to 9,1

  lds   r16,RC5Command             ;
  rcall LCD_WriteHex8              ; display received RC5 command (hex)

  ldi   r16,0x4D ;
  rcall LCD_SetAddressDD           ; go to 13,1

  ldi   r16,'T'                    ;
  rcall LCD_WriteData              ;
  ldi   r16,':'                    ; display "T:"
  rcall LCD_WriteData              ;

  ldi   r16,'1'                    ;
  lds   r17, RC5Status             ;
  sbrs  r17,7                      ; display value of RC5 Toggle bit
  ldi   r16,'0'                    ;
  rcall LCD_WriteData              ;

  rjmp MainLoop                    ; jump to begin of loop
;------------------------------------------------------------------------------
; End of main.asm file
;------------------------------------------------------------------------------

Download complete project for AVR Studio : RC5demo.zip

 

 
(c) Radosław Kwiecień