STM8自学笔记——stm8s.h选择芯片型号

本文介绍了在使用IAR for STM8进行编程时,如何通过修改stm8s.h头文件中的预处理器定义来选择合适的STM8芯片型号,避免编译错误。此外,还提及了在编译过程中,若未正确设置模型,系统会提示错误,并提供了官方库函数使用的注意事项,包括添加断言失败处理函数的代码段。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.通过stm8s.h选择芯片型号

在使用IAR for stm8编程的时候,会使用到stm8s.h的头文件。
stm8.h头文件中最开始会有这么一段

/ 根据您的
应用程序中使用的目标STM8S或STM8A器件取消注释下面的行。
/

/* Uncomment the line below according to the target STM8S or STM8A device used in your
   application. */

/* #define STM8S208 */      /*!< STM8S High density devices with CAN */
/* #define STM8S207 */      /*!< STM8S High density devices without CAN */
/* #define STM8S007 */      /*!< STM8S Value Line High density devices */
/* #define STM8AF52Ax */    /*!< STM8A High density devices with CAN */
/* #define STM8AF62Ax */    /*!< STM8A High density devices without CAN */
/* #define STM8S105 */      /*!< STM8S Medium density devices */
/* #define STM8S005 */      /*!< STM8S Value Line Medium density devices */
/* #define STM8AF626x */    /*!< STM8A Medium density devices */
/* #define STM8S103 */      /*!< STM8S Low density devices */
/* #define STM8S003 */      /*!< STM8S Value Line Low density devices */
/* #define STM8S903 */      /*!< STM8S Low density devices */

你可以针对自己的型号将前面的/ *去掉,取消注释。
另一种方法是不需要自己去除,options-> c / c ++编译器->预处理器中的已定义符号中加入对应的模型,如STM8AF52Ax
在这里插入图片描述

如若不然,会跳出错误,因为h文件中有这一段,未预定义错误报错

#if!defined(STM8S208)&&!defined( STM8S207)&&!定义(STM8S105)&&
!定义(STM8S103)&&!定义(STM8S903)&&!定义(STM8AF52Ax)&&
!定义(STM8AF62Ax)&&!定义(STM8AF626x)&&!定义(STM8S007)&&
!定义(STM8S003)&&!定义(STM8S005)
#错误“请先选择应用程序中使用的目标STM8S / A设备(在stm8s.h文件中)”
#endif

#if !defined (STM8S208) && !defined (STM8S207) && !defined (STM8S105) && \
    !defined (STM8S103) && !defined (STM8S903) && !defined (STM8AF52Ax) && \
    !defined (STM8AF62Ax) && !defined (STM8AF626x) && !defined (STM8S007) && \
    !defined (STM8S003)&& !defined (STM8S005)
#error "Please select first the target STM8S/A device used in your application (in stm8s.h file)"
#endif

2.官网下载的库函数直接用需要在main.c最后加上这么一段代码,才可以编译通过

#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)
  {}
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

赤豆糊_siki

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值