; ; CPU Init module ; ; Initialize all MPU registers and return to calling routine ; ; Trashes R1 ; ; Assumes the various .SET symbols have been updated with the ; appropriate bits needed to initialize the MPU ; ; For the 1200 many init's are simple bit sets. I use whole register ; writes for consistency and compatibility with upscale processors (e.g. 8515) ; ; Once conditional assembly is available, many of the following could be ; not included if no bits are set. ; cpu_init: clr R31 ; Zero all registers ldi ZL, 29 cpu_1: st Z, R31 dec ZL brge cpu_1 clr ZL ldi I_tmp, PORTD_INIT ; set output state before direction. out PORTD, I_tmp ; at reset output is low, direction is in. ldi I_tmp, DDRD_INIT out DDRD, I_tmp ldi I_tmp, PORTB_INIT ; ditto out PORTB, I_tmp ldi I_tmp, DDRB_INIT out DDRB, I_tmp ldi I_tmp, ACSR_INIT ; Analog Interrupt Mask out ACSR, I_tmp ldi I_tmp, TCNT0_INIT out TCNT0, I_tmp ldi I_tmp, TCCR0_INIT out TCCR0, I_tmp ldi I_tmp, TIMSK_INIT ; yeah, this is just a bit set... out TIMSK, I_tmp ldi I_tmp, MCUCR_INIT ; set up sleep mode & Extn interrupt out MCUCR, I_tmp ldi I_tmp, WDTCR_INIT ; Watch Dog... out WDTCR, I_tmp ldi I_tmp, GIMSK_INIT ; External Interrupt mask out GIMSK, I_tmp ldi I_tmp, SREG_INIT out SREG, I_tmp ; enable interrupts ret