📄 picclock.lst
字号:
0066 20DD 00182 call wr_state ; Display H12 and PM states.
0067 2870 00183 goto chk_hsel_iec ; Done.
00184
0068 1490 00185 set_h12_pm bsf state,BIT_PM ; Set PM bit.
0069 300C 00186 movlw D'12' ; Constant.
006A 0293 00187 subwf hours,F ; hours=hours-12 (23..12 -> 11..0).
006B 1903 00188 btfsc STATUS,Z ; Zero set?
006C 0093 00189 movwf hours ; Yes, so reset to '12'.
006D 20CE 00190 call wr_hours ; No, so leave hours alone and display it.
006E 20DD 00191 call wr_state ; Display H12 and PM states.
006F 2870 00192 goto chk_hsel_iec ; Done.
00193
0070 0B95 00194 chk_hsel_iec decfsz idc,F ; Decrement idc. If zero we can reenable interrupts.
0071 3401 00195 retlw 1 ; Return without enabling interrupts.
00196
0072 3090 00197 chk_hsel_done movlw H'90' ; Constant for GIE and T0IE.
0073 008B 00198 movwf INTCON ; Set interrupt register.
0074 3401 00199 retlw 1 ; Return.
00200
00201 ;------------------------------------------------------------------------------
0075 1885 00202 chk_tset btfsc PORTA,BIT_TSET ; Set mode?
0076 3400 00203 retlw 0
00204
0077 138B 00205 bcf INTCON,GIE ; Disable interrupts.
0078 0A95 00206 incf idc,F ; Increment count of number of disables.
0079 1510 00207 bsf state,BIT_SET ; Set the 'set mode' bit.
MPASM 02.30 Released PICCLOCK.ASM 4-13-2000 14:45:46 PAGE 5
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
007A 0191 00208 clrf secs ; Setting time resets seconds count.
007B 20B0 00209 call wr_secs ; Display it.
007C 1190 00210 bcf state,BIT_HSB ; Clear seconds toggle.
007D 20DD 00211 call wr_state ; Update the state output latch.
00212
007E 2044 00213 set_loop call chk_hsel ; Check for H12/H24 display change.
007F 1D85 00214 btfss PORTA,BIT_MSET ; If pin is high then switch is open.
0080 288C 00215 goto set_mins ; Bit not set, switch closed, set minutes.
0081 1D05 00216 btfss PORTA,BIT_HSET ; If pin is high then switch is open.
0082 2895 00217 goto set_hours ; Bit not set, switch closed, set hours.
0083 1C85 00218 btfss PORTA,BIT_TSET ; If pin is high then switch is open.
0084 287E 00219 goto set_loop ; Bit not set, switch closed, loop.
00220
0085 1110 00221 bcf state,BIT_SET ; Clear the 'set mode' bit.
0086 20DD 00222 call wr_state ; Update the state output latch.
00223
0087 0B95 00224 chk_tset_idc decfsz idc,F ; Decrement idc. If zero we can reenable interrupts.
0088 3401 00225 retlw 1 ; Return without enabling interrupts.
0089 3090 00226 chk_tset_done movlw H'90' ; Constant for GIE and T0IE.
008A 008B 00227 movwf INTCON ; Set interrupt register.
008B 3401 00228 retlw 1 ; Return.
00229
008C 0A92 00230 set_mins incf mins,F ; Increment minute count.
008D 0812 00231 movf mins,W ; Get it into W.
008E 3C3C 00232 sublw D'60' ; Is it 60 (W=60-W)?
008F 1903 00233 btfsc STATUS,Z ; Test zero flag, skip clear if no set.
0090 0192 00234 clrf mins ; Clear minutes.
0091 20BF 00235 call wr_mins ; Write minutes.
00236
0092 1D85 00237 debounce_mset btfss PORTA,BIT_MSET ; Wait for MSET button to be released.
0093 2892 00238 goto debounce_mset ; Loop.
0094 287E 00239 goto set_loop ; Released so recheck buttons.
00240
0095 2099 00241 set_hours call inc_hours ; Increment hours and display.
0096 1D05 00242 debounce_hset btfss PORTA,BIT_HSET ; Wait for HSET button to be released.
0097 2896 00243 goto debounce_hset ; Loop.
0098 287E 00244 goto set_loop ; Released so recheck buttons.
00245
00246 ;------------------------------------------------------------------------------
00247 ; Increment hours, set PM indicator bit as necessary.
00248
0099 1810 00249 inc_hours btfsc state,BIT_H24 ; 12h display?
009A 28A9 00250 goto reset_on24 ; No, so we reset when we get to 24.
00251
009B 0813 00252 reset_on12 movf hours,W ; Get hours
009C 3C0C 00253 sublw D'12' ; Is it 12 (W=12-W)?
009D 1903 00254 btfsc STATUS,Z ; Test zero flag, skip clear if no set.
009E 0193 00255 clrf hours ; Clear hours.
009F 0A93 00256 incf hours,F ; Increment hours.
00A0 20CE 00257 call wr_hours ; Write it.
00A1 0813 00258 movf hours,W ; Get hours
00A2 3C0C 00259 sublw D'12' ; Is it 12 (W=12-W)?
00A3 1D03 00260 btfss STATUS,Z ; Test zero flag.
MPASM 02.30 Released PICCLOCK.ASM 4-13-2000 14:45:46 PAGE 6
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00A4 0008 00261 return ; Zero not set, so not 12, so return.
00A5 3002 00262 movlw MASK_PM ; Get PM state bit mask.
00A6 0690 00263 xorwf state,F ; Toggle PM state bit in state.
00A7 20DD 00264 call wr_state ; Update state outputs.
00A8 0008 00265 return ; Return.
00266
00A9 0A93 00267 reset_on24 incf hours,F ; Incrment hours.
00AA 0813 00268 movf hours,W ; Get it in W.
00AB 3C18 00269 sublw D'24' ; Is it 24 (W=24-W)?
00AC 1903 00270 btfsc STATUS,Z ; Test zero flag, skip clear if no set.
00AD 0193 00271 clrf hours ; Clear hours 24->0.
00AE 20CE 00272 call wr_hours ; Write hours to display.
00AF 0008 00273 return
00274
00275 ;------------------------------------------------------------------------------
00276 ; Get seconds value, split to get BCD pair and write to port.
00B0 0811 00277 wr_secs movf secs,W ; Get seconds.
00B1 2100 00278 call bin2bcd ; Convert to BCD.
00B2 0096 00279 movwf bcd ; Save result.
00B3 39F0 00280 andlw 0xF0 ; Mask BCD pair to leave upper digit in W upper nibble.
00B4 380A 00281 iorlw 0x0A ; Select strobe.
00B5 0086 00282 movwf PORTB ; Write to PORTB.
00B6 39F0 00283 andlw 0xF0 ; Clear strobe (by selecting Q0).
00B7 0086 00284 movwf PORTB ; Write to PORTB.
00B8 0E16 00285 swapf bcd,W ; Get lower BCD digit in to W upper nibble.
00B9 39F0 00286 andlw 0xF0 ; Mask of strobe selection bits.
00BA 380C 00287 iorlw 0x0C ; Set WR strobe.
00BB 0086 00288 movwf PORTB ; Write to PORTB.
00BC 39F0 00289 andlw 0xF0 ; Clear strobe.
00BD 0086 00290 movwf PORTB ; Write to PORTB.
00BE 0008 00291 return ; Return.
00292
00293 ;------------------------------------------------------------------------------
00294 ; Get minutes value, split to get BCD pair and write to port.
00BF 0812 00295 wr_mins movf mins,W ; Get minutes value.
00C0 2100 00296 call bin2bcd ; Convert to BCD.
00C1 0096 00297 movwf bcd ; Save result.
00C2 39F0 00298 andlw 0xF0 ; Mask BCD pair to leave upper digit in W upper nibble.
00C3 3806 00299 iorlw 0x06 ; Select strobe.
00C4 0086 00300 movwf PORTB ; Write to PORTB.
00C5 39F0 00301 andlw 0xF0 ; Clear strobe (by selecting Q0).
00C6 0086 00302 movwf PORTB ; Write to PORTB.
00C7 0E16 00303 swapf bcd,W ; Get lower BCD digit in to W upper nibble.
00C8 39F0 00304 andlw 0xF0 ; Mask of strobe selection bits.
00C9 3808 00305 iorlw 0x08 ; Set WR strobe.
00CA 0086 00306 movwf PORTB ; Write to PORTB.
00CB 39F0 00307 andlw 0xF0 ; Clear strobe.
00CC 0086 00308 movwf PORTB ; Write to PORTB.
00CD 0008 00309 return ; Return.
00310
00311 ;------------------------------------------------------------------------------
00312 ; Get hours value, split to get BCD pair and write to port.
00CE 0813 00313 wr_hours movf hours,W ; Get hours value/
MPASM 02.30 Released PICCLOCK.ASM 4-13-2000 14:45:46 PAGE 7
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00CF 2100 00314 call bin2bcd ; Convert to BCD.
00D0 0096 00315 movwf bcd ; Save result.
00D1 39F0 00316 andlw 0xF0 ; Mask BCD pair to leave upper digit in W upper nibble.
00D2 3802 00317 iorlw 0x02 ; Select strobe.
00D3 0086 00318 movwf PORTB ; Write to PORTB.
00D4 39F0 00319 andlw 0xF0 ; Clear strobe (by selecting Q0).
00D5 0086 00320 movwf PORTB ; Write to PORTB.
00D6 0E16 00321 swapf bcd,W ; Get lower BCD digit in to W upper nibble.
00D7 39F0 00322 andlw 0xF0 ; Mask of strobe selection bits.
00D8 3804 00323 iorlw 0x04 ; Set WR strobe.
00D9 0086 00324 movwf PORTB ; Write to PORTB.
00DA 39F0 00325 andlw 0xF0 ; Clear strobe.
00DB 0086 00326 movwf PORTB ; Write to PORTB.
00DC 0008 00327 return ; Return.
00328
00329 ;------------------------------------------------------------------------------
00330 ; Write state bits to state latch.
00DD 0E10 00331 wr_state swapf state,W ; Get state bits in to W<4:1>.
00DE 380E 00332 iorlw 0x0E ; Set WR strobe.
00DF 0086 00333 movwf PORTB ; Write to PORTB.
00E0 39F0 00334 andlw 0xF0 ; Clear strobe by selecting Q0.
00E1 0086 00335 movwf PORTB ; Write to PORTB.
00E2 0008 00336 return
00337
00338 ;------------------------------------------------------------------------------
00339 ; Routine to convert a binary value (0..63) in to a BCD pair. The result is
00340 ; returned in W. The lookup is done as a 'calculated goto' by modifying PCL
00341 ; (the lower eight bits of the program counter). PCL is only eight bits wide
00342 ; with the top five bits coming from the PCLATH register. We use an ORG
00343 ; statement to ensure that addition of the offset (0..63) to the table address
00344 ; doesn't overflow the PCL register (any overflow would be lost and would result
00345 ; in a jump to some other part of the code).
00346
0100 00347 ORG 0x0100
00348
0100 018A 00349 bin2bcd clrf PCLATH ; Clear PCLATH.
0101 140A 00350 bsf PCLATH,0 ; Set bit zero so that goto yields an
00351 ; address 0x01xx.
0102 393F 00352 andlw H'3F' ; Ensure we limit lookup.
0103 0782 00353 addwf PCL,F ; Add offset in W to PCL to calc. goto.
00354
0104 3400 00355 retlw 0x00
0105 3401 00356 retlw 0x01
0106 3402 00357 retlw 0x02
0107 3403 00358 retlw 0x03
0108 3404 00359 retlw 0x04
0109 3405 00360 retlw 0x05
010A 3406 00361 retlw 0x06
010B 3407 00362 retlw 0x07
010C 3408 00363 retlw 0x08
010D 3409 00364 retlw 0x09
010E 3410 00365 retlw 0x10
010F 3411 00366 retlw 0x11
MPASM 02.30 Released PICCLOCK.ASM 4-13-2000 14:45:46 PAGE 8
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
0110 3412 00367 retlw 0x12
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -