当前位置:网站首页>用proteus直接仿真stm32-可以完全丢弃编程器
用proteus直接仿真stm32-可以完全丢弃编程器
2022-08-10 10:22:00 【河西石头】
stm32经济实惠,但它的使用又不如arduino那么便利,总是要弄一个下载器st-link或者也要一个usb转ttl的ch34或者lp2002的转换器连接着,一个“痣”,麻烦!
stm32在许多的小项目中使用非常的频繁,或许很多人的嵌入式入门就从stm32开始,这里我们来看看在proteus中如何来仿真。
对于初学者而言,我们更多的还是想在proteus中仿真一下更好,不必卖硬件,更不必买下载器等。下面我们就介绍如何实现哦!
一、在prtoteus中绘制好原理图
我们做一个blink程序,简单是简单了些,但是好啊,容易看明白
二、写代码
#include "stm32f1xx_hal.h"
void SystemClock_Config(void);
void Error_Handler(void);
static void MX_GPIO_Init(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
while (1)
{
HAL_GPIO_TogglePin(Ld2_GPIO_Port, Ld2_Pin); //Toggle LED
HAL_Delay(1000); //Delay 1 Seconds
}
}
/** System Clock Configuration */
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL4;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV2;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|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_PIN_8
|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
|GPIO_PIN_4|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8
|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12
|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = Ld2_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(Ld2_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_10
|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
|GPIO_PIN_15|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5
|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
__HAL_AFIO_REMAP_PD01_ENABLE();
HAL_GPIO_WritePin(Ld2_GPIO_Port, Ld2_Pin, GPIO_PIN_RESET);
}
void Error_Handler(void)
{
while(1)
{
}
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
}
#endif
三、编译与运行
一开始我们可能会遇到编译器错误
The selected compiler ‘GCC for ARM’ is not installed.
Compilation failed. Check the Project Settings.
1、安装编译器
点击对GCC for arm后的download,则会在检测完成后弹出YaGArto的安装界面,安装好后继续检测
下载好的存放在proteus的安装目录下的data的downloads下
2、配置编译器
安装好后,再次点击download会自动将刚刚安装好的yagarto配置进来,或者点击下面的check也可以
运行效果
往往万事开头难,而嵌入式开发的难就难在环境的搭建,有许多刚开始的童鞋都是死在环境配置的路上,难就难在那一串hello world,难就难在那个闪烁的LED灯blink程序。
希望通过这篇博文帮你重播这个起点的拦路虎,从此一帆风顺~~
边栏推荐
- database transaction
- ESP8266 Tutorial 1 - Introduction to ESP8266 Hardware Platform
- 【Azure云】服务端点和私有链接有什么区别?观点(1)
- JS高级 之 Promise 详解
- Behind iFLYTEK's translation machine stealing the spotlight, cross-language communication has entered a new era
- LiveNVR操作日志页面快速筛选上级国标平台的调用记录直播观看录像回看等操作
- 网络安全笔记6——数字证书与公钥基础设施
- 3D旋转文本动画js特效
- gin-gonic/gin使用详解
- leetcode:334. 递增的三元子序列
猜你喜欢
Automated Testing and Selenium
Network Security Note 6 - Digital Certificates and Public Key Infrastructure
bus event bus use
态势丨黑客侵扰加剧,靶场为网络安全架设“防御盾”
Taro小程序跨端开发入门实战
Shell脚本数组
Redis (six) - transaction and lock mechanism of Redis6 (unfinished, to be supplemented)
自动化测试及Selenium
Techches Transformer the join wisdom source the author cao, visual basic model study
The web project accesses static resources inside the reference jar
随机推荐
金九银十跳槽旺季:阿里、百度、京东、美团等技术面试题及答案
组合模式:Swift 实现
干货!ASSANet:让PointNet++更快更强
dedecms supports one-click upload of Word content
ELK入门
Redis (six) - transaction and lock mechanism of Redis6 (unfinished, to be supplemented)
武功修炼:内功
SQL与NoSQL最终会走向融合吗?
JWT 实现登录认证 + Token 自动续期方案
PTA 7-2 方阵对角线元素求和及计数 题解
关于json转换器缺失的问题,报错内容:No converter found for return value of type
database constraints
owl.carousel poster card Slider carousel switch
bus事件总线 使用
gin-gonic/gin使用详解
LeetCode Algorithm 1472. 设计浏览器历史记录
bus event bus use
效率开发目录
what is rtems
VBA: Inputbox Function and Inputbox Method