; macro.asm (03/2000) ; Helpful little macros used to control built-in peripherals, etc. .NOLIST ; ;--- REGISTER DEFINITIONS (^) = requires r16-31 ; tmp (^) = a scratchpad register ; ; ;--- CALLABLE MACROS ; Name______________ Args_______ Description________________________________ ; DDRB_write n Set B port direction (0=input, 1=output) ; DDRD_write n Set D port direction (0=input, 1=output) ; DDR_write DDRx, i Load DDR[AB] with constant i ; ; SP_load n Load SPL with n ; ; TIMR0_load n Load TCNT0 ; TIMR0_int_enable Enable timer 0 int ; TIMR0_int_disable Disable timer 0 int ; TIMR0_stop Load 0 into TCCR0 ; TIMR0_div_1 Load 1 into TCCR0 ; TIMR0_div_8 Load 2 into TCCR0 ; TIMR0_div_64 Load 3 into TCCR0 ; TIMR0_div_256 Load 4 into TCCR0 ; TIMR0_div_1024 Load 5 into TCCR0 ; TIMR0_ext_falling Load 6 into TCCR0 ; TIMR0_ext_rising Load 7 into TCCR0 ; ; Sleep_mode_disable SM=0, SE=0 in MCUCR ; Sleep_mode_halt SM=1, SE=1 in MCUCR ; Sleep_mode_idle SM=0, SE=1 in MCUCR ; ; EEPROM_read_byte a, r Read byte at into reg ; ;--- macro description END .macro DDR_write ; Sets up port i/o ; ex. DDR_write DDRB 0xff ldi tmp, @1 ; get direction definition out @0, tmp ; put it in DDR .endmacro .macro DDRB_write ; Sets up port B i/o ldi tmp, @0 ; get port B direction definition out DDRB, tmp ; put it in DDRB .endmacro .macro DDRD_write ; Sets up port D i/o ldi tmp, @0 ; get port D direction definition out DDRD, tmp ; put it in DDRD .endmacro .macro SP_load ldi tmp, @0 out SPL, tmp .endmacro .macro TIMR0_load ; load an 8 bit value into the t/c ldi tmp, @0 out TCNT0, tmp .endmacro .macro TIMR0_int_enable ; enable timer interrupt ldi tmp, 0x02 out TIMSK, tmp .endmacro .macro TIMR0_int_disable ; disable timer interrupt clr tmp out TIMSK, tmp .endmacro .macro TIMR0_stop clr tmp out TCCR0, tmp .endmacro .macro TIMR0_div_1 ldi tmp, 0x01 out TCCR0, tmp .endmacro .macro TIMR0_div_8 ldi tmp, 0x02 out TCCR0, tmp .endmacro .macro TIMR0_div_64 ldi tmp, 0x03 out TCCR0, tmp .endmacro .macro TIMR0_div_256 ldi tmp, 0x04 out TCCR0, tmp .endmacro .macro TIMR0_div_1024 ldi tmp, 0x05 out TCCR0, tmp .endmacro .macro TIMR0_ext_falling ldi tmp, 0x06 out TCCR0, tmp .endmacro .macro TIMR0_ext_rising ldi tmp, 0x07 out TCCR0, tmp .endmacro .macro Sleep_mode_disable clr tmp out MCUCR, tmp .endmacro .macro Sleep_mode_halt ldi tmp, 0x30 out MCUCR, tmp .endmacro .macro Sleep_mode_idle ldi tmp, 0x20 out MCUCR, tmp .endmacro .macro EEPROM_read_byte ;
, out EEAR, @0 ; load EEAR with
sbi EECR, EERE ; read EEPROM in @1, EEDR ; copy EEDR to .endmacro ;EOF macro.asm .LIST