📄 实验8_adc12_lcd.s43
字号:
#include "msp430x44x.h" ; Standard Equations
;------------------------------------------------------------------------------
;MSP-Test44x Demo - ADC12 A10, BT,LCD
;
; MSP430F449
; -----------------
; /|\| XIN|-
; | | | 32kHz
; --|RST XOUT|-
; | | LCD
; +-|R33 P5.1| -----------------
; 1m | - |--> | F 5 5 |
; +-|R23 P3.2| -----------------
; 1m | COM0|-----||||
; +-|R13 COM1|------|||
; 1m | COM2|-------||
; +-|R03 COM3|--------|
; | | |
; Vss
;
;------------------------------------------------------------------------------
ORG 01100h ; Program Start
;------------------------------------------------------------------------------
RESET mov #0A00h,SP ; Initialize stackpointer
StopWDT mov #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog
SetupFLL bis.b #XCAP14PF,&FLL_CTL0 ; Configure load caps
mov #0fffh,r15
os_wait dec r15 ;wait for the MCLK
jnz os_wait
call #lcd_display_ona ;initialize the LCD
;-------------------------------------------------------------------------------
;----------------ADC for the temp diode and
;----------------temperature coefficient. They also assume the 2.5V internal
;----------------reference is used for the conversion.
;-------------------------------------------------------------------------------
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
;-----------------------------------------------------------------------------------
;---------------r9 is the time for show "C"temperature
;---------------r10 is the flag for show the "F"or "c" temperature
;---------------r10=0, show "F"temperature
;-----------------------------------------------------------------------------------
mov #01fffh,r9
clr r10
Mainloop bis #ADC12SC,&ADC12CTL0 ; Start conversions
bis #CPUOFF,SR ; Wait for conversion completion
;
DispTemp mov #0h,R15 ; Clear table pointer
mov #32h,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
; SET BERAKPOINT HERE.
; Done comparing. Temp in R5
L_C mov #00h,r7
mov #0h,r15
jmp First_cmp_c ; Compare without incrementing
CMPloop_c incd R15 ; Point to next value in table
dadd #55h,R7 ; Decimally increment R7
First_cmp_c cmp Temp_Tab(R15),R6 ; Compare A/D result
jge CMPloop_c ; Jump to increment and compare
; SET BERAKPOINT HERE.
; Done comparing. Temp in R7
tst.b r10
jz LCD_DISP_1
;-----------------------------------------------------------------------
;show "F" temperature
;----------------------------------------------------------------------
LCD_DISP ;show "F"temperature
mov.b r5,r13 ;D1 show
rra.b r13
rra.b r13
rra.b r13
rra.b r13
and.b #0fh,r13
mov.b lcd_table(R13),&LCDM2 ;lcd show
mov.b r5,r13 ;D0 show
and.b #0fh,r13
mov.b lcd_table(R13),&LCDM1 ;lcd show
mov.b #0fh,r13 ;D5 show "F"
mov.b lcd_table(r13),&LCDM5
jmp choose
;-----------------------------------------------------------------------
;show "C" temperature
;-----------------------------------------------------------------------
LCD_DISP_1 ;show "C" temperature
mov r7,r13 ;show D0
and #000fh,r13
mov.b lcd_table(R13),&LCDM1
mov r7,r13 ;show D1
rra r13
rra r13
rra r13
rra r13
and #000fh,r13
mov.b lcd_table(R13),&LCDM2
mov.b r7,r13 ;show D2
swpb r13
and #000fh,r13
mov.b lcd_table(R13),R15
add.b #80h,r15
mov.b r15,&LCDM3 ;show "."
mov r7,r13 ;show D3
swpb r13
rra r13
rra r13
rra r13
rra r13
and #000fh,r13
mov.b lcd_table(R13),&LCDM4 ;show "C"
mov.b #0ch,r13
mov.b lcd_table(R13),&LCDM6
;----------------------------------------------------------------------------------
choose
dec r9 ;the time for show the kind of
jnz RET_1 ;temperature "F"or"C"is reduse
call #show_clr
;-----------------------------------------------------------------------------------
;---------------r9 is the time for show "F"temperature
;---------------r10 is the flag for show the "F"or "c" temperature
;---------------r10=1, show "C"temperature
;-----------------------------------------------------------------------------------
mov #02fffh,r9
xor.b #1,r10
call #show_clr
RET_1
mov #0ffh,r15 ;delay for the next ADC
delay_1 dec r15
jnz delay_1
jmp Mainloop
;-----------------------------------------------------------------------------------
;--------------------initialize the LCD---------------------------------------------
;-----------------------------------------------------------------------------------
lcd_display_ona mov.b #0ffh,&P3DIR
mov.b #03h,&P4DIR
mov.b #0FCh,&P5SEL ;Enable R(LCD) + COM Lines
mov.b #LCDON+LCD4MUX+LCDP1,&LCDCTL ;STK LCD 4Mux, S0-S19
mov.b #BTFRFQ1,&BTCTL ;Basic Timer : SSEL=0 DIV=0 Reset=1,
;ACLK,32768/256 = 128Hz (7.8ms debounce time)
;Basic Timer reset disabled
;enable basic timer intrpt
call #show_clr ;clear LCD
ret
;--------------------------------------------------
;---------clear the LCD buffer---------------------
;--------------------------------------------------
show_clr
mov.b #01h,R15 ; clear display memory
show_clr1
mov.b #00h,LCDMEM(r15)
inc.b R15
cmp.b #0ah,R15
jnz show_clr1
ret
delay mov.b #0ffh,R15
ttt nop
nop
dec.b R15
jnz ttt
ret
;------------------------------------------------------------------------------
; 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
;------------------------------------------------------
;-------------LCD display -----------------------------
;------------------------------------------------------
lcd_table
db 7bh ;0
db 12h ;1
db 4fh ;2
db 1fh ;3
db 36h ;4
db 3dh ;5
db 7dh ;6
db 13h ;7
db 7fh ;8
db 3fh ;9
db 73h ;A
db 7ch ;B
db 69h ;C
db 5eh ;d
db 6fh ;e
db 65h ;F
;------------------------------------------------------------------------------
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 + -