; Send a pulsed 38 kHz stream to provide a IR output for ; detection by a IR demodulator like used in remote control ; applications. ; ; 11/27/98 Brian Hammill ; ; ; IRED is controlled by PB7 - Common Emitter NPN Transistor drives LED. ; IR Detector/Demodulator idles in high state and is connected ; to PD5 ; An optional visible LED is on PB4 for debugging/indicating. ; The IRED is "on" when PB7 is high. ; First pass will just modulate the LED so we can test xmit. ; I use idle mode to hopefully cut power consumption between LED pulses. ; ; This code should work in the 90S1200 or 90S2323/43. It would be ; possible to use a lower clock frequency too. I used the 2313 and 3.6864 MHz Xtal ; because that is what I had. ; ; This code is provided as-is without warranty and is placed in the public domain ; so that it might demonstrate some of the coding requirements of the AVR controller. ; Brian Hammill - hammill@ipass.net December 1998. ; http://www.ipass.net/~hammill .include "2313def.inc ; The Interrupt Vectors reset: rjmp startup reti ; ext int 0 (not used) reti ; ext int 1 (not used) reti ; timer1 not used reti ; reti ; rjmp timer0 reti ; UART RRF Not Used reti ; UART TRE Not Used reti ; UART TRDE Not Used reti ; analog comparator not used ; Code we need to execute at startup. startup: ; setup timer0 for 10 mS period. ck/1024 ldi R16, $05 out TCCR0, R16 ldi R16, (256 - 15) out TCNT0, R16 ; 3.6864/1024)/36 = 100 Hz ; must init the stack. ; initialize stack pointer ldi R16, RAMEND out SPL,R16 ; initialize the data direction registers ldi R16, 144 out DDRB, R16 ; enable timer interrupts ldi R16,$02 ; enable timer 0 interrupts out TIMSK,R16 ldi R16, 0; enable IDLE mode for sleep. out MCUCR, R16 sei ; globally enable interrupts sleep ; should be able to sleep until timer overflows mainloop: ; loop and wait for an interrupt nop nop rjmp mainloop ; need to send several cycles of 38 kHz every 10 mS. timer0: ; Interrupt service routine gets executed when ; timer 0 expires. ldi R16, (256 - 34 ) out TCNT0, R16 ; reset the counter ; now do the IR send ; IRED connected on portb bit 7 ldi R17, $20 ; number of pulses ; 38 kHz has period of 26.3 uS ; turn LED on for 26.3 uS pulse: sbi PORTB, 7 ; Turn on LED rcall delay1 ; Wait 13 uS cbi PORTB, 7 ; Turn off LED (IR) rcall delay1 ; wait 13 uS dec R17 brne pulse sleep ; back to sleep until another interrupt? reti delay1: ; This is a 13 uS delay. Takes 97 instructions ldi R16, 13 ; was 23 nop ; add 1 clock to total delay delay1_0: dec R16 brne delay1_0 ret