;; ;; Programmer: Craig Stuart Sapp ;; Filename: watchdog.sx ;; Reference: Introduction to Assembly Language Programming ;; with the Scenix SX Microcontroller, version 1.2 ;; Ref Webpage: http://www.sxtech.com/Downloads/intro_to_sx.pdf ;; Ref Page: 40 ;; Webpage: http://devices.sapp.org/program/scenix/watchdog/watchdog.sx ;; Creation Date: 31 May 2000 ;; Last Modified: 2 June 2000 ;; ;; Description: A demonstration of how to use the watchdog timer. ;; This program will light up an LED connected to ;; any of the 8 Port B (rb) I/O pins. The LED will be turned ;; on or off every 144 milliseconds when the watchdog timer ;; expires. ;; ;; The watchdog timer is usually used to reset the processor ;; in the case of a malfunction. The timer increments at the ;; specified period and times out after 256 counts. To reset ;; the timer, use "CLR !WDT". Continuously clearing the ;; watchdog timer before it reaches a count of 256 will prevent ;; it from triggering and thus resetting the program. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; device pic16c55, oscxt5 device turbo, stackx_optionx device watchdog reset Start freq 50_000_000 org 0 Start MOV !option, #%11111011 ; configure watchdog timer MOV !rb, #0 ; set all port Bs to be outputs JNB to, Again ; skip Init if watchdog reset Init ; initialize variables after hard reset MOV 8, #%10101010 ; initial LED pattern for port B Again ; continuous loop for watchdog timeout ; flip LEDs states NOT 8 ; flip stored LED states MOV rb, 8 ; then write new states to port B SLEEP ; do nothing until timeout occurs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Program Notes: ; ; This program has three sections, the Start label area will be ; run every time a reset is generated, either by pressing the ; reset button, turning the processor on, or a watchdog timeout. ; ; After the Start label area is run, the program will progress ; into the Init label area if the program has been reset from ; either a power-on, or a press of the reset button. However if ; the reset is due to a watchdog reset, then the Init section ; will be skiped. This selectivity of the Init section is ; accomplished with the line: ; JNB to, Again ; Which means: if the "to" (timeout) bit is set to 0, goto ; the Again label, else continue through the program. ; The "to" bit is set to 0 if a watchdog timeout has caused ; the reset; otherwise, the "to" bit is set to 1. ; The variable "to" is an assembler abbreviation for bit 4 of ; the status register, so the line above could also be written ; like this: ; JNB status.4, Again ; ; Address location 8 stores the state of the LEDs. ; 1=LED off, and 0=LED on. The Init section of the code sets the ; value of 8 for the first time when running the program. Afterwards, ; when a watchdog timer reset occurs, the initialization of 8 will be ; skipped, and the value of 8 will be flipped and copied into the rb ; register which sets the states of the output pins for port B. ; ; the rb register is set to be all output signals by the command: ; MOV !rb, #0 ; By default all of the rb pins will be inputs, which is like: ; MOV !rb, #$ff ; When the processor is reset, the value of !rb goes to $ff, so ; you will have to reset the direction of the rb pins for every ; reset. Also, if you set the value of !rb from $ff to 0, then ; the value of rb is set to $ff. That is why the state of the ; pins is stored in address location 8; otherwise, the previous ; state of rb would be lost at reset. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Watchdog timer settings: ; ; ; You can tell if the processor was reset from the watchdog ; timer by examining the the bits in the status register. ; Status bit 4 == 0 means watchdog triggered at reset ; Status bit 3 == 0 means sleep instruction was active on wdt ; ; You can control the period of the watchdog timer: ; !option = %11111000 == 1:1 ratio (18 millisecond timeout) ; !option = %11111001 == 1:2 ratio (36 millisecond timeout) ; !option = %11111010 == 1:4 ratio (72 millisecond timeout) ; !option = %11111011 == 1:8 ratio (144 msec timeout) ; !option = %11111100 == 1:16 ratio (288 msec timeout) ; !option = %11111101 == 1:32 ratio (576 msec timeout) ; !option = %11111110 == 1:64 ratio (1.152 sec timeout) ; !option = %11111111 == 1:128 ratio (2.304 sec timeout) ; ; If the watchdog time is active according to the assembler ; directive: "device watchdog", then the devault setting ; for !option will be %11111111. ; ; Every time the watchdog timer resets the program, the ; the settings of !option are erased and replaced with ; %11111111. You will have to rewrite the !option values ; to continue with the same settings. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Assembler Directive Notes: ; ; device pic16c55, oscxt5 ; Assembler directive that tells the assembler to have ; the SX controller to configure itself like a PIC16C55 ; microprocessor and a high-speed oscillator (oscxt5). ; ; device turbo, stackx_optionx ; turbo = pipelined program execution mode ; stackx_optionx = ? ; ; reset Start ; indicates where the program is to start executing. ; "Start" is a user-defined label. This label marks ; where the program will start executing when it is started. ; ; freq 50_000_000 ; Specifies the clock frequency in Hertz. Not needed by ; the SX chip, but helps the debugger determine what clock ; frequency you want to use. The default value is 50 MHz ; if none is specified. The underscore characters are ; optional and used for readability. ; ; org 0 ; "Origin" -- a directive that instructs the assembler to ; begin generating code at the specified address ; ;