STM32F10x 端口翻转 [上一篇]

[ 2014-3-29 10:41:43 | 作者:liming1217 | 出处:原创 | 天气:晴 ] 字体:

/**

******************************************************************************

* @file Project/STM32F10x_StdPeriph_Template/main.c

* @author

* @version V1.0.0T

* @date 11-February-2014

* @brief Main program body

******************************************************************************

* GPIO Test 2014-02-11 0k

*

******************************************************************************

*/

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_conf.h"
#include "stm32f10x.h"
#include "stm32_eval.h"
#include <stdio.h>

//-------------------------------------------GPIO初始化-----------------------------------------//
/*
void GPIO_Configuration(void)
{

GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 &#124; GPIO_Pin_3 &#124; GPIO_Pin_10 &#124; GPIO_Pin_9;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // 一定要设定速度

GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOB, &amp;GPIO_InitStructure);

}
*/

//--------------------------------------配置系统时钟,使能各外设时钟---------------------------------//
/*
void RCC_Configuration(void)
{
SystemInit();

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA&#124;RCC_APB2Periph_GPIOB

&#124; RCC_APB2Periph_GPIOC&#124;RCC_APB2Periph_GPIOD

&#124; RCC_APB2Periph_GPIOE, ENABLE );

}
*/

//-----------------------------------配置所有外设------------------------------//
void Init_All_Periph(void)
{
RCC_Configuration();

GPIO_Configuration();

}

//----------------------------------------延时函数--------------------------------------------//
void Delay(vu32 nCount)
{

for(; nCount != 0; nCount--);

}

/*******************************************************************************
* Name: UART1_GPIO_Configuration
* Deion : Configures the uart1 GPIO ports.

配置UART的GPIO口

* Input: None
* Output: None
* Return: None
*******************************************************************************/
void UART1_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;

//Configure USART1_Tx as alternate push-pull

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // 一定要配置速度

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(GPIOA, &amp;GPIO_InitStructure);

// Configure USART1_Rx as input floating

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOA, &GPIO_InitStructure);

}

/*******************************************************************************
* Name: UART1_Configuration
* Deion: Configures the uart1

配置串口参数

* Input: None
* Output: None
* Return : None
*******************************************************************************/
void UART1_Configuration(void)
{

USART_InitTypeDef USART_InitStructure;

USART_InitStructure.USART_BaudRate = 9600; //- BaudRate = 9600 baud

USART_InitStructure.USART_WordLength = USART_WordLength_8b; //- Word Length = 8 Bits

USART_InitStructure.USART_StopBits = USART_StopBits_1; //- One Stop Bit

USART_InitStructure.USART_Parity = USART_Parity_No ; //- No parity

//- Hardware flow control disabled (RTS and CTS signals)

USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

// - Receive and transmit enabled

USART_InitStructure.USART_Mode = USART_Mode_Rx &#124; USART_Mode_Tx;

/* Configure the USART1*/

USART_Init(USART1, &amp;USART_InitStructure);

/* Enable USART1 Receive and Transmit interrupts */

USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

/* Enable the USART1 */

USART_Cmd(USART1, ENABLE);

}

/*******************************************************************************
* Name

: Uart1_PutChar 发送一个字节

* Deion

: printf a char to the uart.

* Input

: None

* Output

: None

* Return

: None

*******************************************************************************/
u8 Uart1_PutChar(u8 ch)
{

/* Write a character to the USART */

USART_SendData(USART1, (u8) ch);

while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)

{

}

return ch;

}

/*******************************************************************************
* Name

: Uart1_PutString 发送一个字符串

* Deion

: print a string to the uart1

* Input

: buf为发送数据的地址 , len为发送字符的个数

* Output

: None

* Return

: None

*******************************************************************************/
void Uart1_PutString(u8 *buf , u8 len)
{

for(u8 i=0;i&lt;len;i++)

{

Uart1_PutChar(*buf++);

}

}

void RCC_Configuration(void);
void GPIO_Configuration(void);
void USART_Configuration(void);
unsigned char str[]="A";

//------------------------------------------主函数--------------------------------------------//
int main(void)
{
// Init_All_Periph(); //配置所有外设

// UART1_GPIO_Configuration();

// UART1_Configuration();

RCC_Configuration();

GPIO_Configuration();

USART_Configuration();

USART_SendData(USART1,str[0]);

while(1)

{

//GPIO_SetBits(GPIOA, GPIO_Pin_2);

//GPIO_ResetBits(GPIOA, GPIO_Pin_3); //GPIO TEST

/*

GPIO_SetBits(GPIOA, GPIO_Pin_9);

GPIO_ResetBits(GPIOA, GPIO_Pin_10); //GPIO TEST

Delay(100);

GPIO_SetBits(GPIOA, GPIO_Pin_10);

GPIO_ResetBits(GPIOA, GPIO_Pin_9); //GPIO TEST

Delay(100);

*/

//Uart1_PutString("abce", 4);

} //while(1)

}


/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/


分类:默认分类 | 部落: | 评论:0 | 引用通告 | 阅读次数(727)

Tags:无

没有发表任何评论

用 户: 密 码:
验 证: 不不清或没看到请点这里!
标 题:

内 容:

[加粗] [下划线] [居中] [网址] [图片] [代码] [UBB表情]

导航

归档

日历

我的简历

  • 姓名:liming1217
  • 性别:1
  • 注册日期:
  • Email:happyllt2008@163.com
  • 城市:常州
  • 发消息给我

公告

诚心结识测绘同行

部落

  • 没有加入任何部落!

最新回复