;------------------------------------------------------------------------------
; 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
;------------------------------------------------------------------------------ |