MSP430F169部分外围设备初始化代码
发布时间:2008-01-01
初始化时钟,以XT2为系统时钟:
BCSCTL1&=~XT2OFF; //启动XT2振荡器
BCSCTL2|=SELM1; //MCLK为XT2
do
{
IFG1&=~OFIFG;
for(i=0xFF;i>0;i--);
}
while((IFG1&OFIFG)!=0);
初始化串口0:
void init_UART0(void)
{
UCTL0 &= ~SWRST;
UCTL0 |=CHAR;//0X10;
UBR00 = 0x03;
UBR10 = 0x00;
UMCTL0 = 0x4A;
UTCTL0 = SSEL0;//0X10;
ME1 |= UTXE0+URXE0 ; //enable the UART0
IE1 |=URXIE0;
}
初始化串口1:
void init_UART1(void)
{
unsigned int temp;
ME2 |= UTXE1 + URXE1; // Enable USART1 TXD/RXD
UCTL1 |= CHAR; // 8-bit character
UTCTL1 |= SSEL0; // UCLK = ACLK
UBR01 = 0x03; // 32k/9600 - 3.41
UBR11 = 0x00; //
UMCTL1 = 0x4A; // Modulation
UCTL1 &= ~SWRST; // Initialize USART state machine
IE2 |= URXIE1; // Enable USART1 RX interrupt
for(temp=0;temp
{
uart_Host_Rbuf[temp]=0;
}
}
初始化Timer_A:
void init_ta(void)
{
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = 400;
TACTL = TASSEL_1 + ID_3+TACLR; // ACLK, 8分频 递增模式
TACTL|=MC_1; //Timer A mode control: 1 - Up to CCR0
}