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

📄 fet140_adc12_10.s43

📁 基于IAR Workbench for MSP430 的汇编语言例程
💻 S43
字号:
;******************************************************************************
;   MSP-FET430P140 Demo - ADC12 Sample A10Temp and Convert to oC and oF  
;
;   Description; A single sample is made on A10 with refernce to internal
;   1.5V Vref. Software sets ADC12SC to start sample and conversion - ADC12SC 
;   automatically cleared at EOC. ADC12 internal oscillator times sample 
;   and conversion. In Mainloop MSP430 waits in LPM0 to save power until 
;   ADC10 conversion complete, ADC12_ISR will force exit from any LPMx in 
;   Mainloop on reti. Result is converted to Temperature represented as 
;   BCD 0000 - 0145 representing oC saved at 0200h and 0000 - 0292 representing
;   oF saved at 0202h.   
;   ACLK = n/a, MCLK = SMCLK = default DCO ~ 800kHz, ADC12CLK = ADC12OSC
; 
;   Uncalibrated temperature measured from device to devive will vary do to
;   slope and offset variance from device to device - please see datasheet.
;
;                MSP430Fx49
;             -----------------
;         /|\|              XIN|-  
;          | |                 |
;          --|RST          XOUT|-
;            |                 |
;            |A10/Temp         |
;
;   M.Buccini
;   Texas Instruments, Inc
;   January 2004
;******************************************************************************
#include  "msp430x14x.h"
;------------------------------------------------------------------------------ 
            ORG     01100h                  ; Program Start
;------------------------------------------------------------------------------ 
RESET       mov.w   #0A00h,SP               ; Initialize 'x49 stackpointer
            mov.w   #WDTPW+WDTHOLD,&WDTCTL  ; Stop WDT
            mov.w   #SHT0_8+REFON+ADC12ON,&ADC12CTL0 ; 1.5v ref.
            mov.w   #SHP,&ADC12CTL1         ; Enable sample timer    
            mov.b   #01Ah,&ADC12MCTL0       ; A10, internal reference 
            bis.w   #0001h,&ADC12IE         ; Enable interrupt
                                            ;   
Mainloop    bis.w   #ENC+ADC12SC,&ADC12CTL0 ; Start sampling/conversion
            bis.w   #CPUOFF+GIE,SR          ; LPM0, ADC10_ISR will force exit
            call    #Trans2TempC            ; Transform voltage to temperature
            call    #BIN2BCD4               ; R13 = TempC = 0000 - 0145 BCD  
            mov.w   R13,&0200h              ; 0200h = temperature oC
            call    #Trans2TempF            ; Transform voltage to temperature
            call    #BIN2BCD4               ; R13 = TempF = 0000 - 0292 BCD  
            mov.w   R13,&0202h              ; 0202h = temperature oF
            jmp     Mainloop                ; << breakpoint here
                                            ;
;------------------------------------------------------------------------------ 
Trans2TempC;Subroutine coverts R12 = R12/4096*423-278
;           oC = ((x/4096)*1500mV)-986mV)*1/3.55mV = x*423/4096 - 278 
;           Input:  R12  0000 - 0FFFh, R11 working register   
;           Output: R12  0000 - 091h   
;------------------------------------------------------------------------------ 
;            mov.w   &ADC12MEM0,R12          ; Clear IFG flag (not needed)
            mov.w   R12,&MPY                ;
            mov.w   #423,&OP2               ; C          
            mov.w   &RESHI,R12              ;
            mov.w   &RESLO,R11              ;
            rlc.w   R11                     ; /4096
            rlc.w   R12                     ;
            rlc.w   R11                     ;
            rlc.w   R12                     ;
            rlc.w   R11                     ;
            rlc.w   R12                     ;
            rlc.w   R11                     ;
            rlc.w   R12                     ;
            sub.w   #278,R12                ; C    
            ret                             ;
                                            ;
;----------------------------------------------------------------------------- 
Trans2TempF;Subroutine coverts R12 = R12/4096*761-468
;           oF = ((x/4096*1500mV)-923mV)*1/1.97mV = x*761/4096 - 468 
;           Input:  R12  0000 - 0FFFh, R11 working register   
;           Output: R12  0000 - 0262   
;----------------------------------------------------------------------------- 
            mov.w   &ADC12MEM0,R12          ; Clear IFG flag
            mov.w   R12,&MPY                ;
            mov.w   #761,&OP2               ; F          
            mov.w   &RESHI,R12              ;
            mov.w   &RESLO,R11              ;
            rlc.w   R11                     ; /4096
            rlc.w   R12                     ;
            rlc.w   R11                     ;
            rlc.w   R12                     ;
            rlc.w   R11                     ;
            rlc.w   R12                     ;
            rlc.w   R11                     ;
            rlc.w   R12                     ;
            sub.w   #468,R12                ; F    
            ret                             ;
                                            ;
;----------------------------------------------------------------------------- 
BIN2BCD4  ; Subroutine converts binary number R12 -> Packed 4-digit BCD R13
;           Input:  R12  0000 - 0FFFh, R15 working register   
;           Output: R13  0000 - 4095   
;----------------------------------------------------------------------------- 
            mov.w   #16,R15                 ; Loop Counter
            clr.w   R13                     ; 0 -> RESULT LSD
BIN1        rla.w   R12                     ; Binary MSB to carry
            dadd.w  R13,R13                 ; RESULT x2 LSD
            dec.w   R15                     ; Through?
            jnz     BIN1                    ; Not through
            ret                             ;
                                            ;
;-----------------------------------------------------------------------------
ADC12_ISR;  ADC12MEM0 -> R12, exit any LPMx mode   
;           Output: R12  0000 - 0FFFh   
;-----------------------------------------------------------------------------
            mov.w   &ADC12MEM0,R12          ; Clear IFG flag
            mov.w   #GIE,0(SP)              ; Enable Int. exit LPMx on reti
            reti                            ;
                                            ;    
;------------------------------------------------------------------------------ 
;           Interrupt Vectors Used MSP430xx4x          
;------------------------------------------------------------------------------ 
            ORG     0FFFEh                  ; MSP430 RESET Vector
            DW      RESET                   ; 
            ORG     0FFEEh                  ; ADC12 Vector
            DW      ADC12_ISR               ; 
            END

⌨️ 快捷键说明

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