Proteus+MDK simulation run stm32 program

Summary:

This article introduces the use of keil5 and Proteus to simulate and run the stm32 program to realize the cycle change of the lamp

1. Configure MDK project

step1: Open Keil5 and create a project

step2: Configure the project according to the startup function prepared by the realization

step3: include the header file read path

You can see the path I added:

step3: Change output settings

== Output must be checked to generate hex file

step4: Create the main function

The function realized by the main function is that one light, four lights, and 8 lights are cycled on.

#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;
		}
				
	}

}

After everything is configured, the hex file is generated, and the next step is to build the proteus project


2. Establish Proteus project

step1: Open the software and create a new project

In this process, except for the following, choose to create a firmware project, Cortex-M3, STM32F103R6 and the rest are default

step2: add components and connect the circuit

step3: Click on the microcontroller

note:

  • Select the .hex file generated in the first step
  • Set the configuration as follows

step3: start to run as follows


Three, summary

This time through the simulation of keil and proteus, I am familiar with keil's project file configuration programming, and also familiar with the proteus simulation running stm32 program. Simulation is really useful for our study, and many practical errors can be avoided through simulation. It is really important to be familiar with the simulation of proteus and keil.

Guess you like

Origin blog.csdn.net/lee_goi/article/details/109551927
Recommended