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

📄 实验7_思考_ca_temp1.s43

📁 MSP-TEST44X 学习板光盘资料及实验说明 本学习板是按照教育大纲
💻 S43
字号:
#include  "msp430x44x.h"
;******************************************************************************
;   MSP-Test44x Demo - Comp_A Slope ADC to Detect Temp Level Set P5.1 > 25c  
;
;   Description: Comparator_A is used to detect a resistance threashold.  
;   Discharge times of a 0.1uf capacitor through a 10k-NTC (25c) and 10k ohm 
;   reference resistor are compared.  If the NTC discharge time is is lower
;   than the 10k referece, P5.1 is set.  If the NTC discharge time is higher
;   than refernce, P5.1 is reset.  The LED is ON if the temperature is greater
;   than 25c. 
;   ACLK = n/a, MCLK = SMCLK = default DCO ~ 800k 
;
;                MSP430F449
;             -----------------
;        /|\ |              XIN|-  
;         |  |                 |
;         ---|RST          XOUT|-
;            |                 | 
;      +-10k-|P1.0             |
;      |     |                 |	
;      +-NTC-|P1.7             |
;      |     |                 |
;      +-----|P1.6         P5.1|-->LED
;      |     |                 |
;     ===.1uf|                 |
;      |     |                 |			
;      ------|VSS
;
;            NTC = 10k @25c, (P/N 271-110A Radio Shack)
;
Ref         equ    001h         ; P1.0 = Reference 
Sensor      equ    002h         ; P1.7 = Sensor 

;------------------------------------------------------------------------------ 
            ORG     01100h                  ; Program Start
;------------------------------------------------------------------------------ 
RESET       mov.w   #0A00h,SP                ; Initialize stackpointer
Init_Sys    mov.w   #WDTPW+WDTHOLD,&WDTCTL  ; Stop WDT
SetupP5     bic.b   #002h,&P5OUT            ; P5.1 reset
            bis.b   #002h,&P5DIR            ; P5.1 output direction
SetupP2     bic.b   #Sensor+Ref,&P1OUT      ; Sensor, Ref reset
            bis.b   #Sensor+Ref,&P1DIR      ; Sensor, Ref output
SetupCA     mov.b   #CARSEL+CAREF0+CAON,&CACTL1   ; -Comp = 0.25*Vcc -  on
            mov.b   #P2CA0,&CACTL2                ; +Comp = P1.6 
SetupTA     mov.w   #TASSEL1+TACLR,&TACTL   ; SMCLK, clear TAR
            eint                            ; Enable interrupts
                                            ;													  
Mainloop    mov.b   #Sensor,R14             ; R14 = discharge pin 
            call    #Measure                ;
            mov.w   R14,R15                 ; R15 = Sensor discharge time			  
            mov.b   #Ref,R14                ; R14 = discharge pin
            call    #Measure                ; 
            cmp.w   R14,R15                 ; R14 = Reference discharge time
            jlo     ON                      ; jump if R15 < R14 ( >25c )
;	    Display Modes                   ;
OFF         bic.b   #002h,&P5OUT            ; LED off - Reset P5.1 
            jmp     Mainloop                ;  
ON          bis.b   #002h,&P5OUT            ; LED on  - Set P5.2 
            jmp     Mainloop                ;  
                                            ;
;------------------------------------------------------------------------------ 
Measure;    Input:   R14 = Sensor or Ref P2.x bit location
;           Output:  R14 = Sensor or Ref discharge time
;------------------------------------------------------------------------------ 
Charge;     Capacitor is charged via Ref 
            bis.w   #MC1,&TACTL             ; Start timer_a continous mode
            bis.b   #Ref,&P1OUT             ; Ref Set
            bis.b   #Ref,&P1DIR             ; Ref output
            mov.w   &TAR,&CCR1              ; CCR1 = TAR
            add.w   #5000,&CCR1             ; CCR1 ~ TAR+5ms (5tu)
            mov.w   #CCIE,&CCTL1            ; Comp,interrupt
            bis.w   #LPM0,SR                ; Wait for CCR1 interrupt				 
            bic.b   #Ref,&P1DIR             ; Ref = HiZ, Charge complete 
            bic.b   #Ref,&P1OUT             ; Ref = Reset						   
Discharge;  Measure Discharge Time 
            mov.w   #CM1+CCIS0+CAP+CCIE,&CCTL1    ; Neg, CCIB,Cap,interrupt
            push    &TAR                    ; TOS = TAR at SOC
            bis.b   R14,&P1DIR              ; Temp = Sensor or REF 
            bis.w   #LPM0,SR                ; Wait for CCR1 interrupt				 
            mov.w   &CCR1,R14               ; R14 = TAR (CCR1) at EOC
            sub.w   @SP+,R14                ; R14 = discharge time
            bic.b   #Sensor+Ref,&P1DIR      ; Disable Sensor or Ref 
            clr.w   &CCTL1                  ; Disable CCTL1
            bic.w   #MC1,&TACTL             ; Stop timer_a , save power
            ret                             ;
                                            ;
;------------------------------------------------------------------------------ 
TAX_ISR;    Common ISR for CCR1-4 and overflow
;------------------------------------------------------------------------------ 
            add.w   &TAIV,PC                ; Add TA interrupt offset to PC
            reti                            ; CCR0 - no source
            jmp     CCR1_ISR                ; CCR1
            reti                            ; CCR2
            reti                            ; CCR3
            reti                            ; CCR4
TA_over     reti                            ; Timer_A overflow
                                            ;
CCR1_ISR    bic.w   #LPM0,0(SP)             ; Exit LPM0 on reti
            reti                            ;
                                            ;
;------------------------------------------------------------------------------ 
;           Interrupt Vectors Used MSP430x11x1         
;------------------------------------------------------------------------------ 
            ORG     0FFFEh                  ; MSP430 RESET Vector
            DW      RESET                   ; 
            ORG     0FFF0h                  ; Timer_AX Vector
            DW      TAX_ISR                 ; 
            END

⌨️ 快捷键说明

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