Proteus+MDK仿真运行stm32程序

摘要:

本文介绍了用keil5和Proteus来仿真运行stm32程序,实现灯的循环变化

一、配置MDK工程

step1:打开Keil5,创建工程

step2:根据实现准备的启动函数,配置好工程

step3:将头文件读取路径包含进去

可以看到我加入的路径:

step3:更改输出设置

== 输出一定要勾选生成hex文件

step4:创建主函数

主函数实现的功能是,分别一个灯、四个灯、8个灯循环亮

#include "stm32f10x.h"
GPIO_InitTypeDef GPIO_InitStructure;
void delay_ms(uint32_t ms)
{
    
    
	uint32_t i_cnt,j_cnt;
	for(i_cnt=0;i_cnt<3000;i_cnt++);
	for(j_cnt=0;j_cnt<ms;j_cnt++);
	
}
uint32_t i;
int main(void)
{
    
    
  
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_Init(GPIOC, &GPIO_InitStructure);

	GPIOC->BSRR=0xff;
	//单个灯循环亮
	while (1)
	{
    
    
	  for(i=0;i<8;i++)
	  {
    
    
		delay_ms(99000);
		GPIOC->BRR=(1<<i);  
		  
		delay_ms(99000);
		GPIOC->BSRR=(1<<i);
	  }
		//四灯循环亮
	  for(i=0;i<16;i++)
	  {
    
    
			if(i%2==0)
		  {
    
    	
				delay_ms(99000);
				GPIOC->BRR=0x000000f0;
				delay_ms(99000);
				GPIOC->BSRR=0x000000f0;
			}
			else
			{
    
    	
				delay_ms(99000);
				GPIOC->BRR=0x0000000f;
				delay_ms(99000);
				GPIOC->BSRR=0x0000000f;
			}
	  }
		//八个灯循环亮
		for(i=0;i<8;i++)
	  {
    
    
				delay_ms(99000);
				GPIOC->BRR=0x000000ff;
				delay_ms(99000);
				GPIOC->BSRR=0x000000ff;
				delay_ms(99000);
				GPIOC->BRR=0x000000ff;
				delay_ms(99000);
				GPIOC->BSRR=0x000000ff;
		}
				
	}

}

一切配置好之后,就生成hex文件,接下来就是建立proteus工程了


二、建立Proteus工程

step1:打开软件,新建工程

该过程除了以下,选择创建固件项目,Cortex-M3,STM32F103R6外其余都为默认

step2:添加元器件,并连接好电路

step3:点击单片机

注意:

  • 选择第一步生成的.hex文件
  • 把配置设成如下

step3:开始运行如下


三、总结

这次通过keil与proteus的仿真,熟悉了keil的工程文件配置编程,也熟悉了proteus仿真运行stm32程序。仿真对于我们的学习来说确实用处很多,通过仿真可以避免很多实操来的失误。熟悉proteus和keil的仿真确实十分重要。

猜你喜欢

转载自blog.csdn.net/lee_goi/article/details/109551927