@@ -383,12 +383,9 @@ main:
383
383
384
384
; We MUST disable the Watchdog Timer first, otherwise it will remain enabled and will keep resetting the system, so...
385
385
; Disable Watchdog Timer
386
- ldi r16 , _BV(WDCE) | _BV(WDE) ; Load r16 with the value needed to "unlock" the Watchdog Timer Configuration
387
- ; Write a logic one to the Watchdog Change Enable bit (WDCE) and Watchdog System Reset Enable (WDE)
388
-
389
386
mov r17 , rZERO ; Load r17 with zero to disable the Watchdog Timer completely
390
387
391
- rcall set_watchdog_timer ; Call the subroutine that sets the watchdog timer with the values loaded in r16 and r17
388
+ rcall set_watchdog_timer ; Call the subroutine that sets the watchdog timer with the value loaded in r17
392
389
393
390
; check_reset_flags:
394
391
sbrs rMCUSR , EXTRF ; Skip the next instruction if EXTRF is set (if External Reset Flag, skip next instruction, go to run_bootloader)
@@ -613,13 +610,10 @@ exit_bootloader:
613
610
; NOTE!! This part of the code assumes MCUSR has already been cleared
614
611
615
612
; Enable WDT, ~250 ms timeout (force a timeout to reset the AVR)
616
- ldi r16 , _BV(WDCE) | _BV(WDE) ; Load r16 with the value needed to "unlock" the Watchdog Timer Configuration
617
- ; Write a logic one to the Watchdog Change Enable bit (WDCE) and Watchdog System Reset Enable (WDE)
618
-
619
613
ldi r17 , _BV(WDE) | _BV(WDP2) ; Load r17 with the value needed to set the desired Watchdog Configuration (WDCE = 0, not set!)
620
614
; Write the WDE and Watchdog prescaler bits (WDP); System Reset Mode (WDE = 1) and ~250 ms timeout (WDP2 = 1)
621
615
622
- rcall set_watchdog_timer ; Call the subroutine that sets the wathdog timer with the values loaded in r16 and r17
616
+ rcall set_watchdog_timer ; Call the subroutine that sets the watchdog timer with the value loaded in r17
623
617
624
618
; for (;;);
625
619
final_loop:
@@ -1077,8 +1071,11 @@ EP_ISR_END:
1077
1071
1078
1072
set_watchdog_timer:
1079
1073
1080
- ; IMPORTANT!! This function assumes the correct values for the WDTCSR register
1081
- ; configuration are already loaded onto r16 and 17.
1074
+ ; IMPORTANT!! This function assumes the correct value for the WDTCSR register
1075
+ ; configuration is already loaded onto r17; it also modifies r16.
1076
+
1077
+ ldi r16 , _BV(WDCE) | _BV(WDE) ; Load r16 with the value needed to "unlock" the Watchdog Timer Configuration
1078
+ ; Write a logic one to the Watchdog Change Enable bit (WDCE) and Watchdog System Reset Enable (WDE)
1082
1079
1083
1080
wdr ; Reset the Watchdog Timer
1084
1081
0 commit comments