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

📄 mplxad.asm

📁 四通道的AD采样转换数据
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;
;Row1(RB4)           0       1       2       3
;
;Row2(RB5)           4       5       6       7
;
;Row3(RB6)           8       9       A       B
;
;Row4(RB7)           C       D       E       F
;
GetKeyValue
        clrf    TempC
        btfss   TempD,3         ;first column
        goto    RowValEnd
        incf    TempC, F
        btfss   TempD,2         ;second col.
        goto    RowValEnd
        incf    TempC, F
        btfss   TempD,1         ;3rd col.
        goto    RowValEnd
        incf    TempC, F        ;last col.
RowValEnd
        btfss   TempE,0         ;top row?
        goto    GetValCom       ;yes then get 0,1,2&3
        btfss   TempE,1         ;2nd row?
        goto    Get4567         ;yes the get 4,5,6&7
        btfss   TempE,2         ;3rd row?
        goto    Get89ab         ;yes then get 8,9,a&b
Getcdef
        bsf     TempC,2         ;set msb bits   
Get89ab
        bsf     TempC,3         ;       /
        goto    GetValCom       ;do common part
Get4567
        bsf     TempC,2
GetValCom
        movf    TempC,W
        addwf   PCL, F
        retlw   0
        retlw   1
        retlw   2
        retlw   3
        retlw   4
        retlw   5
        retlw   6
        retlw   7
        retlw   8
        retlw   9
        retlw   0a
        retlw   0b
        retlw   0c
        retlw   0d
        retlw   0e
        retlw   0f
;
;SavePorts, saves the porta and portb condition during a key scan
;operation.
SavePorts
        movf    PORTA,W        ;Get sink value
        movwf   PABuf           ;save in buffer
        clrf    PORTA          ;disable all sinks
        movf    PORTB,W        ;get port b
        movwf   PBBuf           ;save in buffer
        movlw   0xff            ;make all high
        movwf   PORTB          ;on port b
        bsf     STATUS,RP0      ;select page 1
        bcf     OptionReg,7     ;enable pull ups
        movlw   B'11110000'     ;port b hi nibble inputs
        movwf   TRISB           ;lo nibble outputs
        bcf     STATUS,RP0      ;page 0
        return
;
;RestorePorts, restores the condition of porta and portb after a
;key scan operation.
RestorePorts
        movf    PBBuf,W         ;get port b
        movwf   PORTB
        movf    PABuf,W         ;get port a value
        movwf   PORTA
        bsf     STATUS,RP0      ;select page 1
        bsf     OptionReg,7     ;disable pull ups
        clrf    TRISA           ;make port a outputs
        clrf    TRISB           ;as well as PORTB
        bcf     STATUS,RP0      ;page 0
        return
;
;
UpdateDisplay
        movf    PORTA,W        ;present sink value in w
        clrf    PORTA          ;disable all digits sinks
        andlw   0x0f                    
        movwf   TempC           ;save sink value in tempC
        bsf     TempC,4         ;preset for lsd sink
        rrf     TempC, F        ;determine next sink value
        btfss   STATUS,C        ;c=1? 
        bcf     TempC,3         ;no then reset LSD sink
        btfsc   TempC,0         ;else see if Msd
        goto    UpdateMsd       ;yes then do Msd
        btfsc   TempC,1         ;see if 3rdLsd
        goto    Update3rdLsd    ;yes then do 3rd Lsd
        btfsc   TempC,2         ;see if 2nd Lsd
        goto    Update2ndLsd    ;yes then do 2nd lsd
UpdateLsd                       
        movf    LsdTime,W       ;get Lsd in w
        andlw   0x0f            ;       /
        goto    DisplayOut
Update2ndLsd        
        swapf   LsdTime,W       ;get 2nd Lsd in w
        andlw   0x0f            ;mask rest
        goto    DisplayOut      ;enable display
Update3rdLsd
        movf    MsdTime,W       ;get 3rd Lsd in w
        andlw   0x0f            ;mask low nibble
        goto    DisplayOut      ;enable display
UpdateMsd
        swapf   MsdTime,W       ;get Msd in w
        andlw   0x0f            ;mask rest
DisplayOut                      
        call    LedTable        ;get digit output
        movwf   PORTB          ;drive leds
        movf    TempC,W         ;get sink value in w
        movwf   PORTA
        return
;
;
LedTable
        addwf   PCL, F          ;add to PC low
        retlw   B'00111111'     ;led drive for 0
        retlw   B'00000110'     ;led drive for 1
        retlw   B'01011011'     ;led drive for 2
        retlw   B'01001111'     ;led drive for 3
        retlw   B'01100110'     ;led drive for 4
        retlw   B'01101101'     ;led drive for 5
        retlw   B'01111101'     ;led drive for 6
        retlw   B'00000111'     ;led drive for 7
        retlw   B'01111111'     ;led drive for 8
        retlw   B'01100111'     ;led drive for 9
        retlw   B'01110111'     ;led drive for A
        retlw   B'01111100'     ;led drive for b
        retlw   B'00111001'     ;led drive for C
        retlw   B'01011110'     ;led drive for d
        retlw   B'01111001'     ;led drive for E
        retlw   B'01110001'     ;led drive for F

;
;
InitAd
        movlw   B'11000000'     ;internal rc for tad
        movwf   ADCON0          ;       /
        ;note that adcon1 is set in InitPorts
        return
;
SampleAd
        call    SavePorts
        call    DoAd                    ;do a ad conversion
AdDone
        btfsc   ADCON0,GO               ;ad done?
        goto    AdDone                  ;no then loop
        bsf     ADOver                  ;set a/d over flag
        call    RestorePorts            ;restore ports
        return
;
;
DoAd
        clrf    PORTB                  ;turn off leds
        bsf     STATUS,RP0              ;select pg 1
        movlw   0x0f                    ;make port a hi-Z
        movwf   TRISA                   ;       /
        bcf     STATUS,RP0              ;select pg 0
        bsf     ADCON0,ADON             ;start a/d    
        movlw   .125
        call    Wait
        bsf     ADCON0,GO               ;start conversion
        return
;
;
Wait
        movwf   TempC                   ;store in temp
Next
        decfsz  TempC, F
        goto    Next
        return

;
;
count  equ      26
temp   equ      27
;
H_byte  equ     20
L_byte  equ     21
R0      equ     22              ; RAM Assignments
R1      equ     23
R2      equ     24
;
;
B2_BCD  bcf     STATUS,0                ; clear the carry bit
        movlw   .16
        movwf   count
        clrf    R0
        clrf    R1
        clrf    R2
loop16  rlf     L_byte, F
        rlf     H_byte, F
        rlf     R2, F
        rlf     R1, F
        rlf     R0, F
;
        decfsz  count, F
        goto    adjDEC
        RETLW   0
;
adjDEC  movlw   R2
        movwf   FSR
        call    adjBCD
;
        movlw   R1
        movwf   FSR
        call    adjBCD
;
        movlw   R0
        movwf   FSR
        call    adjBCD
;
        goto    loop16
;
adjBCD  movlw   3
        addwf   0,W
        movwf   temp
        btfsc   temp,3          ; test if result > 7
        movwf   0
        movlw   30
        addwf   0,W
        movwf   temp
        btfsc   temp,7          ; test if result > 7
        movwf   0               ; save as MSD
        RETLW   0
;
;
;
;

        end
;

        

⌨️ 快捷键说明

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