EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
在Linux下搭建51单片机的开发烧写环境
6 n' Q" \, B0 [
! C# {% x4 F. `" O9 R在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[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; void Delay(uint xms) { uint i,j; for(i=xms;i>0;i--) for(j=110;j>0;j--); } void main() { uchar i; while(1) { for(i=0;i<8;i++) { P1 = tab; Delay(100); } } }12345678910111213141516171819202122232425 编译它: sdcc test.c 会生成这么多的文件: test.lk test.map test.rel test.sym test.asm test.ihx test.lst test.mem test.rst 我们只需要其中的 test.ihx packihx file.ihx >file.hex 转换为hex文件 接着下载hex2bin文件,网址(http://sourceforge.net/projects/hex2bin/files/latest/download)。命令:hex2bin sourcefile.hex。之后就会生成sourcefile.bin文件。 hextobin file.hex 生成bin文件 注意:为了方便以后调用hex2bin,可以将路径加入到 .bashrc文件 在~/.bashrc最后一行加上Hex2bin 所在的文件夹位置 PATH=$PATH:/home/leo/workspace/c51/Hex2bin-2.31 可以写个makefile文件,编译方便些 这是我写的makefile: test.hex : test.c sdcc test.c packihx test.ihx > test.hex hex2bin test.hex clean: rm -RF *.asm *.lst *.mem *.rst *.lnk *.rel *.sym *.ihx *.hex *.map ~ 1234567 第二步:安装烧写工具 a)下载stcflash:github.com/laborer/stcflash,这是个用python写的向单片机烧写bin文件的软件 b)安装环境:sudo apt-get install python-serial c)烧写 : sudo python ./stcflash.py test.bin |