//-----段位式液晶显示操作------//
/*
需要将段位式LCD板接到P5口上
*/
#include <msp430x14x.h>
#include "lcd.h"
//unsigned int receive_buf=0x00;
extern void Port_init(void);
extern void Clk_init(void);
extern void uart_init(void);
extern void Lcd_init(void);
extern void Lcdcmd(UNIT LCDcode);
extern void Disbyte(UCHAR LCDbit,UCHAR LCDdisval);
extern void Delayus(UNIT delaytimeus);
extern void Delayms(UNIT delaytimems);
extern void Disnum(UNIT numval);
extern void displayaddr(UNIT addr);
extern void displaytemp(UNIT temp);
extern void displaylight(UNIT light);
extern unsigned int uart_rx(void);
extern void uart_tx(unsigned int Data );
char temp_receive[4] = {0,0,0,0};
unsigned char temp_rx[4]={0};
void main(void)
{
// unsigned int tmp[3]={0xaa,0x00,0xbb};
unsigned int i,j,addr,light;
unsigned int temp;
UNIT lcdval = 0;
WDTCTL = WDTPW + WDTHOLD; // 停止看门狗
Port_init(); //初始化端口
Clk_init(); //初始化时钟
Lcd_init(); //初始化液晶
uart_init();
P2OUT=~0x00; // lED initial
/*
i=0;j=0;
addr=0x00; //lcd variable initial
temp=0x00;
light=0x00;
*/
//uart receive buf clear
Delayms(500); //延时500ms,大概的延时,不精确!
Disnum(lcdval); //液晶显示数据函数,液晶显示“0000”
char temp_t1[2] = {0xaa,0x1};
char temp_t2[2] = {0xaa,0x2};
char temp_rx[4] = {0,0,0,0};
//char temp_test[4] = {1,2,3,4};
//int wendu;
int count;
displaytemp(0);
/*
while(1)
{
uart_tx(0xaa);
uart_tx(0x01);
temp_receive[0] = uart_rx();
temp_receive[1] = uart_rx();
temp_receive[2] = uart_rx();
temp_receive[3] = uart_rx();
//displaytemp((unsigned int)temp_receive[2]);
}
*/
// while(1);
////////////////////////////////////////
// wait for key down.
while(1)
{
if((P1IN&0x01)==0x00)//扫描键盘P1.0
{
Delayms(50);
if((P1IN&0x01)==0x00)
{
count = 0;
uart_tx(0xaa);
uart_tx(0x01);
for(i=0;i<500;i++)
{
temp_rx[count] = uart_rx();
count = count + 1;
if(count >= 4)
break;
}
displaytemp((unsigned int)temp_rx[2]);
}
/* if(count >=4&&temp_rx[0] == 0xcc &&temp_rx[1]==0x01)
{
displaytemp((unsigned int)(temp_rx[2]));
if(temp_rx[3]&0xf == 0xf)
P2OUT = 0x01;
else
P2OUT = 0x0;
break;
}
}
// if(temp_rx[3] != 0xbb)
// displaytemp(0x888);
}
//等待接收
}
/////////////////////////key2
if((P1IN&0x02)==0x00)//扫描键盘P1.0
{
Delayms(50);
if((P1IN&0x02)==0x00)
{
count = 0;
for(j=0;j<100;j++)
{
for(i=0;i<2;i++)
uart_tx(temp_t2[i]);
for(i=0;i<500;i++)
{
if((IFG1 & URXIFG0) != 0)
{
temp_rx[count] = RXBUF0;
count = count + 1;
if(count >=4&&temp_rx[0] == 0xcc &&temp_rx[1]==0x02)
break;
}
}
if(count >=4)
{
break;
displaytemp((unsigned int)(temp_rx[2]));
if(temp_rx[3]&0xf == 0xf)
P2OUT = 0x02;
else
P2OUT = 0x0;
}
}
// if(temp_rx[3] != 0xbb)
// displaytemp(0x888);
}
//等待接收
}
}
} */
/*
if((P1IN&0x02)==0x00)//扫描键盘P1.1
{
tmp[1]=0x02;
for(i=0;i<3;i++)//发送命令数据报2
{
uart_tx(tmp[i]);
}
//等待接收
/////////////////////////////////////////
// Delayms(500);
for(i=0;i<4;i++)
{
while ((IFG1 & UTXIFG0) == 0); //USART0接收缓存有数据吗?
TXBUF0=temp_t1[i];
}
for(i=0;i<4;i++)
{
temp_receive[i] = uart_rx();
}
i=0xfff;
while(i--);
*/
}
}
}