;**** see also A P P L I C A T I O N N O T E A V R 3 0 5 ************************ ;* ;* Title :RC5 + Sony SIRCS Code IR- send ;* Version : 1.1 ;* Last updated : 2001 ;* Target : AT90Sxxxx (All AVR Device) ;* ;* Support email : www.bellibot.com ;* ;* Code Size : 69 Words ;* Low Register Usage : 0 ;* High Register Usage : 5 ;* Interrupt Usage : None ;* ;* DESCRIPTION ;* This Application note contains a very code efficient software ;* The example program send one command over IR. with 38 khz (36 khz) ;* no timer no interups needed ;*************************************************************************** .include "1200def.inc" ;***** Pin definitions .equ TxD =1 ;Transmit pin is PD1 ;***** Global register variables .def cxtem =R15 .def bitcnt =R16 ;bit counter .def temp =R17 ;temporary storage register .def Txbyte =R18 ;Data to be transmitted .def Cxbyte =R19 ; .def BitTime =R20 ; Bit Time = 1778 ySec .eseg .org 0 .db 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 .cseg .org 0 rjmp reset ;*************************************************************************** ;* ;* "putchar" ;* ;* This subroutine transmits the word stored in the "Txbyte" (Z -register ;* The number of bits used is set with the sb constant ;* word = 2 Stopbit + 1 toggle + 5 Bit Adr. + 6 Bit command = 14Bit ; toggle Bit Store in T-Flag every command ; Adr . in this demo = 0 ; so its easy to decode - 11T00000 the first byte is the same every time ; between you want to flip the Toggle Bit you send the same command twice ; ;* Number of cycles :Depens on bit rate ;* Low registers used :None ;* High registers used :3(bitcnt,Txbyte,Cxbyte) ;* Pointers used :None ;* ;*************************************************************************** .equ sb =8 ;Number of bits (1, 2, ...)+ 1 .equ si =6 put_rc5: ldi Txbyte,0 ; test ADR. ( System adr. 0 - 31 ) bld Txbyte,5 ; load togglebit from Tflag ori Txbyte,0b11000000 ; 2startbits LSL Cxbyte ; Bit 7 + 6 forgeddet LSL Cxbyte ldi bitcnt,sb ; (sb is # of bits) rcall putchar ; send System adr. ldi bitcnt,si mov Txbyte,Cxbyte ;send Command ( 0 - 127 ) putchar: nop putchar3: ROL Txbyte putchar0: brcc putchar1 ;If carry set rcall Null_send rcall One_send ;cbi PORTD,TxD ; send a '1' rjmp putchar2 ;else putchar1: ; send a '0' rcall One_send rcall Null_send nop putchar2: rol Txbyte ;Get next bit dec bitcnt ;If not all bit sent brne putchar0 ; send next ;else sbi PORTD,TxD ; Led off ret ; return ;********************************************************************** ; one bit rc5 code are 1778 ySec. long, from Low to High , 889ySec. each ; zero bit are 1778 ySec. long, from High to Low ; two Startbits , one toggle bit , 5 Bit System , 6 bit Command ; at one = 38khz burst ; zero = pause (nothing ; time over 14 bit = 24,889 msec. ; time over all 113,778 msec. ; after command send wait 113,778 - 24,889 msec.= 88,889 msec. ;*********************************************************************** .equ b =15 ;38kHz @ togle = 26,3ySec / 2 @ 4 MHz crystal ; BitTime = 35 ; 889 YSec One_send: ldi BitTime,36 ; half Bit one One_1: ldi temp,b ; 38 KHz Burst sbi PORTD,TxD One_2: dec temp brne One_2 ldi temp,b cbi PORTD,TxD One_3: dec temp brne One_3 dec BitTime brne One_1 ret Null_send: sbi PORTD,TxD ; LED off ldi BitTime,71 ;72 * 26,3ySec = 889 YSec Null_1: ldi temp,b ; no Burst - half Bit zero nop nop Null_2: dec temp brne Null_2 dec BitTime brne Null_1 ret Pause: ldi Bitcnt,100 ; pause von 88,889 msec. pau_01: rcall Null_send dec Bitcnt brne pau_01 ret ;******************************************************************************** ;************************************* Sony Sircs ******************************** .equ kb =7 ; keycode 7 bit .equ ki =5 ; adr. code 5 - 13 bit'over 5 is extendet adr ? put_sirc: rcall One_sends ; Starbit 2,4 msec burst rcall One_sends rcall One_sends rcall One_sends rcall Null_sends ;0,6 msec pause ldi Txbyte,1 ; adresse TV ;LSL Txbyte ;LSL Txbyte ; bit 5,6,7 forgeddet ;LSL Txbyte ;key code ;LSL Cxbyte ; Bit 7 forgeddet ldi bitcnt,kb ; (sb is # of bits) rcall putchars ; send System adr. ldi bitcnt,ki mov Cxbyte,Txbyte ; achtung cxbytes ,txbytes jetzt anders rum putchars: nop putchar3s: ROR Cxbyte putchar0s: brcc putchar1s ;If carry set rcall One_sends rcall One_sends ;cbi PORTD,TxD ; send a '1' rcall Null_sends rjmp putchar2s ;else putchar1s: ; send a '0' rcall One_sends rcall Null_sends nop putchar2s: ROR Cxbyte ;Get next bit dec bitcnt ;If not all bit sent brne putchar0s ; send next ;else sbi PORTD,TxD ; Led off ret ; return ;********************************************************************** ; SIRCS ; Startbit = 2,4 msec '1' + 0,6 mSec '0' Burst 40 khz ; Command = '0'= 1,2 msec. 0,6 msec '1' + 0,6 msec '0' ; Adress = '1'= 1,2 msec '1' + 0,6 msec '0' ; startbit + 7 Bit Command + 5 - 13 Bit Adresse = 12 - 20 bit ; sequence length = 45 msec incl. pause ; repeat every sequence tree times ;*********************************************************************** .equ bs =15 ;40kHz @ togle = 25ySec / 2 @ 4 MHz crystal ; Burst send for 0,6 or 1,2 msec. One_sends: ldi BitTime,25 ; half Bit one 0,6 msec = 25 ysec * 24 One_1s: ldi temp,bs ; 40 KHz Burst sbi PORTD,TxD One_2s: dec temp brne One_2s ldi temp,bs cbi PORTD,TxD One_3s: dec temp brne One_3s dec BitTime brne One_1s ret Null_sends: sbi PORTD,TxD ; LED off ldi BitTime,50 ; 0,6 msec Null_1s: ldi temp,bs ; no Burst - half Bit zero nop nop Null_2s: dec temp brne Null_2s dec BitTime brne Null_1s ret Pauses: ldi Bitcnt,43 ; pause von (45 msec. - sequence length) pau_01s: rcall Null_sends dec Bitcnt brne pau_01s ret ;***** Program Execution Starts Here*************************************** ;***** Test program runs correctly at 3,67 MHz to 4,096 Mhz at STK 500 & 200 ; the IRled connected at Pin PD1 over a 470 Ohm resistor at Vcc . ; i testet this routine with my TV (Schneider) and the RC5 reciver Prg from Atmel AVR- ; apl.410 reset: clr temp out ddrb,temp ; portb input ser temp out portb,temp ;pull up r out ddrd,temp ; portd output out portd,temp ;all bits high forever: in temp,PINB ; wait key pressed cpi temp,0xff breq forever ; *************** After any key press you must send toggle bit ; set correctly - when you repeat a key longer ; dont send toggle bit !!! com temp ; Key ( on stk Pullup' on ,so we invert mov Cxbyte,temp BRTS toggle ;if t-flag clear then SET ;set otherwise BRTS toggle01 toggle: CLT ; clear ;**************************************************************** ;*************** comment out what you want ********************** ;**************** RC5 ******************************************* toggle01: ;rcall put_rc5 ;send char ; send 38 khz. ;rcall Pause ; this is the time to complete the Signal !!!! ;**************************************************************** ;**************** Sony Sirc ************************************* mov cxtem,Cxbyte ; in put... destroyed rcall put_sirc rcall Pauses ; Sony want tree times the same code ; otherwise she think is an error mov Cxbyte,cxtem rcall put_sirc rcall Pauses mov Cxbyte,Cxtem rcall put_sirc rcall Pauses ;***************************************************************** rjmp forever