; ; *********************************************** ; * IR remote control transmitter with ATtiny45 * ; * Version 2 without timer interrupts * ; * (C)2010 by http://www.avr-asm-tutorial.net * ; *********************************************** ; ; Include-Datei for AVR ATtiny45 .NOLIST .INCLUDE "tn45def.inc" ; Header file for ATTINY45 .LIST ; ; ============================================ ; D E B U G - O P T I O N S ; ============================================ ; ; debug = 0: no Debug ; debug = 1: switch key 1 on .equ debug = 0 .if debug == 1 .equ debugkey = 10 ; 0..9: key, 10:key=star, 11:key=nmbr .endif ; ; ============================================ ; H A R D W A R E - I N F O R M A T I O N S ; ============================================ ; ; Xtal oscillator 2,457600 MHz for processor clock ; ADC1 for keypad input ; PB0 for IR-LED-driver ; _________ ; 1 / |8 ; Reset o--| |--o Vcc ; | AT | ; Xtal1 o--| |--o ADC1 ; | tiny | ; Xtal2 o--| |--o PB1 - Red LED ; | 45 | ; GND o--| |--o PB0 - IR-LED ; |__________| ; ; ; ; ============================================ ; P O R T S A N D P I N S ; ============================================ ; .equ pLedO = PORTB ; IR-LED .equ pbLedO = PORTB0 .equ pLedD = DDRB .equ pbLedD = DDB0 .equ pRedD = DDRB ; red LED .equ pRedO = PORTB .equ pbRedD = DDB1 .equ pbRedO = PORTB1 ; ; ============================================== ; F I X E D + D E R I V E D K O N S T A N T S ; ============================================== ; .equ clock = 2457600 ; clock frequency in Hz .equ cLedFreq = 38400 ; Modulation frequency of the LED .equ cPause = (10000*250000)/clock ; delay ; ; ============================================ ; R E G I S T E R D E F I N I T I O N S ; ============================================ ; ; R0 free .def rHL = R1 ; High duration .def rHH = R2 ; dto. .def rLL = R3 ; Low duration .def rLH = R4 .def rRpt = R5 ; Repeat counter ; free: R5..R15 .def rmp = R16 ; multi purpose outside ints .def rimp = R17 ; multi purpose inside ints .def rAdc = R18 ; ADC result register .def rLastKey = R19 ; last pressed key .def rKeyCnt = R20 ; counter for pressed key .def rCS = R21 ; short term counter ; free R22..R23 .def rCL = R24 ; 16-Bit-counter, LSB .def rCH = R25 ; dto., MSB ; X used for High pulse ; Y used for Low pulse ; Z ; ; ============================================ ; S R A M D E F I N I T I O N S ; ============================================ ; .DSEG .ORG 0X0060 ; ; ============================================== ; R E S E T A N D I N T V E K T O R S ; ============================================== ; .CSEG .ORG $0000 rjmp Main ; Reset-vector reti ; Int0 vector reti ; PcInt0 vector reti ; TC1CompA Int vector reti ; TC1Ovf Int vector reti ; TC0Ovf Int vector reti ; EE RDY Int vector reti ; ANA COMP Int vector rjmp AdcInt ; ADC Int vector reti ; TC1CompB Int vector reti ; TC0CompA Int vector reti ; TC0CompB Int vector reti ; WDT Int vector reti ; USIStart Int vector reti ; USIOvrflw Int vector ; ; ========================================== ; I N T E R R U P T S E R V I C E ; ========================================== ; AdcInt: in rAdc,ADCH ; read ADC result sbi ADCSRA,ADSC ; start conversion set ; set T flag reti ; ; ========================================== ; M A I N P R O G R A M M I N I T ; ========================================== ; Main: ; Init stack ldi rmp,HIGH(RAMEND) ; Init MSB stack out SPH,rmp ldi rmp, LOW(RAMEND) ; Init LSB stack out SPL,rmp ; Init Port B sbi pLedD,pbLedD ; IR-LED direction Port B sbi pRedD,pbRedD ; red LED rcall Wait ; Init ADC .if debug == 1 ; simulate key ldi ZH,HIGH(2*DbgKeyCode+debugkey) ldi ZL,LOW(2*DbgKeyCode+debugkey) lpm rAdc,Z ; key to Adc result set ; set flag rjmp DebugLbl DbgKeyCode: ; 0,1,2,3,4,5,6,7,8,9,Star,Nmbr .db 84,62,161,235,45,137,221,32,110,206,18,185 .else ldi rmp,(1< 6630 µs ; 6: 0: only low cycles ; 1: High+Low cycles ; 5..0: Repeat counter, 0..63 ; 0 = End of table .equ bDbl = 7 .equ nDbl = 1<