目次PIC回路集カウントダウン・タイマー


カウントダウン・タイマー プログラムソースリスト

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
;********************************************************
;
;             The Count-down timer processing
;
;                                 Author : Seiichi Inoue
;********************************************************

        list            p=pic16f84a
        include         p16f84a.inc
        __config _hs_osc & _wdt_off & _pwrte_on & _cp_off

;****************  Label Definition  ********************
c10m    equ     h'0c'           ;Counter adr (10th min)
c01m    equ     h'0d'           ;Counter adr ( 1st min)
c10s    equ     h'0e'           ;Counter adr (10th sec)
c01s    equ     h'0f'           ;Counter adr ( 1st sec)

seg7_0  equ     b'01000000'     ;-gfedcba Pattern 0
seg7_1  equ     b'01111001'     ;         Pattern 1
seg7_2  equ     b'00100100'     ;         Pattern 2
seg7_3  equ     b'00110000'     ;         Pattern 3
seg7_4  equ     b'00011001'     ;         Pattern 4
seg7_5  equ     b'00010010'     ;         Pattern 5
seg7_6  equ     b'00000010'     ;         Pattern 6
seg7_7  equ     b'01111000'     ;         Pattern 7
seg7_8  equ     b'00000000'     ;         Pattern 8
seg7_9  equ     b'00010000'     ;         Pattern 9

seg70   equ     h'10'           ;Pattern 0 set adr
seg71   equ     h'11'           ;Pattern 1 set adr
seg72   equ     h'12'           ;Pattern 2 set adr
seg73   equ     h'13'           ;Pattern 3 set adr
seg74   equ     h'14'           ;Pattern 4 set adr
seg75   equ     h'15'           ;Pattern 5 set adr
seg76   equ     h'16'           ;Pattern 6 set adr
seg77   equ     h'17'           ;Pattern 7 set adr
seg78   equ     h'18'           ;Pattern 8 set adr
seg79   equ     h'19'           ;Pattern 9 set adr

tm_cnt  equ     h'1a'           ;Time adjust counter adr
time_f  equ     h'1b'           ;Time out flag adr
bcd_in  equ     h'1c'           ;BCD input area adr

w_save  equ     h'1d'           ;W Register save adr
s_save  equ     h'1e'           ;STATUS Register save adr

cnt500u equ     h'1f'           ;500usec counter adr
cnt1m   equ     h'20'           ;1msec counter adr

ra0     equ     0               ;RA0 of PORTA
ra1     equ     1               ;RA1 of PORTA
ra2     equ     2               ;RA2 of PORTA
ra3     equ     3               ;RA3 of PORTA
ra4     equ     4               ;RA4 of PORTA

rb6     equ     6               ;RB6 of PORTB

;**************  Debugging mode setting  ****************
;For debugging mode, ";" of next line should be removed.
;#define  _debug

;****************  Program Start  ***********************
        org     0               ;Reset Vector
        goto    init
        org     4               ;Interrupt Vector
        goto    int

;****************  Initial Process  *********************
        org     5
init    bsf     status,rp0      ;Change to Bank1
        movlw   b'00010000'     ;RA4:IN,RA3-0:OUT
        movwf   trisa           ;Set PORTA
        movlw   b'00000111'     ;RBPU/TOCS/PSA=0,PS=111
        movwf   option_reg      ;Set OPTION_REG
        bcf     status,rp0      ;Change to Bank0
        movlw   b'00001000'     ;Set Relay OFF
        movwf   porta           ;Set PORTA
        movlw   seg7_0          ;Set 7segment pattern 0
        movwf   seg70           ;Save pattern 0
        movlw   seg7_1          ;Set 7segment pattern 1
        movwf   seg71           ;Save pattern 1
        movlw   seg7_2          ;Set 7segment pattern 2
        movwf   seg72           ;Save pattern 2
        movlw   seg7_3          ;Set 7segment pattern 3
        movwf   seg73           ;Save pattern 3
        movlw   seg7_4          ;Set 7segment pattern 4
        movwf   seg74           ;Save pattern 4
        movlw   seg7_5          ;Set 7segment pattern 5
        movwf   seg75           ;Save pattern 5
        movlw   seg7_6          ;Set 7segment pattern 6
        movwf   seg76           ;Save pattern 6
        movlw   seg7_7          ;Set 7segment pattern 7
        movwf   seg77           ;Save pattern 7
        movlw   seg7_8          ;Set 7segment pattern 8
        movwf   seg78           ;Save pattern 8
        movlw   seg7_9          ;Set 7segment pattern 9
        movwf   seg79           ;Save pattern 9
        clrf    c10s            ;Clear 10th sec counter
        clrf    c01s            ;Clear  1st sec counter
        bsf     time_f,0        ;Set time out flag OFF

;*************  Timer stand-by Process  *****************
stand_by
        bsf     status,rp0      ;Change to Bank1
        movlw   h'ff'           ;RB7-0:IN
        movwf   trisb           ;Set PORTB to input mode
        bcf     status,rp0      ;Change to Bank0
        bcf     porta,ra0       ;RA0 = 0 (10th min BCD)
        bcf     porta,ra1       ;RA1 = 0
        bcf     porta,ra2       ;RA2 = 0
#ifdef _debug
        movlw   h'fe'           ;(Debugging step)
#else
        call    t1m             ;Wait 1msec
        movf    portb,w         ;Read 10th of min BCD
#endif
        xorlw   h'ff'           ;Reverse 0/1
        andlw   h'0f'           ;Pick-up digit
        movwf   c10m            ;Save 10th of the minute
        bsf     porta,ra0       ;RA0 = 1 (1st min BCD)
#ifdef _debug
        movlw   h'ff'           ;(Debugging step)
#else
        call    t1m             ;Wait 1msec
        movf    portb,w         ;Read 1st of min BCD
#endif
        xorlw   h'ff'           ;Reverse 0/1
        andlw   h'0f'           ;Pick-up digit
        movwf   c01m            ;Save 1st of the minute
        call    led_cont        ;Call LED Countrol sub
        movf    c10m,w          ;Read 10th of minute
        btfss   status,z        ;10th of min is 0 ?
        goto    sw_check        ;Jump to start sw check
        movf    c01m,w          ;Read 1st of minute
        btfsc   status,z        ;1st of min is 0 ?
        goto    stand_by        ;Time is 00:00
sw_check
        bsf     status,rp0      ;Change to Bank1
        bsf     trisb,rb6       ;Set RB6 to input mode
        bcf     status,rp0      ;Change to Bank0
        bcf     porta,ra0       ;RA0 = 0 (Start switch)
        bsf     porta,ra1       ;RA1 = 1
        bcf     porta,ra2       ;RA2 = 0
#ifndef _debug
        call    t1m             ;Wait 1msec
        btfsc   portb,rb6       ;Timer start ?
        goto    stand_by        ;No. Stand-by.
#endif

;**************  Timer start Process  *******************
start   
        bcf     porta,ra3       ;Set Relay ON
#ifdef _debug
        movlw   d'255'          ;(Debugging step)
#else
        movlw   d'43'           ;Set Hard timer value
#endif
        movwf   tmr0            ;Set TMR0
#ifdef _debug
        movlw   d'2'            ;(Debugging step)
#else
        movlw   d'46'           ;Set Soft count value
#endif
        movwf   tm_cnt          ;Save time adjust
        movlw   h'a0'           ;GIE=1,TOIE=1
        movwf   intcon          ;Interruption enable
loop
        call    led_cont        ;Call LED Countrol sub
        movf    time_f,w        ;Read time out flag
        btfsc   status,z        ;Time out ?
        goto    time_out        ;Yes. Jump to time out

#ifndef _debug
        btfsc   porta,ra4       ;Stop switch ON ?
#endif
        goto    loop            ;No. Retry

time_out
        clrf    intcon          ;Interruptin disable
        goto    init            ;Jump to Initial Process

;**************  LED Control Subroutine  ****************
led_cont
        bsf     status,rp0      ;Change to Bank1
        clrf    trisb           ;Set PORTB to output mode
        bcf     status,rp0      ;Change to Bank0
        bcf     porta,ra0       ;RA0 = 0 (7seg 10th min)
        bcf     porta,ra1       ;RA1 = 0
        bsf     porta,ra2       ;RA2 = 1
        movf    c10m,w          ;Read 10th of min count
        movwf   bcd_in          ;Set count
        call    bcd_7seg        ;LED control
        bsf     porta,ra0       ;RA0 = 1 (7seg 1st min)
        movf    c01m,w          ;Read 1st of min count
        movwf   bcd_in          ;Set count
        call    bcd_7seg        ;LED control
        bcf     porta,ra0       ;RA0 = 0 (7seg 10th sec)
        bsf     porta,ra1       ;RA1 = 1
        movf    c10s,w          ;Read 10th of sec count
        movwf   bcd_in          ;Set count
        call    bcd_7seg        ;LED control
        bsf     porta,ra0       ;RA0 = 1 (7seg 1st sec)
        movf    c01s,w          ;Read 1st of sec count
        movwf   bcd_in          ;Set count
        call    bcd_7seg        ;LED control
        return

;*******  Change BCD to 7segment data Subroutine  *******
bcd_7seg
        movlw   seg70           ;Set 7seg pattern head
        addwf   bcd_in,w        ;Pattern table address
        movwf   fsr             ;Set table address
        movf    indf,w          ;Read 7seg pattern
        movwf   portb           ;Set pattern to PORTB
#ifndef _debug
        call    t1m             ;Wait 1msec
#endif
        return

;*************  1msec Timer Subroutine  *****************
t1m     movlw   2               ;(1)       Set loop cnt1
        movwf   cnt1m           ;(1)       Save loop cnt1
tm1lp1  movlw   d'249'          ;(1)*2     Set loop cnt2
        movwf   cnt500u         ;(1)*2     Save loop cnt2
tm1lp2  nop                     ;(1)*249*2 Time adjust
        nop                     ;(1)*249*2 Time adjust
        decfsz  cnt500u,f       ;(1)*249*2 cnt500u-1=0 ?
        goto    tm1lp2          ;(2)*248*2 No, continue
        decfsz  cnt1m,f         ;(1)*2     cnt1m-1=0 ?
        goto    tm1lp1          ;(2)       No. Continue
        return                  ;(2)       Yes. Cnt end
                                ;Total 2501*0.4usec=1msec

;************  Begin Interruption Process  **************
int
        movwf   w_save          ;Save W register
        movf    status,w        ;Read STATUS reg
        movwf   s_save          ;Save STATUS reg
        bcf     status,rp0      ;Change to Bank0
        btfsc   intcon,t0if     ;Time out interruption ?
        goto    timer_int       ;Jump to Timer process
 
;************  END of Interruption Process **************
int_end
        movf    s_save,w        ;Read saved STATUS reg
        movwf   status          ;Recover STATUS reg
        swapf   w_save,f        ;Read saved W register
        swapf   w_save,w        ;Recover W register
        retfie        
        
;***********  Time-out interruption Process  ************
timer_int
        bcf     intcon,t0if     ;Clear timer int flag
#ifdef _debug
        movlw   d'255'          ;(Debugging step)
#else
        movlw   d'43'           ;Set Hard timer value
#endif
        movwf   tmr0            ;Set TMR0
        decfsz  tm_cnt,f        ;Time over ?
        goto    int_end         ;No. Retry
#ifdef _debug
        movlw   d'2'            ;(Debugging step)
#else
        movlw   d'46'           ;Set Soft count value
#endif
        movwf   tm_cnt          ;Save time adjust

;*************  Timer count-down Process  ***************
        decfsz  c01s,w          ;1st of sec is 0 from 1 ?
        goto    countdown       ;No. Jump to countdown

;-----------------  Time-out check  ---------------------
        movf    c10s,w          ;Read 10th of sec counter
        btfss   status,z        ;10th of sec is 0 ?
        goto    countdown       ;Jump to countdown
        movf    c01m,w          ;Read 1st of min counter
        btfss   status,z        ;1st of min is 0 ?
        goto    countdown       ;Jump to countdown
        movf    c10m,w          ;Read 10th of min counter
        btfss   status,z        ;10th of min is 0 ?
        goto    countdown       ;Jump to countdown

time_out1
        clrf    time_f          ;Set time-out flag ON
        goto    int_end         ;Return

;----------------  Timer countdown  ---------------------
countdown
        movf    c01s,w          ;Read 1st of sec counter
        btfss   status,z        ;1st of sec is 0 ?
        goto    cd_c01s         ;Jump to 1st sec cntdown
        movlw   9               ;Set 9
        movwf   c01s            ;Save 9 to 1st of sec
        movf    c10s,w          ;Read 10th of sec counter
        btfss   status,z        ;10th of sec is 0 ?
        goto    cd_c10s         ;Jump to 10th min cntdown
        movlw   5               ;Set 5
        movwf   c10s            ;Save 5 to 10th of sec
        movf    c01m,w          ;Read 1st of min counter
        btfss   status,z        ;1st of min is 0 ?
        goto    cd_c01m         ;Jump to 1st min cntdown
        movlw   9               ;Set 9
        movwf   c01m            ;Save 9 to 1st of min
        movf    c10m,w          ;Read 10th of min counter
        btfss   status,z        ;10th of min is 0 ?
        goto    cd_c10m         ;Jump to 10th min cntdown
        goto    time_out1       ;Counter is 00:00 already

cd_c01s
        decf    c01s,f          ;Count down 1st of sec
        goto    int_end         ;Return

cd_c10s
        decf    c10s,f          ;Count down 10th of sec
        goto    int_end         ;Return

cd_c01m
        decf    c01m,f          ;Count down 1st of min
        goto    int_end         ;Return

cd_c10m
        decf    c10m,f          ;Count down 10th of min
        goto    int_end         ;Return

;********************************************************
;          END of Count-down timer processing
;********************************************************

        end



カウントダウン・タイマー プログラムアッセンブルリスト

MPASM 02.40 Released         COUNTDWN.ASM   6-10-2000  10:16:30         PAGE  1


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00001 ;********************************************************
                      00002 ;
                      00003 ;             The Count-down timer processing
                      00004 ;
                      00005 ;                                 Author : Seiichi Inoue
                      00006 ;********************************************************
                      00007 
                      00008         LIST            P=PIC16F84A
                      00009         INCLUDE         P16F84A.INC
                      00001         LIST
                      00002 ; P16F84A.INC  Standard Header File, Version 2.00(modify)
                      00134         LIST
2007   3FF2           00010         __CONFIG _HS_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF
                      00011 
                      00012 ;****************  Label Definition  ********************
  0000000C            00013 C10M    EQU     H'0c'           ;Counter adr (10th min)
  0000000D            00014 C01M    EQU     H'0d'           ;Counter adr ( 1st min)
  0000000E            00015 C10S    EQU     H'0e'           ;Counter adr (10th sec)
  0000000F            00016 C01S    EQU     H'0f'           ;Counter adr ( 1st sec)
                      00017 
  00000040            00018 SEG7_0  EQU     B'01000000'     ;-gfedcba Pattern 0
  00000079            00019 SEG7_1  EQU     B'01111001'     ;         Pattern 1
  00000024            00020 SEG7_2  EQU     B'00100100'     ;         Pattern 2
  00000030            00021 SEG7_3  EQU     B'00110000'     ;         Pattern 3
  00000019            00022 SEG7_4  EQU     B'00011001'     ;         Pattern 4
  00000012            00023 SEG7_5  EQU     B'00010010'     ;         Pattern 5
  00000002            00024 SEG7_6  EQU     B'00000010'     ;         Pattern 6
  00000078            00025 SEG7_7  EQU     B'01111000'     ;         Pattern 7
  00000000            00026 SEG7_8  EQU     B'00000000'     ;         Pattern 8
  00000010            00027 SEG7_9  EQU     B'00010000'     ;         Pattern 9
                      00028 
  00000010            00029 SEG70   EQU     H'10'           ;Pattern 0 set adr
  00000011            00030 SEG71   EQU     H'11'           ;Pattern 1 set adr
  00000012            00031 SEG72   EQU     H'12'           ;Pattern 2 set adr
  00000013            00032 SEG73   EQU     H'13'           ;Pattern 3 set adr
  00000014            00033 SEG74   EQU     H'14'           ;Pattern 4 set adr
  00000015            00034 SEG75   EQU     H'15'           ;Pattern 5 set adr
  00000016            00035 SEG76   EQU     H'16'           ;Pattern 6 set adr
  00000017            00036 SEG77   EQU     H'17'           ;Pattern 7 set adr
  00000018            00037 SEG78   EQU     H'18'           ;Pattern 8 set adr
  00000019            00038 SEG79   EQU     H'19'           ;Pattern 9 set adr
                      00039 
  0000001A            00040 TM_CNT  EQU     H'1a'           ;Time adjust counter adr
  0000001B            00041 TIME_F  EQU     H'1b'           ;Time out flag adr
  0000001C            00042 BCD_IN  EQU     H'1c'           ;BCD input area adr
                      00043 
  0000001D            00044 W_SAVE  EQU     H'1d'           ;W Register save adr
  0000001E            00045 S_SAVE  EQU     H'1e'           ;STATUS Register save adr
                      00046 
  0000001F            00047 CNT500U EQU     H'1f'           ;500usec counter adr
  00000020            00048 CNT1M   EQU     H'20'           ;1msec counter adr
                      00049 
  00000000            00050 RA0     EQU     0               ;RA0 of PORTA
MPASM 02.40 Released         COUNTDWN.ASM   6-10-2000  10:16:30         PAGE  2


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

  00000001            00051 RA1     EQU     1               ;RA1 of PORTA
  00000002            00052 RA2     EQU     2               ;RA2 of PORTA
  00000003            00053 RA3     EQU     3               ;RA3 of PORTA
  00000004            00054 RA4     EQU     4               ;RA4 of PORTA
                      00055 
  00000006            00056 RB6     EQU     6               ;RB6 of PORTB
                      00057 
                      00058 ;**************  Debugging mode setting  ****************
                      00059 ;For debugging mode, ";" of next line should be removed.
                      00060 ;#define  _debug
                      00061 
                      00062 ;****************  Program Start  ***********************
0000                  00063         ORG     0               ;Reset Vector
0000   2805           00064         GOTO    INIT
0004                  00065         ORG     4               ;Interrupt Vector
0004   287E           00066         GOTO    INT
                      00067 
                      00068 ;****************  Initial Process  *********************
0005                  00069         ORG     5
0005   1683           00070 INIT    BSF     STATUS,RP0      ;Change to Bank1
0006   3010           00071         MOVLW   B'00010000'     ;RA4:IN,RA3-0:OUT
0007   0085           00072         MOVWF   TRISA           ;Set PORTA
0008   3007           00073         MOVLW   B'00000111'     ;RBPU/TOCS/PSA=0,PS=111
0009   0081           00074         MOVWF   OPTION_REG      ;Set OPTION_REG
000A   1283           00075         BCF     STATUS,RP0      ;Change to Bank0
000B   3008           00076         MOVLW   B'00001000'     ;Set Relay OFF
000C   0085           00077         MOVWF   PORTA           ;Set PORTA
000D   3040           00078         MOVLW   SEG7_0          ;Set 7segment pattern 0
000E   0090           00079         MOVWF   SEG70           ;Save pattern 0
000F   3079           00080         MOVLW   SEG7_1          ;Set 7segment pattern 1
0010   0091           00081         MOVWF   SEG71           ;Save pattern 1
0011   3024           00082         MOVLW   SEG7_2          ;Set 7segment pattern 2
0012   0092           00083         MOVWF   SEG72           ;Save pattern 2
0013   3030           00084         MOVLW   SEG7_3          ;Set 7segment pattern 3
0014   0093           00085         MOVWF   SEG73           ;Save pattern 3
0015   3019           00086         MOVLW   SEG7_4          ;Set 7segment pattern 4
0016   0094           00087         MOVWF   SEG74           ;Save pattern 4
0017   3012           00088         MOVLW   SEG7_5          ;Set 7segment pattern 5
0018   0095           00089         MOVWF   SEG75           ;Save pattern 5
0019   3002           00090         MOVLW   SEG7_6          ;Set 7segment pattern 6
001A   0096           00091         MOVWF   SEG76           ;Save pattern 6
001B   3078           00092         MOVLW   SEG7_7          ;Set 7segment pattern 7
001C   0097           00093         MOVWF   SEG77           ;Save pattern 7
001D   3000           00094         MOVLW   SEG7_8          ;Set 7segment pattern 8
001E   0098           00095         MOVWF   SEG78           ;Save pattern 8
001F   3010           00096         MOVLW   SEG7_9          ;Set 7segment pattern 9
0020   0099           00097         MOVWF   SEG79           ;Save pattern 9
0021   018E           00098         CLRF    C10S            ;Clear 10th sec counter
0022   018F           00099         CLRF    C01S            ;Clear  1st sec counter
0023   141B           00100         BSF     TIME_F,0        ;Set time out flag OFF
                      00101 
                      00102 ;*************  Timer stand-by Process  *****************
0024                  00103 STAND_BY
MPASM 02.40 Released         COUNTDWN.ASM   6-10-2000  10:16:30         PAGE  3


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

0024   1683           00104         BSF     STATUS,RP0      ;Change to Bank1
0025   30FF           00105         MOVLW   H'ff'           ;RB7-0:IN
0026   0086           00106         MOVWF   TRISB           ;Set PORTB to input mode
0027   1283           00107         BCF     STATUS,RP0      ;Change to Bank0
0028   1005           00108         BCF     PORTA,RA0       ;RA0 = 0 (10th min BCD)
0029   1085           00109         BCF     PORTA,RA1       ;RA1 = 0
002A   1105           00110         BCF     PORTA,RA2       ;RA2 = 0
                      00111 #IFDEF _DEBUG
                      00112         MOVLW   H'fe'           ;(Debugging step)
                      00113 #ELSE
002B   2073           00114         CALL    T1M             ;Wait 1msec
002C   0806           00115         MOVF    PORTB,W         ;Read 10th of min BCD
                      00116 #ENDIF
002D   3AFF           00117         XORLW   H'ff'           ;Reverse 0/1
002E   390F           00118         ANDLW   H'0f'           ;Pick-up digit
002F   008C           00119         MOVWF   C10M            ;Save 10th of the minute
0030   1405           00120         BSF     PORTA,RA0       ;RA0 = 1 (1st min BCD)
                      00121 #IFDEF _DEBUG
                      00122         MOVLW   H'ff'           ;(Debugging step)
                      00123 #ELSE
0031   2073           00124         CALL    T1M             ;Wait 1msec
0032   0806           00125         MOVF    PORTB,W         ;Read 1st of min BCD
                      00126 #ENDIF
0033   3AFF           00127         XORLW   H'ff'           ;Reverse 0/1
0034   390F           00128         ANDLW   H'0f'           ;Pick-up digit
0035   008D           00129         MOVWF   C01M            ;Save 1st of the minute
0036   2055           00130         CALL    LED_CONT        ;Call LED Countrol sub
0037   080C           00131         MOVF    C10M,W          ;Read 10th of minute
0038   1D03           00132         BTFSS   STATUS,Z        ;10th of min is 0 ?
0039   283D           00133         GOTO    SW_CHECK        ;Jump to start sw check
003A   080D           00134         MOVF    C01M,W          ;Read 1st of minute
003B   1903           00135         BTFSC   STATUS,Z        ;1st of min is 0 ?
003C   2824           00136         GOTO    STAND_BY        ;Time is 00:00
003D                  00137 SW_CHECK
003D   1683           00138         BSF     STATUS,RP0      ;Change to Bank1
003E   1706           00139         BSF     TRISB,RB6       ;Set RB6 to input mode
003F   1283           00140         BCF     STATUS,RP0      ;Change to Bank0
0040   1005           00141         BCF     PORTA,RA0       ;RA0 = 0 (Start switch)
0041   1485           00142         BSF     PORTA,RA1       ;RA1 = 1
0042   1105           00143         BCF     PORTA,RA2       ;RA2 = 0
                      00144 #IFNDEF _DEBUG
0043   2073           00145         CALL    T1M             ;Wait 1msec
0044   1B06           00146         BTFSC   PORTB,RB6       ;Timer start ?
0045   2824           00147         GOTO    STAND_BY        ;No. Stand-by.
                      00148 #ENDIF
                      00149 
                      00150 ;**************  Timer start Process  *******************
0046                  00151 START   
0046   1185           00152         BCF     PORTA,RA3       ;Set Relay ON
                      00153 #IFDEF _DEBUG
                      00154         MOVLW   D'255'          ;(Debugging step)
                      00155 #ELSE
0047   302B           00156         MOVLW   D'43'           ;Set Hard timer value
MPASM 02.40 Released         COUNTDWN.ASM   6-10-2000  10:16:30         PAGE  4


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00157 #ENDIF
0048   0081           00158         MOVWF   TMR0            ;Set TMR0
                      00159 #IFDEF _DEBUG
                      00160         MOVLW   D'2'            ;(Debugging step)
                      00161 #ELSE
0049   302E           00162         MOVLW   D'46'           ;Set Soft count value
                      00163 #ENDIF
004A   009A           00164         MOVWF   TM_CNT          ;Save time adjust
004B   30A0           00165         MOVLW   H'a0'           ;GIE=1,TOIE=1
004C   008B           00166         MOVWF   INTCON          ;Interruption enable
004D                  00167 LOOP
004D   2055           00168         CALL    LED_CONT        ;Call LED Countrol sub
004E   081B           00169         MOVF    TIME_F,W        ;Read time out flag
004F   1903           00170         BTFSC   STATUS,Z        ;Time out ?
0050   2853           00171         GOTO    TIME_OUT        ;Yes. Jump to time out
                      00172 
                      00173 #IFNDEF _DEBUG
0051   1A05           00174         BTFSC   PORTA,RA4       ;Stop switch ON ?
                      00175 #ENDIF
0052   284D           00176         GOTO    LOOP            ;No. Retry
                      00177 
0053                  00178 TIME_OUT
0053   018B           00179         CLRF    INTCON          ;Interruptin disable
0054   2805           00180         GOTO    INIT            ;Jump to Initial Process
                      00181 
                      00182 ;**************  LED Control Subroutine  ****************
0055                  00183 LED_CONT
0055   1683           00184         BSF     STATUS,RP0      ;Change to Bank1
0056   0186           00185         CLRF    TRISB           ;Set PORTB to output mode
0057   1283           00186         BCF     STATUS,RP0      ;Change to Bank0
0058   1005           00187         BCF     PORTA,RA0       ;RA0 = 0 (7seg 10th min)
0059   1085           00188         BCF     PORTA,RA1       ;RA1 = 0
005A   1505           00189         BSF     PORTA,RA2       ;RA2 = 1
005B   080C           00190         MOVF    C10M,W          ;Read 10th of min count
005C   009C           00191         MOVWF   BCD_IN          ;Set count
005D   206C           00192         CALL    BCD_7SEG        ;LED control
005E   1405           00193         BSF     PORTA,RA0       ;RA0 = 1 (7seg 1st min)
005F   080D           00194         MOVF    C01M,W          ;Read 1st of min count
0060   009C           00195         MOVWF   BCD_IN          ;Set count
0061   206C           00196         CALL    BCD_7SEG        ;LED control
0062   1005           00197         BCF     PORTA,RA0       ;RA0 = 0 (7seg 10th sec)
0063   1485           00198         BSF     PORTA,RA1       ;RA1 = 1
0064   080E           00199         MOVF    C10S,W          ;Read 10th of sec count
0065   009C           00200         MOVWF   BCD_IN          ;Set count
0066   206C           00201         CALL    BCD_7SEG        ;LED control
0067   1405           00202         BSF     PORTA,RA0       ;RA0 = 1 (7seg 1st sec)
0068   080F           00203         MOVF    C01S,W          ;Read 1st of sec count
0069   009C           00204         MOVWF   BCD_IN          ;Set count
006A   206C           00205         CALL    BCD_7SEG        ;LED control
006B   0008           00206         RETURN
                      00207 
                      00208 ;*******  Change BCD to 7segment data Subroutine  *******
006C                  00209 BCD_7SEG
MPASM 02.40 Released         COUNTDWN.ASM   6-10-2000  10:16:30         PAGE  5


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

006C   3010           00210         MOVLW   SEG70           ;Set 7seg pattern head
006D   071C           00211         ADDWF   BCD_IN,W        ;Pattern table address
006E   0084           00212         MOVWF   FSR             ;Set table address
006F   0800           00213         MOVF    INDF,W          ;Read 7seg pattern
0070   0086           00214         MOVWF   PORTB           ;Set pattern to PORTB
                      00215 #IFNDEF _DEBUG
0071   2073           00216         CALL    T1M             ;Wait 1msec
                      00217 #ENDIF
0072   0008           00218         RETURN
                      00219 
                      00220 ;*************  1msec Timer Subroutine  *****************
0073   3002           00221 T1M     MOVLW   2               ;(1)       Set loop cnt1
0074   00A0           00222         MOVWF   CNT1M           ;(1)       Save loop cnt1
0075   30F9           00223 TM1LP1  MOVLW   D'249'          ;(1)*2     Set loop cnt2
0076   009F           00224         MOVWF   CNT500U         ;(1)*2     Save loop cnt2
0077   0000           00225 TM1LP2  NOP                     ;(1)*249*2 Time adjust
0078   0000           00226         NOP                     ;(1)*249*2 Time adjust
0079   0B9F           00227         DECFSZ  CNT500U,F       ;(1)*249*2 cnt500u-1=0 ?
007A   2877           00228         GOTO    TM1LP2          ;(2)*248*2 No, continue
007B   0BA0           00229         DECFSZ  CNT1M,F         ;(1)*2     cnt1m-1=0 ?
007C   2875           00230         GOTO    TM1LP1          ;(2)       No. Continue
007D   0008           00231         RETURN                  ;(2)       Yes. Cnt end
                      00232                                 ;Total 2501*0.4usec=1msec
                      00233 
                      00234 ;************  Begin Interruption Process  **************
007E                  00235 INT
007E   009D           00236         MOVWF   W_SAVE          ;Save W register
007F   0803           00237         MOVF    STATUS,W        ;Read STATUS reg
0080   009E           00238         MOVWF   S_SAVE          ;Save STATUS reg
0081   1283           00239         BCF     STATUS,RP0      ;Change to Bank0
0082   190B           00240         BTFSC   INTCON,T0IF     ;Time out interruption ?
0083   2889           00241         GOTO    TIMER_INT       ;Jump to Timer process
                      00242  
                      00243 ;************  END of Interruption Process **************
0084                  00244 INT_END
0084   081E           00245         MOVF    S_SAVE,W        ;Read saved STATUS reg
0085   0083           00246         MOVWF   STATUS          ;Recover STATUS reg
0086   0E9D           00247         SWAPF   W_SAVE,F        ;Read saved W register
0087   0E1D           00248         SWAPF   W_SAVE,W        ;Recover W register
0088   0009           00249         RETFIE        
                      00250         
                      00251 ;***********  Time-out interruption Process  ************
0089                  00252 TIMER_INT
0089   110B           00253         BCF     INTCON,T0IF     ;Clear timer int flag
                      00254 #IFDEF _DEBUG
                      00255         MOVLW   D'255'          ;(Debugging step)
                      00256 #ELSE
008A   302B           00257         MOVLW   D'43'           ;Set Hard timer value
                      00258 #ENDIF
008B   0081           00259         MOVWF   TMR0            ;Set TMR0
008C   0B9A           00260         DECFSZ  TM_CNT,F        ;Time over ?
008D   2884           00261         GOTO    INT_END         ;No. Retry
                      00262 #IFDEF _DEBUG
MPASM 02.40 Released         COUNTDWN.ASM   6-10-2000  10:16:30         PAGE  6


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00263         MOVLW   D'2'            ;(Debugging step)
                      00264 #ELSE
008E   302E           00265         MOVLW   D'46'           ;Set Soft count value
                      00266 #ENDIF
008F   009A           00267         MOVWF   TM_CNT          ;Save time adjust
                      00268 
                      00269 ;*************  Timer count-down Process  ***************
0090   0B0F           00270         DECFSZ  C01S,W          ;1st of sec is 0 from 1 ?
0091   289D           00271         GOTO    COUNTDOWN       ;No. Jump to countdown
                      00272 
                      00273 ;-----------------  Time-out check  ---------------------
0092   080E           00274         MOVF    C10S,W          ;Read 10th of sec counter
0093   1D03           00275         BTFSS   STATUS,Z        ;10th of sec is 0 ?
0094   289D           00276         GOTO    COUNTDOWN       ;Jump to countdown
0095   080D           00277         MOVF    C01M,W          ;Read 1st of min counter
0096   1D03           00278         BTFSS   STATUS,Z        ;1st of min is 0 ?
0097   289D           00279         GOTO    COUNTDOWN       ;Jump to countdown
0098   080C           00280         MOVF    C10M,W          ;Read 10th of min counter
0099   1D03           00281         BTFSS   STATUS,Z        ;10th of min is 0 ?
009A   289D           00282         GOTO    COUNTDOWN       ;Jump to countdown
                      00283 
009B                  00284 TIME_OUT1
009B   019B           00285         CLRF    TIME_F          ;Set time-out flag ON
009C   2884           00286         GOTO    INT_END         ;Return
                      00287 
                      00288 ;----------------  Timer countdown  ---------------------
009D                  00289 COUNTDOWN
009D   080F           00290         MOVF    C01S,W          ;Read 1st of sec counter
009E   1D03           00291         BTFSS   STATUS,Z        ;1st of sec is 0 ?
009F   28B0           00292         GOTO    CD_C01S         ;Jump to 1st sec cntdown
00A0   3009           00293         MOVLW   9               ;Set 9
00A1   008F           00294         MOVWF   C01S            ;Save 9 to 1st of sec
00A2   080E           00295         MOVF    C10S,W          ;Read 10th of sec counter
00A3   1D03           00296         BTFSS   STATUS,Z        ;10th of sec is 0 ?
00A4   28B2           00297         GOTO    CD_C10S         ;Jump to 10th min cntdown
00A5   3005           00298         MOVLW   5               ;Set 5
00A6   008E           00299         MOVWF   C10S            ;Save 5 to 10th of sec
00A7   080D           00300         MOVF    C01M,W          ;Read 1st of min counter
00A8   1D03           00301         BTFSS   STATUS,Z        ;1st of min is 0 ?
00A9   28B4           00302         GOTO    CD_C01M         ;Jump to 1st min cntdown
00AA   3009           00303         MOVLW   9               ;Set 9
00AB   008D           00304         MOVWF   C01M            ;Save 9 to 1st of min
00AC   080C           00305         MOVF    C10M,W          ;Read 10th of min counter
00AD   1D03           00306         BTFSS   STATUS,Z        ;10th of min is 0 ?
00AE   28B6           00307         GOTO    CD_C10M         ;Jump to 10th min cntdown
00AF   289B           00308         GOTO    TIME_OUT1       ;Counter is 00:00 already
                      00309 
00B0                  00310 CD_C01S
00B0   038F           00311         DECF    C01S,F          ;Count down 1st of sec
00B1   2884           00312         GOTO    INT_END         ;Return
                      00313 
00B2                  00314 CD_C10S
00B2   038E           00315         DECF    C10S,F          ;Count down 10th of sec
MPASM 02.40 Released         COUNTDWN.ASM   6-10-2000  10:16:30         PAGE  7


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

00B3   2884           00316         GOTO    INT_END         ;Return
                      00317 
00B4                  00318 CD_C01M
00B4   038D           00319         DECF    C01M,F          ;Count down 1st of min
00B5   2884           00320         GOTO    INT_END         ;Return
                      00321 
00B6                  00322 CD_C10M
00B6   038C           00323         DECF    C10M,F          ;Count down 10th of min
00B7   2884           00324         GOTO    INT_END         ;Return
                      00325 
                      00326 ;********************************************************
                      00327 ;          END of Count-down timer processing
                      00328 ;********************************************************
                      00329 
                      00330         END
MPASM 02.40 Released         COUNTDWN.ASM   6-10-2000  10:16:30         PAGE  8


SYMBOL TABLE
  LABEL                             VALUE 

BCD_7SEG                          0000006C
BCD_IN                            0000001C
C                                 00000000
C01M                              0000000D
C01S                              0000000F
C10M                              0000000C
C10S                              0000000E
CD_C01M                           000000B4
CD_C01S                           000000B0
CD_C10M                           000000B6
CD_C10S                           000000B2
CNT1M                             00000020
CNT500U                           0000001F
COUNTDOWN                         0000009D
DC                                00000001
EEADR                             00000009
EECON1                            00000008
EECON2                            00000009
EEDATA                            00000008
EEIE                              00000006
EEIF                              00000004
F                                 00000001
FSR                               00000004
GIE                               00000007
INDF                              00000000
INIT                              00000005
INT                               0000007E
INTCON                            0000000B
INTE                              00000004
INTEDG                            00000006
INTF                              00000001
INT_END                           00000084
IRP                               00000007
LED_CONT                          00000055
LOOP                              0000004D
NOT_PD                            00000003
NOT_RBPU                          00000007
NOT_TO                            00000004
OPTION_REG                        00000001
PCL                               00000002
PCLATH                            0000000A
PORTA                             00000005
PORTB                             00000006
PS0                               00000000
PS1                               00000001
PS2                               00000002
PSA                               00000003
RA0                               00000000
RA1                               00000001
RA2                               00000002
RA3                               00000003
RA4                               00000004
RB6                               00000006
MPASM 02.40 Released         COUNTDWN.ASM   6-10-2000  10:16:30         PAGE  9


SYMBOL TABLE
  LABEL                             VALUE 

RBIE                              00000003
RBIF                              00000000
RD                                00000000
RP0                               00000005
RP1                               00000006
SEG70                             00000010
SEG71                             00000011
SEG72                             00000012
SEG73                             00000013
SEG74                             00000014
SEG75                             00000015
SEG76                             00000016
SEG77                             00000017
SEG78                             00000018
SEG79                             00000019
SEG7_0                            00000040
SEG7_1                            00000079
SEG7_2                            00000024
SEG7_3                            00000030
SEG7_4                            00000019
SEG7_5                            00000012
SEG7_6                            00000002
SEG7_7                            00000078
SEG7_8                            00000000
SEG7_9                            00000010
STAND_BY                          00000024
START                             00000046
STATUS                            00000003
SW_CHECK                          0000003D
S_SAVE                            0000001E
T0CS                              00000005
T0IE                              00000005
T0IF                              00000002
T0SE                              00000004
T1M                               00000073
TIMER_INT                         00000089
TIME_F                            0000001B
TIME_OUT                          00000053
TIME_OUT1                         0000009B
TM1LP1                            00000075
TM1LP2                            00000077
TMR0                              00000001
TM_CNT                            0000001A
TRISA                             00000005
TRISB                             00000006
W                                 00000000
WR                                00000001
WREN                              00000002
WRERR                             00000003
W_SAVE                            0000001D
Z                                 00000002
_CP_OFF                           00003FFF
_CP_ON                            0000000F
MPASM 02.40 Released         COUNTDWN.ASM   6-10-2000  10:16:30         PAGE 10


SYMBOL TABLE
  LABEL                             VALUE 

_HS_OSC                           00003FFE
_LP_OSC                           00003FFC
_PWRTE_OFF                        00003FFF
_PWRTE_ON                         00003FF7
_RC_OSC                           00003FFF
_WDT_OFF                          00003FFB
_WDT_ON                           00003FFF
_XT_OSC                           00003FFD
__16F84A                          00000001


MEMORY USAGE MAP ('X' = Used,  '-' = Unused)

0000 : X---XXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0040 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0080 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXX--------
2000 : -------X-------- ---------------- ---------------- ----------------

All other memory blocks unused.

Program Memory Words Used:   181
Program Memory Words Free:   843


Errors   :     0
Warnings :     0 reported,     0 suppressed
Messages :     0 reported,     0 suppressed



countdwn_source.zip
countdwn_hex.zip