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

📄 tenbit.sdi

📁 代码保护功能处于持续发展中。Microchip 承诺将不断改进产品的代码保护功能。任何试图破坏Microchip 代码保护功能的行为均可视 为违反了《数字器件千年版权法案(Digital Mille
💻 SDI
📖 第 1 页 / 共 2 页
字号:
,,,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,;
,,,;       Project:                Interfacing PICs
,,,;       Source File Name:       TENBIT.ASM
,,,;       Devised by:             MPB
,,,;       Date:                   27-6-05
,,,;       Status:                 Working
,,,;
,,,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,;
,,,;       Demonstrates 10-bit voltage measurement
,,,;       using an external reference voltage of 4.096V,
,,,;       giving 4mV per bit, and an resolution of 0.1%.
,,,;       The result is converted to BCD for display
,,,;       as a voltage using the standard LCD routines.
,,,;
,,,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
,,,        PROCESSOR 16F877
,,,;       Clock = XT 4MHz, standard fuse settings
00002007,3731,,        __CONFIG 0x3731
,,,
,,,;       LABEL EQUATES   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
,,,        INCLUDE "P16F877A.INC"
,,,        ; standard register labels
,,,
,,,;----------------------------------------------------------
,,,; User register labels
,,,;----------------------------------------------------------
,,,; GPR 20 - 2F allocated to included LCD display routine
,,,
,,,count   EQU     30      ; Counter for ADC setup delay
,,,ADhi    EQU     31      ; Binary input high byte
,,,ADlo    EQU     32      ; Binary input low byte
,,,thos    EQU     33      ; Thousands digit in decimal
,,,huns    EQU     34      ; Hundreds digit in decimal value
,,,tens    EQU     35      ; Tens digit in decimal value
,,,ones    EQU     36      ; Ones digit in decimal value
,,,
,,,;----------------------------------------------------------
,,,; PROGRAM BEGINS
,,,;----------------------------------------------------------
,,,
,,,        ORG     0               ; Default start address
00000000,0000,,        NOP                     ; required for ICD mode
,,,
,,,;----------------------------------------------------------
,,,; Port & display setup
,,,
00000001,1683 1303,,        BANKSEL TRISC           ; Select bank 1
00000003,0188,,        CLRF    TRISD           ; Display port is output
00000004,3083,,        MOVLW   B'10000011'     ; Analogue input setup code
00000005,009F,,        MOVWF   ADCON1          ; Right justify result,
,,,                                ; Port A = analogue inputs
,,,                                ; with external reference
,,,
00000006,1283 1303,,        BANKSEL PORTC           ; Select bank 0
00000008,0188,,        CLRF    PORTD           ; Clear display outputs
00000009,3041,,        MOVLW   B'01000001'     ; Analogue input setup code
0000000A,009F,,        MOVWF   ADCON0          ; f/8, RA0, done, enable
,,,
0000000B,209E,,        CALL    inid            ; Initialise the display
,,,
,,,;----------------------------------------------------------
,,,; MAIN LOOP
,,,;----------------------------------------------------------
,,,
0000000C,2010,start,start   CALL    getADC          ; read input
0000000D,2018,,        CALL    con4            ; convert to decimal
0000000E,205E,,        CALL    putLCD          ; display input
0000000F,280C,,        GOTO    start           ; jump to main loop
,,,
,,,;-----------------------------------------------------------
,,,; SUBROUTINES
,,,;-----------------------------------------------------------
,,,; Read ADC input and store
,,,;-----------------------------------------------------------
,,,
00000010,3007,getADC,getADC  MOVLW   007             ; load counter
00000011,00B0,,        MOVWF   count
00000012,0BB0,down,down    DECFSZ  count           ; and delay 20us
00000013,2812,,        GOTO    down
,,,
00000014,151F,,        BSF     ADCON0,GO       ; start ADC..
00000015,191F,wait,wait    BTFSC   ADCON0,GO       ; ..and wait for finish
00000016,2815,,        GOTO    wait
00000017,0008,,        RETURN
,,,
,,,;-----------------------------------------------------------
,,,; Convert 10-bit input to decimal
,,,;-----------------------------------------------------------
,,,
00000018,081E,con4,con4    MOVF    ADRESH,W        ; get ADC result
00000019,00B1,,        MOVWF   ADhi            ; high bits
0000001A,1683 1303,,        BANKSEL ADRESL          ; in bank 1
0000001C,081E,,        MOVF    ADRESL,W        ; get ADC result
0000001D,1283 1303,,        BANKSEL ADRESH          ; default bank 0
0000001F,00B2,,        MOVWF   ADlo            ; low byte
,,,
,,,; Multiply by 4 for result 0 - 4096 by shifting left.........
,,,
00000020,1003,,        BCF     STATUS,C        ; rotate 0 into LSB and
00000021,0DB2,,        RLF     ADlo            ; shift low byte left
00000022,1C03,,        BTFSS   STATUS,C        ; carry out?
00000023,2825,,        GOTO    rot1            ; no, leave carry clear
00000024,1403,,        BSF     STATUS,C        ; rotate 1 into LSB and
00000025,0DB1,rot1,rot1    RLF     ADhi            ; shift high byte left
,,,
00000026,1003,,        BCF     STATUS,C        ; rotate 0 into LSB
00000027,0DB2,,        RLF     ADlo            ; rotate low byte left again
00000028,1C03,,        BTFSS   STATUS,C        ; carry out?
00000029,282B,,        GOTO    rot2            ; no, leave carry clear
0000002A,1403,,        BSF     STATUS,C        ; rotate 1 into LSB and
0000002B,0DB1,rot2,rot2    RLF     ADhi            ; shift high byte left
,,,
,,,
,,,; Clear BCD registers........................................
,,,
0000002C,01B3,clrbcd,clrbcd  CLRF    thos            ; zero thousands digit
0000002D,01B4,,        CLRF    huns            ; zero hundreds digit
0000002E,01B5,,        CLRF    tens            ; zero tens digit
0000002F,01B6,,        CLRF    ones            ; zero ones digit
,,,
,,,
,,,; Calclulate thousands low byte .............................
,,,
00000030,08B1,tholo,tholo   MOVF    ADhi,F          ; check high byte
00000031,1903,,        BTFSC   STATUS,Z        ; high byte zero?
00000032,2847,,        GOTO    hunlo           ; yes, next digit
,,,
00000033,1403,,        BSF     STATUS,C        ; set carry for subtract
00000034,30E8,,        MOVLW   0E8             ; load low byte of 1000
00000035,02B2,,        SUBWF   ADlo            ; and subtract low byte
00000036,1803,,        BTFSC   STATUS,C        ; borrow from high bits?
00000037,2839,,        GOTO    thohi           ; no, do high byte
00000038,03B1,,        DECF    ADhi            ; yes, subtract borrow
,,,
,,,; Calculate thousands high byte..............................
,,,
00000039,1403,thohi,thohi   BSF     STATUS,C        ; set carry for subtract
0000003A,3003,,        MOVLW   003             ; load high byte of 1000
0000003B,02B1,,        SUBWF   ADhi            ; subtract from high byte
0000003C,1803,,        BTFSC   STATUS,C        ; result negative?
0000003D,2845,,        GOTO    incth           ; no, inc digit and repeat
0000003E,07B1,,        ADDWF   ADhi            ; yes, restore high byte
,,,
,,,; Restore remainder when done ...............................
,,,
0000003F,1003,,        BCF     STATUS,C        ; clear carry for add
00000040,30E8,,        MOVLW   0E8             ; load low byte of 1000
00000041,07B2,,        ADDWF   ADlo            ; add to low byte
00000042,1803,,        BTFSC   STATUS,C        ; carry out?
00000043,0AB1,,        INCF    ADhi            ; yes, inc high byte
00000044,2847,,        GOTO    hunlo           ; and do next digit
,,,
,,,; Increment thousands digit and repeat.......................
,,,
00000045,0AB3,incth,incth   INCF    thos            ; inc digit
00000046,2830,,        GOTO    tholo           ; and repeat
,,,
,,,; Calclulate hundreds .......................................
,,,
00000047,3064,hunlo,hunlo   MOVLW   064             ; load 100
00000048,1403,,        BSF     STATUS,C        ; set carry for subtract
00000049,02B2,,        SUBWF   ADlo            ; and subtract low byte
0000004A,1803,,        BTFSC   STATUS,C        ; result negative?
0000004B,2850,,        GOTO    inch            ; no, inc hundreds & repeat
,,,
0000004C,08B1,,        MOVF    ADhi,F          ; yes, test high byte
0000004D,1903,,        BTFSC   STATUS,Z        ; zero?
0000004E,2852,,        GOTO    remh            ; yes, done
0000004F,03B1,,        DECF    ADhi            ; no, subtract borrow
00000050,0AB4,inch,inch    INCF    huns            ; inc hundreds digit
00000051,2847,,        GOTO    hunlo           ; and repeat
,,,
00000052,07B2,remh,remh    ADDWF   ADlo            ; restore onto low byte
,,,
,,,
,,,; Calculate tens digit......................................
,,,
00000053,300A,subt,subt    MOVLW   D'10'           ; load 10
00000054,1403,,        BSF     STATUS,C        ; set carry for subtract

⌨️ 快捷键说明

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