一、创建工程
1.打开proteus,新建工程
2.创建原理图中选DEFULT
3.选择不创建PCB布板设计
4.创建固件项目,系列选择Cortex-M3 controller 选择STM32
二、配置实验所需原件
1.点击操作界面右侧的P,添加元器件。在搜索栏LED,点击确定
2.在搜索栏中输入res,找到res器件
3.将器件如图进行摆放连线
4.双击电阻,将阻值设定为50
三、在Keil中生成HEX文件
1.在Keil新建main.c,并输入代码
#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<8;i++)
{
delay_ms(99000);
GPIOC->BRR=0x000000ff;
delay_ms(99000);
GPIOC->BSRR=0x000000ff;
}
}
}
2.点击Option for Target,勾选Create HEX file
3.编译程序,生成hex文件
四、配置stm32
1.回到proteus,双击stm32,Program File 选择刚才生成的hex文件,并配置Crystal Frequency改成8M
2.开始仿真.