📄 d413_tmp_sensor_master.s43
字号:
MULT_by_18 rrc.w DATAI2C ;
rrc.w DATAI2C ;
rrc.w DATAI2C ;
rrc.w DATAI2C ;
mov.w DATAI2C,R15 ; R15 = DATAI2C*16
rrc.w DATAI2C ;
rrc.w DATAI2C ;
rrc.w DATAI2C ; DATAI2C right justified
add.w DATAI2C,R15 ; R15 = DATAI2C*18
DIV_by_5 clr.w R13 ; Clear Remainder
mov.w R15,R12 ; Dividend
mov.w #005,R11 ; Divisor
clr.w R14 ; Result
mov.w #17,R10 ; Initialize Loop Counter
DIV1 cmp.w R11,R13 ;
jlo DIV2 ;
sub.w R11,R13 ;
DIV2 rlc.w R14 ;
jc DIV3 ; Error: result > 16 bits
dec.w R10 ; Decrement loop counter
jz DIV3 ; Is 0: terminate w/o err
rla.w R12 ;
rlc.w R13 ;
jnc DIV1 ;
sub.w R11,R13 ;
setc ;
jmp DIV2 ;
DIV3 rra.w R14 ; Result = XXX.Y: Rotate out Y
;
Calc_0 bit.b #001h,Neg_Sign ; Test Neg Sign
jz Calc_2 ;
cmp.w #020h,R14 ;
jlo Calc_1 ;
sub.w #032,R14 ; R14 <= (-)32
mov.w R14,DATAI2C ;
ret ;
Calc_1 bic.b #001,Neg_Sign ;
mov.w #032,R15 ;
sub.w R14,R15 ; 0 > R14 > (-)32
mov.w R15,DATAI2C ;
ret ;
Calc_2 add.w #032,R14 ; R14 > 0
mov.w R14,DATAI2C ;
;
Calc_End ret ;
;
;---------------------------------------------------------------------------
Disp_LCD_Temp ; Subroutine to Display "F" and Temperature (R15) value on LCD
; Input: R15, R12 -- R13 is a working register
; Output: LCD display
;---------------------------------------------------------------------------
mov.b #000h,&LCDM5 ; Clear 5th Digit for temp
mov.w DATAI2C,DIGITS ;
call #Bin2Bcd ;
mov DIGITS,R15 ;
;
mov.b &Temp_Symb,&LCDM1 ; "F" or "C" to display
xor.b #02Bh,&LCDM2 ; "o" blinked on display
mov.w R15,R12 ; Copy BCD number to R12
rra.w R15 ; Rotate a nibble (digit)
rra.w R15 ;
rra.w R15 ;
rra.w R15 ;
and.w #0Fh,R12 ; Expose single digit
and.w #0Fh,R15 ; Expose single digit
mov.b LCD_Tab(R12),&LCDM3 ; Move digit to LCD display RAM
mov.b LCD_Tab(R15),&LCDM4 ; Move digit to LCD display RAM
;
bit.b #001h,Neg_Sign ; Display Neg Sign?
jz Disp_Pos ; Jump if No
bis.b #08h,&LCDM5 ; "-" segment active
jmp Disp_1xx ;
;
Disp_Pos bic.b #08h,&LCDM5 ; "-" segment inactive
Disp_1xx bit.w #000100h,R13 ; Data >99?
jnc Disp_Ret ;
bis.b #012h,&LCDM5 ; 100's digit active
ret ;
;
Disp_Ret bic.b #012h,&LCDM5 ; 100's digit inactive
ret ;
;
;
;---------------------------------------------------------------------------
Disp_LCD_Time ; Subroutine to Display "xx-xx" formatted time (R15) value on LCD
; Input: R15, R12 -- R13 is a working register
; Output: LCD display
;---------------------------------------------------------------------------
mov.w DIGITS,R15 ; Get 2 LSD's
mov.w R15,R12 ; Copy BCD number to R12
rra.w R15 ; Rotate a nibble (digit)
rra.w R15 ;
rra.w R15 ;
rra.w R15 ;
and.w #0Fh,R12 ; Expose single digit
and.w #0Fh,R15 ; Expose single digit
mov.b LCD_Tab(R12),&LCDM1 ; Move digit to LCD display RAM
mov.b LCD_Tab(R15),&LCDM2 ; Move digit to LCD display RAM
mov.b #008h,&LCDM3 ; Move "-" to separate hrs-mins
;
swpb DIGITS ; Get 2 MSD's
mov.w DIGITS,R15 ;
mov.w R15,R12 ; Copy BCD number to R12
rra.w R15 ; Rotate a nibble (digit)
rra.w R15 ;
rra.w R15 ;
rra.w R15 ;
and.w #0Fh,R12 ; Expose single digit
and.w #0Fh,R15 ; Expose single digit
mov.b LCD_Tab(R12),&LCDM4 ; Move digit to LCD display RAM
mov.b LCD_Tab(R15),&LCDM5 ; Move digit to LCD display RAM
ret ;
;
;------------------------------------------------------------------------------
Bin2Bcd; Subroutine for converting 16-bit binary to BCD
; Input DIGIT 16-bit binary, output DIGIT 16-bit BCD
;------------------------------------------------------------------------------
mov #16,r15 ;
clr r14 ;
clr r13 ;
L$1 rla DIGITS ;
dadd r13,r13 ;
dadd r14,r14 ;
dec r15 ;
jnz L$1 ;
mov r13,DIGITS ;
ret ;
;
;---------------------------------------------------------------------------
BT_ISR; Exit any LPMx Mode
;---------------------------------------------------------------------------
clrc ;
dadd.b #001h,&secs ;
cmp.b #60h,&secs ;
jnz done ;
mov.b #0,&secs ; Clear secs
dadd.b #0,&mins ;
cmp.b #60h,&mins ;
jnz done ;
mov.b #0,&mins ; Clear mins
dadd.b #0,&hrs ;
cmp.b #13h,&hrs ;
jnz done ;
mov.b #01,&hrs ; Roll hrs
done mov.w #GIE,0(SP) ; Exit LPMx, interrupts enabled
reti ;
;
;---------------------------------------------------------------------------
P1_ISR; Exit any LPMx Mode
;---------------------------------------------------------------------------
mov.w #GIE,0(SP) ; Exit LPMx, interrupts enabled
;
Test_S1 push #02500 ; Debounce Delay to TOS (2.5ms)
DL1 dec 0(SP) ; Decrement TOS
jnz DL1 ; Delay over?
incd SP ; Clean TOS
clr.b &P1IFG ; Clear P1IFG to clean up
bit.b #S1,&P1IN ; Test if S1 pressed
jnz CheckS2 ; If not jump to CheckS2
bis.b #S1,&P1IFG ; Force S1 IFG set [switch stable]
jmp Testbuttons ; Test S1 or S2
CheckS2 bit.b #S2,&P1IN ; Test if S2 pressed
jz Testbuttons ;
reti ; Exit : switches faulty or not
; pressed long enough
Testbuttons bit.b #S1,&P1IFG ; S1 Pin Toggled?
jz Test_S2 ; If not jump to Test_S2
bit.b #S2,&P1IN ; S2 Pin Toggled as well?
jz Test_S2 ; If so jump to Test_S2
bis.b #LCDON+LCDSON,&LCDCTL ; Enable LCD Display
bit.b #001h,Disp_oF ; In oF Mode?
jz C_to_F ;
;
F_to_C bic.b #001h,Disp_oF ; Set oC Mode Operation
mov.w #0030,&Temp_Alarm ; Temperature alarm 30"oC"
mov.w #00A5h,&Temp_Symb ; Display "C"
jmp Exit_1 ;
;
C_to_F bis.b #001h,Disp_oF ; Set F Mode Operation
mov.w #0086,&Temp_Alarm ; Temperature alarm 86"oF"
mov.w #00A9h,&Temp_Symb ; Display "F"
;
Exit_1 clr.b &P1IFG ;
clr.b &LCDM1 ; Clear the LCD Display
clr.b &LCDM2 ;
clr.b &LCDM3 ;
clr.b &LCDM4 ;
clr.b &LCDM5 ;
clr.b &LCDM6 ;
clr.b &LCDM7 ;
mov.w #Disp_Temp,2(SP) ; Entry on exit
reti ;
;
Test_S2 ;S2 Pin Toggled ;
mov.w #05,TIMEOUT ; Initialize timeout to 5secs
bis.b #LCDSON,&LCDCTL ; Enable LCD Display
clr.b &LCDM6 ;
clr.b &LCDM7 ;
xor.b #LCDON,&LCDCTL ; Toggle LCDM0: (Dis/En)able LCD
Exit_2 bic.b #S1+S2,&P1IE ; Disable P1 Ints
mov.w #Disp_Time,2(SP) ; Enter Time mode on exit
Exit_P1_ISR reti ;
;
;-----------------------------------------------------------------------------
; MSP-STK/EVK LCD Definitions
ORG 0FE00h
;-----------------------------------------------------------------------------
LCD_Tab DB 0B7h ; displays "0"
DB 012h ; displays "1"
DB 08Fh ; displays "2"
DB 01Fh ; displays "3"
DB 03Ah ; displays "4"
DB 03Dh ; displays "5"
DB 0BDh ; displays "6"
DB 013h ; displays "7"
DB 0BFh ; displays "8"
DB 03Fh ; displays "9"
;
;-----------------------------------------------------------------------------
; Interrupt Vectors Used MSP430F413
;-----------------------------------------------------------------------------
ORG 0FFFEh ; MSP430 RESET Vector
DW RESET ;
ORG 0FFE8h ; Port1 Interrupt Vector
DW P1_ISR ;
ORG 0FFE0h ; BT Vector
DW BT_ISR ;
END ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -