飞凌OK6410开发板(裸板)第一个点亮LED灯程序,主要的C程序,完整程序请下载附件。
#define rGPMCON (*(volatile unsigned *)(0x7F008820))
#define rGPMDAT (*(volatile unsigned *)(0x7F008824))
#define rGPMPUD (*(volatile unsigned *)(0x7F008828))
void msDelay(int time)
{
volatile unsigned int i,j;
for(i = 0; i < 2000000; i++)
for(j=0; j<time; j++);
}
void GPIO_Init(void)
{
rGPMCON = 0x11111;
rGPMPUD = 0x00;
rGPMDAT = 0X1F;
}
void LedTest(void)
{
volatile unsigned int i;
while (1)
{
for(i=0; i<4; i++)
{
rGPMDAT = ~(1<<i);
msDelay(10);
}
}
}
void Main(void)
{
GPIO_Init();
LedTest();
}
1.设计要求
EM-STM3210E开发板上有一个LED灯D1,编写程序点亮该灯。
2.硬件电路连接
在开发板上,D1与STM32F103ZE芯片上的引脚PF6相连,如下图所示。
3.软件程序设计
根据任务要求,程序内容主要包括:
1、配置Reset and clock control (RCC)以使能GPIOF端口模块的时钟
2、配置GPIOF端口的PF6引脚(50MHz,推挽输出)
3、调用STM32标准固件库函数GPIO_WriteBit以令PF6引脚输出高电平,从而点亮LED灯D1。
整个工程用户只需要实现源代码文件:main.c,其他工程文件由MDK和STM32标准固件库提供。
main.c文件的内容如下:
[cpp]
/**
********************************************************** ********************
* @file main.c
* @author Max Liao
* @version
* @date 02-Novenber-2012
* @brief Main program body
********************************************************** ********************
*/
/* Includes ------------------------------------------------------------------*/ #include "stm32f10x.h"
/* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/ GPIO_InitTypeDef GPIO_InitStructure;
/* Private function prototypes
-----------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
/* PF6引脚输出高电平,点亮EM-STM3210E开发板上的LED灯D1 */
GPIO_WriteBit(GPIOF, GPIO_Pin_6, Bit_SET);
/* Infinite loop */
while (1) {
}
}
void RCC_Configuration(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // 推挽输出 GPIO_Init(GPIOF, &GPIO_InitStructure);
}
[cpp]
4.程序运行效果。