当前位置:网站首页>STM8L_库函数-模板搭建
STM8L_库函数-模板搭建
2022-07-30 08:35:00 【叶子丶de花】
先创建一个文件夹,用来存放模板Demo

下载STM8的官方固件库 ,工具与软件 – 嵌入式软件 – STM8微控制器软件

选择STM8L_TOUCH_LIB

点击获取软件,同意许可协议

完成后,解压,并运行
![]()
选择文件下载到的位置

获得如下文件
添加STM8L的固件库,L051,L052,L151,L152都可以使用这个库函数

复制上述文件到如下路径

添加STM8l15x_config.h ,以及STM8l15x_it.c ,STM8l15x_it.h

复制上述文件到如下路径

打开IAR FOR STM8

点击创建一个新工程

选择STM8 ,选择 C语言

选择刚才创建的文件夹的USER位置,保存工程
再次点击保存,保存工作空间

右击工程名字,选择增加Add – Add Group..

分别将创建的四个文件名都添加进去

将main.c 拖拉进USER 文件夹内
右击STM8_LIBRARY – Add – Add Files..
按住Shift 全选文件,添加所有文件

右击 USER – Add – Add Files..

添加STM8l15x_config.h ,以及STM8l15x_it.c ,STM8l15x_it.h
HARDWARE 和 SYSTEM没有添加文件

右击工程名字,选择Options..

选择 STM8L052R8,根据自己的芯片型号选择对应的芯片

Debugger 选择 ST-LINK

设置输出.hex文件
添加文件路径和定义


一定要下拉选择第二个,才可以

添加完成,点击确定
修改main.c
#include "stm8l15x.h"
///****************************************************************************************** //
///时钟初始化
static void CLK_Config(void)
{
/* Select HSI as system clock source */
CLK_SYSCLKSourceSwitchCmd(ENABLE);
CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);
/* system clock prescaler: 1*/
CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);
while (CLK_GetSYSCLKSource() != CLK_SYSCLKSource_HSI){}
}
///****************************************************************************************** //
///LED初始化
void LED_Init(void)
{
GPIO_Init(GPIOB,GPIO_Pin_6,GPIO_Mode_Out_PP_High_Fast); //设置PB6为 推挽输出 高速 高电平
GPIO_Init(GPIOB,GPIO_Pin_7,GPIO_Mode_Out_PP_High_Fast); //设置PB7为 推挽输出 高速 高电平
}
///****************************************************************************************** //
///延时函数
void delay_ms(unsigned int ms)
{
unsigned int x,y;
for(x=ms;x>0;x--)
for(y=3000;y>0;y--);
}
///****************************************************************************************** //
///主函数
void main(void)
{
CLK_Config(); //时钟初始化
LED_Init(); //LED初始化
while(1)
{
GPIO_ToggleBits(GPIOB,GPIO_Pin_6);
GPIO_ToggleBits(GPIOB,GPIO_Pin_7);
delay_ms(1000);
};
}
#ifdef USE_FULL_ASSERT
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
先Clean 然后 Rebuild All

删除此包含文件

取消stm8l15x_conf.h中所有注释

删除某些不存在的函数体
存在一个警告,忽略这个警告

官方也明确表示忽略这个警告

点击下载,即可看到 PB6-PB7 两个LED灯闪烁

个人见解,感谢阅读。
边栏推荐
猜你喜欢
![ES报错处理-mapper [xx.xx] of different type, current_type [text], merged_type [keyword]](/img/48/064348ec4d7c2a4fa6ffe7a4778ced.png)
ES报错处理-mapper [xx.xx] of different type, current_type [text], merged_type [keyword]

opencv可以有多有趣

Apache DolphinScheduler's new generation of distributed workflow task scheduling platform in practice - Part 1

ClickHouse

jdbc ResultSetMetaData获取tableName问题

积分专题笔记-与路径无关条件

MySQL Explain 使用及参数详解

Concise Notes on Integrals - Types of Curve Integrals of the Second Kind

仿牛客网项目第一章:开发社区首页(详细步骤和思路)

智能存储柜——解决您的存储需求
随机推荐
[Unity]UI切换环形滚动效果
ant-design form表单校验upload组件(附个人封装的上传组件)
[Mini Program Column] Summarize the development specifications of uniapp to develop small programs
2022/07/29 学习笔记 (day19)异常处理
Concise Notes on Integrals - Types of Curve Integrals of the First Kind
蓝牙技术|了解蓝牙LE Audio的Auracast广播音频
反射技巧让你的性能提升 N 倍
stugc_paper
TreeSet解析
Apache DolphinScheduler's new generation of distributed workflow task scheduling platform in practice - Part 1
FPGA基础协议二:I2C读写E²PROM
积分专题笔记-曲线面积分三大公式
The R installation package has error in rawtochar(block[seq_len(ns)]) :
一个低级错误导致的诡异现象——走近科学能拍三集,(C语言)最简单的数组元素读取,不正确!?
经典毕业设计:基于SSM实现高校后勤报修系统
Detailed description of iperf3 parameter options
Integral Special Notes-Three Formulas for Curve Area Integral
iperf3 参数选项详细说明
ant-design form form verification upload component (with personal packaged upload component)
嘉为鲸翼·多云管理平台荣获信通院可信云技术服务最佳实践