打印

小菜鸟求助,串口发送程序编译通过,在板子上没反应

[复制链接]
1051|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
yisibugua16|  楼主 | 2012-3-2 14:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include "stm32f10x.h"
#include <stdio.h>

#ifdef __GNUC__
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif

void Delay(vu32 count)
{
for(;count!=0;count--);
}

int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);

  printf("\n\r串口1发送实验程序\n");
   while (1)
{
   printf("\n\r串口1发送实验程序\n");
   Delay(0x3FFFFF);
   printf("\n\r串口1发送实验程序\n");
      
}      
}

PUTCHAR_PROTOTYPE
{
    USART_SendData(USART1, (uint8_t) ch);
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
{}
return ch;
}


#ifdef  USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
    while (1)
  {
  }
}
#endif

相关帖子

沙发
yisibugua16|  楼主 | 2012-3-2 15:39 | 只看该作者
:'(有人说下没

使用特权

评论回复
板凳
wyx447166939| | 2012-3-2 20:06 | 只看该作者
不懂看下终端设置对了没

使用特权

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

本版积分规则

0

主题

8

帖子

0

粉丝