#include          "msp430x14x.h" // Standard Equations
;******************************************************************************
;   MSP-FET430P140 Demo - ADC12, Converison of the Temperature Diode
;
;   Description: This program will show how to use the integrated temperature
;                diode to measure temperature.
;
;   This example shows how to use the intergrated temperature diode to measure
;   temperature. When the temperature diode channel (A10) is selected for 
;   conversion, the internal reference is automatically turned on as the source 
;   for the diode. Note however, that it is NOT automatically selected for the 
;   conversion.  Any available reference can be used for the conversion.  In 
;   this example, a single conversion is performed of the temperature diode.  
;   The temperature is then determined from a look-up table, based on the A/D 
;   conversion value. The A/D conversion results are stored in ADC12MEM0. The 
;   temperature is shown in R5 in BCD format, degress F.  Test by setting and 
;   running to a break point at "jmp Mainloop."  To view the temperature, open 
;   a register window in C-Spy and view the contents of R5.
;
;   Note: This example does not perform a calibration on the temperature diode
;   A calibration of the temperature diode may be necessary in an application.
;   See the device datasheet for the temperature diode specification. 
;
;       M.Mitchell
;       Texas Instruments, Inc
;       January, 2002
;******************************************************************************
;------------------------------------------------------------------------------ 
main        ORG     01100h                  ; Program Start
;------------------------------------------------------------------------------ 
RESET       mov     #0A00h,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     #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    bis     #ADC12SC,&ADC12CTL0     ; Start conversions
            bis     #CPUOFF,SR              ; Wait for conversion completion
                                            ;
DispTemp    mov     #0h,R15                 ; Clear table pointer
            mov     #032h,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_Tab(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_Tab    DW      064Fh                   ; 32F
            DW      0652h
            DW      0656h
            DW      0659h                   ;35F
            DW      065Ch
            DW      065Fh
            DW      0662h
            DW      0666h
            DW      0669h                   ;40F
            DW      066Ch
            DW      066Fh
            DW      0673h
            DW      0676h
            DW      0679h                   ;45F
            DW      067Ch
            DW      0680h
            DW      0683h
            DW      0686h
            DW      0689h                   ;50F
            DW      068Ch
            DW      0690h
            DW      0693h
            DW      0696h
            DW      0699h                   ;55F
            DW      069Dh
            DW      06A0h
            DW      06A3h
            DW      06A6h
            DW      06AAh                   ;60F
            DW      06ADh
            DW      06B0h
            DW      06B3h
            DW      06B6h
            DW      06BAh                   ;65F
            DW      06BDh
            DW      06C0h
            DW      06C3h
            DW      06C7h
            DW      06CAh                   ;70F
            DW      06CDh          
            DW      06D0h
            DW      06D4h
            DW      06D7h
            DW      06DAh                   ;75F
            DW      06DDh
            DW      06E0h
            DW      06E4h
            DW      06E7h
            DW      06EAh                   ;80F
            DW      06EDh
            DW      06F1h
            DW      06F4h
            DW      06F7h
            DW      06FAh                   ;85F
            DW      06FEh
            DW      0701h
            DW      0704h
            DW      0707h
            DW      070Bh                   ;90F
            DW      070Eh
            DW      0711h
            DW      0714h
            DW      0717h
            DW      071Bh                   ;95F
            DW      071Eh
            DW      0721h
            DW      0724h
            DW      0728h
            DW      072Bh                   ;100F
            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     