⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mplxad.lst

📁 四通道的AD采样转换数据
💻 LST
📖 第 1 页 / 共 3 页
字号:
MPASM 01.40 Released           MPLXAD.ASM   1-16-1997  16:23:40         PAGE  1


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                    00001 ;*********************************************************************
                    00002 ;This program is to demonstrate how to multiplex four 7 segment LED
                    00003 ;digits and a 4X4 keypad along with 4 A/D inputs using a PIC16C71. 
                    00004 ;The four digits will first display the decimal a/d value of ch0.
                    00005 ;When keys from 0 - 3 are hit the corresponding channel's a/d value
                    00006 ;is displayed in decimal.
                    00007 ;The LEDs are updated every 20mS, the keypad is scanned at a rate of 20 mS.
                    00008 ;All 4 channels are scanned at 20mS rate, so each channel gets scanned 
                    00009 ;every 80mS. A faster rate of scanning is possible as required by
                    00010 ;the users application.
                    00011 ;The RTCC timer is used in internal interrupt mode to generate the
                    00012 ;5 mS.
                    00013 ;
                    00014 ;                                       Stan D'Souza 5/8/93
                    00015 ;
                    00016 ;Corrected error in display routine.
                    00017 ;                                       Stan D'Souza 2/27/94
                    00018 ;
                    00019 ;       Program:          MPLXAD.ASM 
                    00020 ;       Revision Date:   
                    00021 ;                         1-15-97      Compatibility with MPASMWIN 1.40
                    00022 ;
                    00023 ;**********************************************************************
                    00024         LIST P=16C71
                    00025         ERRORLEVEL  -302
                    00026 ;
                    00027         include      <p16c71.inc>
                    00001         LIST
                    00002 ; P16C71.INC  Standard Header File, Version 1.00    Microchip Technology, Inc.
                    00142         LIST
                    00028 ;
  0000000C          00029 TempC   equ     0x0c            ;temp general purpose regs
  0000000D          00030 TempD   equ     0x0d
  0000000E          00031 TempE   equ     0x0e
  00000020          00032 PABuf   equ     0x20
  00000021          00033 PBBuf   equ     0x21
  0000000F          00034 Count   equ     0x0f            ;count
  00000010          00035 MsdTime equ     0x10            ;most significant Timer
  00000011          00036 LsdTime equ     0x11            ;Least significant Timer
                    00037 ;
  00000012          00038 Flag    equ     0x12            ;general purpose flag reg
                    00039 #define keyhit  Flag,0          ;bit 0 --> key-press on
                    00040 #define DebnceOn Flag,1         ;bit 1 -> debounce on
                    00041 #define noentry Flag,2          ;no key entry = 0 
                    00042 #define ServKey Flag,3          ;bit 3 --> service key
                    00043 #define ADOver  Flag,4          ;bit 4 --> a/d conv. over
                    00044 ;
  00000013          00045 Debnce  equ     0x13            ;debounce counter
  00000014          00046 NewKey  equ     0x14
  00000015          00047 DisplayCh equ   0x15            ;channel to be displayed
                    00048 ;
  00000016          00049 ADTABLE equ     0x16            ;4 locations are reserved here
                    00050                                 ;from 0x16 to 0x19
MPASM 01.40 Released           MPLXAD.ASM   1-16-1997  16:23:40         PAGE  2


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                    00051 ;
  0000002F          00052 WBuffer equ     0x2f
  0000002E          00053 StatBuffer equ  0x2e
  00000001          00054 OptionReg equ   1
  00000002          00055 PCL     equ     2
                    00056 ;
                    00057 ;
                    00058 push    macro
                    00059         movwf   WBuffer         ;save w reg in Buffer
                    00060         swapf   WBuffer, F      ;swap it
                    00061         swapf   STATUS,W        ;get status
                    00062         movwf   StatBuffer      ;save it
                    00063         endm
                    00064 ;
                    00065 pop     macro
                    00066         swapf   StatBuffer,W    ;restore status
                    00067         movwf   STATUS          ;       /
                    00068         swapf   WBuffer,W       ;restore W reg
                    00069         endm
                    00070 ;
0000                00071         org     0
0000 280D           00072         goto    Start           ;skip over interrupt vector
                    00073 ;        
0004                00074         org     4
                    00075 ;It is always a good practice to save and restore the w reg,
                    00076 ;and the status reg during a interrupt.
                    00077         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 2052           00078         call    ServiceInterrupts
                    00079         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           00080         retfie
                    00081 ;
000D                00082 Start
000D 203B           00083         call    InitPorts
000E 20EE           00084         call    InitAd
000F 2045           00085         call    InitTimers
0010                00086 loop
0010 1992           00087         btfsc   ServKey         ;key service pending
0011 2015           00088         call    ServiceKey      ;yes then service
0012 1A12           00089         btfsc   ADOver          ;a/d pending?
0013 2028           00090         call    ServiceAD       ;yes the service a/d
0014 2810           00091         goto    loop
                    00092 ;
                    00093 ;ServiceKey, does the software service for a keyhit. After a key service,
                    00094 ;the ServKey flag is reset, to denote a completed operation.
0015                00095 ServiceKey
0015 1192           00096         bcf     ServKey         ;reset service flag
MPASM 01.40 Released           MPLXAD.ASM   1-16-1997  16:23:40         PAGE  3


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

0016 0814           00097         movf    NewKey,W        ;get key value
0017 3C03           00098         sublw   3               ;key > 3?
0018 1C03           00099         btfss   STATUS,C        ;no then skip
0019 0008           00100         return                  ;else ignore key
001A 0814           00101         movf    NewKey,W
001B 0095           00102         movwf   DisplayCh       ;load new channel
                    00103 ;
001C                00104 LoadAD
001C 3016           00105         movlw   ADTABLE         ;get top of table
001D 0715           00106         addwf   DisplayCh,W     ;add offset
001E 0084           00107         movwf   FSR             ;init FSR
001F 0800           00108         movf    0,W             ;get a/d value
0020 00A1           00109         movwf   L_byte
0021 01A0           00110         clrf    H_byte
0022 2106           00111         call    B2_BCD
0023 0824           00112         movf    R2,W            ;get LSd
0024 0091           00113         movwf   LsdTime         ;save in LSD
0025 0823           00114         movf    R1,W            ;get Msd
0026 0090           00115         movwf   MsdTime         ;save in Msd
0027 0008           00116         return
                    00117 ;
                    00118 ;This rountine essentially loads the ADRES value in the table location
                    00119 ;determined by the channel offset. If channel 0 then ADRES is saved
                    00120 ;in location ADTABLE. If channel 1 then ADRES is saved at ADTABLE + 1.
                    00121 ;and so on.
0028                00122 ServiceAD
0028 0808           00123         movf    ADCON0,W        ;get adcon0
0029 008C           00124         movwf   TempC           ;save in temp
002A 3008           00125         movlw   B'00001000'     ;select next channel
002B 0708           00126         addwf   ADCON0,W        ;       /
002C 1A88           00127         btfsc   ADCON0,5        ;if <= ch3
002D 30C1           00128         movlw   B'11000001'     ;select ch0
002E 0088           00129         movwf   ADCON0
                    00130         ;now load adres in the table
002F 3016           00131         movlw   ADTABLE
0030 0084           00132         movwf   FSR             ;load FSR with top
0031 0C8C           00133         rrf     TempC, F
0032 0C8C           00134         rrf     TempC, F
0033 0C0C           00135         rrf     TempC,W         ;get in w reg
0034 3903           00136         andlw   3               ;mask off all but last 2
0035 0784           00137         addwf   FSR, F          ;add offset to table
0036 0809           00138         movf    ADRES,W         ;get a/d value
0037 0080           00139         movwf   0               ;load indirectly
0038 1212           00140         bcf     ADOver          ;clear flag
0039 201C           00141         call    LoadAD          ;load a/d value in display reg.
003A 0008           00142         return
                    00143         
                    00144         
                    00145 
                    00146 ;
003B                00147 InitPorts
003B 1683           00148         bsf     STATUS,RP0      ;select pg 1
003C 3003           00149         movlw   3               ;make RA0-3 digital I/O
MPASM 01.40 Released           MPLXAD.ASM   1-16-1997  16:23:40         PAGE  4


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

003D 0088           00150         movwf   ADCON1          ;       /
003E 0185           00151         clrf    TRISA           ;make RA0-4 outputs
003F 0186           00152         clrf    TRISB           ;make RB0-7 outputs
0040 1283           00153         bcf     STATUS,RP0      ;select page 0
0041 0185           00154         clrf    PORTA          ;make all outputs low
0042 0186           00155         clrf    PORTB          ;       /
0043 1585           00156         bsf     PORTA,3        ;enable MSB digit sink
0044 0008           00157         return
                    00158 ;
                    00159 ;
                    00160 ;The clock speed is 4.096Mhz. Dividing internal clk. by a 32 prescaler,
                    00161 ;the rtcc will be incremented every 31.25uS. If rtcc is preloaded 
                    00162 ;with 96, it will take (256-96)*31.25uS to overflow i.e. 5mS. So the 
                    00163 ;end result is that we get a rtcc interrupt every 5mS.
0045                00164 InitTimers
0045 0190           00165         clrf    MsdTime         ;clr timers
0046 0191           00166         clrf    LsdTime         ;       /
0047 0195           00167         clrf    DisplayCh       ;show channel 0
0048 0192           00168         clrf    Flag            ;clr all flags
0049 1683           00169         bsf     STATUS,RP0      ;select pg 1
004A 3084           00170         movlw   B'10000100'     ;assign ps to rtcc
004B 0081           00171         movwf   OptionReg       ;ps = 32
004C 1283           00172         bcf     STATUS,RP0      ;select pg 0
004D 3020           00173         movlw   B'00100000'     ;enable rtcc interrupt
004E 008B           00174         movwf   INTCON          ;
004F 3060           00175         movlw   .96             ;preload rtcc
0050 0081           00176         movwf   TMR0            ;start counter
0051 0009           00177         retfie                  
                    00178 ;        
0052                00179 ServiceInterrupts
0052 190B           00180         btfsc   INTCON,T0IF     ;rtcc interrupt?
0053 2857           00181         goto    ServiceTMR0     ;yes then service
0054 018B           00182         clrf    INTCON          ;else clr all int
0055 168B           00183         bsf     INTCON,T0IE
0056 0008           00184         return
                    00185 ;
0057                00186 ServiceTMR0
0057 3060           00187         movlw   .96             ;initialize rtcc
0058 0081           00188         movwf   TMR0            
0059 110B           00189         bcf     INTCON,T0IF     ;clr int flag
005A 1805           00190         btfsc   PORTA,0        ;scan keys every 20 mS
005B 2060           00191         call    ScanKeys        ;when digit 1 is on
005C 1985           00192         btfsc   PORTA,3        ;scan a/d every 20mS 
005D 20F1           00193         call    SampleAd        ;when digit 4 is on 
005E 20BF           00194         call    UpdateDisplay   ;update display
005F 0008           00195         return                  
                    00196 ;
                    00197 ;
                    00198 ;ScanKeys, scans the 4X4 keypad matrix and returns a key value in
                    00199 ;NewKey (0 - F) if a key is pressed, if not it clears the keyhit flag.
                    00200 ;Debounce for a given keyhit is also taken care of.
                    00201 ;The rate of key scan is 20mS with a 4.096Mhz clock.
0060                00202 ScanKeys
MPASM 01.40 Released           MPLXAD.ASM   1-16-1997  16:23:40         PAGE  5


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

0060 1C92           00203         btfss   DebnceOn        ;debounce on?

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -