|
//串口通信,通信协议默认
#include
#include "LCD_12864.H"
volatile unsigned char DATE;
void init_uart() //初始化串口
{
P1SEL |= BIT1 + BIT2; //设置端口为串口模式
P1SEL2 |= BIT1 + BIT2; //设置端口为串口模式
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
UCA0CTL1 |= UCSSEL_2; //波特率发生器的时钟源选择:SMCLK
UCA0BR0 = 104; //波特率为9600, (1MHZ/9600)=104
UCA0BR1 = 0;
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; //UCSWRST上电默认为1,设置好串口后再置0
}
void send_str(char *string) //发送字符串 一直发送
{
while (*string) {
while(!(IFG2 & UCA0TXIFG));
__delay_cycles(100000);
UCA0TXBUF=*string++;
}
}
void main(void) {
WDTCTL = WDTPW + WDTHOLD;
P2DIR |= BIT0 + BIT1; //设置P2.0,P2.1为输出
init_12864(); //初始化液晶
P1DIR |= BIT0;
P1OUT &= ~BIT0;
init_uart();
IE2 = UCA0RXIE + UCA0TXIE; //接收数据中断使能 发送数据中断使能
_EINT(); //开总中断
LPM0; //进入低功耗0模式
while(1)
{
}
}
#pragma vector = USCIAB0RX_VECTOR //接收数据中断向量
__interrupt void UART_jieshou()
{
displaychar_12864(1,1,0x30 + DATE);
while(!(IFG2 & UCA0RXIFG)); //等待接收数据
DATE = UCA0RXBUF;
}
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
{
//send_str("293798");
}
|
|