串口0可以:'(
int main (void)
{
SystemInit();
GPIO1->FIODIR|=(1<<26);//方向控制 led
UARTInit(0, 9600); /* baud rate setting */
UARTInit(1, 9600); /* baud rate setting */
while (1)
{
Delay();
UART0->THR =0x55;
UART1->THR =0xaa;
/* Loop forever */
}
}
uint32_t UARTInit( uint32_t PortNum, uint32_t baudrate )
{
uint32_t Fdiv;
if ( PortNum == 0 )
{
PINCON->PINSEL0 = 0x00000050; /* RxD0 is P0.3 and TxD0 is P0.2 */
UART0->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
/* By default, the PCLKSELx value is zero, thus, the PCLK for
all the peripherals is 1/4 of the SystemFrequency. */
Fdiv = ( SystemFrequency/4/16 ) / baudrate ; /*baud rate, Fpclk: 18MHz */
UART0->DLM = Fdiv / 256;
UART0->DLL = Fdiv % 256;
UART0->LCR = 0x03; /* DLAB = 0 */
UART0->FCR = 0x07; /* Enable and reset TX and RX FIFO. */
NVIC_EnableIRQ(UART0_IRQn);
UART0->IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART0 interrupt */
return (TRUE);
}
else if ( PortNum == 1 )
{
PINCON->PINSEL4 |= 0x0000000A; /* Enable RxD1 P2.1, TxD1 P2.0 */
UART1->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
/* By default, the PCLKSELx value is zero, thus, the PCLK for
all the peripherals is 1/4 of the SystemFrequency. */
Fdiv = ( SystemFrequency/4/16 ) / baudrate ; /*baud rate */
UART1->DLM = Fdiv / 256;
UART1->DLL = Fdiv % 256;
UART1->LCR = 0x03; /* DLAB = 0 */
UART1->FCR = 0x07; /* Enable and reset TX and RX FIFO. */
NVIC_EnableIRQ(UART1_IRQn);
UART1->IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART1 interrupt */
return (TRUE);
}
return( FALSE );
} |