羞羞小视频在线观看_羞羞视频免费入口网站_羞羞视频下载APP_男女羞羞视频软件

技術資料>ST單片機

?STM8的C語言編程

發(fā)布時間:2018-04-07   瀏覽量:

STM8的C語言編程(1)--基本程序與啟動代碼分析

 

現在幾乎所有的單片機都能用C語言編程了,采用C語言編程確實能帶來很多好處,至少可讀性比匯編語言強多了。

在STM8的開發(fā)環(huán)境中,可以通過新建一個工程,自動地建立起一個C語言的框架,生成后開發(fā)環(huán)境會自動生成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;

}

 

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_interrupt_vector.c中,除了定義了中斷向量表外,還定義了空的中斷服務程序,用于那些不用的中斷。當然在自動建立時,所有的中斷服務都是空的,因此,除了第1個復位的向量外,其它都指向那個空的中斷服務函數。

生成框架后,就可以用Build菜單下的Rebuild All對項目進行編譯和連接,生成所需的目標文件,然后就可以加載到STM8的芯片中,這里由于main()函數是一個空函數,因此沒有任何實際的功能。不過我們可以把這個框架對應的匯編代碼反出來,看看C語言生成的代碼,這樣可以更深入地了解C語言編程的特點。

生成的代碼包括4個部分,如圖1、圖2、圖3、圖4所示。

完整的資料請點擊下載   飛江科技  www.wastewaterengineeringjobs.com