教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 教育文库 >

STM8的C语言编程(1)- 代码结构框架

来源:网络收集 时间:2026-07-02
导读: 意法单片机STM8的各模块C语言编程 STM8的C语言编程(1)--基本程序与启动代码分析 现在几乎所有的单片机都能用C语言编程了,采用C语言编程确实能带来很多好处,至少可读性比汇编语言强多了。 在STM8的开发环境中,可以通过新建一个工程,自动地建立起一个C

意法单片机STM8的各模块C语言编程

STM8的C语言编程(1)--基本程序与启动代码分析

现在几乎所有的单片机都能用C语言编程了,采用C语言编程确实能带来很多好处,至少可读性比汇编语言强多了。

在STM8的开发环境中,可以通过新建一个工程,自动地建立起一个C语言的框架,生成后开发环境会自动生成2个C语言的程序,一个是main.c,另一个是stm8_interrupt_vector.c。main.c中就是一个空的main()函数,如下所示:

/* MAIN.C file

*

* Copyright (c) 2002-2005 STMicroelectronics

*/

main()

{

while (1);

}

而在stm8_interrupt_vector.c中,就是声明了对应该芯片的中断向量,如下所示: /* BASIC INTERRUPT VECTOR TABLE FOR STM8 devices

* Copyright (c) 2007 STMicroelectronics

*/

typedef void @far (*interrupt_handler_t)(void);

struct interrupt_vector {

unsigned char interrupt_instruction;

interrupt_handler_t interrupt_handler;

};

@far @interrupt void NonHandledInterrupt (void)

{

/* in order to detect unexpected events during development,

it is recommended to set a breakpoint on the following instruction */

return;

}

意法单片机STM8的各模块C语言编程

extern void _stext(); /* startup routine */

struct interrupt_vector const _vectab[] = {

{0x82, (interrupt_handler_t)_stext}, /* reset */

{0x82, NonHandledInterrupt}, /* trap */

{0x82, NonHandledInterrupt}, /* irq0 */

{0x82, NonHandledInterrupt}, /* irq1 */

{0x82, NonHandledInterrupt}, /* irq2 */

{0x82, NonHandledInterrupt}, /* irq3 */

{0x82, NonHandledInterrupt}, /* irq4 */

{0x82, NonHandledInterrupt}, /* irq5 */

{0x82, NonHandledInterrupt}, /* irq6 */

{0x82, NonHandledInterrupt}, /* irq7 */

{0x82, NonHandledInterrupt}, /* irq8 */

{0x82, NonHandledInterrupt}, /* irq9 */

{0x82, NonHandledInterrupt}, /* irq10 */

{0x82, NonHandledInterrupt}, /* irq11 */

{0x82, NonHandledInterrupt}, /* irq12 */

{0x82, NonHandledInterrupt}, /* irq13 */

{0x82, NonHandledInterrupt}, /* irq14 */

{0x82, NonHandledInterrupt}, /* irq15 */

{0x82, NonHandledInterrupt}, /* irq16 */

{0x82, NonHandledInterrupt}, /* irq17 */

{0x82, NonHandledInterrupt}, /* irq18 */

{0x82, NonHandledInterrupt}, /* irq19 */

{0x82, NonHandledInterrupt}, /* irq20 */

{0x82, NonHandledInterrupt}, /* irq21 */

{0x82, NonHandledInterrupt}, /* irq22 */

{0x82, NonHandledInterrupt}, /* irq23 */

{0x82, NonHandledInterrupt}, /* irq24 */

{0x82, NonHandledInterrupt}, /* irq25 */

{0x82, NonHandledInterrupt}, /* irq26 */

{0x82, NonHandledInterrupt}, /* irq27 */

{0x82, NonHandledInterrupt}, /* irq28 */

{0x82, NonHandledInterrupt}, /* irq29 */

};

意法单片机STM8的各模块C语言编程

在stm8_interrupt_vector.c中,除了定义了中断向量表外,还定义了空的中断服务程序,用于那些不用的中断。当然在自动建立时,所有的中断服务都是空的,因此,除了第1个复位的向量外,其它都指向那个空的中断服务函数。

生成框架后,就可以用Build菜单下的Rebuild All对项目进行编译和连接,生成所需的目标文件,然后就可以加载到STM8的芯片中,这里由于main()函数是一个空函数,因此没有任何实际的功能。不过我们可以把这个框架对应的汇编代码反出来,看看C语言生成的代码,这样可以更深入地了解C语言编程的特点。

…… 此处隐藏:581字,全部文档内容请下载后查看。喜欢就下载吧 ……
STM8的C语言编程(1)- 代码结构框架.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/108027.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)