?? its_uart.c
字號:
/***********************************************************************************
Filename: hal_uart.c
Copyright 2007 Texas Instruments, Inc.
***********************************************************************************/
#include "ITS_types.h"
#include "ITS_uart.h"
#include "ITS_board.h"
#include <string.h>
//----------------------------------------------------------------------------------
// void halUartInit(uint8 baudrate, uint8 options)
//----------------------------------------------------------------------------------
void ITSUartInit(unsigned int baudrate)
{
//UART
// Configure USART in UART mode, 8-bit, 1-stop, no parity.
// Hold logic in reset state while configuring other registers
P3SEL |= (BIT6 + BIT7); // P3.5,6 = USART1 TXD/RXD
P3DIR |= BIT6; // P3.6 output direction
UCTL1 = (0*PENA) // 7 Parity Enable 0=Disabled
|(0*PEV) // 6 Parity Select 0= Odd
|(0*SPB) // 5 Stop Bit Select 0= 1 Stop bit
|(1*CHAR) // 4 Character Length 1= 8-bit data
|(0*LISTEN) // 3 Loopback control 0= Loopback disabled
|(0*SYNC) // 2 Synchronous Mode 0= UART mode
|(0*MM) // 1 Multiprocessor Mode 0= Idle-line multiproc control
|(1*SWRST); // 0 Software Reset 1= Logic Held in Reset State ...
// while configuring other registers
UTCTL1 |= SSEL1; // UCLK = SMCLK
switch(baudrate)
{
case 9600:
// UTCTL1 = SSEL0; // UCLK = ACLK
UBR01 = 0xD0; // 2MHz/9600
UBR11 = 0x00; //
// UMCTL1 = 0x4a; //
break;
case 19200:
// UTCTL1 = SSEL1; // UCLK = SMCLK
UBR01 = 0x68; // 2MHz/19200
UBR11 = 0x00; //
// UMCTL0 = 0x55; //
break;
case 57600:
// UTCTL1 = SSEL1; // UCLK = SMCLK
UBR01 = 0x22; // 2MHz/57600
UBR11 = 0x00; //
UMCTL1 = 0x7B; //
break;
case 115200:
// UTCTL1 = SSEL1; // UCLK = SMCLK
UBR01 = 0x11; // 2MHz/115.2k
UBR11 = 0x00; //
UMCTL1 = 0x29; //
break;
default:
break;
}
U1ME |= UTXE1+URXE1 ; // Enabled USART1 TXD/RXD
UMCTL1 = 0;
U1IFG &= ~URXIFG1; // Clear USART1 RX interrupt flag
// U0IE |= URXIE0+UTXIE0; // Enable USART1 RX + TX interrupt
UCTL1 &= ~(SWRST); // 8-bit character - clr SWRST bit
U1IE |= URXIE1; // Enable USART1 RX interrupt
}
//----------------------------------------------------------------------------------
// void halUartWrite(const uint8* buf, uint16 length)
//----------------------------------------------------------------------------------
void ITSUartWrite(const char* buf)
{
int i=0;
while(buf[i]!='\0')
{
while (!(U1IFG & UTXIFG1)); // wait till TX buf empty
TXBUF1=(int)buf[i];
i++;
}
}
//----------------------------------------------------------------------------------
// void halUartRead(uint8* buf, uint16 length)
//----------------------------------------------------------------------------------
char ITSUartRead(void)
{
while (!(U1IFG & URXIFG1)); // wait till TX buf empty
return U1RXBUF;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -