📄 mplxch0.lst
字号:
MPASM 01.40 Released MPLXCH0.ASM 1-16-1997 16:24:14 PAGE 1
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00001 ;*********************************************************************
00002 ;This program is to demonstrate how to multiplex four 7 segment LED
00003 ;and sample ch0 of the a/d in a PIC16C71. The a/d value is displayed
00004 ;as a 3 digit decimal value of the a/d input (0 - 255).
00005 ;The LEDs are updated every 20mS, the a/d is sampled every 20 mS.
00006 ;The RTCC timer is used in internal interrupt mode to generate the
00007 ;5 mS.
00008 ;
00009 ; Stan D'Souza 5/8/93
00010 ;
00011 ;
00012 ;
00013 ; Program: MPLXCH0.ASM
00014 ; Revision Date:
00015 ; 1-15-97 Compatibility with MPASMWIN 1.40
00016 ;
00017 ;**********************************************************************
00018 LIST P=16C71
00019 ERRORLEVEL -302
00020 ;
00021 include <p16c71.inc>
00001 LIST
00002 ; P16C71.INC Standard Header File, Version 1.00 Microchip Technology, Inc.
00142 LIST
00022 ;
00000026 00023 BcdMsd equ 26
00000027 00024 Bcd equ 27
0000000C 00025 TempC equ 0x0c ;temp general purpose regs
0000000D 00026 TempD equ 0x0d
0000000E 00027 TempE equ 0x0e
00000020 00028 PABuf equ 0x20
00000021 00029 PBBuf equ 0x21
0000000F 00030 Count equ 0x0f ;count
00000010 00031 MsdTime equ 0x10 ;most significant Timer
00000011 00032 LsdTime equ 0x11 ;Least significant Timer
00000012 00033 ADFlag equ 0x12 ;flags related to key pad
00000005 00034 ADOver equ 5 ;bit 5 --> a/d over
0000002F 00035 WBuffer equ 0x2f
0000002E 00036 StatBuffer equ 0x2e
00000001 00037 OptionReg equ 1
00000002 00038 PCL equ 2
00039 ;
00040 push macro
00041 movwf WBuffer ;save w reg in Buffer
00042 swapf WBuffer, F ;swap it
00043 swapf STATUS,W ;get status
00044 movwf StatBuffer ;save it
00045 endm
00046 ;
00047 pop macro
00048 swapf StatBuffer,W ;restore status
00049 movwf STATUS ; /
00050 swapf WBuffer,W ;restore W reg
MPASM 01.40 Released MPLXCH0.ASM 1-16-1997 16:24:14 PAGE 2
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00051 endm
00052 ;
0000 00053 org 0
0000 280D 00054 goto Start ;skip over interrupt vector
00055 ;
0004 00056 org 4
00057 ;It is always a good practice to save and restore the w reg,
00058 ;and the status reg during a interrupt.
00059 push
0004 00AF M movwf WBuffer ;save w reg in Buffer
0005 0EAF M swapf WBuffer, F ;swap it
0006 0E03 M swapf STATUS,W ;get status
0007 00AE M movwf StatBuffer ;save it
0008 2039 00060 call ServiceInterrupts
00061 pop
0009 0E2E M swapf StatBuffer,W ;restore status
000A 0083 M movwf STATUS ; /
000B 0E2F M swapf WBuffer,W ;restore W reg
000C 0009 00062 retfie
00063 ;
000D 00064 Start
000D 2021 00065 call InitPorts
000E 202B 00066 call InitTimers
000F 2036 00067 call InitAd
0010 00068 loop
0010 1A92 00069 btfsc ADFlag,ADOver ;a/d over?
0011 2013 00070 call UpdateAd ;yes then update
0012 2810 00071 goto loop
00072 ;
0013 00073 UpdateAd
0013 1C88 00074 btfss ADCON0,ADIF ;a/d done?
0014 0008 00075 return ;no then leave
0015 0809 00076 movf ADRES,W ;get a/d value
0016 00A1 00077 movwf L_byte
0017 01A0 00078 clrf H_byte
0018 20AD 00079 call B2_BCD
0019 0824 00080 movf R2,W ;get LSd
001A 0091 00081 movwf LsdTime ;save in LSD
001B 0823 00082 movf R1,W ;get Msd
001C 0090 00083 movwf MsdTime ;save in Msd
001D 1088 00084 bcf ADCON0,ADIF ;clr interrupt flag
001E 1008 00085 bcf ADCON0,ADON ;turn off a/d
001F 1292 00086 bcf ADFlag,ADOver ;clr flag
0020 0008 00087 return
00088 ;
00089 ;
00090 ;
0021 00091 InitPorts
0021 1683 00092 bsf STATUS,RP0 ;select pg 1
0022 3003 00093 movlw 3 ;make RA0-3 digital I/O
0023 0088 00094 movwf ADCON1 ; /
0024 0185 00095 clrf TRISA ;make RA0-4 outputs
0025 0186 00096 clrf TRISB ;make RB0-7 outputs
MPASM 01.40 Released MPLXCH0.ASM 1-16-1997 16:24:14 PAGE 3
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
0026 1283 00097 bcf STATUS,RP0 ;select page 0
0027 0185 00098 clrf PORTA ;make all outputs low
0028 0186 00099 clrf PORTB ; /
0029 1585 00100 bsf PORTA,3 ;enable MSB digit sink
002A 0008 00101 return
00102 ;
00103 ;
00104 ;The clock speed is 4.096Mhz. Dividing internal clk. by a 32 prescaler,
00105 ;the rtcc will be incremented every 31.25uS. If rtcc is preloaded
00106 ;with 96, it will take (256-96)*31.25uS to overflow i.e. 5mS. So the
00107 ;end result is that we get a rtcc interrupt every 5mS.
002B 00108 InitTimers
002B 0190 00109 clrf MsdTime ;clr timers
002C 0191 00110 clrf LsdTime ; /
002D 1683 00111 bsf STATUS,RP0 ;select pg 1
002E 3084 00112 movlw B'10000100' ;assign ps to rtcc
002F 0081 00113 movwf OptionReg ;ps = 32
0030 1283 00114 bcf STATUS,RP0 ;select pg 0
0031 3020 00115 movlw B'00100000' ;enable rtcc interrupt
0032 008B 00116 movwf INTCON ;
0033 3060 00117 movlw .96 ;preload rtcc
0034 0081 00118 movwf TMR0 ;start counter
0035 0009 00119 retfie
00120 ;
00121 ;
0036 00122 InitAd
0036 30C0 00123 movlw B'11000000' ;rc osc, ch 0 for a/d
0037 0088 00124 movwf ADCON0
0038 0008 00125 return
00126 ;
00127 ;
0039 00128 ServiceInterrupts
0039 190B 00129 btfsc INTCON,T0IF ;rtcc interrupt?
003A 283E 00130 goto ServiceTMR0 ;yes then service
003B 018B 00131 clrf INTCON
003C 168B 00132 bsf INTCON,T0IE
003D 0008 00133 return
00134 ;
003E 00135 ServiceTMR0
003E 3060 00136 movlw .96 ;initialize rtcc
003F 0081 00137 movwf TMR0
0040 110B 00138 bcf INTCON,T0IF ;clr int flag
0041 1C05 00139 btfss PORTA,0 ;last digit?
0042 2045 00140 call SampleAd ;then sample a/d
0043 2071 00141 call UpdateDisplay ;else update display
0044 0008 00142 return
00143 ;
00144 ;
0045 00145 SampleAd
0045 205A 00146 call SavePorts
0046 204C 00147 call DoAd ;do a ad conversion
0047 00148 AdDone
0047 1908 00149 btfsc ADCON0,GO ;ad done?
MPASM 01.40 Released MPLXCH0.ASM 1-16-1997 16:24:14 PAGE 4
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
0048 2847 00150 goto AdDone ;no then loop
0049 1692 00151 bsf ADFlag,ADOver ;set a/d over flag
004A 2067 00152 call RestorePorts ;restore ports
004B 0008 00153 return
00154 ;
00155 ;
004C 00156 DoAd
004C 0186 00157 clrf PORTB ;turn off leds
004D 1683 00158 bsf STATUS,RP0 ;select pg 1
004E 300F 00159 movlw 0x0f ;make port a hi-Z
004F 0085 00160 movwf TRISA ; /
0050 1283 00161 bcf STATUS,RP0 ;select pg 0
0051 1408 00162 bsf ADCON0,ADON ;start a/d
0052 307D 00163 movlw .125
0053 2056 00164 call Wait
0054 1508 00165 bsf ADCON0,GO ;start conversion
0055 0008 00166 return
00167 ;
00168 ;
0056 00169 Wait
0056 008C 00170 movwf TempC ;store in temp
0057 00171 Next
0057 0B8C 00172 decfsz TempC, F
0058 2857 00173 goto Next
0059 0008 00174 return
00175
00176 ;
00177 ;SavePorts, saves the porta and portb condition during a key scan
00178 ;operation.
005A 00179 SavePorts
005A 0805 00180 movf PORTA,W ;Get sink value
005B 00A0 00181 movwf PABuf ;save in buffer
005C 0185 00182 clrf PORTA ;disable all sinks
005D 0806 00183 movf PORTB,W ;get port b
005E 00A1 00184 movwf PBBuf ;save in buffer
005F 30FF 00185 movlw 0xff ;make all high
0060 0086 00186 movwf PORTB ;on port b
0061 1683 00187 bsf STATUS,RP0 ;select page 1
0062 1381 00188 bcf OptionReg,7 ;enable pull ups
0063 30F0 00189 movlw B'11110000' ;port b hi nibble inputs
0064 0086 00190 movwf TRISB ;lo nibble outputs
0065 1283 00191 bcf STATUS,RP0 ;page 0
0066 0008 00192 return
00193 ;
00194 ;RestorePorts, restores the condition of porta and portb after a
00195 ;key scan operation.
0067 00196 RestorePorts
0067 0821 00197 movf PBBuf,W ;get port n
0068 0086 00198 movwf PORTB
0069 0820 00199 movf PABuf,W ;get port a value
006A 0085 00200 movwf PORTA
006B 1683 00201 bsf STATUS,RP0 ;select page 1
006C 1781 00202 bsf OptionReg,7 ;disable pull ups
MPASM 01.40 Released MPLXCH0.ASM 1-16-1997 16:24:14 PAGE 5
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
006D 0185 00203 clrf TRISA ;make port a outputs
006E 0186 00204 clrf TRISB ;as well as PORTB
006F 1283 00205 bcf STATUS,RP0 ;page 0
0070 0008 00206 return
00207 ;
00208 ;
0071 00209 UpdateDisplay
0071 0805 00210 movf PORTA,W ;present sink value in w
0072 0185 00211 clrf PORTA ;disable all digits sinks
0073 390F 00212 andlw 0x0f
0074 008C 00213 movwf TempC ;save sink value in tempC
0075 160C 00214 bsf TempC,4 ;preset for lsd sink
0076 0C8C 00215 rrf TempC, F ;determine next sink value
0077 1C03 00216 btfss STATUS,C ;c=1?
0078 118C 00217 bcf TempC,3 ;no then reset LSD sink
0079 180C 00218 btfsc TempC,0 ;else see if Msd
007A 288C 00219 goto UpdateMsd ;yes then do Msd
007B 188C 00220 btfsc TempC,1 ;see if 3rdLsd
007C 2887 00221 goto Update3rdLsd ;yes then do 3rd Lsd
007D 190C 00222 btfsc TempC,2 ;see if 2nd Lsd
007E 2882 00223 goto Update2ndLsd ;yes then do 2nd lsd
007F 00224 UpdateLsd
007F 0811 00225 movf LsdTime,W ;get Lsd in w
0080 390F 00226 andlw 0x0f ; /
0081 2890 00227 goto DisplayOut ;enable display
0082 00228 Update2ndLsd
0082 20A1 00229 call Chk2LsdZero ;msd = 0 & 2 lsd 0?
0083 1D03 00230 btfss STATUS,Z ;yes then skip
0084 0E11 00231 swapf LsdTime,W ;get 2nd Lsd in w
0085 390F 00232 andlw 0x0f ;mask rest
0086 2890 00233 goto DisplayOut ;enable display
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -