在Linux下没有像keli那样好用的IDE来开发51单片机,开发环境只能自己搭建了。
第一步:安装交叉编译工具
a) 安装SDCC
sudo apt-get install sdcc
b)测试SDCC是否可用,这是个网上找的简单的流水灯代码 test.c, 用来测试
#include "8051.h"
#define uint unsigned int
#define uchar unsigned char
uchar tab[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void Delay(uint xms){
uint i,j;
for(i=xms;i>;i--)
for(j=;j>;j--);
}
void main(){
uchar i;
while(){
for(i=;i
P1 = tab[i];
Delay();
}
}
}
编译它:
sdcc test.c
会生成这么多的文件(我们只需要其中的 test.ihx):
test.lk test.map test.rel test.sym test.asm test.ihx test.lst test.mem test.rst
packihx file.ihx >file.hex 转换为hex文件
hex2bin sourcefile.hex。之后就会生成sourcefile.bin文件。
<