打印

大家帮忙看一下这个例程

[复制链接]
1920|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 | 只看该作者
就是输出字符吧

使用特权

评论回复
5
wudonghua| | 2009-10-28 09:20 | 只看该作者
输出字符到串口函数,
结束了就发送回车字符,没有就发字符C的数据!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

7

主题

62

帖子

1

粉丝