IAR for STM8 程序…

来源:互联网 发布:易语言阿里云api接口 编辑:程序博客网 时间:2024/06/01 08:56

关闭其他无关软件,进行程序的编写和调试,下载

STM8L

unsigned short 无符号短整形  (0-65535)

typedef unsigned short    uint16_t

void Delay(uint16_t nCount 

0xFFFF 一共有几位 1111 1111 1111 1111 2*8=16位 IAR <wbr>for <wbr>STM8 <wbr>程序编写学习笔记 <wbr>--基于IAR <wbr>Embedded <wbr>Workbench=65536

 

void Delay(uint16_t nCount)这个函数在STM8L中基本延时是_us(执行这个语句需要多少周期或者时间)

Configuration is up-to-date. 

表示已经make了一次,且程序无修改。

点击IAR <wbr>for <wbr>STM8 <wbr>程序编写学习笔记 <wbr>--基于IAR <wbr>Embedded <wbr>Workbench

make之后,出现下面的错误

Fatal Error[Pe035]: #error directive: "Please select first the target STM8L device used in your application (in stm8l15x.h file)" C:\Users\Administrator\Desktop\浙台研究\IAR\6\FWlib\inc\stm8l15x.h 53 

可以在下面选择一种 复制到如下图所示的地方

IAR <wbr>for <wbr>STM8 <wbr>程序编写学习笔记 <wbr>--基于IAR <wbr>Embedded <wbr>Workbench

http://www.eefocus.com/fxw451/blog/12-03/245336_bdc0a.html

One of the following macros must also be defined:

        STM8L15X_MD for Medium Density devices.(中等密度的设备)

        STM8L15X_MDP for Medium Density Plus devices.

        STM8L15X_HD for High Density devices.

(CLK_SYSCLKDiv_1 ) 这里的括号如果是中文格式下得括号,会导致出现 无法识别的错误。

怎么生成下载用的hex文件

IAR <wbr>for <wbr>STM8 <wbr>程序编写学习笔记 <wbr>--基于IAR <wbr>Embedded <wbr>Workbench

编译过后,HEX文件所在位置

IAR <wbr>for <wbr>STM8 <wbr>程序编写学习笔记 <wbr>--基于IAR <wbr>Embedded <wbr>Workbench

 

STVP下载完成后,要关闭下载器。IAR 下载之后 也要关闭调试的部分

http://www.waveshare.net/article/STM8-3-1-7.htm

在下载完之后,需要调试,需要看寄存器或者其他的调试窗口的,在View Register 

必须连接设备才可以进行调试

STEP OVER 步进调试 

STEP INTO 进入函数内部

 

 

 

#include "stm8l15x.h"

 

void DelayMS(unsigned int ms)  //延时时间设置,这里要用到clk时钟配置

 

{

 

   unsigned char i;

 

   while(ms != 0)

 

  {

 

  for(i=0;i<250;i++)

 

    ms--;

 

  }

 

  }

 

 

 

 

 

}

 

main()

 

{

 

  GPIOC->DDR 0x80;

 

  GPIOC->CR1 0x80; // 将PC7设置成推挽输出

 

  GPIOC->CR2 0x00;   

 

  while(1)

 

 {

 

 GPIOC->ODR GPIOC->ODR 0x80; 

 

 DelayMS(100); //延时100ms

 

 GPIOC->ODR =GPIOC->ODR 0x7F; 

 

 DelayMS(100); 

 

 }

 

}

 

 

#include "stm8l15x.h"

#define LED1_H()    (GPIO_SetBits (GPIOE,GPIO_Pin_7))

#define LED1_L()    (GPIO_ResetBits (GPIOE,GPIO_Pin_7))

 

 

void CLK_config(void) 

{

 CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1 );//预分频为1,系统默认HSI作为时钟,16MHz

}

 

void GPIO_config(void)

{

  GPIO_Init (GPIOE,GPIO_Pin_7,GPIO_Mode_Out_PP_High_Fast);//定义引脚,推挽输出,10MHz,所以电阻取小

}

 

void delay(unsigned long i)

{

 unsigned int j;

 for(;i>0;i--)

    for(j=1000;j>0;j--);

}

 

void main(void)

{

 CLK_config(); 

 GPIO_config();

 while(1)

 {

  LED1_L();

  delay(500);

  LED1_H();

  delay(50);

 }

}

 



0 0