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

📄 mspf413-tmp100 interface.s43

📁 关于msp430f413用TMP100传感器测量温度的源码
💻 S43
📖 第 1 页 / 共 2 页
字号:
            jnz     I2C_TX_Bit              ; continue until 8 bits are sent
            bic.b   #SDA,&P2DIR             ; SDA=1
                                            ;
TX_Ackn     bic.b   #SCL,&P2DIR             ; SCL=1
            nop                             ; delay to meet I2C spec
            nop                             ;
            bis.b   #SCL,&P2DIR             ; SCL=0
                                            ;
            ret                             ; Return from subroutine
                                            ;
;------------------------------------------------------------------------------ 
I2C_RX  ;   enter SDA=1, SCL=0
;           exit  SDA=x, SCL=0
;------------------------------------------------------------------------------ 
            mov.b   #08,BITI2C              ; number of bits to rcv
I2C_RX_Bit  bic.b   #SCL,&P2DIR             ; SCL=1
            bit.b   #SDA,&P2IN              ; SDA bit -> carry
            rlc.w   DATAI2C                 ; Shift new bit into DATAI2C
            bis.b   #SCL,&P2DIR             ; SCL=0
            dec     BITI2C                  ; all bits read?
            jnz     I2C_RX_Bit              ; continue until 8 bits are read
                                            ;
            ret                             ; Return from subroutine
                                            ;
                                            ;
;------------------------------------------------------------------------------ 
I2C_ACKn;   enter SDA=x, SCL=0
;           exit  SDA=0, SCL=0
;------------------------------------------------------------------------------ 
            bis.b   #SDA,&P2DIR             ; SDA=0, Ack
            bic.b   #SCL,&P2DIR             ; SCL=1
            bis.b   #SCL,&P2DIR             ; SCL=0
            bic.b   #SDA,&P2DIR             ; SDA=1
Ackn_End    ret                             ; Return from subroutine
                                            ;
;------------------------------------------------------------------------------ 
I2C_NACKn;  enter SDA=x, SCL=0
;           exit  SDA=1, SCL=0
;------------------------------------------------------------------------------ 
            bic.b   #SDA,&P2DIR             ; SDA=1, NOT Ack
            bic.b   #SCL,&P2DIR             ; SCL=1
            bis.b   #SCL,&P2DIR             ; SCL=0
NAckn_End   ret                             ; Return from subroutine
                                            ;
;------------------------------------------------------------------------------ 
I2C_Stop;   enter SDA=x, SCL=0
;           exit  SDA=1, SCL=1
;------------------------------------------------------------------------------ 
            bis.b   #SDA,&P2DIR             ; SDA = 0
            bic.b   #SCL,&P2DIR             ; SCL = 1
            bic.b   #SDA,&P2DIR             ; SDA = 1
I2C_End     ret                             ; Return from subroutine
                                            ;
;///////////I2C Subroutines stop///////////////////////////////////////////////

;------------------------------------------------------------------------------ 
Calc_Temp  ;Subroutine handles MSB decoding for negative temperatures
           ;CPU Registers used R13, not saved
;------------------------------------------------------------------------------ 
            bic.b   #001h,Neg_Sign          ; Clear negative Flag
            bit.b   #080h,DATAI2C           ; Test for new negative result
            jz      Calc_End                ; Jump if number is positive   
            bis.b   #001h,Neg_Sign          ; Set negative flag
            and.b   #07Fh,DATAI2C           ; Clear MSB (negative holder)
            mov.b   #080h,R13               ; 128dec to R13 (128-DATAI2C=Value)
            sub.b   DATAI2C,R13             ; R13 is the result now
            mov.b   R13,DATAI2C             ; New Data to convert to BCD
                                            ;
Calc_End    ret                             ; Return from subroutine
                                            ;
;------------------------------------------------------------------------------ 
Disp_Signed_3_5   ;Subroutine to Display 3.5 BCD digits in DIGITS w/ sign
                  ;CPU Registers used R15, R14, R13, not saved
;------------------------------------------------------------------------------ 
Disp_1      mov.w   DATAI2C,DIGITS          ; Move data to DIGITs
            call    #bin2bcd                ; Convert to BDC format
            rlc.w   DIGITS                  ; Shift Data 4 bits
            rlc.w   DIGITS                  ;
            rlc.w   DIGITS                  ;
            rlc.w   DIGITS                  ;
            and.w   #0FFF0h,DIGITS          ; Clear LSByte
            add.w   #000Ch,DIGITS           ; Add "C"
                                            ;
            mov.w   DIGITS,R13              ; Preserve DIGITS
            mov.w   #LCDM1,R15              ; R15 points to first LCD location
                                            ;
Disp_2      mov.w   R13,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   R13                     ; Right Shift 
            rra.w   R13                     ; Right Shift 
            rra.w   R13                     ; Right Shift 
            rra.w   R13                     ; Right Shift 
                                            ;
            add.b   #04h,R15                ; R15 points to next LCD location
            cmp.b   #LCDM13,R15             ; Updated all Segments?
            jne     Disp_2                  ;
                                            ;
            bit.b   #001h,Neg_Sign          ; Display Neg Sign?
            jz      Disp_3                  ; Jump if No
            bis.b   #010h,&LCDM8            ; "-" segment active
                                            ;
Disp_3      bit.w   #00001h,R13             ; Data >99
            jnc     Disp_End                ;
            bis.b   #010h,&LCDM12           ; B-C digit active
                                            ;
Disp_End    ret                             ; Return from subroutine	
                                            ;
;-------------------------------------------------------------------------------
;             Define characters for VI-302 3.5 digit static LCD
;-------------------------------------------------------------------------------
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      05Fh                    ; Displays "A"
            DB      000h                    ; Displays  Blank
            DB      065h                    ; Displays "C"
            DB      059h                    ; Displays "degrees" o
            DB      06Dh                    ; Displays "E"
            DB      04Dh                    ; Displays "F"
                                            ;
;------------------------------------------------------------------------------ 
bin2bcd;     subroutine for converting 16-bit binary to BCD
       ;     input DIGIT 16-bit binary, output DIGIT 16-bit BCD
;------------------------------------------------------------------------------ 
             mov.w   #16,R15                ;
             clr.w   R14                    ;
             clr.w   R13                    ;
L$1          rla.w   DIGITS                 ;
             dadd.w  R13,R13                ;
             dadd.w  R14,R14                ;
             dec.w   R15                    ;
             jnz     L$1                    ;
             mov.w   R13,DIGITS             ;
             ret                            ; Return from subroutine
                                            ;
;---------------------------------------------------------------------------
BT_ISR;     Exit any LPMx Mode
;---------------------------------------------------------------------------
            mov.w   #GIE,0(SP)              ; Exit LPM3, interrupts enabled
            reti                            ; Return from interrupt		 
                                            ;   
;----------------------------------------------------------------------------- 
;           Interrupt Vectors Used MSP430F413         
;----------------------------------------------------------------------------- 
            ORG     0FFFEh                  ; MSP430 RESET Vector
            DW      RESET                   ; 
            ORG     0FFE0h                  ; Basic Timer Vector
            DW      BT_ISR                  ; 
            END                             ;

⌨️ 快捷键说明

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