A detailed overview of setting up a development environment for 51 microcontroller under Linux and writing a detailed program

Publisher:collectorsLatest update time:2023-08-16 Source: elecfansKeywords:Linux Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

There is no easy-to-use IDE like keli under Linux to develop the 51 microcontroller. The development environment can only be built by yourself.


Step 1: Install cross-compilation tools

a) Install SDCC

sudo apt-get install sdcc

b) Test whether SDCC is available. This is a simple running water lamp code test.c found online, used for testing.

#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[i];

Delay(100);

}

}

}12345678910111213141516171819202122232425

Compile it: sdcc test.c

This many files will be generated:

test.lk test.map test.rel test.sym test.asm test.ihx test.lst test.mem test.rst

We only need test.ihx among them

packihx file.ihx >file.hex Convert to hex file

Then download the hex2bin file at the URL (http://sourceforge.net/projects/hex2bin/files/latest/download). Command: hex2bin sourcefile.hex. The sourcefile.bin file will then be generated.

hextobin file.hex generates bin file

Note: In order to facilitate calling hex2bin in the future, you can add the path to the .bashrc file

Add the folder location of Hex2bin to the last line of ~/.bashrc

PATH=$PATH:/home/leo/workspace/c51/Hex2bin-2.31

You can write a makefile to make compilation easier

This is the makefile I wrote:

test.hex : test.c

sdcctest.c

packihx test.ihx > test.hex

hex2bin test.hex

clean:

rm -rf *.asm *.lst *.mem *.rst *.lnk *.rel *.sym *.ihx *.hex *.map

~ 1234567

Step 2: Install the programming tool

a) Download stcflash: github.com/laborer/stcflash, which is a software written in python to program bin files to microcontrollers.

b) Installation environment: sudo apt-get install python-serial

c) Flashing: sudo python ./stcflash.py test.bin


Keywords:Linux Reference address:A detailed overview of setting up a development environment for 51 microcontroller under Linux and writing a detailed program

Previous article:Things to note when developing 51 microcontroller operating system
Next article:51 microcontroller ultrasonic ranging program code sharing

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号