Ubuntu下STC89C52RC开发环境的建立

Wesley13
• 阅读 672

What it is, how to set up a development environment on Linux (Ubuntu), a sample software and some basic explanations.

[TODO: put photos, format, add links to doc etc.]

As I was still in China, and electronic stuffs being far cheaper there than in Europe for some days I've bought with a friend a HOT-51 board with a STC 89C52RC MCU on it (8052 family)

First I know really few things about MCU, embedded programming etc. so please notice it to me if I'm misunderstanding some notions.

The pack we've bought contain the following:

the HOT-51 board (8 digits leds, 8 led, a 8x8 matrix of leds, a 4x4 matrix of button, a stuff to play sound)
a stuff to measure the temperature,
a 2x16 characters screen,
2 motors
a remote
an usb to RS232 cable an usb cable (for alimentation)

the MCU on it is a STC89C52 as said before.

The main goal for us is to have fun while learning the basic of embedded programming, in order to, if we enjoy it, buy after more complex board to start doing concrete software.

setting up a dev environment on Linux

We need 3 things

  1. a text editor (let's say vim ;-))
  2. a compiler (will be sdcc)
  3. an ISP (it will be gSTCISP)

how to get them

For the compiler it's pretty simple

apt-get install sdcc

and you're done

For gSTCISP well you first need to grab the source here
http://sourceforge.net/projects/gstcisp/files/

you will need, in addition to the gtk-dev packages, the libvte

apt-get install libvte-dev

then you can uncompress the archive, run the ./configure, after you will need to modify the Makefile in the src directory (I know it's bad and it should be possible to do it in the makefile.am but I don't want to search, if someone want to propose the "good way" in comments feel free).

in the Makefile replace the line 72 (which start by CFLAGS) by

CFLAGS = -g -O2 -I/usr/include/vte-0.0/

otherwise the make will complain with a :

main.c:25:21: fatal error: vte/vte.h: No such file or directory

once you've finished the make, you can run it with

./gSTCISP

and voila, now you're ready to code :-)

a sample software

the document being in Chinese, it's a bit hard to understand, so here is a sample software that count to 99 with a delay of 1 second using the hardware interruption

#include "8052.h" typedef unsigned int uint; typedef unsigned char uchar; uchar timeTemp = 0; uchar time[8] = {0,0,0,0,0,0,0,0}; void add_one_sec() { // 7 is the top right digit // and 0 the top left one // TODO by inverting the LED position array // should be possible to make it more natural // (0 for the top right one) ++time[7]; time[7] %= 10; // if we were at 000X9 + 1 // the we add one to X if (time[7] == 0) { ++time[6]; time[6] %= 10;// when we reach 00 again if (time[6] == 0) { // we stop the timer - TR0 = 0; } } } // initialize timer 0 void time0_init () { // activate 16 bit timer mode for timer 0 TMOD = 0x01;// enable all interruption // and enable the interrupt 1 (timer 0) IE = 0x82; // 1000 0010 // set the 16 bits register to a delay of 0.05 sec TH0 = 0x3c; TL0 = 0xb0; TR0 = 1; //start timer 0 } // will be called each time the interruption 1 // is raised void time0_interrupt() interrupt1 { // reset the counter to interrupt in 0,05s // with the 11.0592 Xstal TH0 = 0x3c; TL0 =0xb0; // every 4 interrupts we add one to the LEDs digits timeTemp++; // 20 * 0.05s = 1s if(timeTemp == 20) { add_one_sec(); timeTemp = 0; } } int main() { uchar i = 0; // array representing the numbers // from 0 to 9 with the leds // each bits position is linked to one // of the leds used to form the digit // by playing with it you should be able // to make letters etc. uchar code numbers[10] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d,0x07, 0x7f, 0x6f }; // LED position uchar code LED_W[8] = {0,1,2,3,4,5,6,7}; time0_init(); while(1) { // we refresh the value of each LEDs // in sequential order, it should be enough // fast to give the impression of being simultanate P0 = numbers[time[i]] ; P2 = LED_W[i]; i = (i + 1)%8; } }

the comments should be enough to understand how it works (if you've some basic knowledges in embedded programming)

compile it and run it on the board

compile

to compile it and turn it into a .bin here is the command

sdcc main.c && makebin -p < main.ihx > toto.bin

you can replace main.c by the name of your .c file (you will then to change main.ihx too)

run

now you need to load it on the MCU to do this, run gSTCISP (as root), connect your board to your computer using the RS232 to usb cable, also plug the USB-USB cable for power supply (if you don't have an external one)

choose /dev/ttyUSB0 (or 1) , and 4800 bauds

select your .bin file and then nearly at the same time, click on "download" and press the power on button of your board (well I admit it's ), if it says "We are trying to connect to your MCU ..." , just stop the download, power off your board and repeat (do some black magic tricks etc.)

and here you are, now you're able to hack this sample and load anyway .bin you will create/found.

More to come...

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Stella981 Stella981
3年前
Go语言,在Ubuntu9.10和Windows安装
工作环境:Ubuntu9.10A、安装C语言工具Go的工具链采用C语言编写,构建需要安装以下开发工具:GCC,C语言标准库,theparsergeneratorBison,make,awk,和ed(编辑器).对于OSX系统,以上工具是Xcode的一部分。对于Ubuntu/Debian系统,运
Wesley13 Wesley13
3年前
Ubuntu 开发环境搭建
ubuntu安装jdk的两种方式:1:通过ppa(源)方式安装.2:通过官网下载安装包安装.这里推荐第1种,因为可以通过aptgetupgrade方式方便获得jdk的升级使用ppa/源方式安装1.添加ppasudoaddaptrepos
Wesley13 Wesley13
3年前
VBox 启动虚拟机失败
在Vbox(5.0.8版本)启动Ubuntu的虚拟机时,遇到错误信息:NtCreateFile(\\Device\\VBoxDrvStub)failed:0xc000000034STATUS\_OBJECT\_NAME\_NOT\_FOUND(0retries) (rc101)Makesurethekern
Stella981 Stella981
3年前
HIVE 时间操作函数
日期函数UNIX时间戳转日期函数: from\_unixtime语法:   from\_unixtime(bigint unixtime\, string format\)返回值: string说明: 转化UNIX时间戳(从19700101 00:00:00 UTC到指定时间的秒数)到当前时区的时间格式举例:hive   selec
Wesley13 Wesley13
3年前
Ubuntu下搭建JavaEE开发环境(zhuang)
JavaEE是一个非常优秀的Web框架,包含了JSP,Servlet等,今天我们介绍如何在Ubuntu下搭建JavaEE开发环境:1.在http://www.eclipse.org/downloads/?osTypelinux下载EclipseIDEforJavaEE,其中集成了包含JavaE
Stella981 Stella981
3年前
Dockerfile创建tomcat和jdk,并发布java项目
1.准备好需要的jdk和tomcatkun@ubuntu:~$cdtomcatdocker/kun@ubuntu:~/tomcatdocker$lltotal245232drwxrwxrx4kunkun4096May611:34./drwx4ku
Stella981 Stella981
3年前
Linux运维常见面试题之精华收录
Linux运维常见面试题之精华收录1、什么是运维?什么是游戏运维?1)运维是指大型组织已经建立好的网络软硬件的维护,就是要保证业务的上线与运作的正常,在他运转的过程中,对他进行维护,他集合了网络、系统、数据库、开发、安全、监控于一身的技术运维又包括很多种,有DBA运维、网站运维、虚
Stella981 Stella981
3年前
Android蓝牙连接汽车OBD设备
//设备连接public class BluetoothConnect implements Runnable {    private static final UUID CONNECT_UUID  UUID.fromString("0000110100001000800000805F9B34FB");