大家帮忙看一下这个例程

[复制链接]
3364|4
 楼主| wxx116zh 发表于 2009-10-22 11:25 | 显示全部楼层 |阅读模式
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函数看不懂什么意思,各位大侠帮忙解决一下。
梦到天涯 发表于 2009-10-23 09:44 | 显示全部楼层
不太懂
chrron 发表于 2009-10-26 13:49 | 显示全部楼层
这个程序用了一个标准输入输出的库,寒
秋天落叶 发表于 2009-10-27 20:46 | 显示全部楼层
就是输出字符吧
wudonghua 发表于 2009-10-28 09:20 | 显示全部楼层
输出字符到串口函数,
结束了就发送回车字符,没有就发字符C的数据!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

7

主题

62

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部