想要自动刷新温度加了while循环然后没效果不知道该怎么办了,求解???急急急
程序如下(手头有一些Demo有需要的可以留邮箱):
#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,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初始化
void LcdGo(unsigned char doit); //打开或关闭液晶
void LcdBlink(unsigned char doit); // 显示或者消隐显示内容
void LCD_Clear(void); //清屏
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初始化
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;//用作LCD驱动
// P5SEL =BIT2+BIT3+BIT4+BIT5;//用作LCD驱动
}
/*****************************************************************************
打开或关闭液晶
1:打开 0:关闭
*****************************************************************************/
void LcdGo(unsigned char doit)
{
if(doit==1)
{
//打开液晶显示
LCDBCTL0 |= LCDON;
}
else if(doit==0)
{
//关闭液晶显示
LCDBCTL0 &= ~LCDON;
}
}
/***************************************************************************
显示或者消隐显示内容
doit:0:消隐 1:显示
****************************************************************************/
void LcdBlink(unsigned char doit)
{
if(doit==0)
{
LCDBCTL0 &= ~LCDSON;
}
else if(doit==1)
{
LCDBCTL0 |= LCDSON;
}
}
void LCD_Clear(void)//清屏
{
unsigned char index;
for (index=0; index<12; index++)
{
LCDMEM[index] = 0;
}
}
void Init_TS3A5017DR(void) //多路复用器,选择"段式LCD"
{
// Configure TS3A5017DR IN1 and IN2
IN1_IN2_DIR |= IN1 + IN2;
IN1_IN2_OUT &= ~IN1; //IN2=1; IN1=0时, 多路复用器,选择"段式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初始化
LcdGo(1); // 打开液晶模块
LCD_Clear(); //清屏
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; IN1=0时, 多路复用器,选择"IIC_B"
IN1_IN2_OUT &= ~IN2;
// P8.5 and P8.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;
UCB1CTL1 = UCSWRST;
UCB1CTL0 = UCSYNC;
UCB1BR0 = 0;
UCB1I2CSA = 0;
}
void Read_word(uint8_t ptr)
{
I2C_IFG &= ~I2C_RX_IFG;
while(I2C_CTL1 & STOP); //等待总线空闲
I2C_CTL1 |= START+UCTR; //发送模式
TXBUF = ptr; //发送字地址
while(!(I2C_IFG & I2C_TX_IFG)); //等待字地址发送完毕
I2C_CTL1 &= ~UCTR; //读模式
while(I2C_CTL1 & STOP);
I2C_CTL1 |= START; //发送START
while( !(I2C_IFG & I2C_RX_IFG)); //等待从机返回数据
RxTemp = RXBUF << 8;
while( !(I2C_IFG & I2C_RX_IFG)); //等待从机返回数据
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 XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
}while (SFRIFG1&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];
} |