简单stm32程序的编译以及简单C51程序的仿真

    科技2024-03-24  88

    MDK5软件与stm32包的安装与简单stm32程序的编译

    简单STM32程序的编译以及简单C51程序的仿真MDK软件的安装stm32包的安装简单stm32程序的创建与编译简单C51程序的仿真总结

    简单STM32程序的编译以及简单C51程序的仿真

    MDK软件的安装

    1.下载keil uVersion软件 2.安装keil5软件 3.注册keil5软件

    stm32包的安装

    直接下载安装就好 STM32下载地址

    简单stm32程序的创建与编译

    1.新建文件夹MyProject并在文件夹中新建CMSIS(存放内核函数及启动引导文件),FWLIB(存放库函数),USER(存放用户自己的函数) 2.从已安装的STM32F10x-STM32F10x_StdPeribh_Lib_V3.5.0标注库的Libraries文件夹将CMSIS中所有文件复制到新建的同名文件夹中; 从标准库中的C:\STM32F10x标准库-STM32F10x_StdPeriph_Lib_V3.5.0\STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\STM32F10x_StdPeriph_Driver中的inc、src复制进FWLIB文件夹; 从C:\STM32F10x标准库-STM32F10x_StdPeriph_Lib_V3.5.0\STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template将所有文件(主意:文件夹可以不用复制,只复制当前目录下的文件就行)复制到USER中 3.打开已安装的软件Keil uVision5,新建工程temp到MyProject下,设置项目名----选择芯片(STM32F103VE)—下一个窗口直接叉掉就行, 4.使用软件自带的工具导入文件 在project target中填写你的项目名比如temp,在group中添加CMSIS,FWLIB/src,USER,STARTUP,在files文件中点击add file添加对应的文件 main.c代码

    #include "stm32f10x.h" //#include "stm32_eval.h" #include <stdio.h> USART_InitTypeDef USART_InitStructure; /* Private function prototypes -----------------------------------------------*/ #ifdef __GNUC__ /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf set to 'Yes') calls __io_putchar() */ #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) #else #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) #endif /* __GNUC__ */ /* Private functions ---------------------------------------------------------*/ /** * @brief Main program. * @param None * @retval None */ int main(void) { USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; // STM_EVAL_COMInit(COM1, &USART_InitStructure); /* Initialize the LCD */ #ifdef USE_STM32100B_EVAL STM32100B_LCD_Init(); #elif defined (USE_STM3210B_EVAL) STM3210B_LCD_Init(); #elif defined (USE_STM3210E_EVAL) STM3210E_LCD_Init(); #elif defined (USE_STM3210C_EVAL) STM3210C_LCD_Init(); #elif defined (USE_STM32100E_EVAL) STM32100E_LCD_Init(); #endif /* Infinite loop */ while (1) { } } PUTCHAR_PROTOTYPE { /* Place your implementation of fputc here */ /* e.g. write a character to the USART */ // USART_SendData(EVAL_COM1, (uint8_t) ch); /* Loop until the end of transmission */ //while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET) while(1){} } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ while (1) { } } #endif

    5.点击魔法棒,进入C/C++设置界面,在define输入 STM32F10X_HD,USE_STDPERIPH_DRIVER ,并在includepath栏加入头文件路径 6、编译项目并修改出现的错误 在编译过程中可能需要删除或注释掉main函数的#include"stm32_eval.h"

    简单C51程序的仿真

    1.打开keil,新建一个以AT89C51为芯片的项目

    2.新建一个C语言程序

    #include<reg51.h> sbit p1_0=P1^0; sbit p1_7=P1^7; main() { int i; while(1) { p1_0=0; do{}while(p1_7=1); do{}while(p1_7=0); p1_0=1; for(i=0;i<=255;i++){}; } }

    3.设置参数,编译整个项目,并生成.hex文件

    5.打开proteus软件,并画一个电路图

    7.导入.hex文件

    8.仿真结果

    总结

    在此过程中若有问题欢迎指出。

    参考文献:keil新建STM32工程 proteus

    Processed: 0.009, SQL: 8