📄 d413_tmp_sensor_master.s43
字号:
#include "msp430x41x.h"
;******************************************************************************
; D413/TMP100 Demo Program II
;
; Program has been modified to do I2C master communication using
; port P6 instead of P3. P6 is available via pin header on the
; 'MSP430-Day board' for external access.
;
; I2C functions have been modified to allow the slave to hold SCL low
; for introducing a delay and also to fullfill Philips I2C timing specs
; for standard mode transfers at 1.048576 MHz CPU frequency.
;
; Andreas Dannenberg
; MSP430 Applications
; Texas Instruments Inc.
;******************************************************************************
; D413/TMP100 Demo Program - Software Interface TMP100, P1.0 set if
; Temp > 86F (30c).
;Description:
; I2C communication with a TMP100 in default condition is demonstrated.
; If temperature read >= 86F or 30C, P1.0 is set for 5 secs, else reset.
; P3.0 supplies power to the TMP100.
;
; Only upper 9-bits from TMP100 temperature register used, representing
; 7F8h = 128c , 800h = -128c.
;
; I2C Ack error checking not implemented. I2C timing assumed with MCLK ~ 1MHz.
;
;Instructions:
; Display temp and time. (C & F)
; 9-bit TMP Data acquired and used in F calc.
; S1 press - Enable Temp mode, toggle oC/oF modes
; S2 press - Enable Clock display
; Press and Hold S1 Then Press and Hold S2 - TIME set mode: Minutes/Hours count
; up, release to set. (Pushing S2 with S1 held down will increment minutes.)
;
; MSP430F413
; -----------------
; /|\| XIN|-
; | | | 32kHz
; --|RST XOUT|-
; | |
; +-|R33 | -----------------
; R | Sxx|--> | + 7 6 5 4 3 2 1 |
; +-|R23 | -----------------
; R | COM0|-----||||
; +-|R13 COM1|------|||
; R | COM2|-------||
; +-|R03 COM3|--------|
; | | |
; TMP100 \|/| |
; ------- | |
; | Vcc|<-+P3.0+---|P3.0 P1.3|<--- Temperature mode
; | | | | | P1.4|<--- Time mode
; | | 10k 10k | |
; | | | | | |
; | SDA|<-|----+-->|P2.0 P1.0|---> LED
; | | | | |
; ---|A0 | | | |
; +--|A1 | | | |
; +--|Vss SCL|<-+--------|P2.1 |
; \|/ ------- -----------------
;
;
; CPU registers used
#define TIMEOUT R4
#define DIGITS R6
#define RXTXI2C R7
#define ADDRI2C R8
#define DATAI2C R9
#define BITI2C R10
; include the following line to use connector J6 for
; off-board I2C connection instead of the onboard TMP100 sensor
#define USE_OFFBOARD_INTERFACE
; Definitions for I2C bus
#ifdef USE_OFFBOARD_INTERFACE
PxDIR equ P6DIR ; I2C port
PxOUT equ P6OUT ; P6 = J6 (conn. for ext. access)
PxIN equ P6IN
SDA equ 002h ; Px.1 controls SDA line (pull-up)
SCL equ 008h ; Px.3 controls SCL line (pull-up)
#else
PxDIR equ P2DIR ; I2C port
PxOUT equ P2OUT ; P2 = onboard TMP100
PxIN equ P2IN
SDA equ 001h ; Px.0 controls SDA line (pull-up)
SCL equ 002h ; Px.1 controls SCL line (pull-up)
#endif
TMPADDR equ 090h ; TMP100 Device Code with A0=A1=0
TMPPWR equ 001h ; P3.0 supplies TMP100 V_CC
;
; Definitions for Board
LED1 equ 001h ; P1.0- LED Output
S1 equ 008h ; P1.3- S1 Input
S2 equ 010h ; P1.4- S2 Input
;
; Z. ALBUS
; Texas Instruments, Inc
; April 15, 2003
;******************************************************************************
;------------------------------------------------------------------------------
; word & byte RAM variable definitions
ORG 0200h
;------------------------------------------------------------------------------
Temp_Alarm DW 0
Temp_Symb DW 0
Delay DW 0
Disp_oF DB 0
Neg_Sign DB 0
Time_Out DB 0
secs DB 0
mins DB 0
hrs DB 0
;------------------------------------------------------------------------------
ORG 0F000h
;------------------------------------------------------------------------------
RESET mov.w #300h,SP ; Initialize stackpointer
call #Init_Sys ; Initialize system
;
mov.w #010,TIMEOUT ; Initialize timeout to 10secs
clr.b &secs ; Clear secs and mins
clr.b &mins ; Clear secs and mins
mov.b #0012h,&hrs ; Set hrs
;
;*** Default Powerup Mode is oF
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"
;
jmp Disp_430_dAY ;
;
;------------------------------------------------------------------------------
;Main loops are between the ^'s. One for Temp(1), Time(2) and "430 dAY"(3)
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Disp_Temp bis.b #TMPPWR,P3OUT ; Power-up TMP100
mov.b #005,&Time_Out ; Time limit for LED "ON" in secs
;
One_Shot_D mov.b #001h,ADDRI2C ; ADDRI2C = Pointer
mov.b #081h,DATAI2C ; One-Shot Command
call #Write_I2C ;
;
Mainloop_1 bis.w #LPM3,SR ; Enter LPM3
;
Read_Temp mov.b #000h,ADDRI2C ; ADDRI2C = Pointer
call #Read_I2C ;
call #Calc_Temp ;
call #Disp_LCD_Temp ;
;
LED_Cntrl bic.b #LED1,&P1OUT ; LED Off
bit.b #001h,Neg_Sign ; Is value negative?
jnz RST_Tout ; Jump if yes
cmp.w &Temp_Alarm,DATAI2C ;
jlo RST_Tout ; Again
cmp.b #00h,&Time_Out ;
jeq LED_OFF ;
bis.b #LED1,&P1OUT ; LED On
dec.b &Time_Out ;
jmp One_Shot ;
;
RST_Tout mov.b #005,&Time_Out ; Time limit for LED "ON" in secs
;
LED_OFF bic.b #LED1,&P1OUT ; LED Off
;
One_Shot mov.b #001h,ADDRI2C ; ADDRI2C = Pointer
mov.b #081h,DATAI2C ; One-Shot Command
call #Write_I2C ;
;
Main_1_End jmp Mainloop_1 ;
;
;------------------------------------------------------------------------------
Disp_Time bic.b #TMPPWR,P3OUT ; Power-down TMP100
bic.b #LED1,&P1OUT ; LED Off
bic.b #10h,&LCDM8 ; Clear "-"
bic.b #S1+S2,&P1IE ; Disable Sx interrupts
;
Set_Time bit.b #S2,&P1IN ; Test if S2 still pressed
jnz disphrsmins ; Normal mode
bit.b #S1,&P1IN ; Test if S1 is pressed
jnz disphrsmins ; Normal mode
;
bis.b #BIT2+BIT0,&LCDCTL ; Enable LCD Display
mov.w #3000h,&Delay ; Time set delay, increase to
Again dec.w &Delay ; slow down the min count up
; time when setting the clock.
jnz Again ;
;
clrc ; Clear carry
dadd.b #1,&mins ; Increment mins
cmp.b #60h,&mins ;
jnz disphrsmins ;
mov.b #0,&mins ; Clear mins
;
clrc ; Clear carry
dadd.b #1,&hrs ; Increment hrs
cmp.b #13h,&hrs ;
jnz disphrsmins ;
mov.b #01,&hrs ; Roll hrs
;
Mainloop_2 bis.w #LPM3,SR ; Enter LPM3
disphrsmins ;
dec.w TIMEOUT ; Decrement Timeout
jnz Continue ; Continue if not expired
bis.b #LCDON,&LCDCTL ; Turn ON LCD
Continue mov.b &mins,DIGITS ;
mov.b &hrs,R5 ;
swpb R5 ;
add.w R5,DIGITS ; Time is in Digits
disp call #Disp_LCD_Time ; Display Time on LCD
bit.b #01h,&secs ; Flash "-" every other second
jz CLEAR_L ; clear "-"
bis.b #08h,&LCDM3 ; To flash "-"
jmp Cont ;
CLEAR_L bic.b #08h,&LCDM3 ; To flash "-"
;
Cont bit.b #S1,&P1IN ; Test if S1 is pressed
jz Set_Time ; Normal mode
;
clr.b &P1IFG ;
bis.b #S1+S2,&P1IE ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -