分享

STM8自学笔记

 logicsoft 2022-12-30 发布于浙江

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)
  {}
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多