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

📄 +-

📁 MSP430F413C.ZIP可作为MSP430单片机软件编程的学习参考
💻
字号:
#include          "msp430x43x.h" // Standard Equations
;******************************************************************************
;   名称:温度二极管测试程序
;
;   说明: 此程序适用于内部有ADC12模块的430芯片,利用ADC12通道10的温度二极管测量
;         温度。
;         采用单通道单次转换方式(6次),六次的测量值去掉其中的二个极端值,其余
;         平均后作为测量结果,并转换成相应的温度数值(摄氏度)。
;
#define     SUM   R7         ;result
#define     MAX   R8         ;highest result
#define     MIN   R9         ;lowest result


;******************************************************************************
;------------------------------------------------------------------------------ 
main        ORG     08000h                  ; Program Start
;------------------------------------------------------------------------------ 
RESET       mov     #0600h,SP               ; Initialize stackpointer
StopWDT     mov     #WDTPW+WDTHOLD,&WDTCTL  ; Stop watchdog
                                            ;
SetupADC12  mov     #ADC12ON+REFON+REF2_5V+SHT0_6,&ADC12CTL0 
                                            ; Turn on ADC12, 2.5Vref, set SHT0
                                            ; for longer sampling required by
                                            ; temp diode.
            ;mov     #ADC12ON+REFON+SHT0_6,&ADC12CTL0 
                                            ; Turn on ADC12, 1.5Vref, set SHT0
                                            ; for longer sampling required by
                                            ; temp diode.                                
            mov     #SHP,&ADC12CTL1         ; Use sampling timer    
            mov.b   #INCH_10+SREF_1,&ADC12MCTL0  ; Select channel A10, Vref+
            bis     #BIT0,&ADC12IE          ; Enable ADC12IFG.0 for ADC12MEM0            
                                            ;
            mov     #03600h,R15             ; Delay needed for ref start-up
L$1         dec     R15                     ; See datasheet for details
            jnz     L$1                     ;
                                            ;
            bis     #ENC,&ADC12CTL0         ; Enable conversions
            eint                            ; Enable interrupts         
                                            ;
Mainloop    clr     SUM                     ; initialize buffers
            clr     MAX                     ; ADCmin→MAX	
            mov     #0FFFFh,MIN             ; ADCmax→MIN			
            mov     #6,R15                  ;
AD          bis     #ADC12SC,&ADC12CTL0     ; Start conversions
            bis     #CPUOFF,SR              ; Wait for conversion completion
            add     R6,SUM                  ;
            cmp     R6,MAX                  ; Result>MAX
            jhs     L$2                     ; no
            mov     R6,MAX                  ; yes,actualize MAX
L$2         cmp     R6,MIN                  ; Result<MIN
            jlo     L$3                     ; no
            mov     R6,MIN                  ; yes,actualize MIN
L$3         dec     R15                     ; Counter - 1
            jnz     AD                      ;
            sub     R8,SUM                  ; subtract highest result
            sub     R9,SUM                  ; subtract lowest result
            rra     SUM                     ; result/4
            rra     SUM                     ;
            mov     R7,R6                   ;
DispTemp    mov     #0h,R15                 ; Clear table pointer
            mov     #0h,R5                  ; Load R5 with min. temp
            jmp     First_cmp               ; Compare without incrementing
CMPloop     incd    R15                     ; Point to next value in table
            dadd    #1,R5                   ; Decimally increment R5
First_cmp   cmp     Temp_Tab1(R15),R6       ; Compare A/D resultV
            ;cmp     Temp_Tab2(R15),R6       ; Compare A/D result
            jge     CMPloop                 ; Jump to increment and compare
            jmp     Mainloop                ; SET BERAKPOINT HERE.
                                            ; Done comparing. Temp in R5
                                            ;
;------------------------------------------------------------------------------ 
;           Temperature Table       
;           These values assume nominal values for the temp diode and
;           temperature coefficient.  They also assume the 2.5V internal
;           reference is used for the conversion.  
;------------------------------------------------------------------------------
Temp_Tab1   DW      064Fh                   ; 0C
            DW      0655h
            DW      065Bh
            DW      0660h                   
            DW      0666h
            DW      066Ch                   ; 5C
            DW      0672h
            DW      0678h
            DW      067Dh                   
            DW      0683h
            DW      0689h                   ;10C
            DW      068Fh
            DW      0695h
            DW      069Bh                   
            DW      06A0h
            DW      06A6h                   ;15C
            DW      06ACh
            DW      06B2h
            DW      06B8h                   
            DW      06BDh
            DW      06C3h                   ;20C
            DW      06C9h
            DW      06CFh
            DW      06D5h                   
            DW      06DBh
            DW      06E0h                   ;25C
            DW      06E6h
            DW      06ECh
            DW      06F2h                   
            DW      06F8h
            DW      06FDh                   ;30C 
            DW      0703h
            DW      0709h
            DW      070Fh                   
            DW      0715h
            DW      071Bh                   ;35C
            DW      0720h
            DW      0726h
            DW      072Ch                   
            DW      0732h          
            DW      0738h                   ;40C
            DW      073Dh
            DW      0743h
            DW      0749h                   
            DW      074Fh
            DW      0755h                   ;45C
            DW      075Bh
            DW      0760h
            DW      0766h                   
            DW      076Ch
            DW      0772h                   ;50C
            DW      0778h
            DW      077Dh
            DW      0783h                   
            DW      0789h
            DW      078Fh                   ;55C
            DW      0795h
            DW      079Ah
            DW      07A0h                   
            DW      07A6h
            DW      07ACh                   ;60C
            DW      07B2h
            DW      07B8h
            DW      07BDh                   
            DW      07C3h
            DW      07C9h                   ;65C
            DW      07CFh
            DW      07D5h
            DW      07DAh                   
            DW      07E0h                       
            DW      07E6h                   ;70C
            DW      0FFFh                   ;Too high                
            
;------------------------------------------------------------------------------ 
;           Temperature Table(2)       
;           These values assume nominal values for the temp diode and
;           temperature coefficient.  They also assume the 1.5V internal
;           reference is used for the conversion.  
;------------------------------------------------------------------------------
Temp_Tab2   DW      0A84h                   ; 0C
            DW      0A8Eh
            DW      0A97h
            DW      0AA1h                   
            DW      0AABh
            DW      0AB4h                   ; 5C
            DW      0ABEh
            DW      0AC8h
            DW      0AD1h                   
            DW      0ADBh
            DW      0AE5h                   ;10C
            DW      0AEFh
            DW      0AF8h
            DW      0B02h                   
            DW      0B0Ch
            DW      0B15h                   ;15C
            DW      0B1Fh
            DW      0B29h
            DW      0B32h                   
            DW      0B3Ch
            DW      0B46h                   ;20C
            DW      0B50h
            DW      0B59h
            DW      0B63h                   
            DW      0B6Dh
            DW      0B76h                   ;25C
            DW      0B80h
            DW      0B8Ah
            DW      0B93h                   
            DW      0B9Dh
            DW      0BA7h                   ;30C 
            DW      0BB0h
            DW      0BBAh
            DW      0BC4h                   
            DW      0BCEh
            DW      0BD7h                   ;35C
            DW      0BE1h
            DW      0BEBh
            DW      0BF4h                   
            DW      0BFEh          
            DW      0C08h                   ;40C
            DW      0C11h
            DW      0C1Bh
            DW      0C25h                   
            DW      0C2Eh
            DW      0C38h                   ;45C
            DW      0C42h
            DW      0C4Ch
            DW      0C55h                   
            DW      0C5Fh
            DW      0C69h                   ;50C
            DW      0C72h
            DW      0C7Ch
            DW      0C86h                   
            DW      0C8Fh
            DW      0C99h                   ;55C
            DW      0CA3h
            DW      0CACh
            DW      0CB6h                   
            DW      0CC0h
            DW      0CCAh                   ;60C
            DW      0CD3h
            DW      0CDDh
            DW      0CE7h                   
            DW      0CF0h
            DW      0CFAh                   ;65C
            DW      0D04h
            DW      0D0Dh
            DW      0D17h                   
            DW      0D21h                       
            DW      0D2Bh                   ;70C
            DW      0FFFh                   ;Too high                            
;------------------------------------------------------------------------------ 
ADC12ISR    ; Interrupt Service Routine for ADC12
;------------------------------------------------------------------------------
            mov     &ADC12MEM0,R6           ; Move result, IFG is reset
            bic     #CPUOFF,0(SP)           ; Return active
            reti                            ;
                                            ;
;------------------------------------------------------------------------------ 
;           Interrupt Vectors         
;------------------------------------------------------------------------------
            ORG     0FFFEh                  ; MSP430 RESET Vector
            DW      RESET                   ;
            ORG     0FFEEh                  ; ADC12 Interrupt Vector
            DW      ADC12ISR                ;
            END     
            
            
            
            

⌨️ 快捷键说明

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