void UART_Init1(void)
{
/* Step 1. GPIO initial */
P1_MFP &= ~(P13_AIN3_TXD1 | P12_AIN2_RXD1);
P1_MFP |= (TXD1 | RXD1);
/* Step 2. Enable and Select UART clock source*/
UART1_Clock_EN; //UART Clock Enable, APBCLK[16]:1
UARTClkSource_ex12MHZ; //UART Clock is ext12MHz, CLKSEL1[25,24]: 00
CLKDIV &= ~(15<<8); //UART Clock DIV Number = 0;
/* Step 3. Select Operation mode */
IPRSTC2 |= UART1_RST; //Reset UART0
IPRSTC2 &= ~UART1_RST; //Reset end
UA1_FCR |= TX_RST; //Tx FIFO Reset
UA1_FCR |= RX_RST; //Rx FIFO Reset
UA1_FCR |=RFITL_14;
UA1_LCR |= PBE; //可以有校验
UA1_LCR |=EPE; //偶校验
UA1_LCR &= ~WLS;
UA1_LCR |= WL_8BIT; //8 bits Data Length
UA1_LCR &= NSB_ONE; //1 stop bit
/* Step 4. Set BaudRate to 115200*/
UA1_BAUD |= DIV_X_EN; //Mode2:DIV_X_EN = 1
UA1_BAUD |= DIV_X_ONE; //Mode2:DIV_X_ONE =1
/* For XTAL = 12 MHz */
UA1_BAUD |= ((12000000 / 19200) -2); //Set BaudRate to 115200; UART_CLK/(A+2) = 115200, UART_CLK=12MHz
//中断
UA1_IER |= (RTO_IEN|TIME_OUT_EN);
NVIC_ISER |= UART1_INT;
UA1_TOR=0xff00ff;
}
void UART1SendByte(uint8 c) // 发送串口 字节
{
UA0_THR = (uint8_t) c;
while((UA0_FSR&TX_FULL) != 0); //数据发送一段时间 就死在这 不知道为什么呢??????????????????
}
void main(void)
{
// 目标版 系统初始化
UART_Init1();
while(1)
{
UART1SendByte('A');
}
}
|