资源描述:
《stm8的c语言编程1-14讲完整版》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、STM8S的C语言编程(1)--基本程序与启动代码 现在几乎所有的单片机都能用C语言编程了,采用C语言编程确实能带来很多好处,至少可读性比汇编语言强多了。在STM8的开发环境中,可以通过新建一个工程,自动地建立起一个C语言的框架,生成后开发环境会自动生成2个C语言的程序,一个是main.c,另一个是stm8_interrupt_vector.c。main.c中就是一个空的main()函数,如下所示: /*MAIN.Cfile * *Copyright(c)2002-2005STMicroelectronics */ main(){ while(1);} 而在stm8_interr
2、upt_vector.c中,就是声明了对应该芯片的中断向量,如下所示:/* BASICINTERRUPTVECTORTABLEFORSTM8devices * Copyright(c)2007STMicroelectronics */ typedefvoid@far(*interrupt_handler_t)(void); structinterrupt_vector{ unsignedcharinterrupt_instruction; interrupt_handler_tinterrupt_handler;}; @far@interruptvoidNonHan
3、dledInterrupt(void){ /*inordertodetectunexpectedeventsduringdevelopment, itisrecommendedtosetabreakpointonthefollowinginstruction */ return;} externvoid_stext(); /*startuproutine*/ structinterrupt_vectorconst_vectab[]={ {0x82,(interrupt_handler_t)_stext},/*reset*/
4、 {0x82,NonHandledInterrupt},/*trap */ {0x82,NonHandledInterrupt},/*irq0 */ {0x82,NonHandledInterrupt},/*irq1 */ {0x82,NonHandledInterrupt},/*irq2 */ {0x82,NonHandledInterrupt},/*irq3 */ {0x82,NonHandledInterrupt},/*irq4 */ {0x82,NonHandledInterrupt},/*irq5 */ {0x8
5、2,NonHandledInterrupt},/*irq6 */ {0x82,NonHandledInterrupt},/*irq7 */ {0x82,NonHandledInterrupt},/*irq8 */ {0x82,NonHandledInterrupt},/*irq9 */ {0x82,NonHandledInterrupt},/*irq10*/ {0x82,NonHandledInterrupt},/*irq11*/ {0x82,NonHandledInterrupt},/*irq12*/ {0x82,Non
6、HandledInterrupt},/*irq13*/ {0x82,NonHandledInterrupt},/*irq14*/ {0x82,NonHandledInterrupt},/*irq15*/ {0x82,NonHandledInterrupt},/*irq16*/ {0x82,NonHandledInterrupt},/*irq17*/ {0x82,NonHandledInterrupt},/*irq18*/ {0x82,NonHandledInterrupt},/*irq19*/ {0x82,NonHandl
7、edInterrupt},/*irq20*/ {0x82,NonHandledInterrupt},/*irq21*/ {0x82,NonHandledInterrupt},/*irq22*/ {0x82,NonHandledInterrupt},/*irq23*/ {0x82,NonHandledInterrupt},/*irq24*/ {0x82,NonH