Tuesday, January 10, 2006

8051: Example 2

Using Watch-dog Timer

This example describes how the watch-dog timer should not operate. The watch-dog timer is properly adjusted (nominal time for counting is 1024mS), but instruction used to reset it is intentionally left out so that this timer always "wins". As a result, the microcontroller is reset (state in registers remains unchanged), program starts execution from the beginning and the number in register R3 is incremented by 1 and then copied to port P1.
LEDs display this number in binary format...
;************************************************************************
;* PROGRAM NAME : WatchDog.ASM
;* DESCRIPTION : After watch-dog reset, program increments number in
;* register R3 and shows it on port P1 in binary format.
;************************************************************************

;BASIC DIRECTIVES
$MOD53
$TITLE(WATCHDOG.ASM)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING

WMCON     DATA    96H
WDTEN     EQU     00000001B        ; Watch-dog timer is enabled
PERIOD    EQU     11000000B        ; Nominal Watch-dog period is set to be 1024ms 

;RESET    VECTOR
          CSEG    AT      0
          JMP     XRESET           ; Reset vector

          CSEG
          ORG     100H

XRESET:   ORL     WMCON,#PERIOD    ; Define Watch-dog period
          ORL     WMCON,#WDTEN     ; Watch-dog timer is enabled

          MOV     A,R3             ; R3 is moved to port 1
          MOV     P1,A
          INC     R3               ; Register R3 is incremented by 1

LAB:      SJMP    LAB              ; Wait for watch-dog reset

          END                      ; End of program