; CE-2800 Watchdog timer demo ; Purpose: Demonstrates the operation/setup/configuration of the Watchdog timer. .NOLIST .INCLUDE "m32def.inc" ; contains .EQU's for DDRB, PORTB, and a lot more .LIST .DSEG ADFlag: .byte 1 ; 1-byte flag used to indicate whether PA0 or PA1 is being measured .EQU start = 0x2a ; define a symbol to represent address 0x2a in program memory .CSEG ; this means further directives are for the Code Segment .ORG 0x0 rjmp start ; initialize Reset Vector at 0x0000 .ORG 0x2 rjmp int0_ISR ; initialize INT0 Vector at 0x0002 .ORG 0x4 rjmp int1_ISR ; initialize INT1 Vector at 0x0004 .CSEG ; switch back to Code Segment .ORG start ; defines where these instructions start getting placed in Program Memory ; Initialize the Stack Pointer (SP) CPU register for subsequent use .DEF temp=r21 ; temp: register for temporary data store ldi temp, LOW(RAMEND) ; get low byte of the address of the highest byte in Data Memory we can use out SPL, temp ; load it into the low byte of SP ldi temp, HIGH(RAMEND) ; high byte of address of highest Data Memory byte out SPH, temp ; load it into the high byte of SP rcall initPortB rcall initPortD rcall initExternalInterrupts sei ; this ENABLES interrupts globally rcall doStartFlash ; flash the LEDs to signal start of program execution ldi R16, 0x01 ; set rightmost bit repeat_left: out PORTB, R16 rcall delay60 lsl R16 ; shift bits left brcc repeat_left ; and repeat if bit hasn't been rolled into Carry sbr R16, 0x40 ; otherwise reset bit 6 repeat_right: out PORTB, R16 rcall delay60 lsr R16 ; shift bits right brne repeat_right ; and repeat if bit hasn't been rolled into Carry sbr R16, 0x02 ; otherwise reset bit 1 rjmp repeat_left ; and start shifting left again loop_forever: rjmp loop_forever ; subroutine doStartFlash ; flashes the LED's 5 times with a delay of 100ms between each flash doStartFlash: push temp ; save incoming value of temp ldi temp, 5 ; use temp as a counter; initialized to 5 repeat_flash: push temp ; save the value of the count ldi temp, 0xff out PORTB, temp ; turn LEDs on rcall delay100 ldi temp, 0 out PORTB, temp ; turn LEDs off rcall delay100 pop temp ; restore the value of the count dec temp ; decrement the count brne repeat_flash ; if not 0, repeat pop temp ; restore incoming value of temp ret ; end subroutine doStartFlash ; subroutine initPortB ; configure PORTB for digital output initPortB: push temp ldi temp, 0xff ; set all bits to 1 out DDRB, temp ; tell DDRB to configure pins as output (0xff means all output) ldi temp, 0xff out PORTB, temp pop temp ret ; end subroutine initPortB ; subroutine initPortD ; configure PORTD for digital input initPortD: push temp ldi temp, 0x00 ; init PortD for digital INPUT out DDRD, temp ldi temp, 0xff ; enable pull-up circuitry out PORTD, temp pop temp ret ; end subroutine initPortD ; subroutine setupIninitExternalInterruptsterrupts ; enable global interrupt handling, and initilize interrupt handling specifically for INT0 initExternalInterrupts: push temp ; save in temp, GICR ; get current state of GICR (General Interrupt Control Register) ori temp, 1<