yeziruo

利欲驱人万火牛 江湖浪迹一沙鸥


Date: 1545535980

SDCC(Small Device C Compiler)是一个优化的 ANSI - C交叉编译器,目标CPU为基于Intel 8051, Maxim 80DS390, Zilog Z80 和Motorola 68HC08 的单片机。

安装

在Debian/Ubuntu下很容易通过Apt来安装:

sudo apt-get install sdcc sdcc-doc

SDCC使用与编译

SDCC到此就安装完了,我们来简单点个灯:

#include "reg51.h"
#define LED P3_0
void Delay1000ms(){             //@11.0592MHz
        unsigned char i, j, k;
        i = 43;
        j = 6;
        k = 203;
        do
        {
                do
                {
                        while (--k);
                } while (--j);
        } while (--i);
}
void main(){
        while(1){
                LED = 0;
                Delay1000ms();
                LED = 1;
        }
}

编译:

sdcc led.c

编译完后看到目录下生成了许多东西:

# ls
led.asm  led.ihx  led.lst  led.mem  led.rst
led.c    led.lk   led.map  led.rel  led.sym

这里我们只关心led.ihx这个文件,我们需要将它转为hex来烧录:

packihx led.ihx > led.hex

在Linux下可以通过stcflash来烧录它:

sudo apt-get install git python python-serial
git clone https://github.com/laborer/stcflash.git
cd stcflash
python stcflash.py [--port /dev/ttyUSB0] <filename.ihx>
//由于我没有支持的单片机,所以无法演示,stcflash的支持列表和更多使用方法详情请看项目的README

SDCC的多文件编译

例如:

//main.c 引用了 test.c中的函数方法
main.c test.c test.h

这样来编译成为一个HEX:

sdcc -c main.c
sdcc -c test.c
sdcc main.rel test.rel

批判一番

手头上只有几片STC15F104E,就是那个定时器有问题的片子,下载只能通过几个特定版本的STC-ISP来下载的刁端货。

暂无评论

正在回复ID为 ??? 的评论

© 2013-2022 yeziruo. All Rights Reserved. Start5 theme by yeziruo.

CC BY-NC-SA 3.0 CN