历史上的今天
今天是:2025年01月16日(星期四)
2020年01月16日 | 单片机成长之路(51基础篇) - 006 在Linux下搭建开发烧写环境
2020-01-16 来源:eefocus
在Linux下没有像keli那样好用的IDE来开发51单片机,开发环境只能自己搭建了。
第一步:安装交叉编译工具
a) 安装SDCC
sudo apt-get install sdcc
b)测试SDCC是否可用,这是个网上找的简单的流水灯代码 test.c, 用来测试
1 #include "8051.h"
2
3 #define uint unsigned int
4 #define uchar unsigned char
5 uchar tab[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
6
7 void Delay(uint xms){
8 uint i,j;
9 for(i=xms;i>0;i--)
10 for(j=110;j>0;j--);
11 }
12
13 void main(){
14 uchar i;
15 while(1){
16 for(i=0;i<8;i++){
17 P1 = tab[i];
18 Delay(100);
19 }
20 }
21 }
编译它:
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文件,网址(http://sourceforge.net/projects/hex2bin/files/latest/download)。
hex2bin sourcefile.hex。之后就会生成sourcefile.bin文件。
注意:为了方便以后调用hex2bin,可以将路径加入到 .bashrc文件在~/.bashrc最后一行加上Hex2bin 所在的文件夹位置:
PATH=$PATH:/home/jikexianfeng/51-demo/Hex2bin-2.5
可以写个makefile文件,编译方便些
这是我写的makefile:
1 test.hex : test.c
2 sdcc test.c
3 packihx test.ihx > test.hex
4 hex2bin test.hex
5 clean:
6 rm -rf *.asm *.lst *.mem *.rst *.lnk *.rel *.sym *.ihx *.hex *.map
第二步:安装烧写工具
a)下载stcflash: http://github.com/laborer/stcflash ,这是个用python写的向单片机烧写bin文件的软件
b)安装环境:sudo apt-get install python-serial
c)烧写 : sudo python ./stcflash.py test.bin
解决 ImportError: No module named 'serial' 问题
Traceback (most recent call last):
File "/home/jikexianfeng/51-demo/.stcflash/stcflash.py", line 22, in import serial ImportError: No module named serial 解决办法(安装 serial module,这里区分python2和 python3): sudo apt install python-pip //python2 sudo apt install python3-pip //python3 安装python3的 pip3的时候,如果时国内的软件源可能安装不上,(当时用中国科学技术大学的软件源,python3-pip下载有问题),换成ubuntu官网成功下载。 安装pyserial: pip install pyserial //python2 pip3 install pyserial //python3 可以从pyserial下载这里去获取源码进行熟悉和学习。 

史海拾趣
|
2008 电子设计 A题 原创作品 基于ARM (省二等奖内附参赛论文) 本帖最后由 paulhyde 于 2014-9-15 03:32 编辑 这可是我们8天7夜奋斗的结果哦,虽然我们得了省二等奖,但是我们能成功的运用ARM,也很满足了!~!~ 下载不了的可以留下你们的邮箱!~!~! [ 本帖最后由 歹匕示申 于 2008-12-25 14:50 编辑 ] ...… 查看全部问答> |
|
最近忙一个项目,时间紧迫了,可目前遇到一个严重的问题,详情是这样:我用EVC.0编一个程序来把采集的数据保存在嵌入式设备的SQLCE数据库中,但弄来弄去发现保存速度跟不上,不知道各位大侠是否知道有什么方法能实现数据库的高速保存。感激不尽啊, ...… 查看全部问答> |
|
求助:CodeWarrior for ADS 1.2中编译出错 工程中,用ADS编译,出现了Errors: Could not find or load the file 襐IC.a?for target 褼ebugRel?for project 襱est1.mcp? Could not find or load the file 褻omm.a?for target 褼ebugRel?for project 襱est1.mcp? The following access p ...… 查看全部问答> |
|
请登陆淘宝进行详细的细节查询 淘宝地址: http://auction1.taobao.com/auction/0/item_detail-0db2-a975eaf6e989403d6987eeb2fde3c9d9.jhtml 欢迎购买. … 查看全部问答> |
|
小弟刚入道,就遇到棘手的问题,希望大家帮忙啊,谢谢! 问题如下 在Wince下 我在Form1中添加了一个PictureBox1,想在上面画个点,或者圆 结果发现连Paint()函数都没 ,郁闷;还有 CreatGraphic函数也没,该怎么办啊? 使用VB.net2005 谁能发个 ...… 查看全部问答> |




