commit f2c7430f7c4f27a277227c08572b0249f82c0742 Author: Simon Kirby Date: Thu Mar 22 02:09:50 2012 -0700 Ugly support for atmega48. diff --git a/tgy.asm b/tgy.asm index 51d4ee7..17c402d 100644 --- a/tgy.asm +++ b/tgy.asm @@ -50,7 +50,7 @@ ; ;-- Device ---------------------------------------------------------------- ; -.include "m8def.inc" +.include "m48def.inc" ; ; 8K Bytes of In-System Self-Programmable Flash ; 512 Bytes EEPROM @@ -240,6 +240,78 @@ ; ZH: Next PWM interrupt vector (high, stays at zero) -- used as "zero" register ;**** **** **** **** **** +; Macros +.MACRO outx +.if @0 > 0x3f +sts @0, @1 +.else +out @0, @1 +.endif +.ENDMACRO + +.MACRO inx +.if @1 > 0x3f +lds @0, @1 +.else +in @0, @1 +.endif +.ENDMACRO + +.MACRO cbix +.if @0 > 0x31 +inx @2, @0 +cbr @2, @1 +outx @0, @2 +.else +cbi @0, @1 +.endif +.ENDMACRO + +.MACRO sbix +.if @0 > 0x31 +inx @2, @0 +sbr @2, @1 +outx @0, @2 +.else +sbi @0, @1 +.endif +.ENDMACRO + +.if !defined(MCUCSR) +.set MCUCSR = MCUSR +.endif +.if !defined(TCCR0B) +.set TCCR0B = TCCR0 +.endif +.if !defined(WDTCSR) +.set WDTCSR = WDTCR +.endif +.if !defined(SPMCSR) +.set SPMCSR = SPMCR +.endif +.if !defined(SELFPRGEN) +.set SELFPRGEN = SPMEN +.endif +.if !defined(GICR) +.set GICR = EIMSK +.endif +.if !defined(EICRA) +.set EICRA = MCUCR +.endif +.if !defined(ADCSRB) +.set ADCSRB = ADCSRA +.endif +.if !defined(TCCR2) +.set TCCR2 = TCCR2B +.endif +.if !defined(TIFR2) +.set TIFR2 = TIFR +.set TIFR1 = TIFR +.set TIFR0 = TIFR +.set TIMSK1 = TIMSK +.endif + +;**** **** **** **** **** ; RAM Definitions .dseg ; DATA segment .org SRAM_START @@ -356,24 +428,26 @@ eeprom_defaults_w: reset: clr r0 out SREG, r0 ; Clear interrupts and flags - ; Set up stack - ldi ZH, high(RAMEND+1) - ldi ZL, low(RAMEND+1) + ldi ZH, high(RAMEND) + ldi ZL, low(RAMEND) out SPH, ZH out SPL, ZL + ldi XH, high(SRAM_START) + ldi XL, low(SRAM_START) ; Clear RAM and all registers + st Z, r0 clear_loop: st -Z, r0 - cpi ZL, SRAM_START - cpc ZH, r0 - brne clear_loop1 - ldi ZL, 30 ; Start clearing registers -clear_loop1: cp ZL, r0 - cpc ZH, r0 + cp ZH, XH + cpc ZL, XL + brne clear_loop + adiw ZL, 0 ; Set zero flag if ZL:ZH was zero + ldi ZH, 0 ; Start clearing registers at XH, + ldi ZL, 30 ; ending our loop by clearing X brne clear_loop ; Leaves with all registers (r0 through ZH) at 0 ; Save original OSCCAL and reset cause - in i_sreg, OSCCAL + inx i_sreg, OSCCAL sts orig_osccal, i_sreg in i_sreg, MCUCSR out MCUCSR, r0 @@ -398,16 +472,16 @@ clear_loop1: cp ZL, r0 ; Start timers except output PWM ldi temp1, T0CLK ; timer0: beep control, delays - out TCCR0, temp1 + out TCCR0B, temp1 ldi temp1, T1CLK ; timer1: commutation timing, - out TCCR1B, temp1 ; RC pulse measurement - out TCCR2, ZH ; timer2: PWM, stopped + outx TCCR1B, temp1 ; RC pulse measurement + outx TCCR2, ZH ; timer2: PWM, stopped ; Enable watchdog (WDTON may be set or unset) ldi temp1, (1<