📄 picclock.lst
字号:
MPASM 02.30 Released PICCLOCK.ASM 4-13-2000 14:45:46 PAGE 1
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00001 LIST p=16F84 ; PIC16F844 is the target processor
00002
00003 #include "P16F84.INC" ; Include header file
00001 LIST
00002 ; P16F84.INC Standard Header File, Version 2.00 Microchip Technology, Inc.
00136 LIST
00004
00005 CBLOCK 0x10 ; Temporary storage
00000010 00006 state
00000011 00007 secs
00000012 00008 mins
00000013 00009 hours
00000014 00010 ticks
00000015 00011 idc
00000016 00012 bcd
00013 ENDC
00014
00015 ; Constants for bit allocation. The BIT_x constants are actual bit numbers and
00016 ; the MASK_x are bit masks for the same bit.
00000000 00017 BIT_HSEL EQU H'0000'
00000001 00018 BIT_TSET EQU H'0001'
00000002 00019 BIT_HSET EQU H'0002'
00000003 00020 BIT_MSET EQU H'0003'
00021
00000000 00022 BIT_H24 EQU H'0000'
00000001 00023 BIT_PM EQU H'0001'
00000002 00024 BIT_SET EQU H'0002'
00000003 00025 BIT_HSB EQU H'0003'
00026
00000001 00027 MASK_H24 EQU H'0001'
00000002 00028 MASK_PM EQU H'0002'
00000004 00029 MASK_SET EQU H'0004'
00000008 00030 MASK_HSB EQU H'0008'
00031
00032
00033 ; Macro to generate a MOVLW instruction that also causes a model break:
00034 break MACRO arg
00035 DW 0x3100 | (arg & H'FF')
00036 ENDM
00037
0000 00038 ORG 0
0000 2805 00039 entrypoint goto initialise
00040
0004 00041 ORG 4
0004 2821 00042 intvector goto clock
00043
0005 00044 initialise ; Register set up:
0005 0103 00045 clrw ; Zero.
0006 0085 00046 movwf PORTA ; Ensure PORTA is zero before we enable it.
0007 0086 00047 movwf PORTB ; Ensure PORTB is zero before we enable it.
0008 1683 00048 bsf STATUS,RP0 ; Select Bank 1
0009 301F 00049 movlw H'1F' ; Mask for PORTA inputs/outputs.
Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct.
MPASM 02.30 Released PICCLOCK.ASM 4-13-2000 14:45:46 PAGE 2
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
000A 0085 00050 movwf TRISA ; Set TRISA register.
000B 3001 00051 movlw H'01' ; Mask for PORTA inputs/outputs.
Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct.
000C 0086 00052 movwf TRISB ; Set TRISB register.
000D 1283 00053 bcf STATUS,RP0 ; Reselect Bank 0.
00054
00055 ; Initialise clock:
000E 0190 00056 clrf state
000F 1590 00057 bsf state,BIT_HSB
0010 3000 00058 movlw D'0'
0011 0093 00059 movwf hours
0012 3000 00060 movlw D'0'
0013 0092 00061 movwf mins
0014 3000 00062 movlw D'0'
0015 0091 00063 movwf secs
00064
00065 ; Clear 50Hz tick count:
0016 0194 00066 clrf ticks
00067
00068 ; Clear interrupt disable count (idc) semaphore:
0017 0195 00069 clrf idc
00070
00071 ; Initialise display:
0018 20CE 00072 call wr_hours
0019 20BF 00073 call wr_mins
001A 20B0 00074 call wr_secs
001B 20DD 00075 call wr_state
00076
00077 ; Finally initialise interrupts for clock on RB0/INT pin:
001C 3090 00078 movlw H'90'
001D 008B 00079 movwf INTCON
00080
001E 00081 start ; When not processing an interrupt we sit and check input pins:
001E 2075 00082 call chk_tset ; Time set select active?
001F 2044 00083 call chk_hsel ; H12/H24 display format select active?
0020 281E 00084 goto start
00085
00086
00087 ;------------------------------------------------------------------------------
00088 ; Interrupt handler. We come here for every tick of the time base.
00089
0021 00090 clock ; Toggle half-second flag and set state outputs:
0021 0A94 00091 incf ticks,F ; Increment clock ticks.
0022 0814 00092 movf ticks,W ; Get ticks value.
0023 3C19 00093 sublw D'25' ; Is it 25 (W=25-W)?
0024 1D03 00094 btfss STATUS,Z ; Test zero flag.
0025 2841 00095 goto endclock ; Return.
00096
0026 00097 toggle_hs ; Half second - toggle HS flag, write it and return:
0026 0194 00098 clrf ticks ; Reset timebase,
0027 0810 00099 movf state,W ; Get state.
0028 3A08 00100 xorlw MASK_HSB ; Toggle half-second bit.
0029 0090 00101 movwf state ; Save it back to register.
MPASM 02.30 Released PICCLOCK.ASM 4-13-2000 14:45:46 PAGE 3
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
002A 20DD 00102 call wr_state ; Display it.
002B 0810 00103 movf state,W ; Get state.
002C 1D90 00104 btfss state,BIT_HSB ; Is bit now clear?
002D 2841 00105 goto endclock ; Return.
00106
002E 00107 inc_secs ; Incrmement seconds...
002E 0A91 00108 incf secs,F ; Increment seconds count.
002F 0811 00109 movf secs,W ; Get it into W.
0030 3C3C 00110 sublw D'60' ; Is it 60 (W=60-W)?
0031 1903 00111 btfsc STATUS,Z ; Test zero flag, skip clear if no set.
0032 2835 00112 goto reset_secs ; Clear seconds, increment minutes.
0033 20B0 00113 call wr_secs ; Write seconds it to display.
0034 2841 00114 goto endclock ; Done.
00115
0035 0191 00116 reset_secs clrf secs
0036 20B0 00117 call wr_secs ; Write seconds to display.
00118
0037 0A92 00119 incf mins,F ; Increment minute count.
0038 0812 00120 movf mins,W ; Get it into W.
0039 3C3C 00121 sublw D'60' ; Is it 60 (W=60-W)?
003A 1903 00122 btfsc STATUS,Z ; Test zero flag, skip clear if no set.
003B 283E 00123 goto reset_mins ; Clear minutes, increment hours.
003C 20BF 00124 call wr_mins ; Write minutes it to display.
003D 2841 00125 goto endclock ; Done.
00126
003E 0192 00127 reset_mins clrf mins ; Reset minute count to zero.
003F 20BF 00128 call wr_mins ; Write minutes to display.
00129
0040 2099 00130 call inc_hours ; Increment hours, display it with PM flag.
00131
0041 3090 00132 endclock movlw H'90'
0042 008B 00133 movwf INTCON
0043 0009 00134 retfie ; Return
00135
00136 ;------------------------------------------------------------------------------
00137 ; Subroutine. Check the state of the HSEL input and set h12/h24 format as
00138 ; required.
00139
0044 1805 00140 chk_hsel btfsc PORTA,BIT_HSEL ; Test 12/24 select.
0045 2857 00141 goto set_h12 ; H12 set so switch to 12 hour format.
00142 ; fall through ; H12 not set so switch to 24 hour format.
00143
0046 1810 00144 set_h24 btfsc state,BIT_H24 ; Are we on 12 hour format?
0047 3400 00145 retlw 0 ; No, so no need to do anything...
00146
0048 138B 00147 bcf INTCON,GIE ; Disable interrupts.
0049 0A95 00148 incf idc,F ; Increment count of number of disables.
004A 1410 00149 bsf state,BIT_H24 ; Clear h12 flag.
00150
004B 0813 00151 movf hours,W ; Get hours value.
004C 3C0C 00152 sublw D'12' ; Is it 12:xx?
004D 1903 00153 btfsc STATUS,Z ; Test zero flag.
004E 0193 00154 clrf hours ; Reset to zero.
MPASM 02.30 Released PICCLOCK.ASM 4-13-2000 14:45:46 PAGE 4
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
004F 0813 00155 movf hours,W ; Get hours value.
0050 1890 00156 btfsc state,BIT_PM ; Is the PM indicator set?
0051 3E0C 00157 addlw D'12' ; Add 12 to get 24 hour value.
0052 0093 00158 movwf hours ; Save result (does nothing for AM).
0053 1090 00159 bcf state,BIT_PM ; Clear PM flag.
0054 20CE 00160 call wr_hours ; Write hours.
0055 20DD 00161 call wr_state ; Write H12 state and PM state.
0056 2870 00162 goto chk_hsel_iec ; Done.
00163
0057 1C10 00164 set_h12 btfss state,BIT_H24 ; Are we on 12 hour format?
0058 3400 00165 retlw 0 ; Yes, so no need to do anything...
00166
0059 138B 00167 bcf INTCON,GIE ; Disable interrupts.
005A 0A95 00168 incf idc,F ; Increment count of number of disables.
005B 1010 00169 bcf state,BIT_H24 ; Set h12 flag.
00170
005C 0813 00171 movf hours,W ; Get hour value.
005D 3C0B 00172 sublw D'11' ; W=11-W. C is clear for a borrow (W>=12).
005E 1C03 00173 btfss STATUS,C ; Test carry flag.
005F 2868 00174 goto set_h12_pm ; Set PM.
00175
0060 1090 00176 set_h12_am bcf state,BIT_PM ; Clear PM bit.
0061 0813 00177 movf hours,W ; Get hours.
0062 1903 00178 btfsc STATUS,Z ; Is it zero?
0063 3E0C 00179 addlw D'12' ; Yes, add 12 to get 00:xx to 12:xx.
0064 0093 00180 movwf hours ; Save any result.
0065 20CE 00181 call wr_hours ; Display hours.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -