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

📄 ads1100_demo.s43

📁 ADS1100 16-bit sigma-delta differential ADC 与 MSP430F413接口设计。
💻 S43
📖 第 1 页 / 共 2 页
字号:
Disp_Signed_3_5
            push.w  R11                      ; Save R11
            clr.w   R11                      ; Clear negative Flag
            cmp.w   #2000,R12                ; Compare w/ 2000
            jl      Less2000                 ; Jump if less
            mov.w   #00A1Fh,R12              ; Display 'HI'  
            jmp     Disp

Less2000    cmp.w   #-1999,R12               ; Compare w/ -1999
            jge     MoreN2000                ; Jump if greater/equal
            mov.w   #00B0Fh,R12              ; Display 'LO'
            jmp     Disp 
             
MoreN2000   bit.w   #08000h,R12              ; Test for new negative value
            jz      Conv2BCD                 ; Jump if number is positive   
            bis.w   #001h,R11                ; Set negative flag
            inv.w   R12                      ; Negate R12
            inc.w   R12

Conv2BCD    mov.w   #16,R15                  ; Process 16 bits from R12
            clr.w   R14                      ; Clear result upper word
            clr.w   R13                      ; Clear result lower word
Conv2BCD2   rla.w   R12                      ; Shift MSB to carry
            dadd.w  R13,R13                  ; Multiply result by two, add C
            dadd.w  R14,R14
            dec.w   R15                      ; Decrement bit count
            jnz     Conv2BCD2                ; Process next bit
            mov.w   R13,R12                  ; Move result to R12 

            bit.b   #001h,R11                ; Display neg sign?
            jz      Disp                     ; Jump if no
            bis.w   #02000h,R12              ; "-" segment active
Disp        pop     R11                      ; Restore R11

Disp_BCD_3_5                                 ; Displays R12 as BCD
            mov.w   #LCDM1,R15               ; R15 points to first LCD location
Disp2       mov.w   R12,R14                  ; LSD value moved to R14
            and.b   #0Fh,R14                 ; R14 = Nibble now 
            mov.b   LCD_Tab(R14),R14         ; R14 = LCD segment information
            mov.b   R14,0(R15)               ; Segments a & b to LCD
            rra.w   R14
            mov.b   R14,1(R15)               ; Segments c & d to LCD
            rra.w   R14
            mov.b   R14,2(R15)               ; Segments e & f to LCD
            rra.w   R14
            mov.b   R14,3(R15)               ; Segments g & h to LCD

            rra.w   R12                      ; Right shift 
            rra.w   R12                      ; Right shift 
            rra.w   R12                      ; Right shift 
            rra.w   R12                      ; Right shift 

            add.b   #04h,R15                 ; R15 points to next LCD location
            cmp.b   #LCDM13,R15              ; Updated all segments?
            jne     Disp2

            bit.w   #00001h,R12              ; Data >999?
            jnc     Disp3
            bis.b   #010h,&LCDM12            ; B-C digit active (1xxx)

Disp3       bit.w   #00002h,R12              ; Display neg sign?
            jz      DispEnd                  ; Jump if no
            bis.b   #010h,&LCDM8             ; "-" segment active

DispEnd     ret                              ; Return from subroutine	
;-------------------------------------------------------------------------------
; Define characters for VI-302 3.5 digit static LCD
;
; Bit definitions for the LCD segments used in the following table:
;
;    000
;   6   4     
;   6   4
;    333 
;   2   1
;   2   1
;    555
;
;-------------------------------------------------------------------------------
LCD_Tab     DB      077h                     ; Displays "0"
            DB      012h                     ; Displays "1"
            DB      03Dh                     ; Displays "2"
            DB      03Bh                     ; Displays "3"
            DB      05Ah                     ; Displays "4"
            DB      06Bh                     ; Displays "5"
            DB      06Fh                     ; Displays "6"
            DB      013h                     ; Displays "7"
            DB      07Fh                     ; Displays "8"
            DB      07Bh                     ; Displays "9"
            DB      05Eh                     ; Displays "H"
            DB      064h                     ; Displays "L"
            DB      065h                     ; Displays "C"
            DB      05fh                     ; Displays "A"
            DB      000h                     ; Displays Blank
            DB      000h                     ; Displays Blank
;-------------------------------------------------------------------------------
;  Exit any LPMx Mode
;-------------------------------------------------------------------------------
BT_ISR      add.w   &BtIsrMode,PC            ; Jump table
            jmp     BtIsrNrm
            jmp     BtIsrCl1
            jmp     BtIsrCl2
            jmp     BtIsrCh1
            jmp     BtIsrCh2
            
BtIsrNrm    mov.w   #ADS1100_SA,R12          ; ADS1100 I2C Slave Address
            call    #I2CRead16               ; Get 16-bit conversion result
            tst.b   &UpdateDisplay           ; Conversion requested?
            jz      BtIsrNrm_1
            clr.b   &UpdateDisplay           ; Reset flag
            jmp     BtIsrNrm_2               ; Continue processing
BtIsrNrm_1  cmp.w   &LastADCValue,R12        ; Value changed?
            jne     BtIsrNrm_2               ; Continue processing
            reti                             ; Not changed, return            
BtIsrNrm_2  
            mov.w   R12,&LastADCValue        ; Store new value

; The next section is calculating the display value as follows:
; (1) R12 is treated as signed and sign-extended to R13:R12
; (2) The result of (1) is multiplied with CAL_MIN_MAX_SPAN
; (3) CalMax and CalMin are treated as signed values,
;     the difference is calculated and stored into R15:R14
; (4) The final value is calculated by dividing the result of (2)
;     by the result of (3)

            mov.w   R12,R13                  ; R13:R12 = R12 - CalMin
            inv.w   R13
            rla.w   R13
            subc.w  R13,R13
            mov.w   &CalMin,R14
            mov.w   R14,R15
            inv.w   R15
            rla.w   R15
            subc.w  R15,R15
            sub.w   R14,R12
            subc.w  R15,R13
            mov.w   #CAL_MIN_MAX_SPAN,R14    ; R15:R14 = CAL_MIN_MAX_SPAN
            clr.w   R15
            call    #Mul32                   ; R13:R12 = R13:R12 * R15:R14
            mov.w   &CalMax,R14              ; R15:R14 = CalMax - CalMin
            sub.w   &CalMin,R14
            mov.w   R14,R15
            inv.w   R15
            rla.w   R15
            subc.w  R15,R15
            call    #DivMod32s               ; R13:R12 = R13:R12 / R15:R14
            call    #Disp_Signed_3_5         ; Display R12 (lower result word)
            reti

BtIsrCl1    mov.w   #00CDBh,R12              ; Display 'CAL'
            call    #Disp_BCD_3_5
            mov.w   #BT_ISR_CL2,&BtIsrMode   ; Next state
            reti

BtIsrCl2    mov.w   #00B0Fh,R12              ; Display 'LO'
            call    #Disp_BCD_3_5
            mov.w   #BT_ISR_CL1,&BtIsrMode   ; Next state
            reti

BtIsrCh1    mov.w   #00CDBh,R12              ; Display 'CAL'  
            call    #Disp_BCD_3_5
            mov.w   #BT_ISR_CH2,&BtIsrMode   ; Next state
            reti

BtIsrCh2    mov.w   #00A1Fh,R12              ; Display 'HI'
            call    #Disp_BCD_3_5
            mov.w   #BT_ISR_CH1,&BtIsrMode   ; Next state
            reti
;-------------------------------------------------------------------------------
PORT1_ISR   add.w   &P1IsrMode,PC            ; Jump table
            jmp     P1IsrNrm
            jmp     P1IsrCl
            jmp     P1IsrCh
            
P1IsrNrm    bit.b   #040h,&P1IFG             ; Test for on P1.6 (on/off)
            jz      P1IsrNrm2                ; Jump if not pressed
            xor.b   #BTIE,&IE2               ; Toggle Basic Timer interrupt
            xor.b   #BRIDGE_H,&P6OUT         ; Toggle Bridge Supply Voltage
            xor.b   #LCDON,&LCDCTL           ; Toggle LCD on/off
            bit.b   #LCDON,&LCDCTL           ; Is on?
            jz      P1IsrNrm1                ; Skip if not
            mov.b   #ADS1100_SA,R12          ; ADS1100 I2C Slave Address
            mov.b   #ADS1100_8SPS+ADS1100_GAIN8,R14
            call    #I2CWrite8               ; Start conversions
            mov.b   #1,&UpdateDisplay        ; Request display update
            jmp     P1IsrNrm2
P1IsrNrm1   mov.b   #ADS1100_SA,R12          ; ADS1100 I2C Slave Address
            mov.b   #ADS1100_SC,R14          ; Disable conversions
            call    #I2CWrite8               ; Stop conversion (power-off ADC)
            bic.b   #BTIFG,IFG2              ; Clear Basic Timer int flag
P1IsrNrm2   bit.b   #080h,&P1IFG             ; Test for on P1.7 (calibration)
            jz      P1IsrNrm3                ; Skip if not pressed
            bit.b   #LCDON,&LCDCTL           ; Is unit switched on?
            jz      P1IsrNrm3                ; Skip if off
            mov.w   #P1_ISR_CL,&P1IsrMode    ; Enter calibration mode (low)
            mov.w   #BT_ISR_CL1,&BtIsrMode
P1IsrNrm3   jmp     P1IsrE

P1IsrCl     mov.b   #ADS1100_SA,R12          ; ADS1100 I2C Slave Address
            call    #I2CRead16               ; Get 16-bit conversion result
            mov.w   R12,&CalMinTmp           ; Get ADC1100 data
            mov.w   #P1_ISR_CH,&P1IsrMode    ; Enter calibration mode (high)
            mov.w   #BT_ISR_CH1,&BtIsrMode
            jmp     P1IsrE
            
P1IsrCh     mov.b   #ADS1100_SA,R12          ; ADS1100 I2C Slave Address
            call    #I2CRead16               ; Get 16-bit conversion result
            cmp.w   R12,&CalMinTmp           ; Are calibr constants OK?
            jne     P1IsrCh_1                ; Jump if yes
            mov.w   #P1_ISR_CL,&P1IsrMode    ; No,
            mov.w   #BT_ISR_CL1,&BtIsrMode   ; enter calibration mode (low)
            jmp     P1IsrE
P1IsrCh_1   mov.w   R12,&CalMaxTmp           ; Get ADC1100 data
            call    #StoreCalInFlash         ; Program constants
            mov.w   #P1_ISR_NRM,&P1IsrMode   ; Enter normal mode
            mov.w   #BT_ISR_NRM,&BtIsrMode
            mov.b   #1,&UpdateDisplay        ; Request display update
            
P1IsrE      push.w  #07fffh                  ; Delay for key-debounce
P1Delay     dec.w   0(SP)                    ; Do calc on TOS
            jnz     P1Delay
            incd    SP                       ; Correct SP
            clr.b   &P1IFG                   ; Clear all P1 int flags
            reti
;-------------------------------------------------------------------------------
            COMMON  INTVEC                   ; MSP430F41x interrupt vectors
;-------------------------------------------------------------------------------
            ORG     BASICTIMER_VECTOR        ; Basic-Timer interrupt vector
            DW      BT_ISR

            ORG     PORT1_VECTOR             ; Port 1 interrupt vector
            DW      PORT1_ISR

            ORG     RESET_VECTOR
            DW      RESET                    ; POR, ext. reset

            END

⌨️ 快捷键说明

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