1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
; Notes: GP2 = KICK DOG
; GP4 = WD ENABLE
; GP1 = PWR ENABLE
; GP0 = WD FLAG
; GP5 = WD TRIGGER CLR (to clear the flag)
;**********************************************************************
list p=12F508 ; list directive to define processor
#include <p12F508.inc> ; processor specific variable definitions
__CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;***** VARIABLE DEFINITIONS
TEMP_VAR UDATA
dc1 RES 1 ; delay loop counter
dc2 RES 1 ; delay loop counter
dc3 RES 1 ; delay loop counter
dc4 RES 1 ; delay loop counter
dc5 RES 1 ; delay loop counter
dc6 RES 1 ; delay loop counter
dc7 RES 1 ; delay loop counter
VAL RES 1 ; storage
;**********************************************************************
RESET_VECTOR CODE 0x1FF ; processor reset vector
; Internal RC calibration value is placed at location 0x1FF by Microchip
; as a movlw k, where the k is a literal value.
MAIN CODE 0x000
movwf OSCCAL ; factory cal value
TEMPO_500mS
movlw .244
movwf dc2
clrf dc1
delay1 nop
decfsz dc1,f
goto delay1
delay2 nop
decfsz dc1,f
goto delay2
decfsz dc2,f
goto delay1
TEMPO_250mS
movlw .122
movwf dc2
clrf dc1
dly1 nop
decfsz dc1,f
goto dly1
dly2 nop
decfsz dc1,f
goto dly2
decfsz dc2,f
goto dly1
;**************initialization
start
movlw b'11101100' ; GP2 and GP5:INPUTS GP4,GP1 and GP0: OUTPUTS
tris GPIO
bsf GPIO,4 ; enables WD
bsf GPIO,1 ; POWER
bcf GPIO,0 ; FLAG = 0
; TEMPO 5 MIN
movlw .4
movwf dc7
delay7
movlw .119
movwf dc6
delay6
call TEMPO_500mS
decfsz dc6, f
goto delay6
decfsz dc7, f
goto delay7
; END TEMPO 5 MIN
;*************polling on Pulse (KICK DOG, from CPU)
MAIN_LOOP
movlw .119
movwf dc4
delay4
movf GP2, 0 ; reading KICK DOG, result in working register w
movwf VAL ; saving first KICK DOG value in VAL
call TEMPO_250mS
movf VAL, 0 ; restores first KICK DOG value in working register w
xorwf GP2, 0 ; w xor GP2, result in working register w
btfss Z, 0 ; testing zero flag (status register).
goto MAIN_LOOP ; zero flag = 0 => heartbeat detected
decfsz dc4, f ; zero flag = 1 => nothing happened
goto delay4
;************reset
bsf GPIO, 0 ; FLAG
bcf GPIO, 1 ; POWER LINE (turns off)
call TEMPO_500mS ; time to reset
bsf GPIO, 1 ; POWER LINE (reboots)
;***********polling on Trigger (flag removal authorization)
SECOND_LOOP
movlw .4 ; need to go through the loop 5 times
movwf dc3
delay3
; TEMPO 1 MIN+POLLING ON TRIGGER
movlw .239
movwf dc5
delay5
call TEMPO_250mS
btfss GPIO, 5 ; testing WD Trigger CLR (0=> FLAG must be removed)
bcf GPIO, 0 ; FLAG = 0
decfsz dc5, f
goto delay5
; END TEMPO 1 MIN
decfsz dc3, f ; loop over? (dec dc2, skip if zero)
goto delay3
goto MAIN_LOOP ; repeats polling on pulse (KICK DOG, from CPU)
END |
Partager