打印

stm8的串口怎么调试

[复制链接]
1954|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
xiao4933|  楼主 | 2010-8-6 15:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
那位高手高手我stm8串口怎么调试以前学51的时候可以用串口调试助手现在不知道能不能用这个下面是配套的程序。
#include "STM8S105C_S.h"          /* Registers and memory mapping file. */
#include "stdio.h"

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);
    }
}

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);
}
沙发
honami520| | 2010-8-6 21:46 | 只看该作者
一根毛的关系都没有

使用特权

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

本版积分规则

1

主题

1

帖子

1

粉丝