void main(void)
{
unsigned int i;
unsigned char counter;
/*High speed internal clock prescaler: 1*/
CLK_CKDIVR = 0x00;
UART2_CR2 = 0x00; //disable Tx & Rx
/* UART2 configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Receive and transmit enabled
- UART2 Clock disabled
*/
/* Configure UART1 */
UART2_CR1 = 0x00;
UART2_CR3 = 0x00;
UART2_BRR2 = 0x0B;
UART2_BRR1 = 0x08;
UART2_CR2 = 0x0C;
counter = 0;
while(1)
{
/* Output a message on Hyperterminal using printf function */
printf("\nUART2 Example :Please press 1 key from keyboard. \n");
for (i=0;i<10000;i++);
/* Loop until the UART2 Receive Data Register is not empty */
while (!(UART2_SR & 0x20));
/* Store the received byte in RxBuffer */
RxBuffer = UART2_DR;
printf("Key Pressed = %c.\n",RxBuffer);
}
}
/* -------------------------------------------------------------------------- */
/* ROUTINE NAME: putchar */
/* INPUT/OUTPUT: c Character to send. */
/* DESCRIPTION: Send character via UART to PC. */
/* -------------------------------------------------------------------------- */
char putchar (char c)
{
if (c == '\n')
{
/* put '\r' to hardware here */
/* Wait transmission is completed : otherwise the first data is not sent */
while (!(UART2_SR & 0x40));
UART2_DR = ('\r');
/* Wait transmission is completed */
while (!(UART2_SR & 0x40));
}
/* put c to hardware here */
/* Wait transmission is completed : otherwise the first data is not sent */
while (!(UART2_SR & 0x80));
UART2_DR = (c);
/* Wait transmission is completed */
while (!(UART2_SR & 0x80));
return (c);
}
这是个UART发送数据的例子,能发出数据,但是后面一个putchar函数看不懂什么意思,各位大侠帮忙解决一下。 |