1431 views|0 replies

1663

Posts

0

Resources
The OP
 

About the temperature acquisition of TMP006 temperature sensor [Copy link]

I want to refresh the temperature automatically, so I added a while loop, but it doesn't work. I don't know what to do. Can someone help me? ? ? Urgent
The program is as follows (I have some demos on hand, if you need them, please leave an email):
#include <stdint.h>
#include "msp430.h"
#include "I2C_init.h"
#define XT1_PORT_SEL P5SEL
#define XT1_ENABLE (BIT4 + BIT5)
volatile uint16_t RxTemp;
volatile uint8_t temp_char[16] = {'0','0','0','0','.','0',0,0,0,0,0,0,0};
void I2C_init(void);
void Read_word(uint8_t ptr);
void Clk_init(void);
void Convert_temp(uint16_t temp);
void I2C_reset(void);
void Init_lcd(void);//lcd initialization
void LcdGo(unsigned char doit); //Turn the LCD on or off
void LcdBlink(unsigned char doit); // Show or hide the display
void LCD_Clear(void); //Clear the screen
void Init_TS3A5017DR(void); // Configure TS3A5017DR IN1 and IN2
// LCD segment definitions.
#define d 0x01
#define c 0x20
#define b 0x40
#define a 0x80
#define dp 0x10
#define g 0x04
#define f 0x08
#define e 0x02
const char char_gen[] = { // As used in 430 Day Watch Demo board
a+b+c+d+e+f, // Displays "0"
b+c, // Displays "1"
a+b+d+e+g, // Displays "2"
a+b+c+d+g, // Displays "3"
b+c+f+g, // Displays "4"
a+c+d+f+g, // Displays "5"
a+c+d+e+f+g, // Displays "6"
a+b+c, // Displays "7"
a+b+c+d+e+f+g, // Displays "8"
a+b+c+d+f+g, // Displays "9"
a+b+c+e+f+g, // Displays "A"
c+d+e+f+g, // Displays "b "
a+d+e+f, // Displays "c"
b+c+d+e+g, // Displays "d"
a+d+e+f+g, // Displays "E"
a+e+f+g, // Displays "f"
a+b+c+d+f+g, // Displays "g"
c+e+f+g, // Displays "h"
b+c, // Displays "i"
b+c+d, // Displays "j"
b+c+e+f+g, // Displays "k"
d+e+f,// Displays "L"
a+b+c+e+f, // Displays "n"
a+b+c+d+e+f+g+dp // Displays "full"
};
const char char_gen_dp[] = { // As used in 430 Day Watch Demo board
a+b+c+d+e+f+dp, // Displays "0"
b+c+dp, // Displays "1"
a +b+d+e+g+dp, // Displays "2"
a+b+c+d+g+dp, // Displays "3"
b+c+f+g+dp, // Displays "4 "
a+c+d+f+g+dp, // Displays "5"
a+c+d+e+f+g+dp, // Displays "6"
a+b+c+dp, // Displays "7"
a+b+c+d+e+f+g+dp, // Displays "8"
a+b+c+d+f+g+dp, // Displays "9"
a+b+c +e+f+g, // Displays "A"
c+d+e+f+g, // Displays "b"
a+d+e+f, // Displays "c"
b+c+d+e+g, // Displays "d"
a+d+e+f+g, // Displays "E"
a +e+f+g, // Displays "f"
a+b+c+d+f+g, // Displays "g"
c+e+f+g, // Displays "h"
b+c, / / Displays "i"
b+c+d, // Displays "j"
b+c+e+f+g, // Displays "k"
d+e+f, // Displays "L"
a+b+c +e+f, // Displays "n"
g, // Displays "-"
dp,// Displays "dp"
a+b+c+d+e+f+g+dp // Displays "full"
};
//LCD initialization
void Init_lcd(void)
{
LCDBCTL0 =LCDDIV0 + LCDPRE0 + LCDMX1 + LCDSSEL + LCDMX1 + LCD4MUX ;
// LCDBCTL0 =LCDDIV0 + LCDPRE0 + LCDON + LCDMX1 + LCDSSEL + LCDMX1 + LCD4MUX ;
LCDBPCTL0 = LCDS0 + LCDS1 + LCDS2 + LCDS3 + LCDS4 + LCDS5 + LCDS6+ LCDS7 + LCDS8
+ LCDS9 + LCDS10 + LCDS11 ;
P5SEL = 0xfc;//Used as LCD driver
// P5SEL =BIT2+BIT3+BIT4+BIT5;//Used as LCD driver
}
/************************************************************************************
Turn on or off the LCD
1: turn on 0: turn off
****************************************************************************/
void LcdGo(unsigned char doit)
{
if(doit==1)
{
//Turn on the LCD display
LCDBCTL0 |= LCDON;
}
else if(doit==0)
{
//Turn off the LCD display
LCDBCTL0 &= ~LCDON;
}
}
/************************************************************************
Display or hide the display content
doit: 0: Blank 1: Display
************************************************************************/
void LcdBlink(unsigned char doit)
{
if(doit==0)
{
LCDBCTL0 &= ~LCDSON;
}
else if(doit==1)
{
LCDBCTL0 |= LCDSON;
}
}
void LCD_Clear(void)//Clear screen
{
unsigned char index;
for (index=0; index<12; index++)
{
LCDMEM[index] = 0;
}
}
void Init_TS3A5017DR(void) //Multiplexer, select "Segment LCD"
{
// Configure TS3A5017DR IN1 and IN2
IN1_IN2_DIR |= IN1 + IN2;
IN1_IN2_OUT &= ~IN1; //IN2=1; IN1=0, multiplexer, select "Segment LCD"
IN1_IN2_OUT |= IN2;
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
unsigned int iq0, iq1,iq2;
Clk_init();
I2C_init();
Read_word(1);
Init_TS3A5017DR(); // Configure TS3A5017DR IN1 and IN2
Init_lcd(); // lcd initialization
LcdGo(1); // Turn on the LCD module
LCD_Clear(); // Clear the screen
Convert_temp(RxTemp);
for (iq0 = 1000; iq0 > 0; iq0--)
for (iq1 = 1000; iq1 > 0; iq1--)
for (iq2 = 10000; iq2 > 0; iq2--)
;
WDTCTL = WDT_MRST_0_064;
}
void I2C_init(void)
{
// Configure TS3A5017DR IN1 and IN2
IN1_IN2_DIR |= IN1 + IN2;
IN1_IN2_OUT &= ~IN1; //IN2=0; When IN1=0, multiplexer, select "IIC_B"
IN1_IN2_OUT &= ~IN2;
// P8.5 and P 8.6 select as second function
I2C_SEL |= I2C_SCK_B + I2C_SDA_B;
I2C_REN |= I2C_SCK_B + I2C_SDA_B;
I2C_DIR |= I2C_SCK_B;
UCB1CTL1 |= UCSWRST; // Enable SW reset
UCB1CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
UCB1CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
UCB1BR0 = 12; // fSCL = SMCLK/12 = 100kHz
UCB1BR1 = 0;
UCB1I2CSA = SLAVE_ADR; // Slave Address is 048h
UCB1CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
}
void I2C_reset(void )
{
IN1_IN2_DIR = 0;
IN1_IN2_OUT = 0; I2C_SEL =
0
; I2C_REN = 0
; I2C_DIR = 0;



UCB1I2CSA = 0;
}
void Read_word(uint8_t ptr)
{
I2C_IFG &= ~I2C_RX_IFG;
while(I2C_CTL1 & STOP); //Wait for bus to be free
I2C_CTL1 |= START+UCTR; //Send mode
TXBUF = ptr; //Send word address
while(!(I2C_IFG & I2C_TX_IFG)); //Wait for word address to be sent
I2C_CTL1 &= ~UCTR; //Read mode
while(I2C_CTL1 & STOP);
I2C_CTL1 |= START; //Send START
while( !(I2C_IFG & I2C_RX_IFG)); //Wait for slave to return data
RxTemp = RXBUF << 8;
while( !(I2C_IFG & I2C_RX_IFG)); //Wait for slave to return data
RxTemp += RXBUF;
UCB1CTL1 |=UCTXNACK; // 发送停止位和NACK位
UCB1CTL1 |=UCTXSTP;
}
void Clk_init(void)
{
XT1_PORT_SEL |= XT1_ENABLE; // Select XT1
UCSCTL3 |= SELREF_2; // Set DCO FLL reference = REFO
UCSCTL4 |= SELA_2; // Set ACLK = REFO
__bis_SR_register(SCG0); // Disable the FLL control loop
UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx
UCSCTL1 = DCORSEL_5; // Select DCO range 24MHz operation
UCSCTL2 = FLLD_1 + 374; // Set DCO Multiplier for 12MHz
// (N + 1) * FLLRef = Fdco
// (374 + 1) * 32768 = 12MHz
// Set FLL Div = fDCOCLK/2
__bic_SR_register(SCG0); // Enable the FLL control loop
// Loop until XT1,XT2 & DCO fault flag is cleared
do
{
UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG); // Clear OFIFG); // Test oscillator fault flag
} void Convert_temp(uint16_t temp) { uint16_t point=0,aint; LCDMEM[3] = char_gen[(temp>>7)/10]; LCDMEM[4] = char_gen[(temp>>7) - ((temp>>7)/10)*10]; aint = (temp & 0x00F0)>>4; if( (aint&0x0008)==0x0008 ) point = 5; if( (aint&0x4)==0x4) point += 2; if( (aint&0x2)==0x2) point += 1; LCDMEM[5] = char_gen_dp[point]; }















This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list