Manual Mcu8051ide PDF
Manual Mcu8051ide PDF
I would like to thank to the following people for their support during the
project development:
• Trevor Spiteri for help with debugging (patches) the HD44780 sim-
ulator.
Contents
Preface 5
Goals of the project . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Intended Audience . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1 Brief introduction 9
1.1 Main components of MCU 8051 IDE . . . . . . . . . . . . . . 9
1.2 What is MCS-51 . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.3 What is the Assembly language . . . . . . . . . . . . . . . . . 12
2 Quick start 13
2.1 Demonstration project . . . . . . . . . . . . . . . . . . . . . . 13
2.2 Your rst project in MCU 8051 IDE . . . . . . . . . . . . . . 14
4 Build-in macro-assembler 37
4.1 Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.2 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.3 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.4 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.5 The instruction set processing . . . . . . . . . . . . . . . . . . 40
4.6 Assembler directives . . . . . . . . . . . . . . . . . . . . . . . 41
CONTENTS 5
5 Disassembler 61
6 MCU simulator 63
6.1 Short introduction . . . . . . . . . . . . . . . . . . . . . . . . 63
6.2 Modes of simulation . . . . . . . . . . . . . . . . . . . . . . . 63
6.3 Waring conditions . . . . . . . . . . . . . . . . . . . . . . . . . 64
6.4 Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
6.5 Virtual hardware . . . . . . . . . . . . . . . . . . . . . . . . . 65
6.5.1 DS1620 temperature sensor . . . . . . . . . . . . . . . 65
6.5.2 File interface . . . . . . . . . . . . . . . . . . . . . . . 65
6.5.3 LED Panel . . . . . . . . . . . . . . . . . . . . . . . . 66
6.5.4 Single LED Display . . . . . . . . . . . . . . . . . . . . 66
6.5.5 Multiplexed LED Display . . . . . . . . . . . . . . . . 66
6.5.6 LED Matrix . . . . . . . . . . . . . . . . . . . . . . . . 67
6.5.7 Matrix Keypad . . . . . . . . . . . . . . . . . . . . . . 67
6.5.8 Simple Keypad . . . . . . . . . . . . . . . . . . . . . . 68
6.5.9 LCD display controlled by HD44780 . . . . . . . . . . 68
B Regression testing 81
B.1 Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
B.2 More about the implementation . . . . . . . . . . . . . . . . . 81
G Change log 99
7
Preface
(since version 1.3.6). This program was originally intended for education
purposes, but now the area of potential usage is surely signicantly wider.
This program was created to ll a gap in the open source software of this
kind. User interface, source codes, documentation, web pages, etc., are writ-
ten in English in order to make this software available to as many user as
possible, but there is support for internationalization using i18n since ver-
sion 1.3.10. This documentation is written in LATEX. It is very important
to note that this software was not developed for any company, person or
something similar and it is completely noncommercial, open source software
distributed under GNU GPLv2 license intended for a group of people with
common interest, in this case 8051.
Requirements
Hardware requirements are not dened. This program should run without
problems on all POSIX systems (like GNU/Linux, etc.), where all of the
software dependencies were satised. The IDE is ocially distributed as a
source code package (primary programming language is TCL), RPM package
(currently available in ocial RHEL repositories), DEB package (currently
available in ocial Debian repositories) and ebuild for Gentoo Linux (cur-
rently NOT available in the portage tree).
Intended Audience
This manual is intended for any individual, regardless of his or her experience
with assembler, C language, MCU 8051 IDE or Linux, but it is assumed here
that the reader is familiar with basic concepts of assembly language program-
ming and with 8051 processor architecture. Advanced users are not likely to
read this manual, but all suggestions on documentation will be considered.
If you would like to contribute to this project or the documentation, please
consult the project web page.
Thanks for your cooperation which helps to make this software better.
10 CONTENTS
11
Chapter 1
Brief introduction
This chapter will provide you with a brief introduction about the main com-
ponents that are part of MCU 8051 IDE. The purpose of this chapter is to
contextualize you on the sofware, informing about the parts that composes
it. The next chapter will cover rapidly the Graphical User Interface, which
will be described in further details on chapter.
Assembler The assembler is one of the integral parts of MCU 8051 IDE. It
is a macro assembler with support for dozens of directives and capable of per-
forming peephole optimizations. Support for peephole optimizations means
that the assembler can attempt to optimize the resulting code for higher exe-
cution speed and lower size without tempering with its very functionality. It
is important to note that automatic peephole optimization can sometimes be
harmful and so it is disabled by default. A macro assembler is a software that
allows the user to dene a macro instruction, which consists of a sequence
1 Spell checking for comments is available only if you have installed the Hunspell pro-
R Windows
gram. This feature is currently not available on MS
R OS.
12 CHAPTER 1. BRIEF INTRODUCTION
of basic instructions, and use it later instead of repeatedly copying and past-
ing the set of instructions over and over along the source code. Assembler
behavior can be congured either globally, using the proper conguration di-
alog, or locally in source code, by means of assembler directives and control
sequences (e.g. $TITLE('Some title to show in the code listing')).
The assembler is capable of generating four kinds of output code:
+ Object code (machine code) as a binary le, with .bin extension and
in format of raw binary data;
+ Code listing, in .lst extension;
+ Code for integrated MCU simulator, in .adf extension.
Hexadecimal editor This utility is used here for watching and modifying
large blocks of raw data in various memory types of the simulated MCU
(Code, IDATA, XDATA, EEPROM, etc.). There is also hexadecimal editor
intended for editing Intel
R HEX 8 les. Other hexadecimal editors are
specially designed to t specic needs of the given purpose; for example,
there is an hexadecimal editor for viewing and editing code memory, which
displays the current position of the program counter in the machine code of
the simulated program.
Disassembler This tool can translate once assembled code back to source
code. It is important to note that it is somewhat improbable that the result-
ing source code will look "reasonable" It is due to DB and DW and not xed
instruction word length on 8051. Nevertheless, such a generated source code
must posses exactly the same functionality when it gets assembled again.
Disassembler implemented in this IDE is frankly speaking only a little more
that just a toy. If you want a really capable disassembler, maybe you should
try some tool like D52 http://www.8052.com/users/disasm/.
14 CHAPTER 1. BRIEF INTRODUCTION
Notepad In this IDE, it is a simple rich text editor for writing user notes
of whatever kind. Originally, it was intended for writing a list of things which
remain to be done in your project.
Chapter 2
Quick start
Figure 2.1: MCU 8051 IDE with the demonstration project opened within it
16 CHAPTER 2. QUICK START
Chapter 3
Detailed introduction to GUI
• 0: Disabled
Syntax validation conguration button react to left and right click with the
mouse pointer. Right button click decreases the level of validation and the
left button click increases it.
3.1.3 Auto-completion
Pop-up based auto-completion is func-
tion which should make it easier to
use long names for labels, macros, vari-
ables, functions, constants, etc. This
function is interconnected with syntax
editor's analyzer used for syntax high-
light and validation and for the table of
symbols in the right panel. So it main-
tains an overview of all symbols dened Figure 3.3: Syntax highlight, syntax
in your source code le and then when validation and the pop-up based auto-
completion all in action
you write just a few characters which
a symbol starts with, this function will
pop-up window oering you all dened symbols beginning with that letters.
Note that this feature can be disabled in editor conguration dialog and note
also that besides symbols it oers also list of assembly language instruction
mnemonics and assembler directives.
3.2.2 C variables
This panel is a part of simulator user interface that maintains a list of global
static variables dened in your C language code. Names of variables are
displayed along with their current values in simulated MCU. If you program
is not written in C language then this tool has no purpose for you at all.
Otherwise the purpose of this panel is to make it easier to simulate a program
for 8051 written in C language and see what is really happening in there.
This tool is capable of extracting variable values from multiple registers and
the displaying them as one variable, one value. Alteration of variable values
is also possible. And search panel in the top right corner of the panel might
3.2. BOTTOM PANEL 21
help you with nding exact variable which you need to see. But note that
functionality of this tool is in fact severely limited, it supports only global
static variables, integers and oats, but variable value modication is allowed
only for integer variables, no oats.
3.2.5 Notes
This is your personal notes for whatever you want. Originally it was intended
for writing down a list of things which you need to nish in your work, so
some sort of a to do list. But it is just a simple rich text editor with separate
le specic notepad. User can use it as he or she consider appropriate.
3.2.6 Calculator
Calculator is here more or less just for completeness. But you might still
nd it to a real asset to your eorts. This calculator is capable of performing
common arithmetical operations, computing trigonometric functions, logi-
cal operations, etc. Supported numeral systems are hexadecimal, decimal,
octal and binary in both integer and real numbers. Supported angular mea-
surement units are degrees, radians and gradians. The calculator is also
equipped with three memory cells where you can save arbitrary numbers for
future computations. On the right side there is a simple calculator dedicated
to calculation timers preset values for the specied time, clock frequency, etc.
3
3 Essentially the same but much more advanced function has also the special calculator.
3.2. BOTTOM PANEL 23
Windows R operating system and probably will never be, because terminal
Figure 3.12: Embedded rxvt-unicode terminal emulator, with the Midnight Commander
running in it
4 An instance of pattern matching behavior, for example *.c++ matches all les with
.c++ extension.
5 A command line text search utility originally written for Unix. The name is taken
from the rst letters in global/regular expression/print. Its ocial date of creation is given
as March 3, 1973.
6 A video terminal that was made by Digital Equipment Corporation (DEC). Its detailed
attributes became the de facto standard for terminal emulators.
7 Computer software system and network protocol that provides a basis for graphical
user interfaces.
24 CHAPTER 3. DETAILED INTRODUCTION TO GUI
to the current line (line with cursor) in the source code editor. You can also
remove all bookmarks at once by pressing the Clear all button.
Label
Constant
Macro
C variable
C function
Other
with certain hardware tools, most probably MCU programmers. if you are
interested in writing these plug-ins, please refer to chapter 7.
3.5.8 Stopwatch
Stopwatch is a tool which can measure certain things in the simulated proces-
sor, such as number of instructions processed so far, number of microseconds
which would it take for a real processor to execute, number of breakpoints
met so far etc. User can also set it to stop the simulation when certain limit
in the measurement has been met or exceeded.
where the received data will be written. And by button Send selected you
can trigger transmission over the opened physical port, selected chunk of the
data will be send then. Button Clear selected are intended for removing
data from the hexadecimal editors editors.
MCU code memory editor allows user to see and modify contents of
the CODE memory of the simulated micro-controller. Special feature of this
particular editor is that instruction OP code currently pointed by program
counter (PC) is highlighted with dark orange background along with the
instruction's operands. And the same applies also for the previously executed
instruction but highlight color is light orange in this case.
MCU eeprom write buer editor allows to see and modify EEPROM
write buer. Current EEPROM write oset is displayed as well.
32 CHAPTER 3. DETAILED INTRODUCTION TO GUI
tool is completely independent from your project in the IDE. This too might
be particularly useful when you want to and possibly modify content of a
Intel
R 8 hex le, but do not alter the simulated MCU.
with a simple tool set for this purpose. In the Main Menu → Utilities
you can nd these tools:
• HEX → BIN
Convert Intel
R 8 Hex le to raw binary le
• BIN → HEX
Convert raw binary le to Intel
R 8 Hex
• SIM → HEX
Convert simulator assembler debug le (.adf) to Intel
R 8 Hex le
• SIM → BIN
Convert simulator assembler debug le (.adf) to raw binary le
• Normalize Hex
Read and rewrite the given Intel
R 8 Hex le, so that all records satises
• Convert to uppercase
• Convert to lowercase
• Keep current case
Pseudo-variable Meaning
%URL The full URL of the current le
%URLS List of the URLs of all open documents
%directory Project directory
%lename The le name of the current document
%basename Same as %lename, but without extension
%mainle Name of project main le
%line Number of the current line
%column Number of the current column
%selection The selected text in the current le
%text The full text of the current le
• ASEM-51 13
• ASL 14
• AS51 15
1. Write makele,
2. set the IDE to use your makele instead of calling the C compiler di-
rectly (Conguration -> Compiler conguration -> GNU make utility),
2. How many steps will be remembered during the simulation for later
backward steps.
Chapter 4
Build-in macro-assembler
In this chapter we will be concerned with MCU 8051 IDE build-in assembler.
1
With syntax of its statements, directives and 8051 assembler instructions. I
assume that the reader is familiar with general concepts of assembly language
programming and 8051 architecture. So I will not explain these here.
4.1 Statements
Source code les for this assembler must be text les where lines are formed
like these:
[ label: ] [ instruction [ operand [ , operand [ , operand ]]] [ ;comment ]
[ label: ] directive [ argument ] [ ;comment ]
symbol directive argument [ ;comment ]
4.2 Symbols
Symbol names for numbers, macros or addresses dened by user in the code
using appropriate directive. Like with equ directive you can dene a new
1 This assembler manual is inspired by ASEM-51 manual, a great work done by W.W.
Heinz
2 No Breaking Space (0xC2)
40 CHAPTER 4. BUILD-IN MACRO-ASSEMBLER
; Main loop
main: sjmp $ ; Inifinite loop
; Program end
end
symbol and assign a value to it right away. Symbols may consist of upper
and lower case letter, digits and underscore character (_), their length is
not limited, they are case insensitive and they can be the same as language
keywords. Be aware of that there cannot coexists two or more symbols in
the same memory segment which diers only by letter casing, in other words
symbols abc and ABC are completely the same thing.
4.3 Constants
There are two types of constants numeric constants and character constants.
Numeric constants consist of a sequence of digits allowed for the numeric
base used and followed by the radix specier. If the number begins with a
letter, there must be the zero digit placed before the number. For example
abh is not valid numeric constant, but 0abh is. Character constants con-
sist of sequence of one or more characters enclosed by quote character (').
C escape sequences can be used in character constants. If you want to place
quote character (') into the constant, you can either place two quotes instead
of one ( '''') or escape the quote, that means place backslash
4.4 Expressions
Arithmetical expressions are evaluated at compilation time and replaced by
assembler with constant corresponding the their resulting value. Expressions
comprises of arithmetical operators, constants, symbols and another expres-
sions. An example of such expression might be ( X XOR 0FF00H )
Operator Description Example
Unary Operators
NOT one's complement NOT 0a55ah
HIGH high order byte HIGH 0a55ah
LOW low order byte LOW 0a55ah
Binary Operators
+ unsigned addition 11 + 12
- unsigned subtraction 13 + 11
* unsigned multiplication 3 * 5
/ unsigned division 20 / 4
MOD unsigned remainder 21 MOD 4
SHL logical shift left 32 SHL 2
SHR logical shift right 32 SHR 2
AND logical and 48 AND 16
OR logical or 370q OR 7
XOR exclusive or 00fh XOR 005h
. bit operator P1.4
EQ, = equal to 11 EQ 11
NE, <> not equal to 11 NE 11
LT, < less than 11 LT 12
LE, <= less or equal than 11 LT 11
GT, > greater than 12 GT 11
GE, >= greater or equal than 12 GT 11
Example: IF <expr>
IF(2 * 4 - CND)
MOV A, #20h Example:
Example: ELSE
IFDEF CND Example:
IFNDEF <symbol>
Example: ELSEIF <expr>
IFNDEF CND Example:
REPT <expr>
ELSEIF <expr>
Example: Example:
ENDM Example:
ISEG at 10d
Example:
ABC MACRO
MOV B, #12d bseg switch to BIT segment [at address]
ENDM Syntax:
Note:
idata
Deprecated directive. Consider directive BIT dene
instead.}
address in the Internal DATA mem-
ory
Syntax:
skip SKIP bytes in the code memory
Syntax: <symbol> IDATA <expr>
Example:
SKIP <expr> UIV IDATA 20h
Example:
SKIP 5 xdata dene address in the External DATA mem-
ory
Syntax:
equ EQUivalent
Syntax: <symbol> XDATA <expr>
Example:
<symbol> EQU <expr> UIV XDATA 400h
Example:
ABC EQU R0 macro MACRO denition
XYZ EQU 4Eh+12 Syntax:
Example:
ABC BIT P4.5 local dene a LOCAL label inside a macro
Syntax:
LOCAL <label>
set SET numeric variable or variable register
Syntax: Example:
ABC MACRO X
<symbol> SET <expr> LOCAL xyz
<symbol> SET <register> xyz: MOV X, #12d
ENDM
Example:
ALPHA SET R0
ALPHA SET 42*BETA ds Dene Space
Syntax:
DS 2+4
dw Dene Words
Syntax:
db Dene Bytes
Syntax:
DBIT <expr>
Example:
DBIT 4+2
INCLUDE <filename>
Example:
INCLUDE 'my file.asm'
ORG <expr>
Example:
ORG 0Bh
USING <expr>
Example:
USING 2
$DATE(string) $NOLI
Example:
$DATE(1965-12-31)
$nolist Don't list subsequent source lines
Syntax:
$DA(string) $NOLIST
Example:
$DA(1965-12-31)
$nomod Disable predened SFR symbols
Syntax:
$EJECT $NOMOD
Example:
$EJECT
$nomo Disable predened SFR symbols
Syntax:
$EJ $NOMO
Example:
$EJ
$nomod51 Disable predened SFR symbols
Syntax:
$INCLUDE(string) $NOMOD51
Example:
$INCLUDE(somefile.asm)
$paging Enable listing page formatting
Syntax:
$INC(string) $PAGING
Example:
$INC(somefile.asm)
$pi Enable listing page formatting
Syntax:
$LIST $PI
Example:
$LIST
$nopi Disable listing page formatting
Syntax:
$LI $NOPI
Example:
$LI
$nopaging Disable listing page formatting
Syntax:
$NOPAGING
48 CHAPTER 4. BUILD-IN MACRO-ASSEMBLER
Symbol Value
??MCU_8051_IDE 8051h
3
??VERSION 0139h
; DATA segment
dseg at 10q ; Start this segment at address 10 octal (8d)
my_d DATA 'd' ; Define address in internal data memory or SFR area
my_ds: DS 4 ; Reserve 4 bytes here and set ``my_ds'' to point there
; IDATA segment
iseg at 10d ; Start this segment at address 10 decimal
my_i IDATA 'i' ; Define address in internal data memory
my_is: DS 4 ; Reserve 4 bytes here and set ``my_is'' to point there
; BIT segment
bseg at 10b ; Start this segment at address 10 binary (2d)
my_bit BIT 'b' ; Define address in bit addressable area
my_bs: dbit 4 ; Reserve 4 bits here and set ``my_bs'' to point there
; XDATA segment
xseg at 10 ; Start this segment at address 10 decimal
my_x XDATA 'x' ; Define address in external data memory
my_xs: DS 4 ; Reserve 4 bytes here and set ``my_xs'' to point there
org address ; Start writing program code at address defined by symbol ``address''
• IF <condition>
• IFN <condition>
• IFDEF <symbol>
• IFNDEF <symbol>
• ELSE
• ELSEIF <condition>
• ELSEIFN <condition>
• ELSEIFDEF <symbol>
• ELSEIFNDEF <symbol>
• ENDIF
ifdef abc ;<--+ Assemble only if symbol abc has been defined
if ( abc = 13 ) ; | <--+ Assemble if 13 has been assigned to symbol abc
mov a, #01010101b ; | |
elseif ( abc = 14 ) ; | <--+ Assemble if 14 has been assigned to symbol abc
mov a, #0aah ; | |
elseifn ( abc % 2 ) ; | <--+ Assemble if the value assigned to symbol abc is even
mov a, #abc ; | |
else ; | <--+ Else ..
mov a, #377q ; | |
endif ; | <--+
elseifndef xyz ;<--+ Assemble if symbol xyz has NOT been defined
clr A ; |
else ;<--+ Else ...
ifn (xyz mod 2) ; | <--+ Assemble if ( yxz modulo 2 ) is 0
mov a, #128d ; | |
endif ; | <--+
endif ;<--+
if foo = 4d
nop
endif
subb A, #foo
endm
ijk 5
ijk 4
if foo = 4d
nop
endif
subb A, #foo
endm
xyz macro foo, bar
ijk foo
ijk bar
abc
endm
$ Location counter
A Accumulator
AB A/B register pair
C Carry ag (in PSW register)
DPTR Data pointer
PC Program counter
R0..R7 Registers
AND EQ GE GT HIGH
LE LOW LT MOD NE
NOT OR SHL SHR XOR
DA DATE EJ EJECT
LI LIST NOLI NOLIST
NOMACROSFIRST NOMO NOMOD NOMOD51
NOOBJECT NOPAGING NOPI NOPRINT
NOSB NOSYMBOLS OBJECT PAGELENGTH
PAGEWIDTH PAGING PI PL
PRINT PW SB SYMBOLS
TITLE TT
4.13. COMPATIBILITY WITH ASEM-51 59
Code listing contains entire source code which was assembled but with each
line prexed with line number and some additional information which will
be explained later. Besides the original code there is also table of symbols
dened during the assembly unless it was turned o. Code listing is divided
into pages separated by form feed character, this behavior may be altered by
certain assembler control sequences as well as page height and width.
Each line of code listing which contains original source code line may
contain beside line number also some additional information regarding the
compilation of the given line of code. Such a additional information might
look like this and is composed of these parts:
Control sequences aecting format of the generated code listing.
4.14. LIST FILE FORMAT 61
X Line number
X Level of le inclusion
X Level of macro expansion
X Address in code memory
X Machine code or another value to be stored in the code memory
X Value of a symbol
X Original line
of data. Hex les have usually extension .hex or .ihx. These les are text
les consisting of a sequence of records, each line line can contain at most
one record. Records starts with : (colon) character at the beginning of the
line and ends by end of the line. Everything else besides records should be
ignored. Records consist of a sequence of 8-bit hexadecimal numbers (e.g.
a2 or 8c). These numbers are divided into elds with dierent meaning,
see the example below.
: 0F 0000 00 E580F4F590E580F4F590E580F4F590 57
: 0F 000F 00 E580F4F590E580F4F590E580F4F590 48
: 0F 001E 00 E580F4F590E580F4F590E580F4F590 39
: 10 002D 00 E580F4F5907410B3758010B2907410B3 30
: 10 003D 00 758010B2902694052600940426940526 0A
: 10 004D 00 00940426009404269405E580F4F59026 8A
: 0B 005D 00 009404269405E580F4F590 63
: 00 0000 01 FF
X Start code
X Byte count
X Address
X Record type
X Data
X Checksum (two's complement of 8-bit sum of entire record, except for
the start code and the checksum itself)
00 Data record
Chapter 5
Disassembler
Disassembler is a tool intended to generate assembly language code from
an object le. In other words it has certain level of capability of reversing
the assembly process and regaining the original source code from any object
code. But there are some restriction to that capability and the whole thing
is not so simple after all. So let's discuss disassembly process deeper. In
MCU 8051 IDE you can invoke disassembler from the main menu Main
Menu → Tools → Disassemble.
As you can see from the example above, the code generated by disassem-
bler is the same as the original code. But of course original symbol names
have vanished as well as comments, indentation and other tiny details which
cannot be determined from the object code. This is caused by the simple fact
that the object code contains only the machine code. It contains no infor-
mation regarding how exactly the original code looked like. Just instructions
with their operands and data directly written to the code memory by DB
and DW directives. And here we are getting to the real problem which
emerges every time when you try to disassemble not exactly a simple code.
8051 instructions comprises of 1, 2 or 3 bytes, the rst byte determinates
what instruction are we dealing with and so what is its length in bytes. But
64 CHAPTER 5. DISASSEMBLER
if the original code contained directives DB or DW then the disassembler
thinks that these values are instructions too. If the disassembler consider
a arbitrary value given by DB or DW instruction to be an instruction, it
determinates its length according to its OP code (the 1st argument to the di-
rective). And so it takes 0, 1 or 2 bytes next and interprets them as operands
to that instruction. Then when it encounters a real instruction OP code it
might think of it as another operand to something and so misinterpret it.
Then you might end up with a code that is completely dierent from the
original code and makes no sense at all to human. But if you reassemble
such a non sense code with disabled peep hole optimization you must get
the original object code back, and its functionality must not be changed.
Even if the code seems to be absolutely non sense. In that case I strongly
recommend to use another disassembler than is the built-in one. Consider for
example D52 http://www.8052.com/users/disasm/. The built-in diassem-
bler is provided just for completeness, but its suitability for a real reverse
engineering is highly questionable.
END
65
Chapter 6
MCU simulator
Step Execute exactly one intruction, no matter how many machine cycles it
will take. This does not apply for macro-instruction, in that case each
instruction of the macro is executed separately.
Animate Do the same as step but in a loop, one after another until
stopped by a waring condition or user request.
Run This is generally the same as animate, but much faster, because GUI
is not updated so oten as in the animate mode.
(Step Back) Take back the last performed step. There is limited number
of step which can be taken back.
6.4 Limitations
1. UART simualation is limited in current version
2. SPI simulation is not implemented
3. Simulation of reduced power consumption modes is not supported
4. Simulated MCU is many times slower the real one would be on normal
conditions
6.5. VIRTUAL HARDWARE 67
communications with the simulated MCU and in- and its log window
1 Radio buttons that means that one one key can be pressed at the time and when you
press another key, the originally pressed key will return back to non pressed state
70 CHAPTER 6. MCU SIMULATOR
Chapter 7
7.1 Foreword
# Is plugin busy ?
proc is_busy {} { ...; return <BooleanValue> }
7.3. USING MCU 8051 IDE API 73
When you have these steps completed you have prepared basic environment
for the plug-in. Then the HW plug-ins manager in the right panel in IDE's
GUI should now recognize your plug-in and be able to attempt to load it. If it
is not so, then there is denitely something wrong. Any other les which your
plug-in consist of and just whatever you want there should be placed in your plug-
in directory (1). And the initialization le should do nothing else than source
some real plug-in's le(s) and call appropriate functions inside them. One more
important thing, the plug-in runs it dynamically assigned namespace. Take it
into account, otherwise your plug-in wont work! Function init takes the name of
this namespace in parameter current_namespace. So as you can see, it's quite
easy you have just to dene 4 variables and 5 functions and you can interface with
the IDE.
## Get full name of file which is currently displayed in the source code editor
# @return String - Full file name including path or empty string in case there is no project opened
proc get_current_file {}
## Get full name of file which has been chosen as the project main file
# @return String - Full file name or empty string
proc get_project_main_file {}
proc dispose {} {
tk_messageBox \
-title "My First Plug-in" \
-message "Called: dispose {}"
}
proc save_session {} {
tk_messageBox \
-title "My First Plug-in" \
-message "Called: save_session {}"
return "my data, time: [clock format [clock seconds] -format {%T}]"
}
proc is_busy {} {
return [expr {
[tk_messageBox \
-title "My First Plug-in" \
-message "Called: is_busy {}" \
-type {yesno}
]
== {yes}}]
}
acter as line end delimiter. In other words Unix line termination sequence.
• Although it is possible to name the plug-in directory in any way what your OS
accept. It is generally a good idea to follow the mentioned recommendation.
At least the name of the initialization le have to follow the mentioned
recommendation.
Chapter 8
Command Line Interface
MCU 8051 IDE's CLI makes it possible to use entire IDE just as an assembler,
disassembler or converter between .hex les and binary les. MCU 8051 IDE sup-
ports these switches:
Switch Meaning
General
help, -h Show help for CLI
quiet, -q Do not who initialization progress on start-up
nosplash Do not show the splash screen
nocolor, -n Do not show colorful output in console
version, -V Show program version and exit
defaults Ru program in empty session
minimalized Run in minimalized window
config-file filename Specify path to an alternative conguration le
check-libraries Verify whether all required libraries are available
ignore-last-session Start with an empty session
open-project project Open just this project
reset-user-settings Reset all user setting to defaults
Data conversions
auto-indent input Reformat indentation the specied le
hex2bin input output Convert Intel 8 Hex into a binary le
bin2hex input output Convert a binary le in Intel 8 HEX
sim2hex input output Convert MCU 8051 IDE simulator le to Intel 8 Hex le
sim2bin input output Convert MCU 8051 IDE simulator le to binary le
normalize-hex input Normalize Intel 8 HEX (force incremental addressing order)
Assembler/Disassembler
disassemble hex_file Disassemble Intel 8 HEX le to hex_le.asm
assemble asm_file Assemble the specied le
compile asm_file The same as assemble
iram-size size Set size of internal data memory for assembler
code-size size Set size of program data memory for assembler
xram-size size Set size of external data memory for assembler
no-opt Disable peephole optimization
comp-quiet Suppress text output from the assembler
no-sim Disable generation of .adf le
no-bin Disable generation of .bin le
no-lst Disable generation of .lst le
78 CHAPTER 8. COMMAND LINE INTERFACE
Switch Meaning
no-hex Disable generation of .hex le
warning-level 0-3 Set warning level to the specied level
Interesting examples:
# Use MCU 8051 IDE as convertor from binary files to Intel 8 HEX (without GUI)
mcu8051ide --bin2hex /some_directory/my_file /some_directory/my_file.hex
79
Chapter 9
Translating the IDE into dierent
languages
The IDE can be translated to almost any language. The translation can be ac-
complished by creating of a translation denition le. Such a le must follow
certain strict rules in order to work properly. Translation les are normally located
in directory /usr/share/mcu8051ide/translations, on Microsoft
R Windows
R the
Appendix A
License
MCU 8051 IDE and all its compo- Whether that is true depends on what the Program does.
nents is distributed under terms of GNU 1. You may copy and distribute verbatim copies of the Programs
GPLv2. source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
GNU GENERAL PUBLIC LICENSE
notices that refer to this License and to the absence of any warranty;
Version 2, June 1991
and give any other recipients of the Program a copy of this License
along with the Program.
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
You may charge a fee for the physical act of transferring a copy, and
Everyone is permitted to copy and distribute verbatim copies
you may at your option offer warranty protection in exchange for a fee.
of this license document, but changing it is not allowed.
2. You may modify your copy or copies of the Program or any portion
Preamble
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
The licenses for most software are designed to take away your
above, provided that you also meet all of these conditions:
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
a) You must cause the modified files to carry prominent notices
software--to make sure the software is free for all its users. This
stating that you changed the files and the date of any change.
General Public License applies to most of the Free Software
Foundations software and to any other program whose authors commit to
b) You must cause any work that you distribute or publish, that in
using it. (Some other Free Software Foundation software is covered by
whole or in part contains or is derived from the Program or any
the GNU Library General Public License instead.) You can apply it to
part thereof, to be licensed as a whole at no charge to all third
your programs, too.
parties under the terms of this License.
When we speak of free software, we are referring to freedom, not
c) If the modified program normally reads commands interactively
price. Our General Public Licenses are designed to make sure that you
when run, you must cause it, when started running for such
have the freedom to distribute copies of free software (and charge for
interactive use in the most ordinary way, to print or display an
this service if you wish), that you receive source code or can get it
announcement including an appropriate copyright notice and a
if you want it, that you can change the software or use pieces of it
notice that there is no warranty (or else, saying that you provide
in new free programs; and that you know you can do these things.
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
To protect your rights, we need to make restrictions that forbid
License. (Exception: if the Program itself is interactive but
anyone to deny you these rights or to ask you to surrender the rights.
does not normally print such an announcement, your work based on
These restrictions translate to certain responsibilities for you if you
the Program is not required to print an announcement.)
distribute copies of the software, or if you modify it.
These requirements apply to the modified work as a whole. If
For example, if you distribute copies of such a program, whether
identifiable sections of that work are not derived from the Program,
gratis or for a fee, you must give the recipients all the rights that
and can be reasonably considered independent and separate works in
you have. You must make sure that they, too, receive or can get the
themselves, then this License, and its terms, do not apply to those
source code. And you must show them these terms so they know their
sections when you distribute them as separate works. But when you
rights.
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
We protect your rights with two steps: (1) copyright the software, and
this License, whose permissions for other licensees extend to the
(2) offer you this license which gives you legal permission to copy,
entire whole, and thus to each and every part regardless of who wrote it.
distribute and/or modify the software.
Thus, it is not the intent of this section to claim rights or contest
Also, for each authors protection and ours, we want to make certain
your rights to work written entirely by you; rather, the intent is to
that everyone understands that there is no warranty for this free
exercise the right to control the distribution of derivative or
software. If the software is modified by someone else and passed on, we
collective works based on the Program.
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
In addition, mere aggregation of another work not based on the Program
authors reputations.
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
Finally, any free program is threatened constantly by software
the scope of this License.
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
3. You may copy and distribute the Program (or a work based on it,
program proprietary. To prevent this, we have made it clear that any
under Section 2) in object code or executable form under the terms of
patent must be licensed for everyones free use or not licensed at all.
Sections 1 and 2 above provided that you also do one of the following:
The precise terms and conditions for copying, distribution and
a) Accompany it with the complete corresponding machine-readable
modification follow.
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
0. This License applies to any program or other work which contains
cost of physically performing source distribution, a complete
a notice placed by the copyright holder saying it may be distributed
machine-readable copy of the corresponding source code, to be
under the terms of this General Public License. The "Program", below,
distributed under the terms of Sections 1 and 2 above on a medium
refers to any such program or work, and a "work based on the Program"
customarily used for software interchange; or,
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
It is not the purpose of this section to induce you to infringe any If the program is interactive, make it output a short notice like this
patents or other property right claims or to contest validity of any when it starts in an interactive mode:
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is Gnomovision version 69, Copyright (C) 19yy name of author
implemented by public license practices. Many people have made Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w.
generous contributions to the wide range of software distributed This is free software, and you are welcome to redistribute it
through that system in reliance on consistent application of that under certain conditions; type `show c for details.
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot The hypothetical commands `show w and `show c should show the appropriate
impose that choice. parts of the General Public License. Of course, the commands you use may
be called something other than `show w and `show c; they could even be
This section is intended to make thoroughly clear what is believed to mouse-clicks or menu items--whatever suits your program.
be a consequence of the rest of this License.
You should also get your employer (if you work as a programmer) or your
8. If the distribution and/or use of the Program is restricted in school, if any, to sign a "copyright disclaimer" for the program, if
certain countries either by patents or by copyrighted interfaces, the necessary. Here is a sample; alter the names:
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding Yoyodyne, Inc., hereby disclaims all copyright interest in the program
those countries, so that distribution is permitted only in or among `Gnomovision (which makes passes at compilers) written by James Hacker.
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License. <signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will This General Public License does not permit incorporating your program into
be similar in spirit to the present version, but may differ in detail to proprietary programs. If your program is a subroutine library, you may
address new problems or concerns. consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Each version is given a distinguishing version number. If the Program Public License instead of this License.
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
83
Appendix B
Regression testing
B.1 Foreword
The IDE is featured with a regression test-
ing environment, the aim of this to make
the software as reliable as possible. Cur-
rently there is prepared environment for
testing the simulator engine and the built-
in assembler. This allows to write test
cases for specic software features and
check whether the results of these tests
conform to expected results. Regretfully Figure B.1: Assembler regression test
testcases directory also contains les intended for comparison with les generated
during the test and stored in the results directory, these les must have extension
.<x>.exp. Where <x> must be substituted with extension of a le which this
le is supposed to be compared to. In another words, if I want to check whether for
example ./results/something.abc was generated as it should be, I have to create
le ./testcases/something.abc.exp and this le will be automatically compared
with ./results/something.abc.
And that's it! This is simple, isn't it? It's just about comparing les. But how
are the tests run and how the les in the results directory gets generated? For
that we need some Bash script, which is used to run the test, let's call this script
the runtest script. The runtest script must be located in the test directory and
must include the rte.lib.sh le, using the source command (or '.' command).
This script should have set permissions to be executable and this script species
how exactly should be the test performed and also runs the test itself.
When the script is about to exit, this condition is trapped and the 'rte.lib.sh'
reacts by starting the test. So there is no need to explicitly run the test by invoking
some function or something like that. It runs the test automatically when there is
nothing else left to do.
85
Appendix C
Project web page and other media
Figure C.1: Ocial web page of the MCU 8051 IDE project
86APPENDIX C. PROJECT WEB PAGE AND OTHER MEDIA
1. Install GIT
3. Once you have an existing copy of the repository you can just update it each
time when you want the fresh version by this command:
git fetch origin master
4. Then you can try the downloaded IDE version without installation using the
following sequence of commands (for POSIX only)
(a) cd mcu8051ide/lib
(b) ./main.tcl
5. Or install it and the use it using the following sequence of commands (for
POSIX only)
(a) cd mcu8051ide
(b) ./configure && make
(c) sudo su # or just "su"
(d) make install
87
Appendix D
8051 Instructions in numerical
Order
Opcode Mnemonic Operands Bytes Flags Cycles
0x00 NOP 1 1
0x01 AJMP code11 2 2
0x02 LJMP code16 3 2
0x03 RR A 1 1
0x04 INC A 1 P 1
0x05 INC data 2 1
0x06 INC @R0 1 1
0x07 INC @R1 1 1
0x08 INC R0 1 1
0x09 INC R1 1 1
0x0A INC R2 1 1
0x0B INC R3 1 1
0x0C INC R4 1 1
0x0D INC R5 1 1
0x0E INC R6 1 1
0x0F INC R7 1 1
0x10 JBC bit code8 3 2
0x11 ACALL code11 2 2
0x12 LCALL code16 3 2
0x13 RRC A 1 CY P 1
0x14 DEC A 1 P 1
0x15 DEC data 2 1
0x16 DEC @R0 1 1
0x17 DEC @R1 1 1
0x18 DEC R0 1 1
0x19 DEC R1 1 1
0x1A DEC R2 1 1
0x1B DEC R3 1 1
0x1C DEC R4 1 1
0x1D DEC R5 1 1
0x1E DEC R6 1 1
0x1F DEC R7 1 1
0x20 JB bit code8 3 2
0x21 AJMP code11 2 2
APPENDIX D. 8051 INSTRUCTIONS IN NUMERICAL
88 ORDER
Appendix E
8051 Instructions in alphabetical
order
Opcode Mnemonic Operands Bytes Flags Cycles
0x11 ACALL code11 2 2
0x31 ACALL code11 2 2
0x51 ACALL code11 2 2
0x71 ACALL code11 2 2
0x91 ACALL code11 2 2
0xB1 ACALL code11 2 2
0xD1 ACALL code11 2 2
0xF1 ACALL code11 2 2
0x24 ADD A #imm8 2 CY AC OV P 1
0x25 ADD A data 2 CY AC OV P 1
0x26 ADD A @R0 1 CY AC OV P 1
0x27 ADD A @R1 1 CY AC OV P 1
0x28 ADD A R0 1 CY AC OV P 1
0x29 ADD A R1 1 CY AC OV P 1
0x2A ADD A R2 1 CY AC OV P 1
0x2B ADD A R3 1 CY AC OV P 1
0x2C ADD A R4 1 CY AC OV P 1
0x2D ADD A R5 1 CY AC OV P 1
0x2E ADD A R6 1 CY AC OV P 1
0x2F ADD A R7 1 CY AC OV P 1
0x34 ADDC A #imm8 2 CY AC OV P 1
0x35 ADDC A data 2 CY AC OV P 1
0x36 ADDC A @R0 1 CY AC OV P 1
0x37 ADDC A @R1 1 CY AC OV P 1
0x38 ADDC A R0 1 CY AC OV P 1
0x39 ADDC A R1 1 CY AC OV P 1
0x3A ADDC A R2 1 CY AC OV P 1
0x3B ADDC A R3 1 CY AC OV P 1
0x3C ADDC A R4 1 CY AC OV P 1
0x3D ADDC A R5 1 CY AC OV P 1
0x3E ADDC A R6 1 CY AC OV P 1
0x3F ADDC A R7 1 CY AC OV P 1
0x01 AJMP code11 2 2
0x21 AJMP code11 2 2
APPENDIX E. 8051 INSTRUCTIONS IN ALPHABETICAL
94 ORDER
Appendix F
List of supported
micro-controllers
F.0.1 Intel
R
8051 http://download.intel.com/design/MCS51/MANUALS/27238302.pdf
80C51 http://download.intel.com/design/MCS51/MANUALS/27238302.pdf
8052 http://download.intel.com/design/MCS51/MANUALS/27238302.pdf
F.0.2 Atmel R
Flash (Reprogramable)
AT89C2051 http://www.atmel.com/dyn/resources/prod_documents/doc0368.pdf
AT89C4051 http://www.atmel.com/dyn/resources/prod_documents/doc1001.pdf
AT89C51 http://www.atmel.com/dyn/resources/prod_documents/doc0265.pdf
AT89C51RC http://www.atmel.com/dyn/resources/prod_documents/doc1920.pdf
AT89C52 http://www.atmel.com/dyn/resources/prod_documents/doc0313.pdf
AT89C55WD http://www.atmel.com/dyn/resources/prod_documents/doc1921.pdf
AT89LV51 http://www.atmel.com/dyn/resources/prod_documents/doc0303.pdf
AT89LV52 http://www.atmel.com/dyn/resources/prod_documents/doc0375.pdf
AT89LV55 http://www.atmel.com/dyn/resources/prod_documents/doc0811.pdf
ROM
T83C5102 http://www.atmel.com/dyn/resources/prod_documents/doc3c0c80904bc57.pdf
TS80C32X2 http://www.atmel.com/dyn/resources/prod_documents/doc4184.pdf
TS80C52X2 http://www.atmel.com/dyn/resources/prod_documents/doc4184.pdf
AT80C58X2 http://www.atmel.com/dyn/resources/prod_documents/doc4431.pdf
AT87C54X2 http://www.atmel.com/dyn/resources/prod_documents/doc4431.pdf
AT87C58X2 http://www.atmel.com/dyn/resources/prod_documents/doc4431.pdf
TS80C54X2 http://www.atmel.com/dyn/resources/prod_documents/doc4431.pdf
TS80C58X2 http://www.atmel.com/dyn/resources/prod_documents/doc4431.pdf
TS87C54X2 http://www.atmel.com/dyn/resources/prod_documents/doc4431.pdf
AT80C52X2 http://www.atmel.com/dyn/resources/prod_documents/doc4184.pdf
TS87C58X2 http://www.atmel.com/dyn/resources/prod_documents/doc4431.pdf
ROMless
TS80C31X2 http://www.atmel.com/dyn/resources/prod_documents/doc4428.pdf
AT80C31X2 http://www.atmel.com/dyn/resources/prod_documents/doc4428.pdf
101
Appendix G
Change log
1.3.11 -> 1.4
* Bug fixes
* Added new Virtual HW component: LCD display controlled by HD44780
* Added new Virtual HW component: simulated DS1620 temperature sensor
* Added new Virtual HW component: File interface
* Added AT89S51
* Improved performance of Virtual HW
* Added support for spelling checker (Hunspell)
* Added 8051 Instruction table
* Improved table of symbols on the right panel
* Final draft of the handbook
* Bug fixes
List of Tables
1 Software requirements . . . . . . . . . . . . . . . . . . . . . . . . . 6
List of Figures
2.1 MCU 8051 IDE with the demonstration project opened within it . 13
2.2 Project creation dialog . . . . . . . . . . . . . . . . . . . . . . . . . 14