OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 6290|回复: 3

请教各位大虾 我最近在学习模块化编程 把程序分开写就不能用了 (主要是串口程序失效)

[复制链接]

8

主题

33

帖子

0

精华

初级会员

Rank: 2

积分
85
金钱
85
注册时间
2013-7-28
在线时间
0 小时
发表于 2013-8-8 10:18:53 | 显示全部楼层 |阅读模式
我的 代码:
#include "stm32f10x.h"
#include "stdio.h"
#include "usartself.h"
// #if 1
// #pragma import(__use_no_semihosting)             
// //±ê×????è?????§??????                 
// struct __FILE 
// { 
// int handle; 

// }; 

// FILE __stdout;       
// //?¨??_sys_exit()??±???????°??÷?ú????    
// _sys_exit(int x) 
// { 
// x = x; 
// } 
// //???¨??fputc???? 
// int fputc(int ch, FILE *f)
// {      
// while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET); 
//     USART_SendData(USART2,(uint8_t)ch);   
// return ch;
// }
// #endif 
 
// void Usart_Initial();
// void Delay(u8);
// int main()
// {  
// Usart_Initial();

// while(1)
// {
//
// // USART_SendData (USART1 ,z);
// // while(USART_GetFlagStatus (USART1 , USART_FLAG_TXE  )==RESET );
// // if(USART_GetFlagStatus (USART1 , USART_FLAG_RXNE )== SET )
// // {
// // z=USART_ReceiveData (USART1 );
// // }
//
// printf("i love you");
// }
// }

// void Delay(u8 time)
// {
// u8 i,j;
// for(i=0;i<100;i++)
// for(j=0;j<time;j++);
// }
void Usart_Initial()
{
//******GPIO Initial****
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
//***********RCC Initial
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOD |RCC_APB2Periph_AFIO ,ENABLE );
RCC_APB1PeriphClockCmd (RCC_APB1Periph_USART2 , ENABLE );
//******USART 1***
GPIO_PinRemapConfig (GPIO_Remap_USART2 , ENABLE); 
GPIO_InitStructure .GPIO_Mode = GPIO_Mode_AF_PP  ;
GPIO_InitStructure .GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure .GPIO_Speed = GPIO_Speed_50MHz ;
GPIO_Init (GPIOD , &GPIO_InitStructure );
GPIO_InitStructure .GPIO_Mode = GPIO_Mode_IN_FLOATING ;
GPIO_InitStructure .GPIO_Pin = GPIO_Pin_6;
GPIO_Init (GPIOD , &GPIO_InitStructure );
//**********USART Initail
USART_InitStructure .USART_BaudRate = 9600;
USART_InitStructure .USART_HardwareFlowControl = USART_HardwareFlowControl_None ;
USART_InitStructure .USART_Mode = USART_Mode_Rx |USART_Mode_Tx ;
USART_InitStructure .USART_Parity = USART_Parity_No ;
USART_InitStructure .USART_StopBits = USART_StopBits_1 ;
USART_InitStructure .USART_WordLength = USART_WordLength_8b ;
USART_Init (USART2 ,&USART_InitStructure );
USART_ITConfig (USART2,USART_IT_RXNE ,ENABLE );
USART_Cmd (USART2 , ENABLE );

}





这个是.h文件
#ifndef _USARTSELF_H_
#define _USARTSELF_H_
void Usart_Initial();
#endif




正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

8

主题

33

帖子

0

精华

初级会员

Rank: 2

积分
85
金钱
85
注册时间
2013-7-28
在线时间
0 小时
 楼主| 发表于 2013-8-8 10:19:54 | 显示全部楼层
回复【楼主位】yangze68:
---------------------------------
对了 那个重定义printf函数的其实是原子哥的源码里的东西(没有被注释掉)
回复 支持 反对

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2013-8-8 11:11:19 | 显示全部楼层
仿真,看串口寄存器状态.
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复 支持 反对

使用道具 举报

8

主题

33

帖子

0

精华

初级会员

Rank: 2

积分
85
金钱
85
注册时间
2013-7-28
在线时间
0 小时
 楼主| 发表于 2013-8-8 11:28:38 | 显示全部楼层
回复【3楼】正点原子:
---------------------------------
咕~~(╯﹏╰)b 
好的
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-7-15 13:54

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表