Download as pdf or txt
Download as pdf or txt
You are on page 1of 151

Sudan Academy of Sciences ( SAS)

Atomic Energy Council

Design and building of home made 8051


Microcontroller Emulator

By
A b d c l m o n c i m Elobeid Hussein
iVI.Sc. in E l e c t r o n i c s E n g i n e e r i n g
U n i v e r s i t y of K h a r t o u m ( 2002)

A T h e s i s S u b m i t t e d to the S u d a n A c a d e m y of S c i e n c e s
In Fulfillment of the R e q u i r e m e n t s for D o c t o r of Philosophy
D e g r e e P h . D . in Electronics E n g i n e e r i n g

Supervisor
D r . A b d Elrasol G a b a r Elzobaidi

September 2009
Sudan A c a d e m y of Sciences ( S A S )

Examination c o m m i t t e e

Name

External e x a m i n e r Dr. Sid A h m e d Ibrahim

Internal e x a m i n e r Dr. P'arouk Idris llabbani

Supervisor Dr. Abdelrasoul G a b a r Hlzobaidi


Dedication

l
l'or wfwm tfwy tfiougfit we are of their concern
^L&J all uu i a o uu ^ i « J & J l ( J i c -llLa t - L u 5 ^jrti <Vi I t ^ * i m l <—L^Jl IJA
4 . Ij&lM \ »J*-»lL) 3 j^JtjjULa ^ »_L>Ua]|j ac-LiU , A . O \ J j j L i l l

SbVI j l nr.J j j — V A J ^ 1 J J ^ U I SbV ^ J J ^ ^ I J>\jd\ j CjL^ajjJ]


. L p j . 1 .As*-* ialJLi j I^JIJJILU 3JJJJ v b b y j ISjAi^a
^ j j S j J l ^ a J L x J l S ^ a . j (j^ia ^ . l . ^ l . n l <_U*Jl IJtA J.Je»S ^JJjjjfUVI J » l j - i H
^ j J n-> j i j j j cSjLc- C l l l j % a j j j l Lai . d l j j l-t")!! (jiaxJ £ - a (
-^*-LJl
j_c V JJ o > — % ojSI-ll) d i b A j j ^ a J l C J l A a a J t d i a l V i n a ) 4 .aS'i j»£jkloll

<L«AJ ^ J j La S o l e ^ iViiii,all j j - a l i j j J LSIj-aj <<• « j i > i a t i C_>jxl-tll j L j - a . £<e ( J ^ l j a i l

.^jlaJl SjSlill
J- . j l l l <• i u ? i « l l «_1 axubJl ^ J c <4_al.lklu>l j£-aJ 1 >ji>i<i\l L_]jiJ-»ti ^ J c ^ A j l a ^ ^ a U j j ^ 1
J—jl (J}* «JJ J « J «, i j i n a i l <-_) a ml ->It ^ i f i . J L i ^ l j j Vi« i H Ijj <_JJ|JA!I £ - » U J J J | £ < *

a> A i _ J ajoibJl AjLuol Aft J u l (Jj^»"n I—l3tj<a)l ^ _aiJ >*ll.1> j -llialt


.^1%"ujall <jj.il UalLaj I 111 mi l_lSl J A J I g^aUjlil ( J a A U

jj «J^ Ull 4JSJJ.H j £ l j i l l 4 j k - a j > A i ' j l j C i l f l j j l l (jlfi .hjtaj>\t


^ a ) j — j l^lwv 4J&yajf 4JJ a j j i l V I » J j l aJ ^ AJSJJ J^'j^ ^ - ^ J A ^ a l _ ) j ( j j _ ^ i a j j»>-%1niolt
S^l_Ji L ^ a i U a A^jJA ijfrV^S V J L^W^J jLaj ft^c liliiS . J ^ai OXJ LJlSfc ^ J i L I

J__JS jjfjl.^iail ^ a U j J l i j a j J l SjSlill AjLp3 AJIJJ AJJ^J ( _ l l k u IJA l - l S > a . l i l l i j jc-ajuU

k l l l l - S o 3 _ j j b j ^-1 a—li < i i j J ^ J V I J J ^ k i l l J J I J x ^ J «JUb ^ _ > J l S j S l i l l S j 4 . U a . 4 l a a . J J

.(JjJ-llI ^ V i a l l J > ? . a ^ i—lSljaJl ^ a l j j j J l j l LaJUa l ^ - \ j j n j$-»J

Jl > j i J j l ^ ci«x]l IJUb j l i t J J aiaSlI A j L a C Col ^ I r a t i j»Al g j i j u l l < L * j « 1j n « «

^—Sc. ( d l l — i M a j j i i l ^ j - a l « V I ^ji-iwil gtJlii^ <Uja-aJl j j j u ^ l l l 4 i>.ili<i,llj J j l a J l ji»xj

^uukll t ^ r i . t i l t i $ . l j a . V I t j L u i V 4 j i i l l t j i i j a J l nJjjMSlI < £ j A j i ) l (£A ^ . I - ^ I M I / i l l ^alijJ

^ — ^ I j V I J - a «J J a v i l "ajJ j £ l ia^li^J Lk J L > J | jS^aj ^yjil <• « j i h a t i l_l j»»il->ll ^ a (J^a\jjl)j

. j i J J j»J j J a ^ J l j * i j S «jl i^-full t ' l l i-s ajj (jLt t->'inall ^ a U j j A-a^-ail

3—uibvlt ^. a J u a l jSll J uiLuull frLu-all ^,\^*iiaj lilj-ail ^ U J J J ^ ^ W J£^3>-^

d—^yik ^—US J ? »>-» i j l J i « y V i J (jJka. jl a^vmall (j^i ^ ' 'J'^oti


j a(
— J
— Ua
J j 4 j A . j l i J l S j S l J l l ^ - 3 <Uxa^J ^ J J ^ A ^ l u u J l ^ - a l j j j .<Sk^aUjJ ^^JLaLalll
. j b i . J ^ I S ^joi.-Vill IJA j l j l I J I ^ r j i J l 3 ; J i . . } l l J j j l j < a J ^ a x j t 'tj'ii.i ( j l ^AajUiball
L_I j uilaJl ^ l c ,\t Villi J J j'»•!».i JJ jiaj IJl L i j b k j l jirsll a ^ j n l l t"i\jJoft
^ S Sj—j i % i l ^ jjjll a ( a (.\ S J J J S I ( J i - a l jp ( J ^ * i l-Ub C_lSlj-all g t - a l j j j (JA1*J ^»JJ <_kuia-ajl
• I. t j i X n i l C - l j i l l i c i t

11
ABSTRACT

This research targeted design and build of a simple lab made emulator fur the 8051
microcontroller to assist student and researcher in their projects. This will be achieved by
thorough understanding of the software and the hardware of the development tool which
will enliance the user knowledge rather limn considering them as black boxes and
unaware of their capabilities and their limitations.
Regarding the hardware this work preferred to use the same central processing unit the
developer wanted to build with little modification. While the software is a program
loaded in the microcontroller itself responsible (making use of flash microcontrollers) for
communication with the host computer terminal, and monitoring the user program which
is loaded in the external memory by the program.
Any terminal program on the host computer can be used to carry out communication with
monitor program provided that a carriage return should be pressed after monitor power
up to let the monitor adjust its baud rate accordingly. This feature makes the monitor
program so simple and familiar to the user.
For simplicity the software is enhanced with flash programming and erasing subroutine
which can allow the user to store his program there if he put a flash ROM in his hardware
and he can make it as start up program which will run automatically after start up. Also
many programs can be loaded in the flash as long as its capacity is capable Definitely
this requires configuring flash start and end in the source before compiling it. This flash
feature allows the development liardware to be as final board and hence a debugable one
as long us monitor program resides inside the microcontroller.

Considering the debugging stage as the most crucial step in the development cycle, this
work tried to find some suitable and simple solutions that can enhance knowledge. As a
result some commands on the user program like uploading, downloading, displaying,
jumping, selecting among others, running, editing, clearing and communicating with the
host PC can be carried out efficiently. But unfortunately some significant commands on
the user program like tracing, pausing and single stepping were not met.
It is worth mentioning tliat the monitor program is using the serial port for
communication with the host PC, so the user has to be careful not to change any register

iii
involved in serial communication in his program. Also the user program is loaded in the
external memory and the user is required to add some I/O ports if he needs this design a s
last setup.
Tracing and single stepping could be accomplished if some host PC emulation program is
developed and this monitor program is modified to carry out more intelligent
communication with the new host PC environment.

iv
ACKNOWLEDGEMENTS

I gratefully acknowledge Coskim HARMANSAH and Mehmel BAYBURT for their advice
and supervision which represents the backbone of this research and so to this thesis. It is a
pleasure to convey my gratitude to them all in my humble acknowledgment.

In the first place 1 would like to record my gratitude to Coskun H A R M A N § A H for his
supervision, advice, and guidance from the early stage of this research as well as giving me
extraordinary experiences through out the work. Many thanks g o in particular to Serdar
AKDURAK I am much indebted to AKDURAK for his valuable advice in science discussion
and supervision I gratefully thank them for their constructive comments on this thesis.

I would like to thank Pcrihau UNAK and Meral KRAI, for giving me the opportunity to work
on Electronic l.ab equipment in Institute of Nuclear Science in Ege University in Izmir. T o
Mehmet Bayburt, thank for his technical assitances during work I had in Izmir.

I would also like to thank M. Muslim SAC; and Onui KAHVECi for their collobration and
their willingness to share their bright thoughts with me, which were very fruitful for shaping
up my ideas and research.

It is a pleasure to express my gratitude wholeheartedly to Siileyman ERKUT, Giingor POLAT


and their family for their kind hospitality during my stay in Izmir. I would like to express
special thanks to Siileyman ERK.UT for his indispensable help dealing with travel funds,
administration and buieaucratic matters during my stay in Izmir.

I cannot end without thanking my family, on whose constant encouragement and love I have
relied throughout my time during this work. Words fail me to express my appreciation to my
wile Sehna whose dedication, love and persistent confidence in me, has taken the load off my
shoulder.

v
Finally, 1 would like to thank everybody who was important to the successful realization of
this thesis, as well as expressing my apology that I could not mention personally one by one. 1
am grateful in every possible way and hope to keep up our collaboration in the future.

vi
Table of contents
1
Dedication

Arabic abstract ii
Abstract tv

Acknowledgement v

Table of contents vii

List of figures xi

List of tables xiii

Abbreviations xiv

Chapter One: Introduction I

1.1 Background I

1.2 Problem statement 2

1.3 Objectives 2

1.4Melhodology / -

1.5 Research outlines 4

Chapter Two: 8051 Microcontroller 6

2.1 8051 Microcontroller Review 6

2.1.1 Why embedded systems 7

2.1.2 Why 8051 microcontroller 7

2.1.3 8051 Important features 8


2.1.4 8051 Programming 9
2.1.5 8051 Related processors 9
2.2 Memory Organization 1°

2.2.1 External Code Memory 11

2.2.2 External RAM Data memory II

2.2 3 Internal Memory 12

2.2.3.1 Register Banks (O0h to IFh) 12

2.2.3.2 Bit Addressable RAM (20h to 2F) 13

2.2.3.3 General Purpose RAM (30h to 7Fh 14

2.2.4 SFR Registers 14

vii
2.2.4.1 Program Status Word (PSW) register 16

2.2.4.2 Power Control (PCON) register 17

2.2.4.3 rimer/Counter Mode Control (TMOD) register 18

2.2.4.4 Serial Control (SCON) register 19

2.2.4.5 Interrupt Enable (IE) register 21

2.2.4 6 Interrupt Priority (IP) register 21

2.2.4.7 Timer /Counter 1 Control (TI CON) register 2 2

2.2.4.8 Timer/ Counter2 Control ( T 2 C 0 N ) register 2 3

2.3 8051 Addressing modes 2 5

2.3.1 Direct addressing 2 5

2.3.2 Indirect addressing 2 5

2.3.3 Indexed addressing 2 5

2.3.4 Register instruction 2 5

2.3.5 Register specific instruction 2 5

2.3.6 Immediate constants 2 5

2.4 Circuit I lardwarc 26

Chapter Three: Development Tool 31

3.1 Creating a New Project 32

3.2 Building the Project 37

3.3 Debugging the Project 37

3.4 CPU Simulation 39

Chapter Four: Emulation Concept 40

4.1 Writing Microcontroller Code 40

4.2 Translating the Code 41

4.3 Debugging the Code 41

4.3 I Simulators 4 2

4.3.2 Monitors 4 3

4.3.3 Emulators 4 3

4.3.3.1 Emulation control logic and emulation Memory 4 3

4.3.4.3.2 The emulation device 4 4

4.3.3.3 The pinout adaptor 4 4

viii
4.4 Programming Microcontrollers 45

4 4.1 Out - o f - Circuit Programming 4 5

4.4.2 In System Programming 4 5

4.5 Emulation Technical Approaches 46

4.5.1 Base unit and probecard 4 6

4.5.2 Debug board Module 4 7

4.5.3 Dedicated emulators 4 7

4.5.4 Emulators Using Microcontrollers Flash Memory 4 7

Chapter Five: Debugging Strategies 49

5.1 Integrated Development Environment IDE Simulator 50

5.2 In System Debugging 51

5.3 Software JSD Techniques 51

5.3.1 Terminal Based General - Purpose Monitor 51

5.3.2 Terminal Based On-Chip MSC Monitor Program 53

5.3.3 IDE-Based Monitor MON51 54

5.3.4 IDE-Based Monitor ISD51 55

5.4 Hardware ISD Techniques 5 6

5.4.1 In-Circuit Emulator 5 6

5.4.2 Built- In Debug Module (BDM) 5 7

Chapter Six: Software Developed 58

6.1 Monitor Program 58

6.1.1 Initialization parameters and interrupt vectors 6 4

6.1.2 Serial I/O subroutines 6 5

6.1.3 Main menu and monitor user commands 6 6

6.1.4 Memory Management Subroutines 6 8

6.1.5 Power On and Initialization 6 9

6.1.6 Multiplication and Division 7 0

6.1.7 Multi-byte Sequence and Compressed Data Processing 7 0

6.2 Pre-design Stage (Structuring and Modularity) 7 2

6.3 Post-design Stage (Maintenance and Modification) 7 2

6.4 Program Development 77

ix
6.4.1 Creating the project 7 7

6.4.2 Building the project 8 3

6.4.3 Debugging the project 83

Chapter Seven: Results and Discussion 85

Chapter Eight: Conclusion and Recommendations 91

References 9 3

Appendix A 9 4

x
List of figures

2.1 8051 block diagram 6

2.2 8051 chip using external memory 10

2.3 8051 memory organization 11

2.4 Organization of the 8051 internal memory 14

2.5 Special Function Register layout 15

2.6 Circuit diagram of the 8051 board 28

2.7a Top layer (component side) PCB 29

2.7b Bottom layer (solder side) PCB 29

2.8a Top layout (component side) of the board 30

2.8b Bottom layout (solder side) of the board 30

3.1 Development tool features debugging The Code 32

3.2 Open new project debugging tools 33

3.3 Create a new folder 33

3.4 Select devices for target 34

3.5 Open a new file 35

3.6 Adding file to the project 35

3.7 Selecting file to add to the project 36

3.8 Selecting HEX tile output 36

3.9 Start debugging 38

3.10 Program execution 39

5.1 MSC Debugging Strategies Tree 49

5.2 Block diagram of an IDE simulator Concept 50

5 3 Monitor Conceptual Block Diagram 52

6.1 Parameters initialization 59

6.2 Power on segment 59

6.3 Main menu 60

6.4 a, b Initialization segment How chart 61-62

6.5 asc2hex subroutine 73

6.6 pstr subroutine 74

xi
6.7 Run routine 75-76-77

6.8 Create new project 78

6.9 Make new folder 79

6.10 Select device 79

6.11 Make new file 80

6.12 Add file to targe 81

6.13 Create hex file window 82

6.14 Building process 83

6.15 Debugging process 84

7.1 Building the project 85

7.2 Testing the project 85

7.3 Running of the Help command of the program 86

7.4 Running the displays to see the internal RAM 86

7.5 Display of the clear command running 87

76 Downloading some program 88

7.7 Running some user program 89

xii
List of tables

2.1 Different 8051 microcontroller produced by Intel

2.2 Special Function Register names, symbols and addresses

2.3 Program Status Word (PSW) bits distribution

2.4 Power Control (PCON) register bits distribution

2.5 Timer/Counter Mode Control(TMOD) register bits distribution

2.6 Serial Control (SCON) register bits distribution

2.7 Interrupt Enable (IE) register bits distribution

2.8 Internipt Priority (IP) register bits distribution

2.9 Timer/counter Control (TCON) register bits distribution

2.10 Tinier/counter2 Control (T2CON) register bits distribution

xiii
Abbreviations

3): Liquid Crystal Display


HE: Integrated Development Environment
5C: Micro System Controller
): In system Debugging
0: Input and Output
uvT: Universal Asynchronous Receiver & Transmitter
',: Micro Controller
»: AG Semiconductors Company
fl>: NXP Semiconductors company
: Semiconductors company
SC 51: Micro System Controllers 1
40S: N channel Metal Oxide Semiconductor
K)S: Complementary Metal Oxide Semiconductors
D: Central Processing Unit
\M: Random Access Memory
DM: Read Only Memory
I: Kilobyte
IZ: Mega Hertz
,abs: Silicon Labs
): lnter-lntegrated Circuit
I: Serial Paralegal Interface
5PR0M. Electrically Erasable Programmable Read Only Memory
KB: Universal Serial Bus
RVM: Pulse Width Modulation
vD: Analog to Digital
rl A: Digital to Analog
iTC: Real Time Clock
: Data Pointer
plOM: Programmable Read Only Memory
0 - R 7 : RegisterO - Register 7
PROM: Erasable Programmable Read Only Memory

xiv
5W: Program Status Word
K: Special Function Registers
>-P3:PortO Port.t
Dc: Accumulator
Stack Pointer
1: Data Pointer Low byte
»H: Data Pointer High byte
: Interrupt Priority Control Register
: Interrupt Enable Control Register
CD: Timer/Counter Counters Mode Control Register
X)N .Timer/Counter Control Register
ICON: Timer /Counter 2 Control Register
10: Timer / Counter 0 I ligh byte
c Timer / Counter 0 Low byte
II: Tinier/Counter 1 High byte
,1: Timer /Counter I Low byte
12 Tinier / Counter 2 High byte
2: Timer / Counter 2 Low byte
2AP2H. Timer2 Capture Register High byte
2AP2L Timer2 Capture Register Low byte
JON: Serial Control Register
W. Serial Data Buffer
JON. Power Control Register
40D: Serial Mode Control Register
rtOD: Timer /Counter Mode Control Register
J: Personal Computer
X)N: Serial Control Register
: Interrupt Enable Register
: Interrupt Priority Register
: Integrated Circuit
EN. Program Strobe finable
AL: Crystal
(CD: Transmitted Data
tD: Received Data

xv
: Printed Circuit Board
C: Hexadecimal
SI: Compiler for 8051 instructions
: Assembler for 8051 instructions
P: One Time Programmable
DII: American Standard Code for Information Interchange
): Programmable Logic Device
F:Zero Insertion Force
: In-System Programming
4: Debug Board Module
KG: Joint Test Action Group for boundary scan
): In-System Debugging
I: Graphical User Interface
[: In -Circuit Emulator
: Built-in Debugger Module
HN51: Monitor program for 8051

: Write
JL: Address Latch Enable
T: Restart
.: Carriage Return
: Line Feed
Carry
C: Escape
: Most Significant Byte
B: Least Significant Byte

xvi
Chapter One

Introduction
Microcontroller-based systems require knowledge in hardware, in
software, and the specific application area. The hardware contains the
microcontroller, some memory (optional) and input/output interfaced with
external circuitry. These building blocks are found in many commercial
applications, for example, main home appliances contain embedded-systems
interfaced with keypad and an LCD screen.

1.1 Background

l)e\elopmenl of microcontroller-based applications code is best


accomplished in a structured fashion. All major subsystems should be first
identified. Program segment and subroutines should be developed and tested for
each major subsystem. Prototyping (he subsystems and thoroughly evaluating
the code for each subsystem usually save time and effort in the long run.
Modularization of the code makes it easier to debug and modify, finally, the
subroutines are combined in the end product. It is worth mentioning that the
development process which is reduced into only four stages (write code, compile
code, debug code and program) is incomplete as it emphasizes on the procedural
stages and neglects the essential pre-design stage (structuring and modularity of
code) and the pro-design stage (maintenance and modification of code). To
explain the idea let us illustrate the development process briefly.

1- Writing code deals with writing the .source program for the application in
assembly or (' language. This step is simple if one knows the programming
language and microcontroller's architecture ami it's instruction set.

2- Compiling code deals with converting the source code into executable code
for the microcontroller to execute.

. 1 - Debugging code deals with resolving errors and testing it with realistic input
to see it produces the desired outputs. Single stepping, or tracing through the
code is the optimum method to evaluate the behavior of the code
microscopically

I
•I- Programming is the last slop in which the code is loaded in microcontroller
mentors, or external memory.

1.2 Problem statement

It is very common that in the third stage the programmer discovers


errors and returns hack to the first stage to correct the errors and repeat the
process. Since the third stage is very crucial in the development cycle and
ambiguous, ihis studs is intended to resolve this stage by developing a simple
home-made emulator for 8051 microcontroller to assist in the debugging and
hence the development process. The neglect of the pre-design stage in which the
program is made to be modular, structured and documented makes it impossible
for the program to be maintained or modified later on. This point is important
because debugging is required to make some modification.

1.3 Objectives

This research aims to produce an 8051 emulator to be used by


researchers anil students to:

1- Establish rooted knowledge of emulation technique in development and


troubleshooting.

2- Provide cheap and simple tool for development and troubleshooting.

3- Enhance microcontroller based instrument research and development among


electronics engineers.

1.4 Methodology

The research is planned to be executed as follows:

I - 8051 Microcontroller study (theoretical and practical).

2- I heorelical suivey in the Held of emulation.

3- Real- time debugging techniques.

-I- Software development tool study.

5- Software development (communication, debugging & presentation).

6- Emulator building, testing & verification.


7- Writing the thesis.

I lie microcontroller 8051 was studied. Many experiments were carried out using
assembly language and basic language. Experiments covered using input &
output ports, using the counter/timer, using the serial port, measuring sink &
source current of different pins, measuring the duration of signals ,and
measuring the frequencies of different signal. Investigation on emulation
diflerent approaches was carried using the internet. Traditional emulator
working with two microcontrollers was studied thoroughly so as to avoid
disadvantages in the required design. It worth mentioning that, the research
deviated from what is planned in some regards. For instance, it only considered
the simplicity in achieving emulation and forgets about dedicated hardware for
emulation. Keal lime debugging techniques were investigated because user's
program correction and monitoring is a fundamental j o b of emulator. Debugging
strategies were studied also, and terminal monitor option was selected for this
research making use Hash microcontroller features. pvision development
platform was studied thoroughly, and all the features and capabilities of the tool
were investigated regarding project creation, simulation and testing. Many
experiment were made using the simulator which simulator all 8051
microcontroller capabilities. Particularly all sections of the software developed
were tested using this tool Software developed started with a general terminal
program running the host PC to communicate with the emulator. Later serial &
parallel communication program with the host PC was fetched and studied
thoroughly. Further more a monitor program managing emulation commands
was investigated and studied in details. This program used command recognizer
which calls lower orders programs called command routines. It worth
mentioning that some monitor programs found in the internet were studied for
comparison. Using uvision simulator the whole program was checked. In the
hardware the research used special design board, which preformed the target
CPU. 'Ihen the program was compiled and loaded in the microcontroller for
testing & verification and showed excellent results.

3
1.5 Research outline

Beyond this preamble this chapter reviews different chapters of this


thesis. Chapter 2 reviews the hardware used in the development process. It firstly
presents some information about the 8051 microcontroller regarding it's block
diagram, memory organization and the special function register. The use of
special function registers in the software to implement serial communication
with host l'(' is of is of prime importance, so it is explained in this chapter,
lastly the electronic card used to test the overall code performance in the real
lime is presented. In chapter 3 Kcil development tool for the 8051
microcontroller family is reviewed. It supports every level of developer form
professional application engineer to a student just learning about embedded
system software development. It includes C Compiler, Macro Assembler,
Debugger, a Ilex Converter. Real Time Kernel, Linker and some Monitors
programs all under one Integrated Development Environment (IDE). In the
debugger mode the user may use the Simulator which support simulating all
features of the 8051 without actually having any target hardware. This feature is
used very much for testing all subroutines. The only drawback of the simulator
is running not within real time framework. Chapter 4 discusses the Emulation
Principles. It starts with the practical development cycle stages and the tools
used in the development process. It elaborates on debugging and emulation
concept. Then it gives a quick review on emulation techniques. Then it
concentrates on emulation techniques with monitor program enhanced after
development of On-Chip Debugging facilities and Hash memory. In chapter 5,
the modern debugging strategies of Micro Systems Controller (MSC) are
reviewed. These strategies range from simulation-based to In System Debugging
(ISD). categorized as software and hardware strategies. Chapter 6 of this thesis
deals with the Software developed. It shows a general flowchart of the program.
I lien it gives a short description for all its subroutines under some headings like,
initialization parameters and interrupt vectors, serial I/O subroutines, menu and
monitor commands, memory management subroutines, power on and
initialization subroutines, multiplication and division subroutines, multi-byte
sequence and compressed data processing subroutines. Also it touches program
modularity and maintainability. Also in this chapter, the steps of creating the

4
project, building it and finally testing the whole program together, using Keil
development tool, is reviewed. In the appendix the source program is given. In
chapter 7 results obtained using the programs were reviewed after project
building. It is first tested using the development tool for different commands like
help command and display internal RAM command. Also testing using the
hyper-terminal were manifested after loading the IIF.X llle in the real
microcontroller. Chapter 8 discusses the conclusion obtained and points out
some recommendations for future work.

5
Chapter Two

8051 Microcontroller

This chapter gives a brief overview of the hardware used. It first


reviews the 8051 microcontroller (uC) block diagram, the memory organization
and elaborate a little bit on the special function registers, specially those used in
interrupts and the serial communication. This is because their relevant
peripherals are used in the process of emulation. Other peripheral and their
associated special function registers, like I/O ports are left to user to use them as
he likes. At the end this chapter will review the electronic circuit used to test the
software developed.

2.1 8051 Microcontroller review

The 8051 is an 8-bit microcontroller originally developed by Intel.


I here are currently hundreds of derivatives produced by dozens of chip
nianufacturcrs.8051 family is widely used today for embedded control
applications. The 8051 is an 8-bit micro-controller. The basic 8051 chip includes
a number of peripheral I/O devices including two (or three)Timer / Counters, 8-
bit I/O ports, and a 11 ART as shown in figure 2.1 block diagram [9].

L.L
'."nv.j

...! j f

t1 I... -..TOT.

, t
if if inr

I'igurc2.l 8 0 5 1 hlock diagram

6
2.1.1 Why embedded systems

Imhcdded microcontrollers tire used extensively in robotics and


industry. In this application, many specific tasks might be distributed among a
large number of controllers in one system. Communications between each
controller and a central would enable in format ion to be processed by the central
computer, or to be passed around to other controllers in the system. A special
application that microcontrollers arc well suited for is data logging. Stick one of
these chips out in the middle of a corn Held or up in a balloons, and monitor and
record environmental parameters (temperature, humidity, rain. etc). Small size,
low power consumption, and flexibility make these devices ideal for unattended
data monitoring and recording. The automotive market is the most important
driving force in the microcontroller market. Several microcontroller families
were developed specifically for automotive applications and were subsequently
modified to serve other embedded applications 118).

2.1.2 Why 8051 microcontroller

The Intel 8051 is a Harvard architecture, single chip microcontroller


(pC) which was developed by Intel in 1980 for use in embedded systems. Intel's
original versions were popular in the 1980s and early 1990s, but has today
largely been superseded by a vast range of faster and/or functionally enhanced
8051-compatible devices manufactured by more than 20 independent
manufacturers including Atmel, Infineon Technologies (formerly Siemens AG),
Maxim Integrated Products (via its Dallas Semiconductor subsidiary), NXP
(formerly Philips Semiconductor). Nuvoton (formerly Winbond), ST
Microelectronics, Silicon Laboratories (formerly Cygnal), Texas Instruments and
Cypress Semiconductor. Intel's official designation for the 8051 family of uCs is
MCS. 51 11 *>|. Intel's original 8051 family was developed using NMOS
technology, but later versions, identified by a letter "C" in their name, e.g.
80C5I. used CMOS technology and were less power-hungry than their NMOS
predecessors - this made them eminently more suitable for battery-powered
devices.

7
2.1.3 8051 Important features

It provides many Functions (CPU, RAM, ROM, l/O, interrupt logic,


timer, etc.) in a single package.

8-bit data bus - It can access 8 bits of data in one operation (hence it is an 8-bit
microcontroller).

I(>
16-bit address bus - It can access 2 memory locations - 64 kB each of RAM
and ROM.

On-chip RAM - 128 bytes ("Data Memory").

On-chip ROM - -I kB ("Program Memory").

Four byte bi-directional input/output port.

UART (serial port).

Two 16-bit Counter/timers.

I wo-level interrupt priority.

Power saving mode.

A particularly useful feature of the 8051 core is the inclusion of a boolean


processing engine which allows bit-level Boolean logic operations to be carried
out directly and efficiently on internal registers and RAM. This feature helped to
cement the 8051's popularity in industrial control applications. Another valued
feature is that it has four separate register sets, which can be used to greatly
reduce interrupt latency compared to the more common method of storing
interrupt context on a slack | 8 | . The 8051 UARTs make it simple to use the chip
as a serial communications interface. External pins can be configured to connect
to internal shift registers in a variety of ways, and the internal timers can also be
used, allowing serial communications in a number of modes, both synchronous
and asynchronous. Some modes allow communications with no external
components. Once a UART - and a timer, if necessary, have been configured, the
programmer needs only to write a simple interrupt routine to refill the 'send' shift
register whenever the last bit is shifted out by the UART and/or empty the full
'receive' shift register (copy the data somewhere else). The main program then
perforins serial reads and writes simply by reading and writing 8-bit data to

8
slacks. 8051 based microcontrollers typically include one or two UARTs, two or
three timers, 128 or 256 bytes of internal data RAM (16 bytes of which are

bit-addressable), up to 128 bytes of I/O, 512 bytes to 64 kB of internal program


memory, and sometimes a quantity of extended data RAM (F.RAM) located in
the external data space. The original 8051 core ran at 12 clock cycles per
machine cycle, with most instructions executing in one or two machine cycles.
With a 12 Mil/, clock frequency, the 8051 could thus execute I million one-
cycle instructions per second or 500.000 two-cycle instructions per second.
Enhanced 8051 cores are now commonly used which run at six, four, two, or
even one clock per machine cycle, and have clock frequencies of up to 100
MHz, and are thus capable of an even greater number of instructions per second.
All Sil.abs. some Dallas and a few Atmel devices have single cycle cores.
Common features included in modern 8051 based microcontrollers include built-
in reset timers with brown-out detection, on-chip oscillators, self-programmable
flash ROM program memory, boot-loader code in ROM, EEPROM non-volatile
data storage, l-C, SPI. and USB host interfaces, PWM generators, analog
comparators, A/D and D/A converters, R'I'Cs, extra counters and timers, in-
circuit debugging facilities, more interrupt sources, and extra power saving
modes | 8 | .

2.1.4 8051 Programming

Several (' compilers are available for the 8051, most of which feature
extensions that allow the programmer to specify where each variable should be
stored in its six types of memory, and provide access to 8051 specific hardware
features such as the multiple register banks and bit manipulation instructions.
Other high level languages such as forth, BASIC, Pascal/Object Pascal, PL/M
and Modula 2 are available for the 8051, but they are less widely used than C
and assembly.

2.1.5 8051 Related processors

'I'he 8031 was a cut down version of the original Intel 8051 that did
not contain any internal program memory (ROM). To use this chip external

ROM is to be added that will contain the program that the 8031 will fetch

9
and execute. Hie 8052 was an enhanced version of the original Intel 8051 that
featured 256 bytes of internal RAM instead of 128 bytes, 8 kB of ROM instead
of 4 kB, and a third 16-bit tinier. The 8032 had these same features except for
the internal ROM program memory. The 8052 and 8032 are largely considered
to be obsolete because these features and more are included in nearly all modern
8051 based microcontrollers.

2.2 Memory Organization

The 8051 device has separate address spaces for program and
data memory. I here are separate memories for program storage, internal
memory, registers, I/O functions, and external data memory. They each hold up
to 64 kilobytes of instructions and data respectively. Its memory is organized in
Intes and practically all its instruction deal with byte quantities. The logical
separation of program and data memory allows the data memory to be accessed
by 8-bit addresses, which can be quickly stored and manipulated by an 8-bit
CPU. Nevertheless, 16-bit data memory addresses can also be generated through
the Data Pointer (DPI R) register, figure 2.2 shows the external code memory
and data memory connected to the 8051 chip |4J.

ADDRESS BUS (16 bit)

( xl.'lli.il
•< >
Extent.)!
8051 IIA1 A CODE
Ma.-liloly Mommy
(KAMI (ROM)

K/*4 Control tin**

DATA BUS <0-biO

l/i i M o i l ,
HII Vi

I igure 2.2 8 0 5 1 chip using external memory

I he 8051 has three very general types of memory. To effectively program the
8051 it is necessary to have a basic understanding of these memory types. They
are: External Code Memory, External RAM and On-Chip Memory (internal
memory), 8051 memory organization is mapped in figure 2.3.

10
TNT
External
8051 chip DATA
Memory
(up to
Internal 0000 64KB)
Memory
Internal
SI Ks FEFF External
COOK
Internal Memory
RAM
(up to
0000 64KB)

I igure 2.3 8051 memory organization

2.2.1 External Code Memory

The executable program code is stored in external code memory. This


is often in the Ibrm of an external EPROM. The code memory size is limited to
6-IKBytcs in a standard 8051. The code memory is read-only in normal
operation and is programmed under special conditions e.g. it is a PROM or a
flash RAM type of memory.

2.2.2 External RAM Data Memory

External RAM is memory that resides off-chip and often in the form
of static RAM or Hash RAM. This is read-write memory and is available for
storage of data. Up to 64KBytes of external RAM data memory is supported (in
a standard 8051). Hie External Data Memory space contains all the variables,
buffers and data structures that can't lit on-chip. It is principally addressed by
the 16-bit Data Pointer (DPI R), although the first two general purpose register
(R0. Rl) of the currently selected register bank can access a 256-byte bank of
External Data Memory. The maximum size of the External Data Memory space
is 64Kbytes. External data memory can only be accessed using the indirect
addressing mode with the DP'f'R, R0 or R l .

11
2.2.3 Ink-null Memory

litis refers lo any memory thai physically exists on the


microcontroller itself. The 8051's on-chip memory is mapped in Figure 2.4
below. 'Ihe internal memory is shown divided into three blocks, which are
generally referred to as the Lower 128, the Upper 128, and SFR [10]. The
maximum size of the Internal Data Memory space is 256-byles. However,
different 8051 family members integrate different amounts of on-chip memory
as shown in fable 2.1 below. The register implicit, indirect and direct addressing
modes can be used in different parts of the Internal Data Memory space. The
Internal Data Memory space is functionally the most important data memory
space. In it resides up to four banks of general purpose registers, the program
stack. 128 bits of the 256-bit memory, and all the variables and data structures
that are operated on directly by the program.

Lower 12S hyh'.s: OOh to t I'll Register Banks

20h lo 2Fh Bit Addressable RAM

30h to 7Fh General Purpose RAM

Upper /2.V/m'A'v. XOh to Fill Special Function Registers

Table 2.1 Different 8051 microcontroller produced by Intel

Device Internal Program tetital Data Timer/Counters Interrupt Oscillator


Memory
Memory (16-bit) Sources squency (MHz)

W5IAII -IK bytes ROM 128 2 5 3.5-12

0C51IJI1 •IK bytes ROM 128 2 5 0.5 - 24

87C5I •IK bytes HI'KOM 128 2 5 0.5-24


•»
U'5II A 8K bytes ROM 25<» .i 7 0.5 - 33

80C58 32K bytes ROM 256 3 6 0.5 33

2.2.3.1 Register Banks (OOli to I Mi)

I he lowest 32 bytes are grouped into 4 banks of 8 registers. The 8051


uses 8 general-purpose registers RO through R7. When the instruction is

12
executed, one of the eight registers in the selected bank is accessed. Program
instructions call out these registers as RO through R7. Two bits in the Program
Status Word (PSW) select which register bank is in use. This allows more
efficient use of code space, since register instructions are shorter than
instructions that use direct addressing | I 0 | . All of the bytes in the Lower 128
bytes can be accessed by either direct or indirect addressing. The Upper 128
bytes can only be accessed by indirect addressing.

2.2J.2 Bit Addressable RAM (20h to 2Mi)

The 8051 supports a special feature which allows access to bit


variables. Ihis is where individual memory bits in Internal RAM can be set or
cleared. In all there are 128 bits numbered OOh to 7Ph. Being bit variables any
one variable can have a value 0 or I. A bit variable can be set with a command
such as SH IB and cleared with a command such as CLR. for instance:

Sli I'B I5h : sets the bit I5h (becomes I)

( 7/v' /5// ; clears bit 15h (becomes 0)

fhe bit addressing can also be performed on some of the SIR registers, which
will be discussed later on. The Bit Memory space is used for storing bit variables
and Hags. Hits can only be accessed using the bit instructions and the direct
addressing mode.

1.1
AM
' :• l i - l>> I... i:
"Ft,
General i.»u:po>e
RANIaie.,.
t>0 byte-.
:•. '1;
— ——
—....—
:-ni.

60 IUIEIU.IL
y~L
~. p
:-au •• ~ 50
...... 4.J SFR-

«0

Iutrl l l . l l
12 RAM
' - :o .ts
CD
JL.
C'O
IFK 0 - .BiiO. 1 .

0 " : B 1 :
'.i<.:
:.:FI. F' - * 0
r
" .B.uJ. 1 . Register Baulk 0

?«E "
-••= = -
0 " B.-ul. 0 Mil R*f «
•;:Z 05k R«r 5
04b 3eg 4
Oih Re? i
a:n Reg I .
r.h Reg I
OOh 0

l-iuniv 2.-t Oruuni/ation of ihe 8051 ink-mal memorv

2.2.3.3 General Purpose RAM (30h lo 7Fh)

80 Intes oi'lntemal RAM memory are available for general-purpose


data storage. Access to this area of memory is fast compared to access to the
main memory and special instructions with single byte operands are used. The
general purpose RAM can be accessed using by direct or indirect addressing
modes.

2.2.4 SFR Registers

The SI R registers are located within the Internal Memory in the


address range 80h to I'l'h, as shown in figure 2.5 below. Not all locations within
this range are defined. Each SIR has a very spec i lie function. S I R s include the
N
Port latches, timers, peripheral controls, etc. These registers can only be accessed
by direct addressing. Sixteen addresses in SFR space are both byte- and bit-
addressable. The Special Function Register space contains all the on-chip
peripheral I/O registers as well as particular registers that need program access.
These registers include the Slack Pointer, the PSW and the Accumulator.

r\cgi'..:ei-fv>.3p|>eJ Pons

•iailicj^ea tlicrt en;: in OH •> 311

Po/t Pins
.£OC'.m''.|:cltC<r

;ctc.i
S.-OI i

ton K..-.0

figure 2.5 Special lunction Register layout

The standard SOS I has four 8 bit I/O ports: PO, PI, P2 and P3. All four ports in
the 80C5I are bidirectional. I'aeh consists of a latch (Special Function Registers
PO through P3), an output ilriver. and an input buffer. The output drivers of Ports
0 and 2, and the input buffers of Port I), are used in accesses to external memory.
In such application. Port 0 outputs the low byte of the external memory address,
lime-multiplexed with the h u e being written or read, while Port 2 outputs the
high byte of the external memory address when the address is 16 bits wide.
Otherwise, the Port 2 pins continue to emit the P2 SFR content. All the Port 3
pins are multifunctional. They are not only port pins, but also serve the functions
of various special features. I.isl of all special function registers and their
addresses is shown in fable 2.2 below

15
table 2.2 Special I unction Register Nantes. symbols and addresses

. _ _ .... . _ l^jili—.1?—
Ace.. . AeeuniulatDL
^register » _
1*S\\' l'«'M'!!!!' -iW."A \V«»rd .... <JL)»U.....
SI' . ^ K i ' o i ' i K r ... .. »!!•_..
L>!T1< .... .. ..!>J«a.lK>!!««.l2l?iJ«a_
... !>i'!.-... .!,"": H\'c... _. .JSb._
i>!'H ... ._..JiiKhHytc . _

_.H! \*m _.

.. _.!'J_ ... !•!«!._._ _ -_V«iL


_i'2 aoJl
M . M l
... "I".. . i i i r a H .L'rJyrti' VsmM.
... !l: JnitrryiH <•:!»!>!?!«. *i!!U!>L (
_a«l__
!M<!>. !'ii!UT'(;oiinter Mode (JojilroL .
l
' '!'.">•'.'. *VJ»'V*< .L**.»ll!.l ,>i
.m.
\2( ON / ,
Tlnwr«'«'yv!'2i.:«.«iL':».>!
.!!!" |Wtj^r<imB!i»>itt.
... i'l'. ...

JU! !'i»»sr/r^iM!.»y!.L«i
. . 1 1 1 li^HeT/0>U.»M].].•^»!iiiliiV:•.... m..
I! !.2 .n!nsr^»J!s?jiij|hBj!c_.

!L? .._
J«AI'?!! C2 Capture U e g J I i g j . L»YJe .
(
. K .' !'?.L A
[Li'2 CL'Wuic Reg. J a w I»vie„ i:A!>.
SCON ...... JJsda!.OS>ir«l
._ siuJ!:.... ... ^naLOalaJJulTcr

.-mm..... _. J ' ^ e r C o n l r o l _ l?!l._

2.2.4.1 Program Status Word (PSW) register

The Program Status Wort! (PSW) register configures register banks and user

defined Hag. fable 2.3 below shows bits distribution in the bit addressable

register PSW 11()|.

16
I able 2.1 Program Stains Word (PSW) bits distribution

l'SW7 I'SWl) PSW5 PSW-4 PSW.? PSW2 PSWI PSWU

CY AC It) RSI RSO OV - p

etpi psw inil, 0 ;value/br/>sw (which re}> bank to use)

IIIOV psw, ///».vir /'///'/ initialize program stains word

The first line initializes psw inil variuhle by zero while (ho second line
configures PSW by zero making all Hags disabled, and selecting register bank
/ero by making register bank selectors (RSO and RSI) zero.

selh psw. 5 ;sel /lag sinee there is display

jnb psw.5, pintl6h ;olherwise jump if no previous


display

Here PSW.5 (10 llagt) available lor user) is used to signal previous letter display
to continue displaying small characters. It has to be stated that PSW.5 (user
defined (lag) is used several time for different tasks.

2.2.4.2 Power ('ontrol (PCON) register

The Power Control (PCON) register configures power consumption


mode of the chip whether it is IDLE or in POWER DOWN mode, fable 2.4
below shows different bits distribution in the non bit addressable register PCON
|I0|.

table 2.1 Power < 'onirol (PCON) register bits distribution

P( C)N7 ('()N() ('ON5 ( ()NI CON? CON2 ('ON 1 CONO

SMOI) - - - (ill CIO PI) 11)1.

IIIOV /Htm, IMxtSO ;coiifi}>iire peon for fast baud (doubled)

17
II is clear Ilial power saving mode is not enabled and only SMOD is enabled
which impl} baud rale doubling. Power saving is enabled when battery powered
electronic circuits is implemented lor example in data loggers when used in
remote areas.

2.2.4.3 Timer/Counter Mode Control (TMOD) register

The 80C51 has two 16-bit Timer/Counter registers. timcrO and


timer I. Doth can be configured to operate either as timers or event counters. This
is defined by Timer/Counter Mode Control TMOI.) special function register. In
this program timerO and timer I are used lo measure the baud-rate of the host PC
to start communication with the PC. After measuring the baud-rate and
calculating the baud-constant using the following equation

band const 256 - (crystal (12 * 16 * baud-rale))

Timer/Counter Low Byte (II.) and Timer/Counter High Byte (I'll) are loaded
with the baud-constant calculated to establish automatic reloading 110|.

<•//• a .clear A

IIIOV till, a .clear timer!) low byte

IIIOV tht). a .clear limerO high byte

mov ill. a .clear timer I low byte

IIIOV l/il. a ;clear timerl high byte

The upper five lines initialize 1'1.0,'f 110. II. I and II11 with zeros to start
measuring the baud rale for example.

IIIOV a. ill) .•move tiinerO low byte to A

IIIOV rl). a .move A content lo rO

IIIOV a. l/iO ;movc limerO high byte to A

IIHIV rl. a ;move A content to rl

The upper four lines load (he measurement result into rO and rl.

IIIOV till, a ;move the reload value to till

18
mov ill. a ;mo\e the reload value to til

The tipper two lines reload time I with some value to start counting down.

The Timer/Counter Mode Control register (TMOD) configures timer/counter.


Table 2.5 below shows bits distribution in the non bit addressable register
TMOI).

I able 2.5 Timer/Counter Mode ( onlrol( I'MOD) register bits distribution

TMOD7 "MOIM) MOD5 MODI 1 MOD'S MO 1)2 MODI I'fvfODO

GATI: (7! Ml Ml) li.Vli: (7T Ml MO

Timer//1 Timei7/()

IIIOV tinod. Ii0x2l .set timer III for H hit auto-reload and
limeiilOJiir 10 hit auto reload mode

2.2.4.4 Serial Control (SCON) register

The Serial Control (SCON) register configures the serial port. Table
2.6 below shows the different bits distribution in the bit addressable register
SCON 110|.

I'able(2.6) Serial Control ( S C O N ) register bits distribution

SCON 7 SCON<> SCON5 iC< )N4 SCON.3 CON2 SCONI JCONO

SMO SMI SM2 Kl-N ins RH8 II Rl

Our program configure the SCON twice, once at the begining of autohaud
subroutine.

mov scon, 110x42 -.configure scon for Shit var-baud,


receive disabled

fhe second at the end of autohaud subroutine to set the new baud-rate

Mov scon. 110x52 .configure serial port control

Now REN is enabled for receiving data through the serial port

cin: jnh ri. cin :loop if receive interrupt flag not set

clr ri ;clear receive interrupt flag


1
I)
In the first line the program loop until receive interrupt is high; when it is high, it
clear it in the second line and continue cin subroutine processing.

coul: jnb //', caul .display it

clr ti .clear transmit interrupt

In the first line the program loop until receive interrupt is high; when it is high, it
clear it in the second line and continue coul subroutine processing. The serial
port receive and transmit registers both access the serial buffer SBUF. Writing to
SBUF loads the transmit register, and reading SBUF accesses a physically
separate receive register.

cin: jnb ri. cin .loop if receive interrupt flag not set

clr ri .clear receive interrupt flag

mov a. sbuf .put serial buffer into A

ret .return

In cin subroutine sbujcontent (which is coming from the serial port) is moved to
A for further processing.

coiit: jnb ti. cout .display it

clr ti .clear transmit interrupt

mov shut, a :put A into serial buffer lo send

ret .return

while in cout subroutine A content is moved to sbufio be sent by the serial

port.

It has to be stated that the program developed has very limited use of special
function register and only when very necessary so as to spare them for the user
program developed by the developer. Also the register used should not be
modified in the user program to avoid eon diet. This means the baud rate
specified should he kept. The resources used for example like the serial port
should not be used by the developer as it is specified for communication with the
host PC at a certain baud rate.

20
2.2.4.5 Interrupt Enable (IE) register

The 80C51 provides 6 interrupt sources as follows:.

External interruptO (IE0)

External interrupl (IEI)

TimerO overflow interrupt (TEO)

Timer I overflow interrupt (TF1)

Timer2 overflow interrupt (TE2)

Serial port interrupts (Rl or TI)

These interrupt are enabled by the bit addressable. Interrupt Enable (IE) register
as shown in Table 2.7 below [10].

Table 2.7 Interrupt Enable (IK) register bits distribution

IE bit No. IB7 11-6 11-5 II-4 113 1122 ii:i

Interrupt Name
- - ;
n 2 Rl or T TP I ii: i no IKO

Enable Signal KA - KT2 l-S i:ii I:XI irro •:xo

*EA= Enable All

** All bits arc set by the programmer.

clr a .clear A

mov ie, a ;reset interrupt enable register

The above two lines disable all the interrupts by putting zeros in all IE bits

2.2.4.6 Interrupt Priority (IP) register

All interrupts are internally prioritized as follows INTO. TEO, IN'I'I,


TF1 and lastly the serial port interrupt (Rl or TI). But any interrupt source can be
individually programmed to one of two priority levels to achcivc some kind of
flexibility. These interrupt are prioritized by the bit addressable Interrupt Priority
(IP) register as shown in Table 2.8 below [10].

21
table 2.S Interrupt I'rioiilv (II') register bils distribution

II' bit No. 11*7 Il'o Il'5 ii'-i IIM ll'2 IIM 11*0

IciTiipls hit name 1-2 priority K lor II 1 priority 1:1 priority 10 priority ;() priority
enable enable enable enable enable
- - >ril) enable

IlilsMllllol - - t* r> I'S I'll l»XI HX) l'XO

Since all interrupts are already prioritized by hardware as mentioned above,


there might be no need for making some priority changes by software.

clr a :clear A

niov //>, a ;re\cl interrupt priority register

The above two lines enable the hardware priority as they clear all IP bits

2.2.4.7 Timci7( 'ounterl Control (IX O N ) register

The External Interrupts INTO and IN'l'l (1F.0 and WW) can each be
either level-activated or edge-activated, depending on bits I TO and I'll in
register ICON. The Hags that actually generate these interrupts are bits IF.O and
1H1 in ICON. When an external interrupt is generated, the llag that generated it
is cleared by the hardware when the service routine is vectored. TimerO and
timer 1 overflow interrupt (I TO and IT I) are both activated by run bit-command
TRO and IR1 in register I'CON. The flags that are generated are bits TFO and
IT I in register ICON |10|. These interrupt are enabled by bit addressable
Interrupt Finable (III) register as shown in fable 2.9 below.

I able 12.')) I iniei i-uunler ( ontiol t I ('ON) register bits distribution

'let>N hit No. ICON7 ()N(> ICON5 K'ON-l ICON? ICON2 'I'CON 1 TCON0

InliTiiipls bit III IT inn ITU 1II) run II. 1 flag 11:1 edge or 11:0 flag 1:0 edge or
inline Overflow Dill overflow emit level level
Hap llag triggered riggered

Hit SMIIIXII III IKI 1 ID IKI) II 1 III MO 110


* Kun command signals arc enabled by programmer (software)

* Edge or level signals are determined by programmer (software)

* Overflow flags are set by hardware when there is overflow and is cleared by
hardware when interrupt service starts.

* Edge flags arc set by hardware when there is interrupt and is cleared by
hardware when interrupt service starts.

Our program for example command timer I to start timing by the following line
when it is measuring baud rate

setb //•/ ;now we're timing it

It also cheeks whether timer I ovelllows by the following line

aulob2c:jb If I, auiobl :clieek for timeout while waiting

It starts limerO at a certain condition by the following line

vi7/> trO .start liming last -I bits

It stops limerO for some reason by the following instruction

•I : ! i i • ; I op t. i iih.- 1 0

2.2.4.8 Tiinoi7('ounter2 Control (T2CON) register

Timer/eounler2 is not available in all 8051 microcontrollers


particularly old ones. It is found in 8052 chips. It offers a third timer/counter
beside timer/counterO and timer/counter I. All timer2 configuration bits are
within T2CON register as shown in fable 2.10 below 110|.

I able 2.10 rimcr.Vuimter2 Control ( I 2CON) register bits distribution

h ' o n t)ii n.i l.'l O N 7 i;roNi. IJl'ON> .H ONI 21'«)N2 JMONI T2CONO

I'll lumie 1 line i \ i i la.' < Koeeiu -


ll.ilr.nill 1 xt l l a j ' Slail oi ('oimlci line i» reload

eiialilo lliif.
meillnu CIJ-lllIC Ol rliK-k eloek stop HI Inner

Iclil.hl)
lla >
s

till h>nilnil II -J 1X12 IUI K ICI K .XI N2 TR2 iv r C1VKI.

Reside timer2 configuration 12CON contains other bits as follows

23
*<P/RI. bil determine capturing time of a certain event triggering timcr2 input
(12) or reloading a counter by a certain value when counter input (T2) is
triggered.

*EXEN2 bit determine capturing or reloading occurs by a signal at timer


external input (I'2MX).

* I ( I K bit determine serial transmission clock (whether timer I or Iimer2).

*R('I.K bit determine serial receiving clock (whether timer I or timer2).

*l XI 2 bit determine whether capturing or reloading is due to T2 or T2EX.

It has to be mentioned that the program developed used timcrO and timer I
overflow interrupts lo measure the host computer baud rate during jiowcron
subroutine only. Also it uses serial port interrupt during communication with the
host, lo use any of the interrupts in the 80C5I family, (he following steps must
be considered.

1. Set the I-A (enable all) bit in the Hi register to I.

2. Set the corresponding individual interrupt enable bil (EXO, 1:10. EX I, ET1,
l-S and li I 2) in the Hi register to I.

3. f inter overflow interrupt ( l i t ) , I I I and 11'2) have to be started by bits in


IXX >N (TRO and I R I ) and T2CON (TR2) while serial port interrupt (RI or Ti)
and external interrupt (Hit) and Hi I) do not need starting.

4. External interrupt (110 and IE I) have to defined whether they arc edge
triggered or level triggered within ICON by bits (110 and f f l ) .

5. Begin the interrupt service routine at the corresponding vector address of that
interrupt.

6. Serial port interrupt Hags (Rl or TI) has lo be cleared (bits in SCON) by
software after the transmit or receive operation, while external interrupt flags
(11-0 and IE I) in ICON and timer overflow interrupt flags (TEO, TE1 and TE2)
(within IX ON and T2CON) are cleared by hardware when the interrupt routine
is serviced.

7. Interrupts priority may be modified by bits (PXO, 1T0, 1WI, I T 1 . PS and


8. Timer overflow interrupt (TEO. II'1 and TE2) are delected by flags within
ICON a n d T 2 C O N .

«>. External interrupt (IEO ami I I I ) are detected by flags within ICON.

10. Serial port interrupt (Rl or 11) is detected by flag within SCON.

2.3 8051 Addressing modes

All members of the 8051 family executes the same instruction set
which is optimized for 8-bit. It provides a variety of addressing modes for
different memory types. Ureif definitions of these modes are as follows | 8 | :

2.3.1 Direct addressing:

'The address of the operand is specified by an 8-bil Held in the


instruction (only for internal RAM and SERs).

2.3.2 Indirect addressing:

1 he address of the operand is specified by a register. Used for both


internal and external memories. RO or Rl arc used for addressing.

2.3.3 Indexed addressing:

The address of the operand is specified by DPTR or PC. It is used


only for program area for reading look-up table.

2.3.4 Register instruction:

Contents of RO through R7 in the current register bank can be


accessed by these instructions.

2.3.5 Register-specific instruction:

Contents of certain register like Ace and DPTR are accessed by these
instructions.

2.3.6 Immediate constants:

The value following the opcode (//constant) is operated with the Acc
or DPTR.

25
It worth mentioning that the programming instructions deals with arithmetic
operations, logical operations, data transfer operations. Boolean operations,
jumping and calling operations. Details information are available in instruction
set.

2.4 Circuit Hardware

The hardware used is a simple circuit consisting of an 8051


microcontroller beside some necessary items as shown in Tig 2.6 below. The
different items are as follows:

1. 8051 microcontroller, dell tied by UI.

2. 7411( 'TOO dual input NAND gates, defined by U2 (for making RAM like
R( )M containing the code as the PSEN is active when fetching the opcode).

3. 7411( I 573 octal D latch, defined by 11.3. I his is for latching the lower
address byte to the memories as lower address byte and data are multiplexed on
porlO.

4. 27C512 normal or 301 512 Hash ROM. defined by U4 (pin compatible ICs,
even different si/e are also possible, depending on user program size).

5. 6264 static RAM (64Kbit), defined by D5 (pin compatible ICs, even


different size are also possible, depending on user data size).

6. 24COI IIC protocol Ef PROM, defined by U6.

7. PCI 8583 real lime clock, defined by 117.

8. 74 I IC'f 10 triple NAND gate, defined byU8 (for decoding and Hash writing).

9. 7805 voltage regulator, defined by 110.

10. 11.006MHz. XI Al for the microcontroller.

11. 32.768 KHz for real time clock.

12. BC857and BC847 transistors for buffering TXD and RXD signal to the
serial port, defined Ql and Q2.

13. Some resistors, capacitors, diodes and connectors.

The schematic drawing of the circuit is shown in figure 2.6 on the next page.
While the circuit is built.on a double side Printed Circuit Board (PCB). The
26
component side and the solder side arc shown in Figure 2.7a, Figure 2.7b while
the layout of the components side is shown in Figure 2.8a while the layout of the
solder side is shown in Figure 2.8b below.

27
Figure 2.6 Circuit diagram of the 8051 board

28
Figure 2.7a l o p layer (component side) I V B

Figure 2.7b Bottom layer (solder side) P C B

29
32.76BkHz f D 3
1 1 — Ul B0C32 at
U5 62296
J3
0.1
G
12pF
PCF8583 RX

..LI

T 3k8'
V

Ta&i.:: n
2 C 0 .
C Z 1 ' » '
1N100?
O-UDKrt 74HCT673

D
11095

U2\. PCB051
filitrr"
JP2
22quLi25iL |X2 xi
1
33pF

Figure 2.8a I o p layout (component side) o f the board

8MN11
Sr830
mi £1
3K3
r::::i
to I - 1
001
n exe
6&3 — 1 J
1.0
[ Z D
It
tr
oat F .....

1.0
[ Z D
B 001
001
001
C Z D
luOl

figure 2.8b Bottom layout (solder side) of the board

30
Chapter T h r e e

Development Tool

uVision is a standard Windows; application and an integrated software

development platform that combines a robust editor, project manager, and m a k e facility.

uVision supports all of the Keil tools for the 8051 including the C compiler, macro

assembler, linker/locator, and objeel-HKX converter. uVisiou helps expedite the

development process of embedded applications by providing the following [5]:

Full-featured source code editor.

Device Database for pre-conllguring the development tool setting.

Integrated make facility for assembling, compiling, and linking y o u r embedded

applications, and Dialogs for all development tool settings.

True integrated .source-level Debugger with high-speed C P U and peripheral

Simulator.

Links lo development tools manuals, device datasheets & u s e r ' s guides.

Using Keil Software tools, the project development cycle is roughly the s a m e a s it is for
any other software development project [5j.
\ . CtevWe a pvotacA Vo seAce\ \\\e W>5>\ vtastae vmi\ \Y»e tool settings.

2. Create source Files in assembly or C.

.1 )hri)()y<nir:ipp)iailioii v.ith lite project tiiiitutgcr.


4. Correct evvovs in source Viies.

5. Test linked, aoplicauon.

The development . c l e described above may b e best illustrated by different software of

Keil development tool features as shown in Figure 3 . 1 . The uVision screen provides the

user with it menu bar for c o m m a n d entry, a tool bar where the user can rapidly select

command buttons, and windows for source files, dialog boxes, and information displays.

jiVision lets the user simultaneously open and view multiple source files. The menu bar

provides the user with m e n u s for editor operations, project maintenance, development

tool option settings, program debugging, w i n d o w selection and manipulation, and on-

line help. The Watch window lets the user view and modifies program variables and lists

.31
the current function call nesting. The contents of the Watch Window are automatically

updated whenever program execution stops. The user can enable View "Periodic

Window Update" lo update variable values while a target program is running. The

Memory window displays the contents of the various memory areas. U p to four different

areas can be review in the different pages. The context menu allows the user to select the

output format | 5 | .

fl* k*>3» E«HW COW &%JC" ttcO

" 3 h a c p j «t * « s : a ;»I si 8 h fr* t: | * i t « \ M vv'&tM:


jll
, Work-
Pioiect T^S. 1 -IS DQ02Q9K PWOOIWI
H 000209E0 CMO space
WiiMOW 531 )
•11 OHM 3.«
uuntf ( • II ATIUIURO R I « » III
d- i II aan?03rt M.4.M
• ID IIUU2U31C l o u r
h h i U | ! 131II) i 54s 1
* i i t p i « y • I: -9 00020W1 RCR»
w a i U («di«?i*i') : 8 01030400 N O T

I I
I Ntlli«
»«4«tir* dt*i>'.*y ( d t t r w i t ) - -7 00112052c oeroiioo

IMplrty • i i
p u n - . t ( ".i. use l mruiMl.i
OTOONIL) J I OiFDOO.L.OIIN:
wklU (adi«»loy)i
Puiiimeiai M
l>:*ln*.f ( ' " . t . L t . i t l ! « . j u i
'iWUtimil JO UlHllK>.l.tllU2ll.
nlil t o (adi&Ploy):
a t . x t f l . 9 - 1; : B&oarEio JB OIFMIO.I.O«02O:
Wafc/V
I....I. »KLTN (Mdovplwyl: NILINI iiiii Ca«
ffi203i? MIISFEIO JB HiP|HII.I.NT«?O: Sracfc
' aAiiaitiB IB niFCinn/".niO?o!i2
•.asm. ill.play ( i . l r . n t ) ;
ICT'.'irMh M.F7IIIU0 MIIV U7.*>JftQUIU
I 2007

I 0
j start aoAKsr^aoit

iMemory
Display c m r » < l Hoasutitatttltf: (ESC ' Window
Tib*; U-.tti:M..4U V/.AHi
Output AMlt:t

Window

MVIitKIA. It' VO 00 I

> M l : o n oo 30 oo «
I004101C- 00
11)04102:.. 00 00 ( _
>OOU02£; 00 00 00 00 00 00 00 G
19041037. 00 00 00 I T 00 oo oo T
>9041O4O.
mpiuiw* nit 00 00
iin 00
on 00 iui 00
tyi 00 »H iwi
OO 0
| • | . F.U«LL^'.>'J.LI«>/L».L.L*,\F<•£»*/ t\< [ J^f.lli«tiifM^U«Ti»
»A04*.04» 00 tr 00 00 00 00»•/ 00 <
)

I igure .1.1 Development tool features

3.1 Creating a new project

pVision includes a project manager which makes it easy to design

applications for the 8051 family. The user need to perform the following steps to create

a new project:

Create tt new design project. Select New Project from the Project pull-down menu as

shown in Figure 3.2 below |5).

.32
B P

Figure 3.2 ()pen new project


The user will prompted to ehose a name for his new project. It is preferred that the user,
create a separate folder as shown in Figure 3.3 below, where all the files of his project
will he stored. The user should choose a name and click Save.

Create New Protect

Save tn: |, )EST "3 © d* 1 1 »


5j];lest1 Uv2

F::e name: | Teitl' Save

3 Cancel

figure 3.3 Create a new Colder

Hie following window will appear, where the user will be asked to select a device for
Target 'Target 1': as shown in Figure 3.4 below [ 5 |
I
!

figure 3.4 Select devices tor target

from the list at the left. The Select Device dialog box shows the uVision device
database. The user should select the microcontroller he wants to use. When the user
clicks OK to continue, a new p o p - u p window will appear. It will ask whether the user
would like to copy the standard 8051 startup code to the project folder. The user should
select Yes when prompted t o add the start-up code to the project folder. The
STAUTUP.ASl file is the startup code for most 8051 CPU variants. The startup code
clears the data memory and initializes hardware and reentrant stack pointers. In addition,
some X051 derivatives require a CPU initialization code that needs to match the
configuration of hardware design. Then using the file menu the user can open a new file
as shown in figure 3.5 below or he may open an old one. If the file is new the user
should print his code in the window and save it with .asm or .(.' extention.

34
m
i"-: IF. t . ^ c : Let-, j 'i.^-e j j JC-OS I-CS . tisv
|lM rM
•i-fl ... <L't i"3|iKl| *. vi

o ; c : : ".*.<..• H.os =

J5I6H.J,.- .... • • • i i i j p
1 1

Ml

figure i 5 open a new file

Now lhe source code is ready, but it lias not been added to the project. To add the source
code to the project, the user should right-click on Source Group I and select Add files to
Group 'Source Group / ' as shown in figure 3.6 below.

U S

,5; iJ= U (J
ha ..-I '.A jni|!ai •»
T.M C.'J .•.V.JTaryet 1

« T ~ ' "

j A T M M E * LO GROUP ' S O U I T E CIIOUP 1 '

i I

lit; 3.6 Adding tile lo (he project


A pop-up window will appear. The user should select the file he created to add or any
oilier file as shown in figure 3.7 below, and then, click on Add to add the file to the
group.
I'ig 3.7 Selecting file to add to the project

The user should cheek Create HEX File to enable the program to create hex files. This
have to be turned ON manually to generate IIKX files. The user should make sure it is
turned ON, by right-clicking on target I » Options for target 'target I', then under the
'output tab, by checking the box 'generate IIKX file' as shown in Figure 3.8 below.
This step is very important as the 11HX file is the compiled output of the project that is
going to be transferred to the microcontroller.

Pl'tiCiii* J°rIflJBet'Jj»n!et.t.' ,

I" G c £ e Batch fit

Or. | j Defaults |

I'igure 3.8 Selecting III!X file output

36
3.2 Building the project

Before testing the source code, the user has to compile his source code, and
correct eventual syntax errors. In Kfill. I DPI, this step is called 'rebuild all targets' and
has this icon: lt*l. When building an application with syntax errors, uVision will display
errors and warning messages in the Output Window - Build page. A double click on a
message line opens the source file on the correct location in a uVision editor window.
After testing the application, it is required to create an Intel HEX file to download the
software into an liPROM programmer or simulator. uVision creates HEX files with each
build process when Create HEX file under Options for Target - Output is enabled.
The build target toolbar button translates only modified or new source files and
generates the executable file. pVision maintains a file dependency list and knows all
include files used within a source file. Even the tool options are saved in the file
dependency list, so that pVision rebuilds files only when needed. With the Rebuild
Target command, all source files are translated, regardless of modifications [5|.

3.3 Debugging the project

,pVision Debugger will lest the applications developed using the C51
compiler and A51 macro assembler. The uVision Debugger offers two operating modes
that arc selected in (he Options for Target - Debug dialog: Using Simulator allows you
to configure the p Vision Debugger as software-only product that simulates most features
(if the 8051 microcontroller family without actually having target hardware. T h e user
can lest and debug his embedded application before the hardware is ready. uVision
simulates a wide variety of peripherals including the serial port, external I/O, and timers.
The peripheral set is selected when you select a CPU from the device database for your
target. After clicking on the debug icon'-U , the user can start debugging as shown in
figure 3.0 below. The user will notice that some part of the user interface will change,
some new icons will appear, like the run icon circled in the following figure |5J:

37
Qfile £dit y.iew £ r o j e « £«t»ug Fljsh Pejipherals l o o t s £VC8 JJindow flelp

•m fe^puHS « a *
Target I

T4>.j«t; I
01
02
1
j H : S o u r c * Group 1 03
04
I
05
08
0/
08 »:::r
09
10
11 K:K;I
12 ii, ».;-:.r
13
14
15
16

JUJ

I'iguie .>.') Start debugging

I he user can click on Che 'Run' icon and the execution of the program will start as shown

in I'igure 3.10 below. The user can see the behavior of the pin 0 or port one, but clicking

on 'peripherals, I/O ports. Port 1'. The user can always stop the execution of the program

by clicking on the stop button ( 'O ) and can simulate a reset by clicking on the 'reset'

button K i t . The user can also control the execution of the program using the following

icons: ^ ^* ^ which allows following the execution step by step. Then, when

finished with the debugging, the user can always return to the programming interface by

clicking again on the debug button ('-'l ).

3X
Qfi'« I d * J£i*w PioJ«ct £ebu.j F l i j h jp«riph«rjlj} Jooli §VCS Jgindow fcjgle

, ; ; j .|
v 'l/O-Puitt Port 0
Portl
01 Timer Port J
02
Port 2
Oi
04 >:r. *:
05
lu',
0/
00
09
10
OH ci.
:i.:
12 ti::
13
14
IS
16
.^1

I Symbols H=] test .asm

Load " C : \\electr"onTc3 Name Value

13. &SM ASSIGN jrj


iUWttK.-...A7«JliU J

I -'inure 3.10 I'lounini execution

3.4 CPU Simulation

(iVision simulates up ti) 16 Mbytes of memory from which areas can be


mapped lor read, write, or code execution access. The uVision simulator traps and
reports illegal memory accesses. In addition to memory mapping, the simulator also
provides support for the integrated peripherals of the various 8051 derivatives. The on-
chip peripherals of the CPU selected are configured from the Device Database selection
the user have made when he created his project target [5 j .

39
*

Chapter Four

Emulation Concept
Developing software and hardware for microcontroller-based systems
involves the use of a range of tools that can include editors, assemblers, compilers,
debuggers, simulators, monitors, emulators and programmers. To the newcomer
microcontroller based system development is often not clear. How all these different
components play together in the development cycle? And what are the differences for
example between emulators and simulators? To complicate matters more, there are
quite different approaches and technologies for emulation available that make it
difficult for embedded system engineers to choose the right tools. Good approach for
understanding the tools is the review of the development cycle which is reduced in the
following four steps 11 f> |.

1. Writing the code

2. Translating the code

3. Debugging the code from mistakes

4. Programming Hash or OTP (One Time Programmable) memory of the microcontroller

The cycling is clear coming from the nature of the process which indicates that
whenever a mistake is discovered (which is always happening and several times) the
whole process is repeated again. Therefore the development tools mentioned above are
used in all these four steps of the process as follows:

4.1 Writing microcontroller code

Software code for a microcontroller is written in a programming language


(often Assembler or C). This source code is written with standard ASCII text editor and
saved as ASCII text file. Of course programming in Assembler requires learning the
microcontroller specific instruction set (assemble mnemonics) and result in compact
and fastest code. A higher level language like C is independent of a microcontroller
specific architecture, but requites controller specific extensions to the standard Imgunge
to be able to control all of the chip's peripherals and functionality. The code yielded is

40
portable and fast to develop but the penalty is larger eode size ( 4 0 % compared to
assembler). This will require more space and the program will run 4 0 % slower than
assembler code. Also the programmer has to be familiar with the C language.

4.2 Translating the code

The source code needs to be translated into instructions the microcontroller


can execute. The microcontroller instruction set is represented by op codes which are
Unique sequence of bits (zeros and ones). These op codes are decoded by the
microcontroller's instruction decoder logic and then executed. Instead of writing op
eodes in bits they are commonly represented as hexadecimal numbers, where one hex
number represents four bits within a byte. So it takes two hex numbers to represent
eight bits (one byte). For this reason microcontroller code in machine readable form is
also called hex code and the file that stores that code is called hex tile. Assemblers or C
compilers translate the source code into "hex code" that represents machine instruction
"op codes". To support modular programming useable libraries of codes most
assemblers and compilers come with linkers and librarians. I-inkers are used to link
code modules saved in different files together into a single final program. At the same
time they lake care of chip's memory allocation by assigning each instruction a,memory
address in such a way that different modules do not overlap, librarians help to manage
anil organize a library of re usable code modules. Once the ASCII source code text file
has been assembled (with an assembler) or compiled (with a compiler) and the files has
been linked (with a linker), the output results a number of files that can be used for
debugging the software and programming the actual microcontroller memory.

4.3 Debugging the code

A debugger is a piece of software running on the PC, which has to be tightly


integrated with the emulator used to validate the code. For this reason all emulator are
accompanied with their debugger software. I "Jul also some compilers include debugger,
which work with certain emulator. Debugger allows the download of code to emulator
memory and then control all the function of the emulator from the PC. Common
debugging feature include the capability to examine and modify the microcontroller's
on-chip registers, data and program memory; pausing and slopping program execution

41
at dc/incd program locations by setting break points; single stepping (execute one
instruction at a time) through the code: and looking at the history of executed code. So
far text editor, assembler, C compiler, linkers, librarian and debugger are mentioned.
This can become a big challenge to alternate back and forth between all these programs
during the debugging process (discover a bug, edit the source code, compile it again,
link it again, download the modified code again to the emulator, and so on). This is
where an Integrated Development Hnviroiunent (IDH) comes in. An integrated
development environment puts all of the previously discussed software components
under a common unified User Interlace, so that it become possible lo make a code
change and get the modified code loaded into the emulator with a few mouse clicks
instead of dozens. A good IDH allows for example, lo click on a syntax error message
produced by the compiler and have the source code with the highlighting offending
instruction pop-up for editing the text editor. One click of a button and the modified
code gets translated, linked, anil downloaded to the emulator. An lDli stores the
configuration setting for the project such as compiler switches and so on, so as to
recreate easily the project later. When it comes to debugging code and testing
applications, there are different tools that can be utilized. 'I'hey differ in development
time spent and debugging features available. These are simulators, monitors and
emulators. •

4.3.1 Si in ula tors

Simulators try to model the behavior of the complete microcontroller in


software. Sonic simulators go even a step further and include the whole system
(simulation of peripherals outside the microcontroller). No mailer how fast the host PC
is, there is no simulator on the market that can actually simulate the microcontroller
behavior in real-time. Simulating external event can become a time consuming
exercise, as the developer have to create "stimulus" files that tell the simulator what
external waveforms to expect on a particular microcontroller pin. A simulator also can
not talk to the target system, so functions needed by external peripherals are so difficult
lo verify, for that reason simulators are best to test algorithms that run completely
within the microcontrollers (such as math routines). They are the perfect tools lo
complement emulators for large development teams, where buying an emulator for each
developer is financially not feasible.

4.3.2 Monitors

Monitors commonly bundle hardware boards anil in-system programmer


with some software components (assemblers, linkers, debugger and code-size limited
compiler). They allow very basic emulation and debugging functions. They are usually
with Hash-based microcontrollers, as they allow an actual microcontroller to emulate
itself. This is done by including in-system programmer to download the code into the
Hash and execute it. The monitor code in the hardware board allows stopping of
execution (break) and examine memory. Of course, it uses some of microcontroller's
resources (interrupts, stack memory, data memory and some pins). That is why this
approach is called intrusive or non-transparent emulation.

4.3.3 I'mutators

An emulator is a piece of hardware that ideally behaves exactly like the real
microcontroller chip with all its integrated functionality. It is the most powerful
debugging tool of all. A microcontroller's functions are emulated itt real-time and non-
intrusively. An emulator by definition always works transparent or non-intrusively.
This means none of microcontroller's on-chip resources or l/O pins are lost due to
emulation. If emulation is non transparent, then it is not an emulator, but an evaluation
board. When developing a project of medium complexity, a non-intrusive emulator will
save a lot of time and effort.

All emulators contain three essential functions in different implementation forms:

I - The emulator control logic and emulation memory

2- The actual emulation device

>- The pinoul adaptor

4.3.3.1 ICiiiulatioii control logic and emulation memory

Control logic is the more difficult and expensive part of emulators, as it is


required to recreate functions that might be lost due to the emulator using these

43
resources (in other words, some standard I/O pins). My recreating such functions with
additional logic, emulators work truly transparent and non-intrusive. This means all the
pins, all the memory, and all the peripherals functions available like with the real
microcontroller. I'veu more, control logic is required to implement emulator features
such as break points, external event, single stepping, loop counters and trace memory.

An emulator uses external static RAM for the emulated program memory, because
ROM and O i l * (One Time Programmable) memories are not suitable due to program
changes. RAM memory allows the code to be changed quickly and an "indefinite"
number of times during the software debugging process. For flash based
microcontroller which grantee 1000 times of reprogramming, Hash memories are used
for emulation despite their limited life-time and low speed for the sake of price.

4.3.3.2 The emulation device

Emulators typically vise external RAM memory for program storing. Hence
it becomes apparent that, they can not use standard sample of the emulated
microcontroller for emulation purposes. They need special bond-out chips of the
microcontroller to be emulated. Those bond-out chips have additional pins that allow
the emulator electronics to feed the external stored program information to the
microcontroller instead of the on-chip memory content in standard microcontroller.
Also they control program execution (low and access on-chip registers and data
memory. Instead of special bond-out chips, some emulators manufacturers program the
microcontroller's complete functional model into a PIT) (Programmable Logic
Device).'! he main drawback of this approach is; how accurate will the PI.l) model of
the microcontroller resemble the real standard microcontroller. Anyway it works in
real-time with models of less complexity and slow speed. On the positive side, such
emulators can easily be reconfigured to support many different derivatives of a
microcontroller family.

4.3.3.3 The pinout adaptor

A pin adaptor gives the emulator's target connector, the same "package" and
pinout as the microcontroller to be emulated. Most emulators give a range of choices of

44
exchangeable pin adaptors that supports the exact derivative and package of your
specific microcontroller.

4.4 P r o g r a m m i n g microcontrollers

The last step in the development cycle is programming the chip, lo carry out
the j o b needed in the target hardware. Microcontroller programming depends on the
chip version whether it contains Hash memory or O T P (One Time Programmable)
memory. It is also classified according to the chip's position IN or OUT-of the target
hardware as follows:

4.4.1 Out-of-C'irciiit Programming

OTP microcontrollers are typically programmed out-of-circuit. That means


the chip is programmed before being soldered in the target board, for this purpose
production grade programmers are needed; which arc special programming hardware
similar to standalone f P R O M programmers. Programming process is carried through a
parallel bus of address lines, data lines, control line and 1IV programming voltage line,
therefore programmer are connected to the parallel port of the driving PC and
microcontroller programming utility is invoked. These programmers offer the choice of
optional, high quality, expensive, zero-insertton-foree (ZIP) pin adaptors to support
different packages.

4.4.2 In-Systcm Programming (ISP)

flash microcontrollers can be both in-circuit (in-system) and out-of-circuit.


In-circuil programming means that, the microcontroller is already soldered into the
target hardware and can be programmed via one of its communication interfaces
('HART, SIM). Ibis requires that, the signals needed for programming routed to an in-
system-programming (ISP) connector. ISP connector required varies from one
microcontroller lo another, so it is recommended that, before the PCI! layout is made,
which ISP connector required is decided. ISP process is done via the serial port of the
driving PC, therefore it is slower than out-of-circuil programming. But on the other
hand, ISP has some advantages as follows 116]:

1- It programs code and data memories.

45
2- It allows upgrading the system without disassembling.

3- It allows code incryplion and protection.

4- There is no need for expensive socket adaptors.

4.5 Emulation Technical approaches

Since development of microcontrollers, not only their unit volume has been
increasing over years, but also their application has been increasing too. One main
problem that has arose in using microcontrollers dealt with debugging • systems
incorporating these devices, since their program memory and data memory are
integrated inside the chip. I'mutators are designed to solve these problems. They are
used to design and run program outside the microcontroller memory to control the
process and discover the bugs. I''initiator used different approaches that can be reduced
in the following

4.5.1 Base unit and I'robecard

Many emulator consists of a base unit and probecard (the base unit is
connected to a I V via the serial, parallel or USB port) It contains the majority of
emulator electronics (emulation control logic and emulation memory), with the
exception of the emulation chip it self. The emulation chip is a special bond-out version
of the actual microcontroller and mounted on a separate small PCB, called the
probecard. This probecard connects via a ribbon cable to the base unit, and has a pinout
adaptor at the bottom, which allows the probecard to be plugged into a socket on the
actual target board in place of the actual microcontroller. The advantage of partitioning
the emulator into base unit and probeeard is that, one base unit can support many
different derivatives of the given microcontroller architecture (for example, all 8051
devices). \\y purchasing different probecards the emulator can then be changed to
support all the on-chip features and packages of the specific microcontroller derivatives.
Another advantage is that the probecard can be kept relatively small, which make it
easier to plug into the target in space constrained applications. I'robecard approach also
minimize the physical distance of the emulation chip from the location of the final
microcontroller, minimizing the impact of noise and additional capacilive and resistive

46
loading dial can become a big issue when analog peripherals need to be emulated.
Motherboards and daughtereards is a similar approach under different name.

4.5.2 Debug Board Modules (lHilYI)

In this approach all of the emulator electronics and the emulation chip are
combined onto one single board, large sized I'CB not housed in an enclosure. The
connection to the target system is accomplished by ribbon cable. This means that, all
signals of the microcontroller to be emulated arc routed via the ribbon cable that
connects the target system with the emulator. This is not preferred particularly when
A/I) converter signals are to be measured accurately during emulation. D B M s emulate a
single specific microcontroller and cannot be modified to support other derivative of a
family, on the other hand DBMs arc typically low priced than others, and their
debugging capabilities arc below probecard approach.

4.5.3 Dedicated emulators

There are several forms dedicated emulators, which only supports a very
narrow range of microcontroller devices (microcontrollers with identical functionality
and pinoul. but different memory sizes). They take the form of DBMs that can be
plugged directly into the target systems or base units and probecards with probecards
not being exchangeable. They are actually built on a small single I'CB with or without
an enclosure.

4.5.4 Emulators Using Microcontroller Flash Memory

With the advent of flash program memory new approach in microcontroller


becomes possible. The write/ erase capability of Hash program memory, in combination
with emulation support circuitry and code embedded in microcontroller; enable such
microcontroller to be its own emulator. This does not work with all Hash
microcontroller particularly earlier generation which lack the necessary on-chip
emulation support circuitry, flash microcontrollers with the necessary on-chip
emulation support circuitry can, regardless of the package, be soldered directly into the
target system. This of course grantee that the chip actually sees the exact environment
as the final one. This is a big advantage when it comes to emulating analog peripherals.

-17
The connection required to enable PC-based software debugging is accomplished by
few digital I/O pins of the microcontroller who have additional functions created by a
small piece of hardware. One common approach of the on-chip emulation interface is
the JTA(i interface, found mostly on 10-bit and higher microcontroller, flash
emulators do not require RAM memory to store program code, but they use lite
microcontroller's Hash memory. Another advantage is that, they also double function as
Hash programmer, since the program code can be downloaded into the chip's memory.
Also flash emulators arc in fact one. and the same emulator can support all flash
derivatives of a given microcontroller architecture. If a new device with new
functionality comes out, all needed is a sample of that new device and an update of the
debugger software. Therefore there is no need to buy new probecards or debug board
module or dedicated emulators for each new derivative. Disadvantage of using flash
emulators is that, program downloads (required after every code change) take much
longer time; also the microcontroller's flash memory life-time is limited and depends on
the write/erase cycles number given by the manufacturer.

48
Chapter Five

Debugging Strategies

For simple code, debugging is usually not an issue. However, as code size

increases, not only d o e s the need for debugging increases, the complexity of debugging

increases as well. Debugging may further be complicated by other issues, such as the

requirement of real-time debugging or the insertion or removal of debug code into the

final product code. Consequently, thought must be given to the debug strategy that is

used in a given application. Figure 5.1 depicts the available debugging strategies for

Micro System Controller ( M S C ) devices. 'I'he strategies range from simulation-based to

in-system debugging. ISI) is further categorized into software-based 1SD and hardware-

based ISD. T h e e x a m p l e s used in this application note focus on C and Assembly

programming, but the principles can be applied lo other p r o g r a m m i n g languages [19].

MSC Debugging Strategies

Simulator

Sc-ftware ISD HaiJv.aie ISD

h'liiiimil Mxiiiti'i IDt MoiiiU'i Unlit In Debug;


In Circuit r.iimlator
M M : MON MOX

figure 5.1 MSC Debugging Strategies Tree

-I')
5.1 Integrated D e v e l o p m e n t E n v i r o n m e n t I D E simulator

1DI\ is a set of development tools integrated in a user-friendly, Graphic Use

Interface ( G U I ) environment. Development tools integrated into the same environmen

shorten the code development cycle and reduce code errors, which also enhances c o d

quality. IDHs provide tools such as editors, assemblers, compilers, linkers, projec

management, and revision control, as well as device simulators in the same environmen

| 7 | . Simulators enable users to simulate code execution without requiring actual targe

hardware. Users can verily algorithms and timing, and simulate peripherals, interrupts

and l/O. This simulation is important because it allows the user to start cod<

development and even evaluate system performance before the target hardware i:

available, figure 5.2 below depicts the conceptual block diagram o f an IDE simulato

for the MSG device. Users can perform disassembly, break point, memorj

watch/modify, code execution trace, or peripheral monitor. Simulators also support codt

coverage tools that mark the code that has been executed. Simulators also providt

performance analyzer tools that record the execution lime for functions such that uses

can profile code performance. The most c o m m o n operation in simulators is codt

stepping. Simulators support single-step with step-into a target function, or step-over i

given function. T h e machine cycle count is accurate in the simulators, as well; therefore

execution time can easily be evaluated for inefficiencies.

Piocessoi Model

o
a
H • Llegistei File
t

Peiipheials

figure 5.2 Block diagram o f an IDC simulator Concept

50
Code simulation is a low-cost approach to code development, since it does not requin

any target hardware for debugging. When the code development reaches the stage tha

requires target hardware, however, debugging in the target system. In - Systen

. Debugging (ISD) is needed.

5.2 In S y s t e m D e b u g g i n g

Instead o f PC simulation. ISI) executes and debugs code in the actual targe

system. A d - h o c debugging is the easiest method for 1SD. Ad-hoc debugging is simph

inserting d e b u g code wherever needed. In Example below, for instance, two number:

(10 and 4 0 0 0 0 ) of different data types arc added. An error result of 25526 will b<

stored, since the unsigned n u m b e r 40000 is the same as 25536 for a 16-bit signec

number. T h e ad-hoc debugging method would simply add a print/ statement and inspec

the result. This style is good for simple code testing. When the code size increases

however, the n u m b e r of print/ statements becomes unmanageable. Other systematic

debugging m e t h o d s need to be used ( I ) .

ml i=IOJ:

unsigned int 40000:

y=/-» k:

printf("%ii ~ %d\ %d",j,i,k):

There are two categories of In-System-Debugging as shown in Figure 5.1 software

based and hardware-based ISI). Software-based ISI) is further divided into terminal-

based and IDE-based. Terminal-based debugging includes a genera I-purpose monito

and an on-chip debugger. IDE-based debugging includes a source level monitor am

flash-enabled-1 SI). Hardware-based ISD is further categorized into In-Circuit Emulator

(ICE) and Built-in D e b u g g e r Module ( B D M ) .

5.3 Software I S D T e c h n i q u e s

5.3.1 Terminal-Based General-Purpose Monitor

A terminal-based general-purpose monitor is a software monitor that reside

in code memory. T h e monitor program concept, as shown in Figure 5.3. acts as a

51

i-
interpreter between the user code and the terminal program. The monitor allows for
downloading code into the target system memory from PC terminal programs using the
on-chip U A R T , and then performing debugging features, such as memory or special
function register (SFR) read-modify, CPU status, or calling a user routine, single step, or
break.

MSC Target

r
MSC De^ice

PC COM port
Data Metnorv
R S 232

with Terminal
Emulator

Monitor Code

Figure 5.3 Monitor Conceptual Block Diagram

Two techniques may be used with the monitor code. First, the user code may be
downloaded together with the monitor code into the M S C Hash memory. Alternatively,
because program and data memories arc separate (that is, designed with Harvard
architecture), the user program can be stored in external data memory with the monitor
load command. When the user issues an execution command for the downloaded code,
the CPU fetches the downloaded code from external data memory. For a typical data
memory access, the memory is only accessible via a M O V X instruction. External
hardware is needed to enable the program fetch from data memory. The external
hardware may be a simple gate or diodes/resistor, which enables the data memory access

52
when the PSEN device signal is active. The biggest advantages for using the software
monitor are its simplicity and low cost. The disadvantages are:

1. Monitor debugging is only good for assembly language debugging. Since the monitor
interface is only a PC terminal emulation program, source-level debugging is not
supported. Source-level debugging functions such as single-step requires a symbol-table
and machine code to source code relationships.

2. Monitor programs have many hardware restrictions, such as needing an external


R A M memory PSEN connection and serial port baud rate setup. Greater effort is needed
to adapt the monitor program for the target system.

3. The existing monitor commands may not meet the needs of the user, and
modifications to the monitor may be needed. Furthermore, the source code for the
monitor program may not be easily available.

4. The monitor code and monitor PC communication port arc general-purpose resources
of the target system and are used for debugging purposes. Therefore, the application
code must avoid using these resources during debugging, and the application code must
be coded according to the monitor code coding style. For example, the interrupt vector is
re-mapped from OOOOh to a higher program memory address.

5.3.2 Terminal-Based On-Chip MSC Monitor Program

Some microcontroller has an on-chip, 2kB boot loader ROM that also
contains embedded debug sub-routines. Using the boot loader debug subroutines, such
as autobaud, put_string, and andjuirser, gives the user the lowest debugging setup.
Monitor programs are closely related to the target system hardware setup. General-
purpose monitor programs (most developed in the 1980s and 1990s) support EPROM
programming. The M S C devices are embedded flash memory devices. The MSC
embedded debug subroutines support not only the basic debugging commands such as
SSingleStep, B-Break, and Q-Continiie; they also support flash memory commands
such as CP-CodePageErase, CW-CodeWrite, XP-XDataPageErase, and L-LoadFlash.
For the M S C M o n to translate into debug overhead, the minimum configuration is
needed; Which is only 29 bytes of flash code space, as follows:

53
Sinclude (regl210. inc)

CSEG at 807FH

db OBFH; HCRO: PM1--0 RSI-1 to protect 0-100011 Flash

CSEG at OOOOH; Monitor code start

LCALL autohaud

mov R6, iihigh greet

mov R7, iilow greet

kail jnitstring

LIMP andj?arser

greet: dh Oah.Odh, "MSC Monitor",0

CSEG at 033H

; any other Aitxlnl handler

LIMP monitor_isr

In addition, since user code is stored in Hash memory, the downloaded code can be used

for the final application. The prototypes for the available embedded subroutine of the

Boot Loader R O M typically must be provided. The M S C Monitor is Hash resident, and

the Load c o m m a n d is used to download user code. Since the memory requirement for

the M S C monitor is very low, the user code may be linked with the M S C Monitor. The

MSC Monitor and the general-purpose monitor require a PC terminal emulator such as

Hyper-term, Tera-lerm, Procom. or Telix. These terminal programs have no information

about the source code or monitor operation. However, PC IDE programs have special

handshaking with monitor programs for extra source code information that a general-

purpose monitor or M S C M o n do not have. These sophisticated source-level interfaces,

when combined with the debugging commands, provide a user-friendly environment.

5.3.3 IDE-based Monitor: MON51

The M O N 5 1 program is a flash memory resident program that communicates

with the I D E to achieve source-level debugging, when it is used for M S C code

54
development. Here is an example to show the usage of the debugger: Program, as shown
below, toggles P3.4 after each output message using the built-in ROM routine
putstring.

$incltide (reg 1210. hie)

CSEG at 80001{

loop: mov R6, tthigh msg

mov R7, #low mxg

leall put string

epl p3.4

pnp loop

msg: dh "Toggle P3J".Oah,(Mh.O

CSEG A T 0FFD5H

jmi string:; void put_siring(char *string):

END

The IDE GUI greatly enhances the debugging efficiency. At any time, the user can
monitor the C P U register and any memory contents. However, this debug strategy
requires external m e m o r y , putting a great burden on the systems, which do not require
external m e m o r y .

5.3.4 IDE-based Monitor: ISD51

For small m e m o r y configuration devices, with only 4 k B of internal flash

memory, loading a t5'pical monitor program of around 6 k B for debugging purposes is

not possible. S o m e monitors provide a low source-level monitor program, requiring only

500 bytes of code memory. Since it is source-level, debugging quality is much better

than assembly-level monitors. It does not need the von Neumann-type external code

memory (true In-Systcm-Debugging is possible without extra debugging hardware),

which is important for small remote sensor applications. The 1SD51 operation is

different from the general-purpose monitor, and M O N 5 1 . Those monitor programs are
preloaded into the target system and wail for user c o m m a n d s lor downloading user code.
Due to the small size requirement for the I S D 5 1 . it is compiled and downloaded together
with user code in the target system. For those monitor programs to implement break-
point function (for example, for memory inspection), the CPU has to enter the interrupt
service routine for break address check; this is called software break-point. Some chips
have a built-in hardware break-point, that delects break addresses with hardware. 1SD51
fully utilizes the hardware break-point function, improving the execution performance
over software break-point by a hundredfold.

5.4 H a r d w a r e I S D T e c h n i q u e s

5.4.1 In-Circuit Emulator

ICE is hardware interfacing to the MSC device that can perform debugging

features such as trace, break-point, and stepping. It docs not use the M S C serial port or

occupy any code/data memory space, nor does it require any C P U cycle over for

debugging features. ICE can performs the debugging through control of the external

memory bus. I C E debugging requires the lowest target system over task and carries the

highest debugging capabilities. The ICE is integrated smoothly with the IDE; therefore,

the GUI, code profiling, and coverage features are supported. There arc several

disadvantages of using ICE:

1. Since ICE is hardware-based, with a deep trace and break point buffer, the

development tool cost is much higher than the software-based monitors.

2. External m e m o r y ports (PO, P2, PSEN, R D . WR. AIT-, and RST) are needed for ICH

connection. These ports cannot be used for target system applications.

3. To perform debugging, the ICE must be running at the same speed as the target

system. The m a x clock rate at 3 3 M H z means optimum requirements for the ICE timing

at this speed.

4. When driving the ICE hardware at high speed, the increased loading will compromise

analog performance, which is highly undesirable for In-system debugging.

5. ICE is not suitable for low-pin-count devices that typically carry no external memory

port for ICE interfaces.

56
5.4.2 Built-in Debug Module (BDM)

The B D M is a hardware logic module that is designed within the device.


Typically, the B D M interfaces the target system with the PC via a JTAG port. The BDM
has the advantage that debugging is running at the system maximum clock rate with
minimum effect o n analog performance. The debugging capabilities, however, such as
trace buffer size and number of break points are limited. It is because of the feature that
hardware occupies the device silicon area.

57
Chapter Six

Software Development

Microcontroller emulation, which is defined as the process of making


software and hardware assembly, that works exactly like a specific microcontroller
under the control of PC passed through different stages. A significant step was
production of Hash microcontroller which allows the microcontroller to emulate itself
under the control of some monitoring program controlled by a PC through the serial
port. Due to the lack of source information about IDE-based debugger for developing
IDE-based monitor, this study dealt with terminal-based monitor program whose source
code is given in appendix A. I his chapter will give an overview of the software
developed under the monitor program headings and will review the building process
carried out to produce it.

6.1 Monitor Program


The program is designed in an interactive way. It displays so many messages

and help information that guide the user during operation. Although it is covering a wide

area of program debugging still more modification is needed to make it efficient

particularly when IDE-based debugger is combined to it and hence breakpoint, single

step and trace can be meaningful. This monitor program is not very optimized for speed

and memory requirement, it is just written in a structured fashion with functions for each

task to m a k e it easy to understand and modify. The simplest representation of this

terminal monitor program is an initialization segment shown in Figure 6 . 1 , a power on

segment shown in Figure 6.2 and a loop that executes menu flowchart shown in Figure

6.3 below:

58
Start

Initialize constant parameters

Figure 6.1 Parameters initialization

Disable Interrupts
Reset ports
Delay 100.000 cycle
Erase flash if enabled
Run start up code if any
Run autobaud if not defined
Display welcome message

Figure 6.2 Power on segment

59
c Menu

) to UploacT*^

Prompt menu message


Input characters

Look for user command in memory

Execute user command

Display nevvline

Figure 6.3 Main menu

It is clear from the flowchart above that the monitor program supports user program

downloading, uploading, dumping memory area, j u m p i n g to some address location,

editing address content, running some program, displaying help messages, displaying

directories, erasing external area, displaying internal memory, clearing some memory

range and entering n e w memory location. The flowcharts shown in Figure 6.1, 6,2 and

6.3 above arc simplified. Presenting the whole flow chart requires over 100 pages.

Anyway, the initialization segment flowchart is shown in Figure 6.4 below and some

sample flow charts are shown in this chapter later on.

60
location t o LIMP iiitanipt
v*ctow c h u t c t t o = 8OODI1

4*fmlt location for


Uqu VKtot, 0x80001 tlteu<«r p t o c n m

(•qu p»jn, 0x80001 t t f i i u t i m o f iwrttoiy

• n J o f t l » memory
«quW»w,0xl000|

I«t tO >tOn-2»IO VftkM


«T> m i » m , OXFTRFL if fU<hit»u)WI

I fi»*t nwntoiy

• .W^ti^it o f FHsli ROM

r Iwt imntntv tocitit-m


o f Flult ROM

|«qaen»h,0«rFTr|
*J>I #1 M * j-iit. 0 pi) <-3D »M* *» i«« pin f»At>n*
_B5 -3Ppin 15, P3.5(T0

j r
D*«» tftVt

mini o f e h u tittw» t o
_. _ - p w * Aniitgnplovl*

I
I
„I.)it»cloiy

[*?i<iu k#y,'M'l
tun p t e f t u t t

IJWJJ witJc«y. 'R*|


lovl li*x fit*

I *<iudnM kty.'L'l

,~r" new wwnmiy toctlton

hmp

«-jn juiup_k«y, 7 [

Figure 6.4a Initialization segment flowchart

61
_ hex dump inemoiy
equ dumpjtey, 'H'
hex dump internal memoty
I
equ intm_key, T

_ —edit memoiy
equ edit_key, 'E'

clear memory
equ clrm_key, 'C

erase flash rem

equerfr_key,'Z'

_.l 1.0592 MHz


equ pgmwait, 19
equverwait, 5
twenty delays for 11.0592 MHz

equ eiwait 1,20

^ _ _ _ e a c h delay .5 ms @22.1184MHz
equ erwait2,229

value for psw

equ pswjnit, 0

block of 16 bytes for download

equ dnld_parm, 0x10


location of the stack

equ stack, 0x30

save baud for


"warm boot, 4 bytes
equbaud_save, 0x78
org base

reset vectoi

ijitvp poweiou
|.orgbase+3

Ijmp vector+3
tnov dpi, ro"
tnov dph, r7

,ret
"A

Figure 6.4b initialization segment flowchart

62
The program developed so far, does not have subroutine to allow single stepping and
register inspection. But register inspection can be displayed by a print message in the
user subroutine. Tor example, if a user wants to examine at a certain step the value of the
B register, the following block of code may be placed at the inspection point.

push A

mov A, li

call coul

call new/hie

call cin

pop A

This method of debugging is similar to print/ function using C. The accumulator is


stored in the stack. Then register B value is moved to the accumulator. The cout
subroutine displays the value of the accumulator, which is the value of B register. The
subroutine newline places a new line after the value of the B register. The subroutine cin
waits for a character until a key is pressed on the host. Finally the value of the
accumulator is restored by poping it of the stack. These steps may be combined in a
subroutine as follows:

inspect:

mov A, B

call cout

call newline

call cin

ret

Which is called by the main as follow:

push A

call inspect

pop A

63
Structured programming is adopted, which assigns a different route for each task, to
manage a large number of routines. To make the program readable, it's routines are
grouped in the source under the following seven headings:

1. Initialization parameters and interrupt vectors

2. Serial I/O subroutines

3. Main menu and monitor user commands

4. Memory, Management Subroutines

5. Power on and initialization

6. Multiplication and division

7. Multi-byte sequence and compressed data processing

The program is written in Assembly language to make it short and fast as required for
such objectives. Microvision development tool is used for writing, compiling and
debugging which is reviewed in one chapter before.

6.1.1 Initialization parameters and interrupt vectors

This part of the program assigns the constant addresses and values for the
following parameters:

1- Monitor base address


2- Interrupt vectors base address
3- User program starting address
4- External memory address range
5- Baud-rate constant value
6- Flash address range
7- Flash enable, erase and write address and data
8- Menu key values (help, directory, run, download, upload, new location, j u m p , dump,
internal memory display, edit, clear memory and erase flash R O M )
9- Power on reset vector

10- External interrupt 1 vector


11- External interrupt2 vector

64
12- Convert registers into pointer subroutine (small one)
13-Convert pointer into registers subroutine (small one)
14-TimerO vector
15- Timer 1 vector
16- Timer2 vector

17-Display dash subroutine (small one)

18- Display space subroutine (small one)

6.1.2 Serial I/O subroutines

cin: receives a character from the serial port.

dspace: sends double spaces to the serial buffer.

newline2: displays two empty lines, by sending CR and I,F to the serial port using cout
function.

ghex: gets 2 digit hex number from serial port. C = set if ESC pressed, cleared otherwise.
psw.5 = set if return pressed without input, clear otherwise.

2hexl6: gets 4 digit hex number from serial port. C -- set if BSC pressed, cleared
nT
otherwise, psw.5 set if return pressed without input, clear otherwise.

fthex!6x: multiplies r3-r2 content by 16 (shift left by 4).

ehex!6y: divides r3-r2 content by 16 (shift right by 4).

asc2hex: converts ASCII character in A to its equivalent HEX. If A content is not a valid
hex value (not in the range 0, 1,2 9, A, F) carry is set (C = 1).

phex: changes the 8-bits value in A into two nibbles (4-bis). Then changes each nibble to
it's ASCII, and sends higher nibble then the lower nibble to the serial port using cout
function.

phex!6: changes the 16-bits value in the DFTR into two 8-bits values in DIM! and DIM,.
Using phex8 it sends the 4 HEX digit in ASCII form to the serial port.

pstr: prints (sends to the serial port) multiple consecutive strings without needing to

reload DPTR (which takes 3 bytes of code!)... This is useful for inserting numbers or

spaces between strings.

65
upper. Converts the ASCII code in Acc to uppercase, if it is lowercase code.

lemlr. returns the length of the string in rO. The siring mentioned starts at the DPTR
content location. The string end is either 0 or bit.7 set.

esc: Checks to see if <ESC> is waiting on serial port. C=clcar if no <ESC>. C~set if
<ESC> pressed. Then buffer is Hushed.

6.1.3 Main menu and monitor user commands

menu: first prints out the prompt I, then it prompts another message asking for input and
it waits there. When the user enters his response it looks for similar external commands
in the external memory. When it is successful it executes corresponding routine. When
finished it returns. If it didn't find in the external memory it comes and looks for it in the
internal command. If successful it will jump to it and execute it. When not successful it
returns back to the beginning of the menu to repeat the process. The details of menu
explanation are embedded within the text in appendix.

dnld: routine download hex files from the serial port. 1 lex file is a number of data
• records terminated by C R and LF. A data record example is as follows:

:xxyyyy00aabbccddee mmZZ

where : Start of record

xv No. of data byte (two hex digits)

yyyy Starting address of the record (4 hex digits)

00 Record type No. for hex file

aabbccddee....mm Hex data (two hex digit numbers., equal xx)

ZZ Checksum value of all data record digits

. The download function receives from the serial port in this form, interprets it and save it.
The procedure explanation is embedded in the text in appendix. Also a number of
messages are displayed.

jump: routine asks for the address to which it will jump. If escapc(C=l) was pressed, the
program is aborted. If no address was entered (void input, p s w . 5 = l ) , the program returns

66
to where it was. When an address is entered the program makes a stack of 8 byte length
and j u m p to the specified address.

dump: displays 16 lines of 16 address location in hex format, beside it displays the
ASCII equivalent of address contents. The starting address is the content of r 6 - r 7 .

edit: routine edits external ram. It displays a message at the start to let the user enter the
address location he wants to edit. Then it displays the address beside it's content and ask
the user to enter the new value. When hex characters are entered the routine modifies the
specified location and moves to the next address. If non hex characters entered the
routine displays a message.

dir. routine maps the display formal and send information about the directories in the
memory to the display. It starts by displaying some messages and j u m p searching for
headers. It displays the name, value and type of the header it finds. It continues doing
this for the whole user memory.

run: subroutine searches file headers. When it finds a run-program, it prints its name on
the screen in a formatted layout. When il is finished, it asks for the choice to be entered
among the list. If ESC is entered the program return control to the menu, otherwise the
input is matched within some ranges to check it's compliance with choice list. When it is
okay the headers were searched for the run-programs in sequence. When the search is
successful the function will pass the address to another subroutine (at the end), which
will make a stack of 8 byte length and j u m p to the specified address.

help: routine is invoked from the menu. It displays help text and j u m p lo help2 to give

information about the help.

upld: routine uploads hex files to the serial port. I lex file is a number of data records
terminated by C R and LF. A data record example is as follows:-

•xxyyyyOOactbbccddee mmZZ

where : Start of record

xx No. of data byte (two hex digits)

yyyy Starting address of the record (4 hex digits)

67
00 Record type No. for hex file

aabbccddee....mm Hex data (two hex digit numbers., equal xx)

ZZ Checksum value of all data record digits

Firstly nplil gets the beginning address in r3/r2 (r2=LSB). and the final address in r5/r4
(r4=LSB), and prints them out beside some messages. Then it reads data from the
specified address, process it, and sends it to the serial port in the above form.

clrm: subroutine clears a memory area. The range is obtained by getjnem subroutine
and the clearance is carried by the smart _wr subroutine. The subroutine will scan all the
range starting from the lower address and going upward till the end address.

nloc: subroutine prompts to the user to enter the new location. If no address was entered
or ESC was pressed the subroutine is aborted.

erfr. subroutine prompts to the user information about erasing some area. If the user
entered ' Y \ erfr erases Hash and ROM. and displays message about erasure or about
error. It uses erall for erasure.

intm: displays the content of 128 internal address locations. It organizes the display in 8
lines, each one showing 16 location content. It carries out the display in two loops one
for lines and the other for frame.

6.1.4 Memory Management Subroutines:-

tlash wait: routine polls the flash ROM wait looping until the flash ROM is stable.
DPTR must be initialized with the address to read.

flash en: routine sends the flash enable codes for writing.

prsm: routine writes Acc into flash memory at DPTR. C is set if error occurs, G is clear
if it worked. The routine uses flash en routine. It calls also flash wait routine after
writing data. The routine then checks the data written to set or reset C flag.

erall: erases all the flash ROM and return C = l if failure, 0 0 if okay. It calls erhlock
for block erasure. Then it scans all the flash area if they are not completely deleted
(deletion = FF) to signal error. When deletion is okay 0 0 otherwise O l (error).

68
erblock: is an erase command. Il is called by erall. and is intended to be callable for the
flash memory so that custom block erase code can be implemented. It uses flash en
subroutine

find: searches for header in the external memory identified by the sequence A5. R5. P.O
and A5. The memory range searched is defined by hinem and emem. The input DPTR
pointing to the start of search address (only MSB used). Output is DPTR location of next
module. C = set if a header found. C - clear if no more headers

smart wr: routine tests the presence of Hash first. If no Hash was found it write to the
ordinary R A M . When a flash was found il checks the address to be written tt). is il in the
flash range or out. When it is inside, it uses prgm subroutine to write it's contents,
otherwise it writes it's content in the normal RAM. Writing to flash ROM or ordinary
RAM will be indicated. Carry bit will indicate successfully written (C=0), or not written
(C=l).

6.1.5 Power On and Initialization:

poweron: makes the hardware to be initialized by the following routine. Description of


poweron routine is embedded in the text.

stcode: routine is invoked automatically during poweron at the start. This routine will
look for startup specifier (249) among file headers. When it is successful, it saves its
return location and j u m p to that startup subroutine. When it returns it continues
searching for others and does the same until all startup routines are finished. At this
moment the function will return back to poweron routine.

aulobaud: routine is invoked automatically during poweron at the start when the
following line

equ baud const, 0 ;flag for automatic baud rate detection

is selected during initialization. To do automatic baud rate detection, measurement and


setting. It is assumed that the user will press the carriage return, which will cause the
below bit pattern to appear on port 3 pin 0 (CR = ASCII code of decimal 13 (OBh)),

69
0 10 1 1 0 0 0 0 1

II II
start b i t — + +--lsb msb--+ + — s t o p bit

To set the baud rate, the following formula is applied in calculation.

baud const =•• 256 - (crystal/(12 * 16 * baud-rate))

Timer HI is started in 16 bit mode at the transition between the start bit and the LSB and
is stopped between the M B S and stop bit. That will give approximately the number of
CPU cycles for 8 bits. Divide by 8 for one bit and by 16 since the built-in U A R T takes
16 timer overflows for each bit. After division the result has to be inverted since timer
HI counts up. O f course, timer HI gets used in 8-bit auto reload mode for generating the
built-in UART's baud rate.

6.1.6 Multiplication and Division:

pintSu: prints the unsigned 8 bit value in Ace in base lO.This is carried by dividing the
number by 100 and displaying the quotient (hundredth digit), then diving the remainder
by 10 and displaying the quotient (tenth digit) and lastly displaying the remainder (units
digit).

pint!6u: prints 16 bit unsigned integer in DPTR. using base 10. The function use pintxl6
function to divide the number by 10000 to display 10000th digit, and by 1000 to display
1000th digit, and by 100 to display 100th digit. Then it uses div to divide by 10 to
display 10th digit. Lastly it displays units digit.

pint!6x: divides r2-r3 by r4-r5 and leaves remainder in r2-r3 and returns quotient in
Ace. The division is carried by sequential subtraction.

6.1.7 Multi-byte Sequence and Compressed Data Processing:

tin filter: looks for multi-byte sequences for up, down, left, right, page-up, and page-
down, as well as ordinary escape and ordinary characters. Codes are required to arrive

70
sequentially otherwise the characters are treated as ordinary user keystrokes, cin filler

returns a single byte when it sees the multi-byte escape sequence, as shown here.

return value key escape sequence

A
11 ( K ) up 1B5B41

A
10 ( J ) down 1B5B42

A
21 ( U ) .right 1B5B43

A
8( I1) left 1B5B44

A
25 ( Y ) page up 1 B 5 B 35 7E

A
•26( Z) page down 1 B 5 B 3 6 7E

pestr: prints the compressed strings. A dictionary of 128 words is stored in 4 bit packed

binary format. When pcslr finds a byte in a string with the high bit (bil.7) set, it prints

the word from the dictionary. A few bytes have special functions and everything else

prints as if it were an ordinary siring.

Special codes for pcslr:

0 = END O F STRING

13 = C R / F F

14 = CR/LF & E N D O F STRING

' 31 = N E X T C A P I T A L (next word code should be capitalized)

dcomp: actually takes care of printing a word from the dictionary at DPTR position in

packed words table. This function scans the dictionary sequentially till il reaches the

particular word number. Then it reads the nibbles coded in the dictionary location and

translates them using some tables. Then the translated code is printed out. The nibbles

are managed by r4. r4=0 if next nibble is low, 1*4=255 if next nibble is high. It uses

getjiextnibble function to read the dictionary.

get next nibble: gets character specifier from table and update DPI"R and switch nibble

specifier r4.

71
6.2 Prc-design Stage (Structuring and [Modularity):

It has to be staled that the hierarchical organization of the software will not
be noticed in this chapter but the deep investigation of the source code at the appendix
will illustrate that. This will prove the structural and modular nature of the program
which is composed of module and subroutines in hierarchy. The lowest subroutines are
small and general-purpose used by higher-level subroutines. Bach higher-level routine is
more specific to the application. 'litis is due to the considerable efforts devoted to the
pre-design stage of the development cycle which is usually overridden. In this stage the
problem is partitioned into relatively sub-problems. Such modularization led to
reduction in code complexity and better code understandability. Moreover, such
modularization raised the necessity of data structures. That is hierarchical charts
showing the place of each module in the system, as well as the module-calling
convention is used in this stage. Beside that, the interface between the module that
communicate together and description of inputs and outputs of each module is
developed. That is hierarchical structure was the basis of this modular and structured
program.

6.3 Post-design Stage (Maintenance and Modification):

Generally programs do not break-down, all errors were in the program when
it is developed. These errors might be due to coding errors, specification errors or
incorrect assumptions during parameters passing from one module to the other. Anyway
this is minimized by code understandability which is enhanced by clear programming
style mentioned above and combined with comment in each line in the source code in
appendix. This is regarding maintenance while modification can be carried straight
forward by adding the new subroutine and modifying the above flowchart and the jump
table in the source code. Drawing flow charts increases code understandability to the
optimum, but the problem comes in the huge number of pages needed to make such
documentation. However, some samples arc presented here for justification, for
example Figure 6.5 shown below describes the asclhex subroutine.

72
a s c 2 h e x : A S C 2 H E X

clrc
a d d a, # 2 0 8

Figure 6.5 ase2hex subroutine

Another sample describing pstr is shown in Figure 6.6 below

73
pstr; send string to serial port

mov c, acc.7
smla,#)x7F
acall cout

" Cany?

Figure 6.6 pstr subroutine

Another sample describing run routine is shown in Figure 6.7 below

74
IUI1 ,RUN

Iine2 [
acall newline2
(list print the
menu, count itrins

n o v r2, #255 have w e found 'cm all'.'?


u o v dplr, #binem
Jec dph ftgt, 8) S a m p , 255. run2b

J
- I * , inc dph cjne a. #((«neni+1) Sgt
sjmp tun 3 m-<. Catty' I In
mov a, dph
Kail find

Yes

uov dpi, #1
clra
this one doesn't move a. (fftndptr
run .. find nest oil a, #0000001 lb
.:pla

I
icall ilspace
inc i2
print the key to press

... inov a. # W
»dd a,12
icaQ cout_sp
Kcal dash_sp
ttov dpi. #32
n.m3 at c Ihet c any to ronW
and the command name
E
~hcall psl
sir /
Kcall ncwline
nc
and continue doing this

r cjne r2. #255, rnn-1


mov dptr, #prompt5
nin2|—
ajmp p c s t r j i

<" Late' 1

Figure 6.7 Run routine (continue on next page)

75
NOV
T
Aftt t I¥PI"->MPT3
WALL PC*LR_H
MOV A, ifA' TT»I4 *<K TLW hit; TPW«T».-N'
WILL CO-IT
Kali ivh

INWA.i'AT

«\-*N TTU V M *JH* CHOW**


V*ALL EOUT

TNOV DPTR, #PTOMPT4


WATT PCITT_H
C M FILTTT_H

:JWT A, I¥2?, WW4*-I


KJMP RMVLUIT TLWY UWY ITIT V$LT .ESdP-gl
MOV R3, A
NOV a, # 3 1
:LIC
ITM» A, I 2
«U*»V A, I 3

C»NV ? >

.1.
f%ll.'o.it
|^ALL UPP*I I'LT*--L: T*T T#* IF IT** IIIVUT
3 2 , IT"*© EONV*TT LO «IPP*TF*A<»

XT.
!«OV a. T3

4
if ttiavtyp* '! V*J Ih-IN*A*

F 3 h*.« tit* »UNB*T TLWY TYP«4


< 'CANY? >

A«3DR2 K U TH* MAXIMUM ITMUF*R Sl3


IF TLWY TYPT'I OR«T TIN M I X
TTVN* * , ( 2
l.C
•IT* A. T3

Figure 6.7 Run routine (continue on next page)

76
inc i 3
movdpU'.flbmem
foe dph

Inc dph &gt, 8j &4INP, mn5b


"-•Hnov a. dph

_X.
sjtnp 11 mS
*r-ntt find

mov dpi, UA "H'TNL.IN'T ' V I D« THIS


clr a
CANY?
move a. fc$«+dptr

rpl a

this one doesn't


count til we find run... find next
the one they want cJjnz t3, nui5
icaflnewline
mov dpi, #64
ajtnpjump doit
v

Figure 6.7 Run routine

6.4 P r o g r a m development

KEIL uVision is the name of software dedicated to the development and


testing of a family of microcontrollers based on 8051 technology, The software can be
downloaded and evaluated from the website. Most versions share merely the same
interface. KEIL uVision is used for the development and testing of our different
subroutine• and the overall program. Here in these paragraphs, the different step
undertaken to carry the development process arc reviewed | 5 | .

6.4.1 Creating the project

To create a project, write and test the previous example source code, open
Keil and start a n e w project follow the following steps:

77
1- T o create a project, write and test the previous example source code, the user should

follow the following steps in figure 6.8 below | 5 | .

J^S^i^^&^^BB^^WJ' p
*iiP *"'* I ° ° '
h s
lyes hiimIOO H«*

import pVislonl Project...


£ p « n Projoct...

!" ; 3"2^iT»'tV.J. M,- Components, gnvironmont. Books...


,

Hi
•as

1 C!\«l«ctronics\|iioj»cts\Oir."-Oksol»t»V»i>ti t»st\t»<t.l lo2


2 Cs\«l«CWonicsVproj«ct«\DACOS\OAO rESTIt«3Vl*C.Uv2
3 Cl\«l«ctronics\piojects\DFM01 (rrtqutney m t t « r j \ A T 8 9 C 5 2 \ l V « t tst.Uv2
£ Cl\»lectronlcs\piojects\DrM01 (ti«<iuency m»t«rl\AT8«C52\f(«<i.Uv2
5 C : \ o l o c t r o n i c s V r o j o c t s W O B O C O t A A l 89(.°S2\cUl«i 2 7 - 1 1 •jnue.llvi
§.C!\«l«ctronlcs\|>roJ««s\DTHERMO\AT8?S52\HO.«imo.Uv2
7 C!\«1««ronics\pioi«cts\ROBOCOtlRl\T.ic'.icii <onUol\ATO?SS2\eonUoll*f.Uv2

•I U •» 8 Ci\«l«ctronics\projects\RoboconRl_b«a\AT09S52\slav«.Uv2
2
-

Cl\*l«ctronlcs\proj«cts\Robocon-Rt_bK»\AT89SS2\M»»Mr_B_2.Uv2
. X° C{\oltctronics\proj«cts\Robocon-Rl_bot»\AT89S32\M»st«r.Uv2
1
ILL
>ste a new project

Fijiure <>.X Clonic new projori

2- The user will be prompted to choose a name for his n e w project. Create a separate

folder where all the files of his project will be stored, choose a name and click save as

shown in Figure 6.9 below.

78
Create Mew Project: Egg
1
a d ra*

• Project v;orks By Recent


PocuT-en:*)

Device

My Documents

% Computer

Place*
Seve o t>pe. ^ect *. es:'
BuiM
I I T l\ A Command A fWnFtes /

Figure 6.9 Make new folder

I- The following window in Figure 6 . 1 0 will appear. The user will be asked to select
levice for target 'Target 1':

$ r ,.„..„... ^ „ . . . . . .
ffll« i^*;a«.^|^(^'£ftM;,Fli«h. P.tlfktr.li Lol. JVC8 Kind.. B«l|>.
'.; <- -*-iW 1
a>.'iimliTai' A A> t«

r U»Ei«^'Ur*er(L><S1)inU«ado(BL5l .,
r ll.-f' EiwrMtoJ Auftnbh: & V ; | j ; « i 4 i 1 « / A « l

a AT89LV51 6051 b«i^Fi<Sl<A:CMOSc<>«i<iteivith'lhiM'L«nlPlogiMi


M o r a y l o c k . 32I/Otwt,3TiMtt/Counien.'8iMemptaSoucM.
.
:

] | Q AT89LV52
| ! a AI89LV55
' • AT89S2051
, Q AT89S4051 J
l-a AT89S4D12
1 |-a AT89S51
• BWMUH.
] i a AT89S53
1 f Q AT89S8252
1
Q AT89S8253
i ! • ATS«C5122
j AT9tC140

ir^^^^^W'^fSr ''''" -
I •••'OK f - Cancel |" ' • ' •' • He*

II'I,,' i I

•'imiie 10 Select <lovio

79
4- From (he lisl at the left, select brand name ATMEL. then under ATMUL, select

AT89S52. A brief description of the device appears on the right. Leave the two upper

check boxes unchecked and click OK. The AT89S52 will be called your 'Target device',

which is the final destination of your source code. The user will be asked whether to

'copy standard 8051 startup code' click No.

5- Then click File. New, the following window in Figure 6.11 should appear. 'I"he box
named ' T e x t l ' is where your code should be written later.

^;ii^)^:fj^^^^^^ ';p^Mlis
{ .Ioo'ls . $ V C S Window M«lp

i' G ? B 0 , i ' ^ . t e ' i ' S ' i :W if A % % * %\ "

few---
'iJ*#-V"A""

U s'Textl

1
K f l l l H H
-

# 1 > (Simulation

l-'if.uiv ( t . 11 Make new fik

6- Use 'Save as' and choose a file name for your source code ending with the letter

'mm', 'monlest' for example.

80
7- Then add this file to your project work space at the left as shown in Figure 6.12. by
pointing the mouse to source group 1 in project work space, and right mouse click.

r
wtorlsl_l - pVtsfon 3
iini • i .......^n, „, ^^^^^^•>:>^-Y ii"*.

nI
I Target 1 mm
1 ! So'urc« <3>oup
Options for Group 'Source Croup 1 '

g * b u i W target
;£|y ftuildttrott

Hew Group
Add File* to Gioup 'Source Group 1*
' tSl l d * 9 * Components
r>a

; R«mo«« Group 'Some* Group I ' »nd its nl«s

ln,c1udt D«p«ndtnci*s

1
mprpnrJT

ISmulation

Figure 6.12 Adit life m l.'inid

After right-clicking on 'source group / ' , click on VlriV//7/t«.y to group...', then you will be
prompted to browse the file to add to 'source group 1', choose the file that you just
saved, eventually 'montesl.asm' and add it to the source group. You will notice that the
file is added to the project tree at the left.

81
8- Make sure that option to generate HEX file is turned ON. This is done by right-
clicking on target 1, selecting Options for target 'target 1*, then clicking 'output' tab.
Check the box 'generate H E X file' as shown in Figure 6.13. This step is very important
as the H E X file is the compiled output of our project that is going to be transferred to the
microcontroller |5J.

Options for Target 'Target T m


Device | Target Output J Ustm j Userg | C51 | A51 | BL51 Locate j BL51 Msc | Debug | U M e t |

r
Select FoWerforObjects.. Name of Executable: r;'"*" 2

• Create Executable: .vnonitorz

P Debug Information S* Bra-.vse Information

| P Oeate HEX File H E X Format:

<" Create Ubrar/: .'mon<tor2.L!B I ' Create Batc'i Fi'e

Figure 6.13 Create hex file window

9- N o w the user can start to write the source code in the window tilled 'monies!.asm'

Then before testing the source code, the user have to assemble your source code, and

correct eventual syntax errors. In KEIL IDE. this step is called 'rebuild all targets' and

has this icon: S .

82
6.4.2 Building the project

T h e user c a n use the output w i n d o w to track eventual syntax errors as shown

in Figure 6.14 b e l o w [5J.

monteit - nVfs!on3 - [C:\Dpcutnerits and totlr>gsVibdulmori^mVD«ktop\coskiiri»moiKHm\8051n)oi).asm)

&oject BfibuQ Flash Periphwa's I o * S'.'CS 'Mo--'


j)Efe Eit t£%>
JaJxll
$ Kl 0 Hi :
:•
i 09 a <a |lpl'•:•> !

tMa)

ijectivori-space 0529
0530 3C
0531
0532 xch •>, r l
0533
0531 aoall
0535
0536 n<->\' a , r2
053?
0539 swap a
0539
or! a. r3

El SC51W. [

2 3 5 I r . c r . . a e r . i - H l t : e r r c r > . ? : syrrrAX
7
S?*CR
SvSlrcor..a«r.f : error ^2: ST?~.^ T:F-.*I'.*A7"
;: s:r.er..asBH«'Hi:
,
warr.ir.e A4i; ::iss:::3 'E::B -
3rATE:-!s::r
Targes not creased

<_|} \> f \ B u i l d / . C o m m a n d A F » r i « l ? » " /

I ieiiif (>. I ) Ituikliiu*. p i o c c s s

If after correcting errors and rebuilding the targets, the 'output window' shows that there

is 0 error, then t h e user is ready to test the performance of his code. In keil, like in most

development environment, this step is called Debugging, a n d h a s this icon: 'Si.

6.4.3 Debugging the project


After clicking o n the debug icon, the user will notice that some part of the

user interface will change, s o m e n e w icons will appear, like the run icon circled in

Figure 6.15 below:

83
j n r w n t e s t - „ } i V i s f o n 3 - [ C : \ D o c u i n e n t s a n dS ^ n g s t a t H f u l m o n e i m X D e s k b ^ f

I'i^iMV 6 . 1 5 l ) c h i i i : s . ' . i n < . " . p m c i "

The user can click on the 'Run' icon and the execution of the program will start. In this

example, the user c a n see the behavior of the pin 0 or port one a s s h o w n in Figure 6.15

above, by clicking o n 'peripherals. I/O ports. Port 1'. T h e user can always stop the

execution of the program by clicking on the stop button ( O ) and he can simulate a

reset by clicking o n the 'reset' button r J t . He can also control the execution of the

program using the following icons: ^ ^ ^ which allows the user to follow the

execution step by step. Then, w h e n he is finished with the debugging, he can always

return to the p r o g r a m m i n g interface by clicking again on the d e b u g button (@L).

84
Chapter Seven

Results and Discussion

The source program was built using uvision development tool and then tested

(Figure 7.1 and Figure 7.2 below) [7].

QZE9D0SI
CI

- S_I T*IM I

" B j tt tU »» ^ .
Build t«cget 'Tarftct 1'
nssembllug moitl. *>•»...
Unking...
FtOflCMx 3i*»t dat«-8.0 Kd«t(.-0 cod<!*30."
•123" • 0 Krrorto), (I tKtrnlneto) •

H~

Figure 7.1 Building the project

E<# V«W> D«MTT ORTMQ PMR^VALT LOCK SVCS WIDOW TJT»

PrOled, WMfeJftCW
- * J TMMM I

load **C:\\t>oci«nj*nt» *nd 3»*tt.«o*\\c©9kt)n_1j*J

ASM ASSIGN BrRthMonble IttenhRimltle


•< I ' I - 1. K WNM X(<MIW»MMI X risdkililM VII « f

Figure 7.2 Testing the project

85
All features of the program that do not require external R A M were tested using the
simulator and found perfect; for example:

Help c o m m a n d of the program when tested showed the result in Figure 7.3.

,= U ART. 01 -
8051 Microprocessor Monitoring Learning » Board

ADDR:8000smon» Help

Standard Commands
?- This help list
H- List programs
R- Run program
L- Download
U- Upload
N- New location
J- Jump to memory location
H- Hex dump external memory
I- Hex dump internal memory
E- Editing external ram
C- Clear memory
User Installed Commands

ADDR: 8 0 0 0 £ m o n »
ADDR: 8 0 0 0 « r o o n »
V

Figure 7.3 Running of the Help command of the program

Internal memory display in which the program displays the contents of the internal 256

R A M area showed the result in Figure 7.4 [7J.

•• UAUt #1 .. ,
ADDR:0005£mon» Hex dump internal memory

00: 00 00 01 OB 43 00 05 00 B6 08 00 00 00 00 00 00
10: 00 00 00 00 00 00 00 00 00 00 00 00 no 00 00 no
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
30: 00 DF 01 82 07 07 84 01 43 BE OE EA OA 00 OA 00
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
70: 00 00 00 00 00 00 00 00 FA FA AF FA 00 00 00 00
BO: 0 0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
90: 00 00 .00 00 00 00 00 00 00 00 00 00 00 00 00 00
AO: 0 0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
BO: 0 0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
CO: 0 0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
DO: 0 0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
EO: 0 0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ro: 0 0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

ADDR:0005«roon>> |

Figure 7.4 Running the displays to see the internal R A M

86
Clear internal memory feature in which the program will clear the internal RAM showed

the result in Figure 7.5 [7]

39E1
40 00
00 00
00 00 00 00 000 00 00
00 00 00 00 00 00
so 00
00 00
00 00 00 00 0
00 00
00 00 00 00 00 00
60
00 00 00 00
00 0 0 00 0 0 0 0 0 0 0 0 00 00 00 00 00
70 00 00 00 0 0 0 0 00 0 0 0 0 FA FA AF FA 0 0 0 0 00 00
80 00 00 00 00 00 00 00 00 00 00 00 00 00 0 0 00 Of)
90 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
AO 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
BO 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
CO 00 00 00 00 00 00 00 00 0 0 00 00 00 00 0 0 00 ou
DO 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
EO 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
FO 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

ADDR:0005smon>> Clear memory

First Location: 0000


Last Location: FOOO
Are you s u r e ?

ADDR: 0 0 0 5 6 n r o n »

Figure 7.5 Display of the clear command running

Download, upload, directory, run, j u m p , dump, edit and erase c o m m a n d s could not be
tested at this stage as they need external memory. In fact some steps were taken in all
these features until encountered by the lack of external memory, hence aborted by
escape character. This is clear evidence that it is running perfectly.

Using E P R O M programmer the HEX file of the source at the appendix was loaded in

8952 microcontroller chip which contains 8Kbyte Hash memory for holding the

program. Then the chip is inserted in the circuit described in Chapter 2. Making serial

connection between the host PC and the circuit, and then powering up the circuit are the

only two steps needed. Using the hyper terminal in (he host PC for communication the

test went on as expected as follows when the circuit is powered on the hyper terminal

received some characters from the monitor indicating communication and waiting for

baud rate measurement. Pressing carriage return makes the monitor enter baud rate

measurement and respond by welcome message:

87
Downloading s o m e program using L command resulted in successful download as

shown in Figure7.6.

Welcome to MON2

8051 Microprocessor Monitoring Learning « Board

Program Name Location Typo


l i s t 1000 E y. I. e r 11 n 1 <: oiniti a n d
Single-Step 1400 External command
Memory Editor (VTlOO) 1800 External command

ADDP. L o c : 2 0 0 0 > Download

Begin a s c i i t r a n s f e r of I n t e l ex f i l e , or ESC t.o a)>ort

Download completed

Summary:
114 l i n e s received
1808 bytes received
1808 bytes w r i t t e n
No errors detected

J
(C^JnecTed 0 : 0 3 : 2 3 " ' JAuto delect"~ |57BW 8-N-i

Figure 7.6 Downloading some program

When the R A M is not working properly, an error like (Unable to write) should appear.

Other errors such as checksums, unexpected hex digits are indicated as download

problems.

Running the user program command using R showed what is shown in Fig(7.7) below.

To run the e x a m p l e without a header, use the "Jump" c o m m a n d by pressing "J".

Program will ask y o u for the address where it will j u m p to run the program. You can

type 2000 or j u s t press enter if the default value is 2000.

88
EJeseiaE
l_pdtoi itV-ejwHyp£eaTi»etmItnaiarolfet Hepl
M*wwwJ*lwrtl MwmAiiflrtiJ IWIIWIIMMHIIM *m*mmm "
BIQ0E3

31
APDR Loc:2000 > Juinp t o memory location

Jump t o memory l o c a t i o n (2000), or E S C to quit: i'000

running program:

Ple««« *"yr« a word ( 4 char max) : TKOT


iHtititltlt!! MMUM Mtiltlftt HttittiUM
#n#ifit1f1t ####### ####### MfMM
## ## ## ##
## ## ## ##
## ###### ##### ##
## ## ## ##
## ## ## ##
## ####### ####### ##
## ####### ###### ##

Press anykey_

C6Weldft11:29 TiAutodeled"' (57600Wfl


• •: {lE&OtI."*'|?>JPT'fRFsT*JC*'*|Ff,-«*;i
I'igure 7.7 Running some user program

It has to b e mentioned that the serial port is used by the monitor program for
communication with the host PC; therefore the user should be careful not to change the
baud rate and he should be capable of differentiating between communicating with
monitor o r the user program. Also the hardware can be developed by adding another
serial port connector which the user can use freely. Beside this some Programmable
Peripheral Interface (PPI) integrated circuits like 8055 can be added to the circuit which
allows the user to connect parallel input and output devices like switches and displays.
This can be very useful for troubleshooting beside the serial port. This monitor program
is designed for using flash memory and static RAM in the external memory. The flash
memory (although not present now) is very useful for storing program in the absence of
power. In this case all flash parameters have been defined in the source code as required
and the (has_flash) parameter should be changed to one. When flash is added also flash
erase facility is also imported and should be added using a j u m p e r or push button as in
some cases t h e user need to erase the flash content on reset. T o load a program in the
flash region it has to be built in the memory range of the flash; therefore the flash range

89
(eflash and bflash) in the source code need to be known by the user and considered in

making the hex file.

Single stepping a n d tracing (the most powerful tools for debugging) could not be

executed by this program because they are not included in the program. This is due to

the fact that this program is terminal-based monitor, while single stepping and tracing

require IDE-based monitor in which the user interface c o m m u n i c a t e s with the monitor

by a series of characters rather than single character as in terminal-based monitor.

H o w e v e r this p r o g r a m can be developed to achieve single stepping and tracing if

thorough investigation is carried out for IDE based c o m m u n i c a t i o n protocols.

90
Chapter Eight

Conclusion and Recommendations

Results found in the last chapter indicate that the emulator developed
is working properly. Regarding user program downloading, uploading, displaying
memory area, j u m p i n g to source location, editing, running .displaying directories,
erasing, and displaying internal memory showed excellent results.

Although emulation capabilities are limited in the above features only, they are

quite enough for debugging significant portion in the emulation process. It worth

mentioning that, the work targeted exploration of the emulation process assisting in the

development of microcontroller based equipment. It ended up with different strategies

for debugging and different approaches, not expected, aiming to incorporate the

necessary hardware and software for debugging inside the microcontroller itself. This is

why the work concentrated on basic emulation feature and left advanced emulation

features like single stepping, tracing and pausing for future work. This could be

accomplished if some host PC emulation program is developed or studied thoroughly and

this monitor program is modified lo carry out more intelligent communication with the

new P C environment.

Furthermore this study could be nucleus for source-level debugging investigation which

is optimum debugging w h e n under stood, taking in mind recent trends for debugging and

emulation.

It is inevitable to mention here the advantages of such emulator regarding simplicity

and low cost while the disadvantages arc the following limitation:

1- Not supporting source-level debugging

2- Hardware restrictions such as external RAM requirement and serial port set up.

2- C o m m a n d s many need modification.

4- General purpose resources like the serial port is used for debugging so it must not

be used in the application.

5- Applications must be coded according to the monitor coding style .

91
As a conclusion this work tried to disclose emulation of 8051 microcontroller so as to
facilitate the debugging process and fortunately achieved significant success and
hopefully pointed out some point as recommendations for further investigation.

92
REFERENCES

1. 8051 Tutorial, Vault Information Services, 1999.

2. Eight-Bit 80C51 Embedded Processors. A M D Corp.. 1990.

3 . 8-Bit Embedded Controllers, Intel Corp., 1990.

4. 8-Bit Embedded Controllers Handbook, Intel Corp., 1998.

5. Getting Started and Creating Applications. Keil I Iser's Guide 2000.

6.1 leffcrnan, D., 8051 Tutorial, 2002.

7. Keil uVision IDE A S M compile tutorial, Hi-Tronic, 2005.

8. Karakehayov, Z., Christensen, K. S., Winthcr, ()., Embedded System Design with

8051 Microcontroller: Hardware and Software, 1999.

9. 80C51 family and hardware architecture. Philips Semiconductors. 1996.

10. 80C51 family p r o g r a m m e r ' s guide and instruction set. Philips Semiconductors.

1995.

1 1 . Microcontroller Users' Guide, Signctics Corp., 1989.

12. Steiner, C , T h e 8051/8052 Microcontroller: Architecture, Assembly Language,

and Hardware Interfacing.

1 3 . Yeralan, S., Ashutosh, A.. Programming and interfacing the 8051

Microcontroller, Addison Wesley Publishing Company, 1995.

14. Douglas V. Hall, Microprocessors and interlacing Programming and hardware,

M c G r a w - Hill Book company, 1986.

15. U R L : http://www.futurlec.com Augst 2008

16. URL:http://www.farnel.com/datashcct June 2008

17. URL:http//wvvvv.NXP.com June 2008

18. URL:http//www.faq.om/microcontrollcr Augst 2008

19. URL:htto//www.spvfu.com Augst 2008

20. URL:http//www.patents.com Atmst 2008

93
Appendix A

T e r m i n a l b a s e d Monitor p r o g r a m s o u r c e code

Initialization parameters and .Interrupt Vectors

T h e s e t w o p a r a m e t e r s c o n t r o l w h e r e MOM2 w i l l b e a s s e m b l e d , a n d w h e r e i t : w i l l
a t t e m p t t o LJMP a t t h e i n t e r r u p t v e c t o r locations.
base equ 0x0000 ; a d d r e s s l o c a t i o n f o r MON2
vector equ 0x2000 / a d d r e s s l o c a t i o n t o LJt-H' i n t e r r u p t , v e c t o r ; :

/ T h e s e t h r e e p a r a m e t e r s t e l l MON2 w h e r e t h e u s e r ' s m e m o r y i s i n s t a l l e d . 'bmem" a n d


;"emem" d e f i n e t h e s p a c e t h a t w i l l b e s e a r c h e d f o i p r o g r a m b e n d e r s , u s e r i n s t a l l e d
;commands, s t a r t - u p p r o g r a m s .
pgm equ 0x2000 / d e f a u l t : a d d r e s s l o c a l ion t o r t h e u s e r pt.oqram
bmem equ 0x1000 ; t h e b e g i n n i n g of e x t e r n a l memory
• emem e q u OxFFFF ; e n d of e x t e r n a l memory

;To s e t t h e b a u d r a t e , u s e t h i s f o r m u l a o r s e t t o 0 t.oi a u l . o d e t e c t i o n b a u d c o n s t
; = 256 - ( c r y s t a l / (12 * 16 * b a u d - r a t e ) ) .
;Most e m u l a t i o n p r o q r a m s i n t r o d u c e i n t e n t i o n a l d<> 1 .!\ wh'Mi S ' M i d i n q n s c i i . d a t a ,
;which y o u w o u l d w.mL t o t u r n o i l (<>i d o w n l o a d i n g l a i ' . i " » p i o g i a m s i n t o RAM. Ko r
; f l a s l i ROM, t h e m a x i m u m s p e e d i s s e t b y t h e t i m e it t,\i:>-:; t o p r o g r a m o . - f h
.•location.

baud_const equ 0 / f l a g f o r a u t o m a t i c b a u d r a t e d e t e c t i o n (when 0)


baud_const equ 255 ; 5 7 6 0 0 b a u d - r a t e w i t h 1 1 . 0 5 0 2 Mllr.
baud_const equ 253 , 1 9 2 0 0 b a u d - r a t e w i t h 1 1 . 0 5 9 2 MHz
baud_const equ 252 , - 1 9 2 0 0 b a u d - r a t e w i t h 1 4 . 7 4 5 6 MHz
baud_const eqn 243 ; 4 8 0 f t b a u d - r a t e w i t h 12 MHz
l i n e delciy equ 6 ;No. of c h a r t i m e s t o p a u s e r i m i n g u p l o a d s

; T h e s e a r e f l a s h ROM p a r a m e t e r s . I f " h a s f l a s h ' i s s e t t o z e r o , a l l f l a s h r e m


,'features a r e t u r n e d off, o t h e r w i s e " b f l a s h " anr " o f l a s h " s h o u l d s p e c i f y 'be
/memory r a n g e w h i c h i s f l a s h ROM.
;"erase_pin" a l l o w s you t o s p e c i f y t h e b i t a d d r e s s f o r a p i n w h i c h ( i f h " Id low)
.•will t e l l MON. t o e r a s e t h e f l a s h ROM c h i p w h e n i t s t a r t s u p . This is useful ii
;you d o w n l o a d p r o g r a m s w i t h t h e " s t a r t - u p " b o n d e r s o n t.bem a n d I h e c o d e y o u ' v e pui
;in t h e f l a s h ROM c r a s h e s .

has_flash oqu 0 / f l a s h i n s t a l l e d f l a g (when not. Z>MO)


bflash equ 0x8000 / f i r s t , memory l o c a t i o n ol F l a s h R O M
eflash equ OxFFFF / l a s t m e m o r y l o c a t i o n of. F l a s h R<>K
erase_pin equ 0 ;00 - d i s a b l e erase pin fealui.o
erase pin equ 0xB5 ; B 5 = p i n 1 5 , P 3 . 5 (Tl.) ( e r a s e p i n a d d r e s s )

/ S p e c i a l f l a s h ROM p r o g r a m m i n g a d d r e s s e s w e r e met. b y b a s e a d d r e s s a d d e d t o flash


;memory r e g i s t e r a d d r e s s e s . T h i s i s d o n e f o r f l a s h ROM e n a b l i n g , w r i t i n g a n d
/erasing.

flash_base equ bflash /flash start - 0x8000

flash_enl__addr equ 0x5555 + f l a s h base /send data to a d d r . for f l a s h enable


flash_enl addr equ 0x595A + f l a s h base /different, flash version
flash_en.l_ d a t a equ OxAA

flash_en2_addr equ 0x2AAA + f l a s h _ b a s e /send data to addr. for flash enable


flash_en2_addr equ 0x26A5 + f l a s h _ b a s e /different flash version

94
/. I a s h on2 dai a qu f'.xf.:.

C l a s h wr a d d r o q u ()xr>i>5!> ' I l.eish b a s e ;N<MI'I •> a d d r . Cm i ! a:;h wr i t<


r
l L a s h wr a d d r o q u 0x5<-*5A + f l a s h b a s e /different .lash v e r s i o n
f l a s h w> d a t a , OxAO

CJ a s h o r I a d d r oqu 0x!°-> i flash base / s«=nd d a t a t.oaddr. for Clash erasure


f l a s h e r l addr equ Ox.'^'vA » flash base ;di f ferent flash version
f lash_erl_data equ 0x80

flash_er2_addr equ 0x555b t flash base ; s e n d dat.a to addr. for Clash erasuc
f l a s h _ e r 2 addr equ 0x595A t flash base /different llash version
flash er2 data equ 0x10

;Koy d o f i n i . l i o n : . - f o j MOM.
i
h e l p key oqu / h e l p .••croon
• d i r key Oqll •M' ; d i I o i -1 n r y
run key o q u ' R' ;run proqram
dntd key e q u • IV /download
upld key equ • u * ;upload
1
n l o c key e q u M' / n e w m e m o r y l o c . i t i • >ii
jump . k e y oqu ' J ' / j u m p 1 " m e m o r y lo<vi» i o n
<.lurap k e y equ * i r ; h e x <lump m e m o t y
intra k e y oqu ' i • ; h e x dump i n t e r n a l ; ; e m o t y
e d i t key equ 'E' / e d i t memory
clrm__key eqn ' C ; c l e a r memoiy
erfr_key equ 'Z' / e r a s » f 1 a s h r om

;Tiniing p a r a m e t e r s f o r some f l a i l ROMs.


; pgmwait equ J 0 ; 2 2 . 1 1 8 4 MH:-. c r y s t a l assumed ( d e l a y ? M.
pgmwait equ 19 ;1.1 . 0 5 9 2 MHz
verwait equ 5
; erwaitl equ '10 ; f o u r t y d e l a y . - - 0 2 2 . 1 1 K 4 MH:-.
erwaitl equ 20 ; t w e n t y d e l a y s f o r 1. I.0T>"2 MH?.
; erwait2 eqn 22 9 ; o a c h d e l a y . ' > m s (J22 . 1 11'< 4M11 /.

/These s y m b o l s c o n f i g u r e MON i n t e r n a l m o n u u y u s a g e .
psw i n i t equ 0 ; v a l u e l o r psw ( w h i c h reu bank t o u s e )
dnld_parm equ 0x10 ; b l o c k o f 1 <*> b y t e s f o r d o w n l o a d
stack equ 0x30 / l o c a t i o n of t h e s t a c k
baud s a v e equ 0x78 r s a v e l o c a t i o n f o r baud-'*on.-*t warm b o o t , (4 bytes)

;The f o l l o w i n g map s o m e MOM s u b r o u t i n e s


org base ; s t a r t from b a n e
ljmp poweron ;jump t o power on reset: v e c t o r
.**************•***•******** .
org base I 3 / s t a r t , from b a s e t '
ljmp vect.orH 3 ; jump t o e : : t i n t o v e c t o r
. * > * * * * * * * * * * * * * * 4 * 4 * 4 1 *• * l .

r6r7todptr: ;e<>uvM;t r
'"id r 7 i n t o d p t i
mov dpi, r6 / m o v e rti t o dpi
mov dph, r7 / m o v e rG t o dph
ret /rerurn
* * * * * * * » * * * . A * * * * * * * * * * * . * .

org b a s e i 11 /si.art from b a ' II


vector-i-l] ; iuinp t o t int'M 0 \-.>clot

dptrtdr6r7: / c o n v e r t d p t r .into i:6 a n d r l


mov r6, dpi / m o v e d p i t o t:C
1

mov r7, dph / m o v e dpli t o r 7


ret /return

95
-
org b a s e ^19 /start t rom b a s e i 1-i
ljmp v e c i '.r:+l /jump t o oxt i n t l vector
. 4 *********** * * * * 1 * * •* * * » * * .

clash: mov a, »'- ' ; l o a d (••) i.nl o A


ajmp COt.lt /jump t o output: e h a i a e t e r (-)
nop /no operation
. * * * * * * * * * * * * * * * * * * •* * * I - * - - * .

org b a s e t 2 7 / s t a r t I 'ram b a s e i 27
ljmp v e c t o r + 2 7 / j u m p ti> t i m e r ! v e c t o r
.*****•**•** + ****+*••*•*•»< * * * * * .
cout_sp:acall C O U t / c a l l con!: t o output; e h a r a e i o i
ajmp space /jump t o d i s p l a y a s p a c e
nop / no o p e t a I i * h i
* * * * * * * * * * * * » * * * * * * . * * * *•* . .

org b a s e i 3 5 / s t a r t t r o m b a s e '• 3 5
ljmp v e o t . o r + 3 5 /jump t o u a r t v e c t o r
.*************************.
dash_sp:acall d a s h / c a l l to d i s p l a y dash
ajmp s p a c e /jump t o d i s p l a y space
nop / n o o p e r a t i on
. * * * * * * * * * * * * * * * * * * * * * * * , * .
f *

org b a s e i 4 3 / s t a r t front b a s e i 4 3
1 jiiip v e c t o r * 43 / j u m p t o timer;*, v e c t . r u r
(fco >.>)

.lump T a b l e Lot F't out am'.-. "nbroiit. i t i e s falls

/Never c h a n g e this line!! Othet pt.ogt. ims d e p e n d on those locations to access mon
/functions.

org base-i 4 6 ; st a r t
ajmp phox 1 /*-:!•:; ( o o t 4<
ajmp coul ;30
ajmp c.i.n / 32
ajmp phex /34
ajmp phex16 ;36
ajmp pstr ;3ft
ajmp ghox ;3A
ajmp ghex16 ; 3C
ajmp esc /4F,
ajmp upper ;40
ljmp autobaud ;42
pcstr_h: Ijmp pest r ;45
• ajmp n e w l i.ne /40
ljmp lenst r /4A
Ijmp p i n 1811 /4n
ljmp pints / 50
Ijmp p i n t : lt'iu ;53
ljmp cmar 1. wi ;50
ljmp prgm ;59
ljmp erall ;5C
ljmp find /5F
cin_f i l t e r _ h :
ljmp cin_ ft Iter ;62
ajmp asc2hex ;65
ljmp erblock ;67

Serial 1/0 Subroutines


;cin receive- a oha1noter from the serial por<

cin: jnb r i , «.:in ; .1 o o p i l r o c t t i v o i n t e r r u p t f l a g not set


clr r i ; clear receive interrupt flag
mov .a, sbuf ;put s e r i a l buffer i n t o A
ret ;return

;dspace sends double spaces to the serial buffer

d s p a c e : aca.l I. spare ; c a l l . d o u b l e s p a r e t r a n s m i t ii.n


s p a c e : mov a , I! ' ' ; p u t s p a r e i nt o A
cout: _ jnb ti, cout ;d i s p l a y i t
clr ti / c l e a r transmit interrupt
mov sbuf, a ;put. A i n t o s e r i a l b u t t e r t o s e n d
ret ; r e t urn

newlineZ d i s p l a y s two empty .linos, by s e n d i n g <:\K a n d I.F t o the • 1 i A I P E R I. u s i nq


cout f u n c t i o n .

newline.2: ; p r i n t t w o now l i n e s
a call n o w ! i tie ; d i s p l a y new l i no
newline:push acc ; s a v e A (to print one newlitiv)
mov a, #13 ;put carriage return into A
aca.l 1 cout / d i s p l a y it;
mov a, #10 ;puf l i n o food i n t o A
acal 1 cout / d i s p l a y if
pop acc ;rest ore A
ret ; r e t urn

ghex g e t s 2 d i g i t h e x n u m b e r f r o m s e r i a l p o r t . (' - s e t .if. KSC p r e s s e d , cleared


otherwise, psw.5 ~ set if return pressed without, i n p u t , c l e a r o t h e r w i s e .

ghex:
ghex8: c l r p s w . L> /clear user defined flaq
ghex 8 c :
acall cin fii t e r h /uet f i t s t d i g i • (msb)
acall upper / convert. t o uppercase
cjne a, #27 , ghe.x8f / jump i T. n o t e s c a p e c h a r
setb c /clear c a r L Y flaq
clr a /clear A
ret /RET u r n
cjne a, #13 , ghexSh /jump i f not a c a r r i a g e r o t n i n
setb p s w . !'i / s e t THE u s o t 1 ie 1 i n e t 1 1 ! a q
clr c /clear c
clr • a /c1ea t A
ret / ROT 1.11 11
mov r2, a / m o v e c h .u tmsb) i nt •• 1 2
aca.l I asc2be X ; c o n v e r ! a s c i i to hex t o check
qhexi-'c / j ump i ! n e t h e x
xch a , I:2 /EXCHAIKI .i h e x c h a r (msb) a n d c h a r
acall cout / d i s p l a y c h a r (msb)
ghex8 j :
acal! c i n _ l i 1 tot. h /uer s e c •nd d i t | i •• (isl-))
a call u p p e T: /convert TO u p p e r c a s e
cjne a, #27 , ghexSk / j u m p i1 NOT e s c a p e c h a r
sjmp ahexBd / j uinp i f escape
cjne a , # 1 3 , ghexiim / j ump i. f not a c a r r i a g e return
mov a, r2 / p u t HEX (msb) i n t o A
clr c /clear c
ret / r o t u 1 !i

<>7
ghex8iri:cjne a, #8, ghex8p ; jump i f n o t a b a c k s p a c e
ghexSn: a c a 11 cout / i f b a c k s p a c e , d i s p l a y i.t a n d
sjmp ghex8c ;jump back
ghex8p: c j n e a , 921, ghexBq ;jump i f not a n e g a t i v e aeknow 1 edge
sjmp ghex8n ;jump i f n e g a t i v e a c k n o w l e d g e
ghex8q: mov r3, a ; m o v e c h a r ( I s b ) i n t o r '<
acal 1 asc2hex / c o n v e r t a s c . i l t o h«x t o c h e c k
jo ghex8j /jump i f c a r r y (non hex o a r ) n

xcii a, r3 / e x c h a n g e hex char ( I s b ) and c h a r (Isbi


a c a 1 1. cout / d i s p l a y char Msto
mov a, r2 /move h e x c h a r (msb! i n t o A
swap a /swap A (exhango the n i b b l e s )
orl a, r 3 / o r A vi i V i i h e x c h a r t I s b )
clr c /clear c
ret /return

g h e x l 6 g e t s 4 d i g i t , h e x number from s e r i a l p o r t . (' - s e t i f ESC p r e s s e d , cleared


otherwise, psw.5 — set i f return pressed without input, clear otherwise.

ghex16:
• mov i-2, #0 /clear rl
mov i:3, 110 / c l e a r r?
mov r4, #4 /number of d i g i t s loft.
clr psw. 5 /user defined flag bit
ghex16c :
acali cin f i l t e r h / s e r i a l input
acal 1 upper /change input char t o u p p e r c a s e
cjne a, if27, ghexl6d / j u m p i f i n p u t , i s not. a n e s c a p e
setb c / h a n d l e e s c key
clr a /clear A
mov dph, a / c l e a r dph
mov dpi, a / c l e a r dpi
• ret /return
ghexl6d : c j n e • a , If8, g h e x l f i f / j u m p i f t h e i n p u t not a b a c k s p a c e
s jir.p ghex16k /jump down, s i n c e b a c k s p a c e
ghexl6f :cjne a , # 1 2 7 , gh.ex.16q /jump i f i t 127
ghexl6k : c j n e r4, #4, ghexl6e /jump i t some d t q i t s e n t e r e d
sjmp ghex16c /jump i f no d i g i t , e n t e r e d
ghexl6e : a c a l l cout / d i s p l a y input
acall ghexl6y / d i v i d e b y 16
inc r4 / i n c r e m e n t r4
sjmp ghexl6c /jump t o get. a n o t h e r d i g i t
ghexl6g : c j n e a, #13, g h e x l 6 i /jump i f not c a r r i a g e r e t u r n key
mov dph, r3 /move r3 t o dph
mov dpi, r2 /move r2 t o dpi
cjne r4, »4, ghexlCh /jump i f some d i g i t s e n t e r e d
clr a / c1eai A
raov dph, a / c l e a r dph
mov dpi, a / c l e a r dpi
setb psw.5 / s e t general purpose j titerrupt
ghexl6h:clr c /clear c
ret /return
g h e , x l 6 i :mov r5, a /keep a s c i i value of the d i g i t
aca.11 asc2hex / c o n v e r t to hex
jc ghexl6c /jump i f not hex
xch a, r 5 /prepare a s c i i digit: to d i s p l a y
l e a 11 cout / d i s p l a y d i g i t i n r5
mov a, r5 / r e t u r n hex d i g i t for f u t t h e r p r o c e s
push acc / s a v e t h e d i g i t from d e s t r u c t i o n
acall ghexl6x / m u l t i p l y b y 16
pop acc /restore the digit (1st byte)

98
add a , t;2 ; a d d d i g i t . a !' t e i mu .11 i p! i c a t i o n
mov • r2, a ; s t o r e new v a l u e j u r 2
clr a /clear A
acldc a, r3 / a d j u s t t h e (2nd b y t e )
mov r3, a / s t o r e r.3
cljnz vl, ghexl6c / j u m p i f r'1 n o t z e t . - . , t i b r i n g t h e n e x t .
clr c /clear o
mov d p i , r2 /put. r2 i n t h e p o i n t e r (1ower b y t e )
mov d p h , r3 / p u t t 3 i n 1 h e p<> i n! «"r ( h i g h e r b y t e t
re!:. / 1 oi u i n

/ghexl6x taul t i p l i e s r3-r2 content by Id (shift left by 4).

ghexlfc.x:
mov a, r3 /load r3 i nto A
swap a /swap A (to p r o c e s s lower nibble)
anl , #1111.0000b /mask out (unwanted nibble after swapping)
mov v 3 , •i /put it b a c k i n f o r
mov a, r2 / l o a d r2 i n t o A f o r processing
swap c! /swap A for further froce^Ping
anl a, # 0 0 0 0 1 1 1 1 b /mask h i g h e r n i b b l e
orl a, i 3 / a n l A w i t h R3
mov ' r3, a /sve r e s u l t i n t o t3
mov a, r2 /.load A w i t h r2
swap a / s w a p A f o r furt hot p i o e o s s i ng
anl a , HI I . 1 1 0 0 0 0 b / m a s k out l o w e r n i b )} e
mov r2, a / s a v e A int o i 2
ret /return

/ghexlCy divides r3-t:2 content by 16 (shift right by 4).

ghexl6y:
mov a, r2 / l o a d r2 i n t o A
swap a /swap A (to p r o c e s s higher n i b b l e )
anl a, tfOOOOllllb / m a s k out. ( u n w a n t e d n i b b l e a f t e r s w a p p i n g )
mov r2, a /put. it. b a c k i n t o r2
mov a, r3 /.load r3 i n t o A for p r o c e s s i n g
swap a /swap A for f u r t h e r p r o c e s s i n g
anl a, #11110000b /mask l o w e r n i b b l e
orl a, r2 / a n d A w i t h R2
mov r2, a / s v e r e s u l t i n t o r2
mov a, r3 / l o a d A w i t h r3
swap • a /swap A for further p r o c e s s i n g
anl a, #00001111b /mask out h i g h e r n i b b l e
mov r-3, a /save A i n t o r3
ret /return

a s c 2 h e xconvert ASCII c h a r a c t e r i n A t o its e q u . i v a . l e n t - . IIKX. If A content is not


v a l i d hex v a l u e ( n o t i n t h e r a n g e 0, 1, 2, 9 , A, F) c a r r y is set
(C = . 1 ) .

asc2hex:
add a, #208 /add t o execl.udo d i g i t s with a s c i i lower than zero
jnc hex_not. /jump i f no c.airy, d i g i t lower
add a, #246 /add to execlude d i g i t s with asei.i h i g h e r than n i n e
jc hexjuaybo / j u m p i f e a t . r y , d i g i t may b o A, H, 0 , I), K o r F
add a, #10 / a d d t o c a n c e l 2 4 6 add.il. i o n
clr c /clear c
ret /totut n
hex_ m a y b e :
add a, #249 /add to exeeludo digits with ascii lower than A

99
jnc hex not /jump i f no c a r r y , d i g i t lower
add a, #250 ;add t o e x e c l u d e d i g i t s w i t h aso i i h i g h e r thar
jc hex not ; j u m p i f c a r r y , d i g i t i s n o t A , B, C, D, E n o r
add a, #16 ; add to cancel l a s t addit i o n s
clr c ; c l e a r c.
ret ;return
hex_not:setb c ; set c
ret ;return

; p h e x c h a n g e s t h e 8 - b i t s v a l u e i n A i n t o t w o n i b b l e s (1 - I d s ) . T h e n c h a ; o s e.|,:h
; n i b b l e t o i t ' s ASCII, and s e n d s h i g h e r n i b b l e then the 1 ower n i b b l e t t h e s(>r i a !
;port using eout function.

phex :
push •rl CO ; s a v o A b e c a u s e we h a n d l e n i b b l e - ( h i g h !
swap a ;swap the n i b l e s
anl a, #15 ; m a s k out l o w e r n i b b l e
add a, #24C / a d d t i . c h e c k whet h o i h e x h i <ihe i ' h in •>
jnc phex b ; j u m p t o a d d 5 8 , i l ri"l h i iter I li
add a , #7 ; i f h i g h e r t h e r e f o r e d i d i t i s A , B, c, b , or
phex b : a d d a, #58 ; a d d 58 t o a d i u s t it t o a s o i i
aca.l 1 ecu t ;output A content
pop act: ; i o s t o r e A t o r 2nd n i b b l e {1ower u i b b 1 e )
phexl: push acc ;save A
anl a, #15 ;mask out h i g h e r n i b b l e
add a, #246 / a d d l o c h e c k whet h e t h".-: h i g h o i t n a n '.'
jnc phox c ; jump t ( i a d d '•(!, i f n o t h i g o r t h
add a , #7 / i f h i g h e r t h e r e f o r e d i g i t i s A , B, C, 1), oi K
phex_c : add a, #58 ; a d d 58 t o a d j u s t , i t t o a s o i i
acal.1 cout ;output A content
pop • acc /restore A
ret ;return

p h e x l 6 c h a n g e s t h e 1 6 - b i t s v a l u e i n t h e d p t t i n t o tw>> s < ~ b i t s v a l u e s i n d p h a n d
d p i . U s i n g p h e x H i t s e n d s t.he 4 H E X d i g i t in A e f ' M l"ini t o t h e s e r i a l port.

phexl6:
push acc ;save A
mov a, dph ; load higher p o i n t e r eontout nil
acall phex ;ea.ll 8 b i t output function
mov a, dp 1 ; l o a d lower p o i n t e r content o A
acall phex ;call 8 bit output function
pop acc /restore A
ret ;return

;pstr p r i n t s (sends t o t h e s e r i a l port) m u l t i p l e c o n s e c u t i v e s t r i n g s without


/needing t o r e l o a d dptr (which takes 3 b y t e s of c o d e ! ) . . . 'this i s useful, for
/ i n s e r t i n g numbers or s p a c e s between s t r i n g s .

pstr: push acc /save A


pstrl: clr a /clear A to use in the pointer
move a, @a+dptr / g e t addr. content
inc dptr /point, to next addr.
jz pstr2 /jump i f i t i s z e r o
mov c, acc.7 / s t o r e b i t 7 i n c a r r y (end f l a g )
anl a, #0x7F /mask bit: 7 o f A content.
acall cout /display character
jc pstr2 /jump t o the end i f c a r r y s e t
s jmp pstrl / o t h e r w i s e , jump t o b e g i n i n q
pstr2: pop acc /rest ore A
ret / r e f u i ri

100
/upper Converts the ascii code in Acc t <• ' i p p e t c - i s - - , if i! js lowereas*.

upper:
cjne a, #97, upper2 / i ump i f <;har i s ( a )
upper2.: j c upper4 / j ump i f c h a r l o w e r t h a n (a)
cjne a, # 1 2 3 , upper3 / j ump i f c h a r i s (r.!
upper3: jnc upper4 / j ump i f char h i g h e r than (z)
add a, #224 /convert t o u p p e r c a s e by a d d i n g
upper4: r e t /return

l e n s t r r e t u r n s t h e l e n g t h o f t h e s t r i n g i n rO. The s r i n q m e n t i o n e d si a t t s at th"


d p t r c o n t e n t l o c a t i o n . T h e s t r i n g e n d i s e i t h e r (.) ot. b i t . 7 s o t .

lenstr: mov rO, #0 / r e t u r n s l e n g t h of a s t r i n g 1 n


push acc / s a v e A t o u s e t h e ac.-um l a t . >r
lenstrl :clr a /clear A
move a,0a+dptr /load A with addr. content
jz lenstr2 / i s i t end of s t r i n g
mov c,acc.7 / l o a d c a r r y w i t h acc;. 7 ( e n d f 1
inc rO /increment counter
Jc lenstr2 / j u m p t o e n d i f c a r r y SP-'
inc dptr ;increment pointer
sjmp lenstrl / l o o p back
l e n s t r 2 •pop acc / rest'ore A
ret /return

esc Checks t o s e e i f <ESC> i s w a i t i n g on s e r i a l port, '.'-cleat if n o '.KSC>, C=s<?t


i f <ESC> p r e s s e d . Then b u f f e r is flushed.

esc:
push acc /save A to use the aceumlator
clr c /clear c
jnb ri,esc2 /jump i f r e c e i v e i n t e r r u p t i s not s e t
mov a,sbuf /.load A w i t h s e r i a l b u f f e r contents
cjne a,#27,escl /jump i f s e r i a l b u f f e r c o n t e n t s i s n o t an e s c
setb c / i f s e r i a l buffer contain e s c . Set carry flag
clr ri /clear receive interrupt
pop acc /restore A
ret • /return

T h e Menu a n d M o n i t o r User Commands

/menu f i r s t p r i n t s o u t . t h e prompt. 1 , t h e n it p r o m p t s a n o l b e t m e s s a g e a s k i n g f o r
/ i n p u t a n d i t w a i t s t h e r e . When t h e u s e r e n t e r h i s r e s p o n s e i t l o o k s f o r s i m i l a r
/ e x t e r n a l c o m m a n d s i n t h e e x t e r n a l , m e m o r y . When i t i s s u c c e s s f u l i t e x e c u t e s
/ c o r r e s p o n d i n g r o u t i n e . When f i n i s h e d i t r e t u r n s . I f i t d i d n ' t f i n d i n t h e
/ e x t e r n a l memory i t c o m e s and l o o k s f o r it. i n t h e i n t e r n a l command. I f successful
/ i t w i l l j u m p t o i t a n d e x e c u t e i t . When n o t s u c c e s s f u l i t r e t u r n s b a c k t o t h e
/ b e g i n i n g o f t h e m e n u t o r e p e a t t h e p r o c e s s . T h e d e l a i l s oJ menu e x p l a n a t i o n is
/embedded w i t h i n t h e t e x t ,
menu:
mov dptr, •promptI / p o i n t t o prompt 1 m e s s a g e
acal 1 pcstr_ h / d i s p l a y message
mov a, r7 / m o v e r7 t o A f o r o u t p u t :
acall phex / c a l l phexS t o output a b y t e
mov a, r6 /move r6 t o A f o r o u t p u t
acall phex / c a l l phexB t o o u t p u t a b y t e
/mov • d p t r , #prompt2 / p o i n t t o prompt 2 m e s s a g e
acall pstr / d i s p l a y message

101
/Now t h e p r o m p t is p a s t a n d some: i n p u t i s e x p e c t e d .
a c a . l i. cin filter h /get the input c h a r a c t e r
cjne a , # ' : ' , meuuO / j u m p t o menuO, i f n o t :
acall dr\l.d_now ; o t h e r w i s e down I o a d
sjmp menu ; j u m p t o menu
meruit): acall upper /•change A c o n t e n t t o u p p e r c a s e
;Push r e t u r n a d d r e s s o n t o s t a c k t o e n a b l e jumping t o t h e program.
mov b, #(menu & 255) ; l o a d r e t u r n a d d r e s s low b y t e
push b ;push the return address
mov b , if ( m e n u >> 8) ;J.oad r e t u r n a d d r e s s h i g h b y t e
push b /push the return address

; l o o k t h r o u g h memory f o r a p r o g r a m h e a d e r that, i s u s e r i n s t a l l e d command, to mate!


/ w i t h t h e p r e s s e d u s e r command.
menux:' mov b, a ; n o w s e a r c h f.<.>r e x t o i n a l commands..
mov d p t r , ft bittern ; l o a d d p t r . w i t h bmem
m e n u x l :: a c a l l f ind ; f i n d header of files
jnc menuxend ; j u m p , s i n c e a l l commands s e a r c h e d
mov d p i , #4 / p o i n t t o f i g u r e out i t s t y p e
clr a /clear A
move a,@a+dptr /.load i t s t y p e
cjne a , # 2 5 4 , m e n u x 2 ; j u m p i f n o t e x t command (FK)
inc dpi /•increment t o f i n d specifier
clr a ;clear A
move a,da+dptr ;move s p e c i f i e r i n t o A
cjne a , to, m e n u x 2 ;jump i f s p e c i f i e r and B n o t e q u a l
acall space /display space
mov ' dpi, #32 ; p o i n t t o h e a d e r name
acall pstr /display it
acall newline / d i s p l a y new l i n e
mov dpi, #64 /point to header
clr a /clear A
jmp @a+dptr /jump t o it !
menux2: i n c dph / i n c rente n t d p h
mov a, dph / m o v e d p h Co A f o r e o m p a r i s i o n
cjne a , # ( ( e m e m U ) >> 8) 1 2 5 5 , m e n u x ] / j u m p b a c k i f not T i d
menuxend:
mov a, b /move char in B t o A
; S i n c e n o u s e r i n s t a l l e d command w a s f o u n d , u s e t h e b u i l t . i n o n e s .
menula:
menulb: c j n e a, # h e l p _ k e y , menulc
mov d p t r , # h e l p cmd2 /point to message
a c a 1.1 pestr h zdi s p l a y i t
a jmp help / j u m p t.o s u b r o u t i n e
menulc: c j n e a, # d i r _ k e y , menuld
mov dptr, #dir_cmd
• acall pestr h
ajmp dir
menuld: c j n e a, #run_key, menule
mov d p t r , # r un_ cmd /point to message
a c a .1.1 pestr h /display it
ajmp run /jump t o s u b r o u t i n e
menule: c j n e a, # d n l d _ k e y , menulf
mov d p t r , # d n l d _ cmd
acall pestr h
ajmp dnld
menuIf: c j n e a, # u p l d _ k e y , menulg
mov d p t r , # u p l d cmd
acall pestr h
ajmp up I d
menulg: c j n e a, # n l o c key, menulh

102
mov d p t r , # n l o c cmd ;point to message
acall pcstr h ;display i t
ajmp nloc ;jump t o s u b r o u t i n e
menulh: cjne a , Hjump k e y , m e n n l . i
mov dptr, Itjumpcmd
acall pcstr h
ajmp j unip
menul j.: cjne a, tdump k e y , m e n u l i
mov d p t r , ttdump emd
acall pcstr h
ajmp dump
menulj: cjne a, HediL_key, menulk
mov d p t r , # e d i t cmd ;point to message
acall pcstr h ;di splay i *
ajmp edit ; j ump I. o s u b t o u t i n e
menulk: cjne . a, ifclrinjtey, menul1
mov dptr, #clrm_cmd
acall pcstr h
ajmp clrm
menu11: cjne a, # e r f r k e y , menulm
mov a, #has_flash
jz menu e n d
mov d p t r , # e r f r cmd ;point to message
acal 1 pcstr_h / d i s p l a y i'
ajmp er f r ;jump t o s u b r o u t i n e
menulm: c j n e a, # i n t m k e y , menuIn
mov dptr, #intm_cmd
acall pcstr_h
ljmp intm
menuIn:
/ I n v a l i d i n p u t , n o commands to run...., So n e w l i n e wi 1.1 just return to menu.
menu_end:
ajmp newline

d n l d r o u t i n e d o w n l o a d h e x f i l e s f r o m t h e s e r i a l p o r t . . Hex f i l e i s a n u m b e r o f
d a t a r e c o r d s t e r m i n a t e d b y CR a n d h F . A d a t a r e c o r d e x a m p l e i s a s f o l l o w s : -
:xxyyyyOOaabbccddee mmZZ
where : Start of record
xx No. o r datci b y t e (two hex d i g i t s )
yyyy S t a r t i n g a d d r e s s o f t h e r e c o r d (-1 h e x d i g i t s )
00 R e c o r d t y o e No. f o r hex f i l e
a a b b c c d c i e e . . . . mm Ilex d a t a ( t w o h e x d i g i t , n u m b e r s . , e q u a l x x )
ZE Checksum v a l u e of a l l d a t a r e c o r d d i g i t s
The d o w n l o a d f u n c t i o n r e c e i v e s f r o m t h e s e r i a l p o t t i n t h i s f o r m , interpetts
and s a v e i t . The p r o c e d u r e e x p l a n a t i o n i s embedded i n t h e t e x t . A l s o a number
messages are explained as follows:
d n l d s l = " B e g i n s e n d i n g I n t e l HEX f o r m a t f i l e <ESC> t o a b o r t "
d n l d s 2 = "Download a b o r t e d "
d n l d s 3 = "Download c o m p l e t e d "
16 b y t e p a r a m e t e r t a b l e : ( e i g h t 1 6 b i t v a l u e s )
* 0 = lines received
* 1 = bytes received
* 2 bytes written
* 3 = bytes unable to write
** 4 = i n c o r r e c t checksums
* 5 = unexpected begin of l i n e
* 6 u n e x p e c t e d h e x d i g i t s ( w h i l e w a i t i n g for b o ! )
* 7 unexpected non-hex d i g i t s (in middle of a l i n e )
dnld:
mov dptr, ttdnldsl /point to message to d i s p l a y

103
acall pestr_h r"begin sending file ESC • t o a b o r t '
acall dn.ld_in.it c a l l i n i f i a l i s a t i o n >'i l o w
;Lo.ok for b e g i n l n g of l i n e marker i . t
dnldl: acal.I t cin ;get in a character
cjne ' a, # 2 7 , d n l d 2 ;jump i f not e s c a p e
sjmp dn.ld_esc /jump s i n c e e s c a p e
dnld2: cjne a, # ' : ' , dnld2b ;jump i f n o t :
sjmp dnld2d ; j u m p s i n c e ( : } t o e •nt. i n u e b e l '
;Check to s e e i f i t ' s a hex d i q i t , error i f i t i s .
dnld2b
acall asc2hex ; c o n v e r t a s c i i t o hex
jc dnldl ; i f c a r r y s e t (not hex) jump b a c k
mov rl, #6 / s p e c i f y t h e c o u n t e r Cor u n e x p e c t e d h e x
acall dnld_inc /increment counter
sjmp dnlcl'l /jump back
; E n t r y p o i n t f o r m a i n menu d e t e c t i n g " character.
d n l d now:
mov a, , A
# ' ;move c h a r a c t e r t o A
acall cout ;display character
acall dnld i n i t ; c a ] l i n i t i a l i z a t i o n below
d n l d 2 d : mov rl, #0 / s p e c i f y c o u n t e r f o r Mo. o f trials
acal 1 dnld inc ; i ncrement. c o u n t e r
taking in the record l i n e of data
dnld3: ;mov a, # ' . ' ;move (.) i n t o A
; a c a l l ' cout ;display characfei
mov r 4 , #0 ; i:4 w i l l c o u n t u p c h e c k s u m
acall dnld ghex /get hex c h a r a c t e r (No. of data b y t e s )
mov rO, a / m o v e N o . <>f d a t a b y t e s t o rQ
a , V .'
mov ; move (.) i n t o A
acal] cou t /display '.' ehuraetot
acal] dnld ghex ; q e t h e x c h a r a c t e r ( s t a r t i n g adck . msb)
mov dpit, a /High b y t e of load address
acall dnld ghex ; g e t hex c h a r a c t e r ( s t . a r t i n f addr. ]sb)
mov dpi, a ;l.ow byt.e o f .load a d d i e s s
aca.l 1 dnld ghex ;get: hex c h a r a c t e r ( r e c o r d t y p e . . h e x e t c )
cjne a, # 1 , d n l d 4 /jump i f r e c o r d t y p e n o t 1 i . e . (hex type)
sjmp dnld end /jump i f r e c o r d t y p e i s ] (non hex t y p e )
dnld4: jnz d n l d unknown ;jump i f r e c o r d t y p e i s n o t z e r o
dnld5: mov a , rO ;mov i n t o N o . o f d a t a b y t e s A
jz d n l d g e t cksum ;jnmp a f t e r last: d a t a was w r i t t e n
acal 1 dnld ghex /Get data b y t e
mov r2, a ; m o v e d a t a b y t e t o r:2
mov r l , #1 /specify counter bytes received
acall dnld inc ;increment eounter
mov , a, r2 ;load A with data byte
lcall s m a r t wr ; w r i t e b y t e , c = l i f an e r r o r w r i t i n g
clr a ;clear A
addc a, #2 ,-add 2 t o c a r r y ( 2 ~ w r i t t e n , 3 " n o t . w r i t t e n )
mov rl, a / s p e c i f y counter t y p e ( w r i t f e n or not w r i t t e n )
acall dnld inc /increment counter
inc dptr /increment dptr (point to the next location)
djnz rO, d n l d S /jump back t o w r i t e t h e rest.
t cksnm :
acall dnld ghex / g e t hex and add checksum t o i 1 c o n t e n I
mov a, r4 /move checksum v a l u e t o A
jz dnldl / j u m p i f n o t z e r o , t o r e c o r d c h e e k sum e r r o r
dnld_sumerr:
mov r l , #4 / s p e c i f y c o u n t e r t y p e for cksum e r r o r :
acall dnld_inc /increment counter
sjmp dnldl /jump t o beciining

104
; I l a n d l e unknown .line type.
dnld_unknown:
mov a, i 0 / m o v e N o . of '.lata hyt '•• A
jz dri) d g e t o k s u m / s k i p data if s i z e i s r:ot*>
dnld_ukn2:
acal) dnld_ghex / c o n s u m e a l l o f unknown d a t a
djnz rO, d n l d _ u k n 2 ; d e c r e m e n t a n d jump i f d a t a not. finisher
sjmp dnld_get_cksum ;jump t o g e t checksum
. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** * * * * * * * * * .

/Handles the proper end-of-download marker.


dnld_end:
mov a , rO move No. o f d a t a b y t e s t o A
jz ' d n l d end 3 should u s u a l l y be zero
dnld_end_2:
acall dnld_ghex rconsume a l l o f u s e l e s s d a t a
rO, d n l d u k n 2 d e c r e m e n t a n d jump i f d a t a n o T FLLLJ S I I ' M I
djnz
dnld_end_3:
dnld_ghex ;got the last checksum
acal 1
a , r<l /•move c h e c k s u m v a l u e ? t o A
mov
dnld_ sumerr ; j u m p i f n o t z e r o TO F L N O E R I O R
• jnz
dnld_dly ; c a 1.1 d e l a y
a c a l .1
dptr, #dnlds3 ;point to message
mov
p c s t . r _ h , - d i s p l y " d o w n l o a d wont. o k .
acall
/•Consume a n y CR o r LF c h a r a c t e r t h a t may h a v e b e e n o n t h e e n d o f t h e 1 a s t !i n o .
j nb ri, dnld_sum ; jump i f r e c e i v e i n o r n i p i not SO|;
acall cin /•input c h a r a c t e r
sjmp d n . l d sum ; j n m p t o summary
. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * '

/•Handle e s c r e c e i v e d i n t h e d o w n l o a d s t i e n m .
dnlcl_esc:
acall dnlddly /call delay
mov dptr, #dnlds2 /point to string
acall , pcstr h / d i s p l a y "download abot t e d . "
sjmp dnld_sum / jump t o s u m m a r y
/
. A * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * » * * * * 1 * * * * * * *
/.

/A s h o r t d e l a y s i n c e m o s t t e r m i n a l e m u l a t i o n p r o g r a m s w o n ' t b e r e a d y t o r. eee.1 v e
/anything immediately after they've transmitted a t i l e . . . T h e f o l l o w i r iq d o l a y i s
/estimated a s r o u g h l y 128k c y c l e s , appox 0 . 1 s e c
dnld_dly:
mov rO, #0 / l o a d rO w i t h z e r o
dnlddly2:mov r l , #0 /load rl with zero
djnz rl, * / d e c r e m e n t r l , l o o p i f n o t z e r o i n the. TNO
djnz rO, dnlddly2 /jump back i f not z e r o
ret /return
.***************************** *- •* * * * * * ***•
/ C o u n t e r i n c r e m e n t i n g , p a r a m e t e r s p e c i f i e d b y r l . ! l " t e , v a l u e s i n A c e a n d Rl are
/destroyed.
dnld_inc:
mov a, r 1 /rl s p e c i f res parameter to inclement
anl a, ttOOOOOlllb /and j u s t in case
rl a / r o t a t e t o r e s e r v e t w o l o c a t i o n s ( I s b , msb)
add a, #dnld_parm /define address of l s b to increment
mov rl, a /now rl p o i n t s t o l s b
inc @rl /increment lsb
mov a , @rl /move t o check I s b
jnz dnldin2 /jump i f not z e r o
inc rl /otherwise point to next l o c a t i o n (msb)
inc @rl / i n c r e m e n t msb
dnldin2:ret /return
***************************** * * * * * * * * * * * * * * * * * * * * **.

105
;Get p a r a m e t e r ; and i n c t o next one (@rl), carry clear iI patamet
; b i t v a l u e r e t u r n e d In d p t r .
1 f,
d n l d _gp:
setb c ; s e t . c a r r y Cor n u n r.er •> p a r m
mov d p i , @rl ;put: w h a t a t a d d r . a s d p i
inc rl / p o i n t t o t h e next
mov d p i ) , t?rl / p u t w h a t a t a d d r . a s Iph
• inc rl ;point t o t h e next
mov a, d p i /move t o check i f dp! i s z e r o
jnz dnldgp2 / jump i f d p i i s it"! .:<. t ! •
mov a, dph / m o v e t o c h e e k i f dph i s z » r o
jnz dnldgp2 / j u m p i f d p h i s not r e ro
clr c /clear c
dnldgp2:ret /ret urn
.**< * * * * * * * * * * * * * * f i r * * * * * * * .

/A s p e c i a l v e r s i o n o f g h e x j u s t l o r t h e d o w n l o a d . Does n o t l o o k f o r c a r r i a g e
/ r e t u r n o r b a c k s p a c e . H a n d l e s ESC k e y b y p o p i n g t h e r e t u r n a d d r e s s a n d t h e n j u m p s
/ t o t h e e s c . k e y h a n d l i n g . T h i s g h e x d o e s n ' t e c h o c h a r a c t e r s , a n d i f it. s e e s ':',
/ i t p o p s t h e r e t u r n a n d j u m p s t o an e r r o r h a n d l e r f o r ' : ' i n t h e m i d d l e o f a
/ l i n e . N o n - h e x d i g i t s a l s o jump t o e r r o r h a n d l e r s , d e p e n d i n g on w h i c h d i g i t .
dnld_ghex:
dnldghl:acall cm /input 1st d i g i t
acall upper /convert char to uppercase
cjne a, #27, dnldgh3 /jump i f n o t e s c .
dnldgh2:pop acc / e l s e pop 2nd p u s h e d
pop acc /pop the Ist pushed
sjmp dnld_ e s c /jump t o e s c a p e
dnldgh3:cjne a, # " ' : ' , d n l d g h S / j u m p i f n o t ( : } b o u i u i tig > f r e c o r d 1 i l i e s
dnldgh4:mov rl, #5 / s p e c i f y c o u n t e r Cor wi o n q i >e.q i ti o f 1 i n a
acal.1 dnl.d_.inc /increment countet
pop ace / p o p 2nd p u s h e d
POP acc ; p o p 1 s t p u s lied
ajmp dnld3 / j u m p t o b e g i n ! n g ( w e ' r e o n a n e w 1i n o !
dnldgh5:acall asc2hex / c a l l asc2hex
jnc dnldgh6 /jump i f hex
mov r l , #7 / s p e c i f y counter for none hex
acall dnld_inc /increment counter
sjmp dnldghl /jump back t o beg r ui ng
dnldgh6:mov r2, a / k e e p f i r s t d i g i t i n r2
dnldgh7:acall cin / i n p u t 2nd d i g i t
acall upper /convert to uppercase
cjne a, #27, dnldgh8 / j ump i f n o t e s c .
sjmp dnldgh2 / j ump i f e s c .
dnldgh8:cjne a, I":*, dnldgh9 /jump i f not :
sjmp dnldgh4 / j ump i f
dnldgh9:acall asc2hex :convert to hex
jnc dnldghA. : j ump i f n o t h e x
mov r l , #7 / s p e c i f y counter for none hex
' acall dnld_inc /increment counte L
sjmp dnldgh7 /jump back
dnldghA:xch a, r2 / e x c h a n g e 1 s t and 2nd d i g i t s
swap a /swap 1st d i g i t
orl a, r2 / o r 1 s t and 2nd d i g i t s
mov r2, a / s t o r e r e s u l t i n r2
add a, r4 / a d d new n u m b e r t o p r e v i o u s c h e c k s u m
•mov r4, a / s t o r e r e s u l t i n t o r4
mov a, r2 / m o v e nev; n u m b e r t o A
ret /return
.**/****************************************** .
/dnlds4 = 'Summary:"
/dn'lds5 = ' lines received'

106
/dnidsda - " byte:- r e c e i v e d "
-
/ d n . l d s 6 b ~ " b y t e s wr.it t.en"
; Print, o u t d o w n l o a d summary,
d n i d sum:
mov a, r6 ;move p o i n t e r low b y t e i n t o A
push acc ;push i t
mov
a, rl ; move p o i n t e r h i g h b y t e i n t o A
push ace ; push i t
mov ' d p tr, Kdnldsl ; p o i n t 1o m e s s a g e
acall pcstr h /display it
mov r l , Udnld parm ; move d o w n l o a d p a r a m e t e r v a l u e i n r 1
mov t . 6 , # d n l . d s 5 (, 2 5 5 ; m o v e " l i n e i e o e i v e . 1 " l o w b y t e i n ! (>
mov r7, fldnldsS » ; move " l i n e r e c e i v e d " h i g h b y t e in 1
acal 1 d n l d iO ; ca 1 1 download item d i s p l a y
"byte |eeejve<|" byl e iii
m<>v i t > , l l d n l . d s G a h ,'. •:.'> ; tin i v o low ! 1.

mo v r'l, fldnldsfia -• >i ; mov" "byte te . i ve<l" high byte in r


acal J dnld_i 0 / e a I .1 11.>wn 1 o n . 1 i V e i n d i sp 1 • iy
mov r 6 , i f d n l d s C b S ;;.'.;> /move " b y t e w t . i t t e n " l o w b y t e i n t i.
mov r 7 , # d n l d s 6 b >• o ;move "byte w i i l t e n " high byte i n i 7
acall dnld_i() ; call download item d i s p l a y
4 * * * 4 * 1 ; * * * * * * # * * * 4-+* » * 4 * * 4 * .
dnld_err: ;now p r i n t o u t e r r o r summary t
mov r 2 , #5 ;make r? a s a c o u n t e r
dnlder2:acall dnld_gp ;get parameters
jc dnlder3 ;jump i f any e r r o r s
djnz r 2 , dn.lder2 / d e c r e m e n t a n d jump t.o s e e o t h e r p a i a m e t e r
/ N o e r r o r s , s o we p r i n t t h e n i c e m e s s a g e
mov dptr, #dnldsl3 ; p o i n t , t.o m e s s a g e
acall , pcstr_h / d i s p l a y i t "No e r r o r s d e t e c t e d "
sjmp dlnd_sum_done / j u m p t o summary d o n e
/ T h e r e w e r e e r r o r s , s o n o w we p r i n t t h e m .
dnlder3:
mov dptr, #dnlds7 /point to message
acall pcstr_h / d i s p l a y it " E r r o r s :"
/But l e t ' s not be n a s t y . . . o n l y print if necessary
mov r l , # ( d n l d p a n n i 6)
mov r6, # d n l d s 8 & 255 m o v e " b y t e s u n a b l e t o w r i t e " l o w b y t e i n r<.>
mov r 7 , ttdnldsS » i! m o v e " b y t e s u n a b l e t o w r i t e " h i g h b y t e i n r7
a c a l l dnld_item c a l l download item d i s p l a y
mov r6, #dnlds9 S 255 move " i n c o r r e c t , c h e c k s u m s " low b y t e i n r6
mov r7, #dnlds9 » ft move " i n c o r r e c t c h e c k s u m s " h i g h b y t e i n r7
a c a l l
d n l d _ i t e m c a l l download item d i s p l a y
mov r 6 , #dnldslO & 255 m o v e " u n e x p e c t e d b e g i n o f f i l e " l o w b y t e i n rC
mov r7, (fdnldslO » 8 wove " u n e x p e c t e d b e g i n o f f.il*»" h i g h b y t e j n r7
a c a l .1. d n l d _ i t e m o n 1 I d o w n 1 oa-1 i t e m < I i s p 1 a y
mov r6, # d n l d s l l & 255 move " u n e x p e c t e d h e x d i g i t s " low b y t e i n r6
mov r7, #dnldsll » 8 m o v e " u n e x p e c t e d h e x d i g i t s " h i g h b y t e i n r7
a c a l l dnld_item c a l l download item d i s p l a y
mov r 6 , # d n l d s l 2 & 255 move " u n e x p e c t e d iion h e x d i g i t s " l o w b y t e i n rt.
mov ' r7, #dnldsl2 » 8 m o v e " u n e x p e c t e d n o n h e x d i g i t s " h i g h b y t e i n r7
a c a l l dnld_item c a l l download item d i s p l a y
* * * * * * * * * * 4* ** * * H * t*» 1****4 •*•*** * * * * * * .

dlnd_sum_done:
pop acc / p o p p u s h e s and p u t i n r7 and r 6
mov r7, a /move A t o r7
pop ace /pop to A
" mov r6, a /move A t o r6
ajmp newllne / d i s p l a y n e w l i n e a n d r e t u r n t o menu
.**********************.**********************•******.
dnld_item:
acall dnld gp /get parameters (ertot conditions/

107
jnc d n l d i:< /jump i f e r r o r s
dnld_i2:acall space / d i s p l a y space
lcall pinllGu /print value
acall r6r'/todptr /make p o i n t e r t o t h e m e s s a u o
acall pestr h / d i s p l a y the message
dnld _ i 3 : r e t /return
. * *fr*• A A- * * . *• * *
A*****AA**A**A*AA.Ai*Ai**»A»i»

dnld 10: a c a l l dnld gp / n o n - e r r o r c o n d i f.i.ons


sjmp d n l d 12 /jump t o r2
. * A * A- * * A A A A A- * * A

/Initialize ail dnld parameters to zero.


dnld_init:
mov rO, t d n l d parm / l o a d r I w i t h oarm b a s e ddt .
dnldO: mov PrO, !I0 ; e 1 OH I i i
inc rO / go ! ••• the ii">:i
cjne 1.0, I)dnld parm I 16, dnldl) ; 1 oop l o c l e a t ;11 I
ret /tot i u n

/dnlds'7: Ktrors:"
/dnldsS: b y t e s unable lo write"
/dnlds9: i ncorrect checksums"
/dnldslO: unexpected begin of line"
/dnldsll: unexpected hex d i g i t s "
,-dnldsl2: unexpected non-hex d i g i t s "
/dnldsl3: 'No e r r o r s d e t e c t e d "

/jump r o u t i n e a s k s for I he a d d r e s s t o w h i c h il w i l l lump. II e s c a p e [ C ~ I I was


/ p r e s s e d , t h e p r o g r a m i s a b o r t e d . Tt NO a d d r e s s was e n t e r e d ( v o i d i n p u t , psw.!f>-
/ t h e p r o g r a m l e t u r n s t o w h e r e i t w a s . When h i i a d d r e s i s e n t e r e d t h e p r o g r a m mak
/ s t a c k o f 6 b y ! e l e n g t h a n d jump t o i h e s p e c i f i e d a d d r e s s ,
jump:
mov d p t r , HP romp T (1 / l o a d p o i n t e r w i t h m e s s a a e a d d r .
a e a .1.1 post r H / d i s p l a y the message
a c a 11 r 6 r 7 tx» i p t r / t o p r e p a r e d a t a in dpt I FOR n e x t 1 u n c i i o n
acall phex1b / d i s p l a y address content
mov d p t r , #prompt4 / l o a d p o i n t e r w i t h m e s s a g e a d d .
acall • pestr_h / d i s p l a y the message
acal 1 ghex16 / g e t hex v a l u e (dptr v a l u e )
jb psw.!», j ump3 /jump i f f l a g s o l
jnc jump2 /jump i f c a r r y not. set.
ajmp abort2 / o t h e r w i s e abort
juirtp2:
a call DPT I T ..T-l.RV / s a v e d p f i •••line I N I a n d I /
jump3 :. a c a l 1 new Li ne / o u t p u I: a .1 i no
mov d p t ) , '1 r u n s 1 / t o a d p o i n t ET w i t h m e s s a g e ictrir .
acal I p c s t i . II / d i s p l a y THE m e s s a g e
a c a 1.1 r6r7t o d p t r /restore pointer
/Jump t o u s e r c o d e I'dpur: ( t h i s u s e d by run command a l s o )
jumpdoit:
clr a /clear A
mov psw, a /move A t o psw
mov b, a /move A t o B
mov rO, #7 /move 7 t o r 1) ( l o a d c o u n t o i )
j d i t c l r :mov @r0, a /clear. 7 addresses
djnz rO, j d i t c l r /loop to clear
mov s p , #8 / s t a r t w/ sp**7, l i k e a r e a l r e s e t
push acc / u n l i k e a real r e s e t , push 0000
push acc / i n c a s e t h e y e n d w i t h a RF'.T
jmp @a+dptr /jump t o t h e a d d r e s s

108
; clMttij. d i s p l a y s K> l i n e s o f I (j a d d r e s s 1< i o n .in ii'-:-: it anal !•••:.! i d e i ! disp!.-,
/the as o i i. oqn ival.ent o f a d d r e s s content T!v-- s i n i l i n add! s s i:- ! h e enlout
;r6-r7
dump :
mov ' r 2 , #16 ; N o . o f ! i n e s i*> • o r i ul
a c a J 1. n o w l ino>' / d i s p l a y n e w I i tie
dumpl aca.I! r(»r7l odpfcr / t o p r e p a i " d a i a i n d p i r !•>• n e v i !un>:! i"i;
acall phexl(> / d i s p l a y a d d r . l o c a t i o n i o 'lump i n
mov a, » ' : ' /move : to A
aeal I eout sp /display :
tnov r3, #lf> / r 3 No. of h y f e s t o p i i n t
a c a l i. r bi:7l'..ilpl i / t o p i e p a i o d p i i I . a u< -xl t i m e t i o n
dump 2: ol r a /cleat A
mo Vi: a, Haldpl.i. / r e a d .ukii i'sr. ••oil o i l
Inc dpt. r / i noionion! dpi i
a c a 1.1. phex / d i s p l a y e a c h b y t e i n he:-:
acall space /display space
•rl j t r . : r 3 , dump? / . l o o p I f>t n e x t ' b y t e .
acal i dspace /display double space
mov r3, #16 zr3 No. of b y t e s t o d i s p l a y hex and non-lies
aca! L c 6i:7 t o d p t . i /make the p o i n t e r attain
dump 3 : clr a /clear A
move a, @aiclptr /read again
ine dpti / p o i n t t o next.
aril ,a, #0111111 lb /avoid unprintable characters • 127
c jno n , # 1 2 7 , dtinip31> / c h e c k i !.' i s n o t | 21
clr n / i f .127 d e l e t e e h a t a e l
dump 3 b add a, #224 / a d d t.o s c r e e n c o n t r o l eharaetets
jc duiop4 / c a r r y m e a n s n o e o n l i o ) c h a t a c t ••!
clr a /avoid control ehnrael"rs
dump4 : add a, #32 / a d d i t i o n t o c o m p e n s a t e f o r X24 a d d i t i o n
a call cout ;di spI ay cha i a c t o t
d in:: r.5, d n m p 3 / l o o p a g a i n t o d i s p l a y next cliaiaclei
acall nowline / d i s p l a y a new l i n e
acall line dly /delay
acall dptrtorf>r7 / s a v e d p t r i n r 6 a n d i.7
acall esc /call escape
jc dump 5 /jump i f e s c was p r e s s e d
djnz r 2 , dunipl / l o o p back up t o p r i n t next, line
dump5: ajmp nowlino / j u m p t o n e w l i i i e t o r e t u r n t o menu

/ e d i t r o u t i n e e d i t s e x t e r n a l , rain. I t d i s p l a y s a l u o s s a c i " at. t lie s t a r t t o lc-t l i r e


/ u s e r e n t e r t h e a d d r e s s l o c a t i o n h e w a n t s t.o e d i t . T h e n It. d i s p l a y s t h e a d d r e s s
/ b e s i d e i t ' s c o n t e n t a n d a s k t h e u s e r t o e n t e r t h e n e w v a l u e . When h e x c h a r a c t e r ;
/are e n t e r e d t h e r o u t i n e m o d i f y t h e s p e c i f i e d l o c a t i o n and move t o t h e n e x t
/ a d d r e s s . I f non hex c h a r a c t e r s e n t e r e d the r o u t i n e d i s p l a y s a m e s s a g e .

edit:
mov dptr, tfodit.sl / l o a d dptr with message addr,
acall p c s t r _h /display message
acal 1 r6r/todptr / t o p r e p a r e d a t a in dpt.i t o r n e x t. f u n c t i o n
editl: acall. phexl6 /display l o c a t i o n p o i n t e d t o by d p t r
mov a,#' : ' /move : to A
a c a l 1. COIll. Sp /display :
mov a, 8 • ( • /move ( t o A
acall cout /display '('
acall d p t r tor<>r7 /save dptt i u r<> • u i d 1.7
clr a /clear A
move a, @a+dptr / r e a d dpt: i a d d i . C e n t e n l . a n d

109
acal] phex d.i s p ! ,<y
mov d p t r , # p r ompt1o l o a d dpt i v; i • h :!!«•"• s :
aca ] 1 pest.r h d i s p l a y m o ; : . - ' i .<• ;•••!
acal 1 ghex ,.|ol now h'•:: •• a 1 'i<•
jb psw. 5, ed i ! 2 jump 1 '• p . . ' '• • ;

jc e d i 12 a 1 • i 'mil • it •i•rv
acal.] i fit 71 o d p t i
1 o a 1 1 smar 1 wr: wr i t " ' ••••! i
acal 1 new!i no . ,ut p i p .) i|' ' '
acall r 6t.'7todpti. 1 , . r . ,, , . , | p : ,
: ! ,,,;>.
i no dptr p o i n t t • •)!•• !!•:•:'
a c a 1. 1 dpi. r I or in 7 r . a • dpt t is: t '. u>'
ajmp edit.1 l o o p 1 ..•,(•!•.
edit2: mov . dpi: r , (fed] 1 s 2 load dpi, ' i;
a j mp p e s t i. h d i S| • 1 ay !i"":::' ! !•

; d i r r o u t i n e m a p s t h e d i s p l a y !• 1 •-•••'!•! : •:' •!,!•:

; i n t h e memory t o t h e d i s p l a y , it s s b y d i s p l a y in
/ s e a r c h i n g f o r h e a d e r s . .11 d i s p 1 a y s
; f i n d s . I t c o n t i n u e s d o i n g t h i s for
dir:
mov d p t r , ttprompl '* ;po:„, i r-ss/
acal 1 p e s ft h ;di s p l a y :'">ss v
mov t 0 , 112 1 ; !•-•') t <• •=• a =
dirOa: acal 1 space? /'•lit put 1 Sp V
djnz rO, d i r O a / I c . p b:<<-'-. i t i
;mov d p t r , II p r o m p t 9 b ,M"'' i nt • •••
acall pestr h / d.i s p 1 .ay rv •:=." c
mov d p h , tt(bmem > - 8) / l o a d dph w i t h
dirl: acai 1 find / f i n d h o a !-..
j <-• dir 2 / pii'.ip i I ho... | c i
d i r e n d : a jmp new]ine
dir2:
acal I dspaee r d i s p ' iy ,•
mov d p i , in 2 / p o j nt ' • • 1
aca] 1 pstr r d i s p l a y it
mov d p i , 1(32 /point
aca.l 1 1 enstr :! i n 1 !
mov a, #33 : b - , l ;,
],-
c i. j.
a , rO tbt
subb
mov rC), a In
mov a, #• ' ;|..=,.| s p a - - i p r

dir3: a c a . l 1. cou t / d i s p l a y spa--o


djnz rO, d i r 3 / loop to d i s p l a y
mov d p i , #0 / p o i n t to headot
acall phexl6 / d i s p l a y t h e h'>.-
mov rO, # 6 / ! e a I count ° i
mov a, #' • / 1o;vl ' o d i s p l ,\
dir4: aca] 1 cou I / d i s p l iy s p a c -
djnz rO, d i r 4 / 1 Oi >p (• t i !!•/'•.•<
mov d p i , «4 ; p o i n\ '. • • \ i i'.t s •
clr a /cJ'vu: A
move • a, l?a+dptr / l o a d i t s t ypo
mov L-2, d p h /save this,
dir5: cjne a, # 2 5 4 , dir.M. / jump i t <:••'. !• t
mov dptr, #lypel / p o i n t ! .. ..;:> ...
sjmp dir 7 / inrip t o I ; . •• p.-
dir5b: cjne a, # 2 5 3 , d i r ' . c / jui-ip i ! ti' ' H t
d i r 5 b b : mov dpt. r , Iltype4 / r •' : ;'• '• • • .•• • . i' '

I 10
s jmp di r ? ; jump to i j 7 1 u-! ok
a i r 5c:: cjne ' a, 93:., d i r l . d ; jump i f n o t 2 "Mi
mov dptr, #t:ypo2 /point to ordinal y pioqinn 1

s jmp dir7 ; jump t o ,i j t / i..<» 1, ,w


Ciir5d: e jne a, Il2i'i, dir.'je ;jump i f not
sjmp dLr:r>l.i. ; jituip t o d i i M>b
dirbe:
dir6: mov d p t . r , II t y p e 5 /point' t o ???
dirV: • aeali p e s t r li /print, out the type
mov d p i ) , r.2 / ( j o b a r k a n d f i n d t h e n e x t one
acal! n e w l i i.e / d i s p l a y new l i n o
mov a , # ( e m e m ">> 8 ) / . l o a d e n d m e m o r y hin.li b y t o
cjne a , d p h , d i rH / d i d w e j u s t d i s p l a y t h e l a s t "M
ajmp d i i. e n d /jump t o d i r end
dir8: inc dph" / I n c r e m e n t , dph
mov a , dpi i / m o v e d p h 1 " A w i t h emem h i g h b y !
cjne a , !l ( ( o m o m H . )
8) ft 2 5 5 , cl.irl. / j u m p i t net equal
ajmp dir. end / j u m p t o d.i r e n d

/ t y p e l = E x t Command
ztype4=Startup
; type2=Program•
/type5=???

/ r u n s u b r o u t i n e s e a r c h e s f i l e h e a d e r s . When i t . f i n d a l . ' i i r i - p r o q r a m , i t p r i n t s its


/ n a m e o n t h e s c r e e n i n a f o r m a t e d l a y o u t . When i t i s f i n i s h e d , it. a s k s f o r the
/ c h o i c e t o b e e n t e r e d among t h e l i s t . If e s c . i s e n t e r e d t h e program r e t u r n
/ c o n t r o l t o t h e menu, o t h e r w i s e t h e input i s matched w i t h i n some r a n g e s t o check
/ i t ' s c o m p l i a n c e w i t h c h o i c e l i s t . When i t i s o k a y t h e h e a d e r s w e r e s e a r c h e d f o r
/ t h e r u n - p r o g r a m s i n s e q u e n c e . When t h e s e a r c h i s s u c c e s s f u l , t h e f u n c t i o n w i l l
/ p a s s t h e a d d r e s s t o a n o t h e r s u b r o u t i n e (at. t h e e n d ) , w h i c h w i l l m a k e a s t a c k o f n
/ b y t e l e n g t h and jump t o t h e s p e c i f i e d a d d r e s s .
run:
acal 1 newli no2 / d i s p l a y a .1 i n o
mov r:2, « 2 V > / f i r s t , p r 1 nl t h e m e n u , e o u n l item:;
mov d p t t , IIbmem / l o a d menioi y b e q i n i n q
dec dph /decrement dph
run?.: inc dph /increment dph
inov a, dph / m o v e d p h t o A t o c o m p a r e w i t h emein h i g h b y t
cjne a , # ( (emem-i I ) ' > 8 ) & 2 5 i , i u n 2 b / d i d w
s
r
i each the end
sjmp , riin3 / j u m p i f we r e a c h e d e n d
run2b: acall find /find header
jnc run 3 / h a v e w e f o u n d thorn a l l ?
mov d p 1 , If '1 / p o i n t t o f i g u r e out i t s t y p o
clr a /clear A
move a, Oatdptv / l o a d i t s t ype
orl a, HOOOOOOllb /check specifiei |>y o r l a n d e p l
cpl a /complement A
jz run2 / i f z e r o , t h i s one d o e s n ' t r u n . . . f i n d next.
acall dspace /display double space
inc r2 / i n c r e a s e Ho. o f s u c c e s s f u l headers
mov a, #'A' /.load cliar.act.er t o b e u s e d a s 1 i n e - m i m b o r o
add a, r2 / c h a n g e l i n e - c h a r a c t or s
acal. 1 cout. s p / d i s p l a y J i n e - e h a r a o ! oi a n d s p a ' : "
acall dash sp / d i s p l a y d a s h and s p a c e

1
mov / p o i n t t o h e a d e r name
acall pp
d s ti r, 32 /display it
acall newline / d i s p l a y new l i n e
ajmp run2 /back to continue find job
run3: cjne r 2 , # 2 5 5 , r u n 4 / a r e t h e r e a n y m o r e t o r u n ? Jump i f yes
mov d p ! t , (pr<•nipt'•> /point I n »!•'.-sa-!•' >• i . o O i i . i the •
a jmp p e s t 1 It /display il
till I V > Ipt i , llpr empt. ', ; ask 1
l i e 1 > i q q u e s t i.. n !
aoal 1 pc.-:;tr h /display it
mov a, I'A' / l o a d A c h a r a d e ! a s (.-.tot .| t anqe i
a c a 1J cout / d l a p 1 ay it
aca i J dasli / d i s p l a y dash
mov a, #'A' ranqo)
/ l o a d A t o a d d t o ,2, as (end o f
acid
acal 1
a, r.'/.
COIlt.
/ a d d r2
/display addition result
mov dptr, If p r o m p t ' I / p o i n t t.o m e s s a g e r » . | a d i n q t h e c l i O j C O
aeall p e s t r It /d i sp t ay i 1
acal 1 cin tilt.et h ,-qet input --hat act.ot
c i no a, 1127, runlaa / jump i t n o t • F.:"c •
ajmp newli n o / w h e n e s c jump a n d f t i i n i ' • • m e n u
run4aa: mov r3, a / s a v e chat a e t o r in i '
mov a, #31 / l o a d A w i t It 3 1
clr c ; o . l . e a i , -at r y l o t I esl
subb
mov
a,
a,
i 2
r3
/subttaei
/move e h a i a c t o r
Me .-.(' i|.>a..lot r. ( s - a o i e
info A again
1 <: 1 1 c.i i t y 1

jc run'I a / jump i f h e a d e r s m o i e t h a n 3."


a c a 11 upper /change character t o uppoicase
rurrla: acal. 1 eout /display ehnraotei
mov r 3, a
/ s a v e i n rI aga i n
a c a . l .1 new!in" / d i s p l a y new | i h p
;Check to see i f i t ' s u n d e r 32 , i f s o c o n v e r t t o u p p e r c a s e .
mov a, t-3 /load ehaiaotoi info A
add a, !! (2!iCi - ' A ' ) / c o n v e r t c h a t i n t o a N o . s l a r t i n q f i ' o m ".(it••
jnc run4 / j u m p b a c k , i f n o c a r r y ( t y p e d l.<-• s s t h a n 'A')
mov • r3, a / l o a d 1.3 w i t h t h e N o . typed
mov a, i;2 / l o a d A w i t h No. o f headers
clr c / c l e a r carry tor Iesl
subb a, r3 /subtract 1 lie N o . t y p e d f i n m N o . o f header;!
jc run 4 / j u m p 1J c a t t y ( M o . t y p e d m o r e than max tango)
inc t.3 /increment- No. typed
mov d p t r , II b mem / l o a d bmem 1 o 1 i n d t h e h e a d e i
dec dph /decrement (oi adjustment
run5: inc dph / j ncremont. dph
mov a, dph / m o v e dpli t o A t o c o m p a r e i t w i t h emem h i g h b y t e
cjne a , # ( ( e m e n d 1 ) >•> 8 ) & 2 5 ) 5 , r u u 5 b / j u m p i f n o t r e .a e h t h e e n d
sjmp run8 / e l s e jump t o e n d
runSb: acal 1 find /find header
jnc runB / S h o u l d n ' t e v e r do t h i s jump!
mov dpi, #4 /point, t o f.iqure out i t s type
clr a /clear. A
move a, @a-»dptr /load its type
orl a, #0000001 lb / c h e c k s p e c i f i e r b y o r 1 a n d cp.l.
cpl a /complement A
jz run!i / i f z e r o , thi.s one doesn't" r u n . . . f i n d noyt
djnz r.3, run.') /count t i l we f i n d t h e o n e t h e y v; •ml
a n a 11 newline / d i s p l a y new 1 i n o
mov dpi, #64 / p o i n t t.o h e a d e r
ajmp j u m p doi.(• / j u m p 1" p r o c e s s ( i n t h e it imp- f ui > ••t i o n )
run 8 : ret /return

/ h e l p r o u t i n e : s e n v o k e d from t h e menu. It displays help text and jump u> lie.lpX to


/give'information about the help.
h e l p :
mov dptr, #lielpitxt. /point to messaqe
acall pcstr: h /display it

112
mov r4, llholp key ; 1 o . i d • -i w i i ii Hi ••p k-y
mov d p t r , K i i e l p omd ; pi > • lit 1o llie;j)j,J..|e
acall h e 1 p2 ; c. 11 1 l i e ] p . ; r m i u ui i w
mov r 4 , #di L key
/mov d p t r , Kd'ir cmd
acal 1 help2
mov r4, l i n n key
;mov d p t r , 11 r u n cmd
a c a l .1 I.e.l.p2
mov r:4, Hdnldkey / l o a d 1.4 w i t h h e l p Ify
; mov dpfr, II d o I d cmd ; p e i nt t e m e s s a g e
a o a 11 lie 1 p 2 ; c a 1 1 l i e ] p / s u b t m i l i»»* •
inov r-1, II u p I d k e y
; mov dptr, Hupl<l <:iud
a c a .1.1 help2
niov r 4 , llnloe key
/mov dptr, l l n l o c cni'l
aca.l 1 , help2
mov r-l, f j i i i n p k e y ; 1 oad i 4 w i 1 h he 1 p key
;mov d p f r , 1! iump emd ; p o i.nl t o llie;;.<:.|r.|,'.
acall holp2 ; e a l l help..'' s u l u o u t i n n
mov t : 4 , Bdunip k e y
; mov d p t . r , M u m p ctnd
a c a 1.1 help2
mov r 4 . Hi nt in k e y
;mov • I p t r , I! i n 1 in cim!
acall h e ! p2
mov r4, fiedlt key ; toad i4 w i t h h e l p key
; mov dptr, l i e d i t ci'.id ; p o i nl t n m e s s a g e
aca.11 he lp2 ; c a l l Iielp2 subroutine
IIIOV r4, #e.!t:m_koy
;mov d p t r , Hclrin cmd
aca.l 1 hel 2 P

IIIOV a, Alias Hash


jz help skerim
mov r4, llei.fr key / l o a d r 4 v/i t h h e l p lie-.
;mov dptr, l l e r f r cmd /point to message
acal 1 iie.l.p2 / c a l l l i e l . p 2 s u l . r o u t , i !)•
help. erfm:
mov dptr, llhelp2t.xt. /point to help2txt
acal l pestr h ,'tl i s p l a y m e s s a g e
mov dptr, llbroem jnuivo tmietn 1 o d p i t ! •. s e „ , , h
:

help3: acal 1 find / f i rut h e a d e i


jnc help4 / j iimp i ! n e h e a ' !• •! I ••und
niov dpi, #4 / p o i nt' t <> 1 i g u r o o u t i t s t y p e
clr a ;c1oa t A
move a,@a+dptr /load its type
cjne a , II2•SI, h e l p 3 a / j u m p i f l i e l KK ( e x t command i
acall dspaee /display double space
inc dp] /increment', d p i
clr a /clear A
move a , @a t-dpt.r /move s p e c i f i e r i n t o A
acall cout. / d i sp.l a y S ) >ee i t i e r
acali dash sp / d i s p l a y d a s h and s p a c e
mov dpi, #32 / p o i n t t o h e a d e r name
aca 11 pstr / d i s p l a y it
acall newline / d i s p l a y a new l i n o
help3a: i n c dph / i n c r e m e n t dph
raov • a, dph / m o v e d p h t o A t o ceinpa.t e i t . wi f h eraem h i g h
cjne a , # ( (emend-1) » 8) « 2 5 ' j , h e J p 3 / jump I f n o t r e a c h t h e e n d
help4:

113
; he.! p 2 p r i n t ••••• i j s t a n . la i d I i n o s o f ! K ' P .
;1 n d p t i ) i n . • p o t a t o c o m m a n d a b o v e .
help?:
acal 1 dspaoo ; d i s p l a y d< 'ul • I e s p a c e
mov a, r4 / l o a d A w i t h h e l p key
acal 1 cout / d i s p l a y h e l p key
acall dash sp / d i s p l a y dash and s p a c e
a c a 1.1 pcstr h / d i s p l a y m e s s a g e point'-" i n dp • r
ajmp newline / d i s p l a y new l i n e a n d r » t u r n t o I ep
ak

u p l d - r o u t i n e u p l o a d s h e x f i l e s t o t h e s e r i a l p o r t . Hoy. f i l e i s a n u m b e r •<
•t d a t a
r e c o r d s t e r m i n a t e d b y CR a n d I..F. A d a t a r e c o r d e x a m p l e i s a s toliows:-
: xxyyyyOOanbbcc.ddee liimZ!'.
where : Start of record
xx No. o f d a t a b y t e (two hex d i g i t s )
yyyy S t a r t i n g a d d r e s s o f t h e l e c ' U ' l (4 h e x d i g i t s )
00 R e c o r d t y o e [jo. for hex file
anbbceddoe....mm [lex d a t a ( t w o h e x d i q . i l n u m b e r s . , e q u a l x x )
7,'L Checksum v a l u e of a l l d a t a r e c o r d d i g i t s
F i r s t l y u p l d g e t s t h e b e g i n n i n g a d d r e s s in r 3 / r 2 ( r 2 " l s b ) , mid t h e f i n a l :ldr e s s
i n r 5 / r 4 ( r 4 - l s b ) , a n d p r i n t s t h e m out. b e s i d e some m e s s a g e s . T h e n i t r e a d s d a t a
f r o m t h e s p e e d T i e d a d d r e s s , p r o c e s s it a n d s e n d s i I r. t h e • • r i a l p o t t in th*
above form.

a c a 11 g e t mem / g e t c o m m a n d l o c a l i oiir;
mov d p t r , Huplds / p o i n t t o m e s s a g e ( . ' d a r t i n g adi
acall pcstr h /display i t
mov a , r:3~' /move h i g h s t a r l i n g addr.. b y t e
a c a 11 phex / d i s p l a y l:
mov a, r 2 /move low s t a r t i n g a d d i . byl • I e a
a c a 11 phox /di spI ay i t
/mov dpt.r, Sup I d s - ! / p o i n t t o m e s s a g e !in I i m i a. I d i . )
aeai 1 p e s I. r / • l i s p I a y il
mov / m o v e h i g h e n d i n g ad-ii . b y l e t o t
a c a l 1. pin / d i sp.l a y i t
mov a , r'l / m o v e l o w ' - n d i n g , i d d i . b y t r- t o A
a call phex / d i.sp I a y i !
acal 1 n e w l i no / d i s p l a y new l i n e
.-Need t o adju:: end l o c a t i o n by I...
mov d p h , t-5 / m a k e dpi.r . M o v e rS t o dpi-,
mov d p i , r-1 / m o v e r'l t o d p i
inc dptr /increment dpti
mov r4, dpi / s a v e d p t r . . , m o v e d p i t o r-'l
mov t.S, dph /move dph t o r5
mov d p t . r , IIprompt7 / p o i n t t o m e s s a g e
acall pcstr h / d i s p l a y it.
acall e in / i n p u t any response
cjne •i, 1127, u p l d . V / j u m p i l 11-'l e s c a p e
ajmp abort i t / j u m p t o al'oi t a n d u M u r n t
new 1 1 n e / o u t p u t new I i n e
upld2e: aca.l.l
/ m a k e d p t . i . , m o v e i A t.o
mov dpi, i2 dpi
/move r< t o dph
mov dph, i 3
/clear c
upld.3: clr
mov a , rA / m o v e t o A " e n d i n g a d d r . low b y ! .
subb a, d p i / s u b t r a c t , " s t a r t i n g addi . lower hyt' from A
mov r?., a /move r e s t to r2
mov a, r5 / m o v e t o A " e n d i n n a d d r . li i.Q'i b y t o .
subb a , dph / s u b t r a c t , " e n d i n g a d d r . l o w e r b y t e " from A

114
jr.". Upi.Pl ; i:itn}• i ! •..".<. 1 • • i i , ' in -n i. • i,•••::' i 1.
mov a, t. / ; m o v e i e w e i 1 >y i . o i 1l | . . .-. A

i "• lipid'/ ; jump i ' i l l • l<>iie


a til t i l e d i n 11> I >yt.e p a c k a t f .
jnz up.id 4 ; i 1 >.. 16 l e f t , then do n e x t 16
i, f i l l 1001)01. ; b e c a i i s i . • d a ! .i man i p u

off
sjmp lipid*. /otherwise just jini

O
IlOVV m<>
upld'l: / l o a d r 2 w i t h t h e N o .. o f d a t a 1 •• u p l o a d
sli i t

U t
upId5: ar.z,
, #•: '

> 11
aca I : // dbiosupilna y h(e: ) I i tie
inov a, rZ / l o a d A w i t h No. oi data to uploa
•leal 1 Phex ! .yl.es f • > upl o a d
i«i
t
acall p h e x 1 f. // dd ii ss p
p 1l aayy m
N oe .m ooi fy d-it
1 o c aa

t •• -\
mov a, dph / m a k e e h o e k s s u m , inov. ion
add a, dpi / a d d l o w e r a d f i i . byl • -
• hi'ihei i«ld> . b y l '•

1e .
add a, i 2 lplo.,.1

111'VI 1 .1
>
/ a d d No. ..! d i l a
clr a /clear A
i, / s l u r e . .||< •. -(:•-! mi i n 1

yp. :
acal 1 1 >: / d i s p l a y 0 ( 1 (.-...).• I',.
e.l r a /clear A
upld6:
i ic.i I

i. i .oio. ,., • j |,!


move a , Wa • • Ipl i
a call phex // pdui ls p al ad yIi ee sa sc h 1 •b y tme i
acid a, r 3 /update checsum

111'VI
/ s a v e checksum in r3
inc di.3,
ptr: a /point" t o next: a d d r .
d jnz r2, upldO / d e c ; e m e u l . a n d j u m p :s i . n c e inoi •.• ; . , • I . e s n e e d i n
mov a, r3 / p r e p a r e c h e c k s u m I'm o u t put
op] a ; compi emenl' c h e c k s ' i i n
Inc. a / ineremenl complement { o l i o ' s • • mil •' 1 e n i e n i )
acall phex /dispLay checksum
acall tiewlirio / d i s p l a y new l i n o
acall line dly

to
acall esc / d e l a y some t ime ipe i s pen.fin
//c. ihf e cnko e s c s eper e sifs ee
1 1 i lie
i;e>:t
jnc upld3 d.;c.
d.
:
sjmp a b o x 1 ii • roi'oi'i
upld7: mov
a e a l .1
a,
cent:
/ jump l r .
/display (: 1
db.it
/ m o v e ( : ) t o A ( i . e e o i d 1 i.ne s t a r ' . i
i i I )i< a e i s e s c a p e

clr a /clear A
acall phex /display zeros
acall phex
* it it
a call
inc.
phex
o
i; i n c rite i n e n l A i i

a c a l 1. phex /display .1
mov a, »2W.>
aca 1 1 phex // .dl oi sa pd l aAy wiKP"
th IT
u p l d R : a imp n e w 1 i ii"Z laoi: lop

/display new i i ne .md return to s


. * * * * * •» * * * * * * * * * * * * * * * * * * * * * * * • > • * . * .
ly d e l a ys bet ween 1 i ne while u p 1 o.i'i i i i . j , so ! ho.sl c , n b<
/ ( i . e . m o s t w i n d o w s s o l ' t w a r o ) . I d tic d e l a y v a l u e he !0.-ejy.Hcfb y
i s d e t e r m i n e d! oqu duritm
; i n i t i a l i zat.i e n .
l i n e d l y :

ei :
mov a, ril / m o v e r fi e m i t o n ! -I'-'iii'i
push aec ; s a v e i i ) e.>nl . 'iii
! o A f
inov i 0, 1! 1 m o del ay' 2 / . l o a d rO w i t h d e l a y 1 a c t o i i. i :•'!
d2 : iiiov a, UiO / g e t baud r a t e c i •list
d3 : i n c • a /increment thO
nop /no operation
nop * / . i i

jnz line d' /jump back i| A n< • . - . o i o


djnz rO, T i n e &,: /..leci einenf and jump b a c k if del ay not zeti
pop a c c /pop A to r e s t o r e rO

115
; g e t mem s u l i c o n t i i i e g « l . s I h o b e g i n a n d e n d i o c o i o n s l o t .: ) <-v; c o m m a n d s . |t
; E S C o r iin i n p u t ' n i l " i ' > ( i , i.l p e p s i t ' s »wn l o t m i» a n d ' • • ' l i e M"ii';.
. • r o u t i n e i s c a l l e d b y e.i rm r o u t i n e a n d i : o i l ; :! , - v i i i i un ••! i o n s < m i d i n o i I."
/for entering iddrosso.
g e t . mem:
a c a ! .1
till u/
n o w ] i.iie>'
• Ipi.r, Sbeg s t i ;poinl
;d i s p 1 .iy I wo 1 i ip>s
t o " a s k i n g s l a t ! j nq a d . l t . message"
a .-a 1 i p c s t r ii ;d i s p l a y m e s s a g e
a o a J .1. g t i e x 11. / e n t e r t h e s l a i i ing addi
jc pop i l ; •jtmip i l c a r r y s o l (K.';.'.'. i s p . e s s e . ! )

push
p s w . '>, o o p i I
,ipl,
; j u m p i t 11 a g s e t (i -R. w
i 1 h hi 1 ! i gu I e • -n t e i. e-1',
pusli dpi ;
; s
s a
a v
v e
e s
, i t
p a| i 1. i 1 a d d i .
a c a 11. new.l i r i o ; d i s p 1 a y now 1 i n o
mov c i p t r , Dot id s t r ; p o i n t t o " a s k i n g e n d i n g addi. . m e s s a g e "
a c a 1.1 pcstr h ; d i s p 1. a y mo s s a g e
acal. 1 qhexl 6 / e n t e r t h e e n d i n g addi .

IV
111.
mov
r!>, d p h
rl, dpi
/ t r a n s f e r e n d i n g a d d r . t • r S a n d i 'i
/1 r a n s t o r d p i t '> v l
pop acc / p o p t o i e s l •>i o s 1 . a r t i net a d d i . ( l o w b y t e ) i n !•'•'
mov 12, a / m o v e . ! o r>'
POP ace /pop. t o r o s l o i o si irr i n g a d d t . ( h i g h byt e ) i u i
mov r.<, a / m o v e |. o i l
jc p o p i t. / j u m p i •' c a r i y s e t (h'.:~-C i s p | . - S S e . . i )
jb p s w . 5 , pop i t /jump i f f l a g s e t (CR wi . • h o u r f i g u r e entered)
ajmp n e w .11 n e / d i s p l . y new l i n o a n d r e t irn t o s t a c k p o i n t e r
pop acc / p o p s t o c a n c e l pit.'-lis
pop acc.
t:
aea.l 1 n e w 1 i t to / d i s | i 1 a y n e w I i n.>
mov d p t r , ilaboi t /point t o abort, m e s s a g e
ajmp p c s t . r It / d i s p l a y it-

c l r m s u b r o u t i ; ie. c l e a r s a m e m o r y a r e a . T h e r a n g e i s o b t a i n e d b y g e t iu-mi;
subr o i l , i no
a n d t h e c l e a r , n i c e i s c a r r i e d b y t h e s m a i l : wr s u b r o u t i n e . T h e s u b r o u t i n e w i l l scan
a l l t h e r a n g e s t a r t i n g from t h e iowot a d d r e s s ami g o i n g upward I i I I t h e end
address.
clrm:
acal 1 g e t mem / g e t start: and end a d d r e s s e s
mov • dpt.r, Inure /point to message asking d e l e t e ..Y or e l s e
acali pcstr h /display it
acall cin_filter_h / e n t e r Y or e l s e
acall upper / c h a n g e c h a r a c t e r i.o u p p e r c a s e
cjne a, ft'Y', a b o r t i t /jump i l not Y t o abort
acall newline?. / . i f Y d i s p l a y new line
clrm2: mov dph, r3 / p o i n t t o a d d r . , m o v e s t a r t i n g a d d r . h i g h t o dpii
mov d p 1, r 2 /move s t . a r t i n g addi . low b y t e t o dpi
clrm3: c l r a /clear A
lcall s m a r t wr /actual clearing
mov a, r5 / m o v e e n d i n g a d d r . h i g h b y t e t.o A
cjne a, dph, clrml / j u m p b a c k i f d p h not: e q u a l t o e n d i n g h i g h b y t e
mov a, r4 /move e n d i n g a d d r . low b y t e t o A
cjne a, d p ) , clrm'l / j u m p h a c k if: not. e g t i . i l l o e n d i n g l o w b y ! "
ret ;return

clrm<l: inc
sjmp
dptr
cl nil!
/increment dpii
/ too)., b a c k

116
; n i o e s u b i . o i . i t i n o p i • >ni|'i
/ e n t e r o d o r F.P c w a s p i e s s c d
t o t h e u s e r l o e i , t < ; i i | , , . n e w 1 • •<• i L i . a i . 1! n • .1' !'
ille s u b r o u t i n e i s a b o r t e d .
a
i I ' •s vi •

nloc:
mov dptr, 11 r t e m p i 6 /point to display mossa-v
aoai I p e s t i . Ii /display it.
a on 11 g h e x l '"• / e n t e r h e x a I'll .
jc abort..:.; /jump t o abort i f <:''•. p i . - s s o d w i t h ' . l i t 1!
jb psw. 5, abort;' /jump to abort i f KSC i s p r e s s e d
acall d p t r t oi(-.r7 / c h a n g e d p i r r e t u r n e d b y g h e x If. t< r t.. H1..I t /
ajmp riewli no/ / d i s p l a y n e w l i n e a n d r e t u r n l... m e n u

-
/ e r f r s u b r o u t i n e prompt s t o t h e u s e r i n f o r m a t i o n a b o u t e r a s i n g some I t ea If the
/ u s e r e n t e r e d >Y' , o i . 1 i • l a s e . s 1 l a s h a n d i o i a , a n d - l i p i a y s lues.-'ag.- a l i o il •• u s u r e •
;abou r e r r o r . 1 t. u s e s e rn 1 1 f o r e r a s u r e .
e r f r:
a o a i .1 n o w ! i ne>' / d i sp.l a y t wo 1 i n e s
in.'V d p t ) , if e i J: r cind / p o i n t to d i s p l a y in.-ss.ge
a c a 1.1 p e s t r Ii ; d i sp.l a y 1 f
mov a, # \ ' /prepare to d i s p l a y ','
acal 1 cout sp /display and s p a c e
mov d p t r , ' ilr u r e /point I., d i s p l a y m e s s a g e
acal i /display it
pestt h
acal 1 c in fill er!. / g e l . input V oj "is.--
aeal 1 upper /convert to uppercase
Oj no • i, « ' Y \ , i b c i l. i I / jump i t n o t Y t o abor <
aeail ni'-wl j ne>' / d i s p l a y d o n b l < > nev.' l i n e s
1 oa 1 1 e r a 1 1 / e r a s e .ill ( f l a s h a n d I><H\)
mov dptr, Ifoi f r . . k /point to d i s p l a y message
-pie O t f l . eiK.i / j u m p i ! e i . ' i l l s u e . -edo» 1 ( I ' - f l )
mov dpt. i , lie i f r e r . r /point to d i s p l a y message if M i l e d (i; 1)
e r f r en d :
ajmp p e s t 1 11 / d i s p i n y iI

; i n t in d i s p l a y s t h e c e n t .111 o | I 'tt i n t e r n a l u d d t e - : s 1 • "-.it i o n s . . '! o i u• r, i •••• it-..-


! lues, e a :h o n e s h o w i n g 1 i> l o c a l i o n c . n l e n i . | l c n i . i o • -.:il I in-
/display in V
/display in t w .. l o o p s o ie l e i . I i lies. a n . 1 ' h- • •. •! IH-U 1 " i I i am' •.

i n tin: anal 1 new Ii n e /d.i s p 1 a y new 1 i no


mov i t ) , 110 / l o a d r . e r o i n i l l (1 n i t i a 1. i r e c o u n t "i-l
intm?: acal 1 newline / d i s p l a y now 1 i l i e
cjne
a imp
i:0,
new!i ne
# 0 x f t t't, i n I'nit
/jump if c o u n t e r o o u t e u i i s not. 12 H
/ o t h e r w i s e d i s p l a y new l i n e a n d r e t u r n t o menu
intm'i: mov a, ri) /move c o u n t e r cent cut t o A
aca.l I phex / d i s p l a y eount.e: content ( o n c e e a - - h H-. t iiii.--)
mov a, #':• /move ' : ' to A l o d i s p l a y
acnll cout /display 1
:'
i n tan4 : a c a . l 1. space /display space
mov a , (•!) ti / m o v e c o n l out o f a d - l r . in ' - o u u i e r t i • A
a c a 11 phex / d i s p l a y addr. . c o n t e n t
i ne rO / iiicreinent count or
mov a, rO /move count or a m i n i l to A
an.l • a, 8 0 0 0 0 . 1 1.111. / m a s k A w i t h I S ( o r g a n i z e e v e r y 1<. i n • • n o 1 i n e
jnz
sjmp
i n tin
i utm?
A / j u m p if: l i n e n o t
/ jump f o r a n e w 1 i n o
finished

Memory Managmenl S u b r o u t i n e s

/ f l a s h w a i t r o u t i n e p o l l s t h e f l a s h com w a i t l o o p i n g u n t i l t h e I lash rum-is


/ S t a b l e . DPTK m u s t b e i n i t i a l i z e d w i t h I h'- a d d r e s s t " r e a d .

117
flash wait
push h ; s a v o B l o q i s t o r 11< t o q i s t o i is used'.
c i t: .i
-
; e l e a i A
m. - v i, /move what it d p ' : t- • A
fiwi: mov b, ;iimvf> A < " n t or.l
-
!.<> l< ( o r '•!i'""!;i,Uii
i no r '• ; inci omen I !
el r a /cleat A
ll|. I V C a, ;movo wlirtl- al. dpt t i-> A W A I I !
cine a, ;cciii[Mir- pimp Pari: i! A 'Hid )• n . J oqn.
pop I, ;whon si a b l e p o p whit is p u s h e d
ret ; to I. u 111
; flash en r o i U i n o sonds t h e flash e n a b l e c o d e s for wi i I i ii'i.
flash e n :
mov dot r, 8 f l a s h on 1 a d d r / l o a d d p t r wi I h f l a s h o n ' a d d i
mov a, II f l a s h , o n l data /.load A w i t h f l a s h o n l data
movx fctdptr, a /move onl data to o;t i a d d i
mov dpfr, II f l a s h e n ? a d d r / l e a d d p t . r w i t h f l a s h on.- a d d i
mov a , # f l a s h ..en?, d a t a / l o a d A w i i h M a s h <<\\/ d a t a
movx ' fldpt l., a /novo on? d a ' a to on? addi
ret / i et u r n

/ p r g m r o u t i n e • / r i t e s A r c . i n t o f l a s h memoi y at. !>!TR. '' ' S s o l I: o i i o ; oconis.


/ c l e a r i f .it w o r k e d . The r o u t i n e u s e s f l a s h en r o u t i n " , i t c a l l s a l s o f l a s h wai
/routine a f t e r w r i t i n g d a t a . T h e r o u t i n e t h e n chock.-: 1 h o d a t a w r i t t e n l e set. .a
/reset C flag.

prqm: xch a, lO / exchanqe dat i t . o wi t i e with r (I


/save A
push
;i<-< • /save dpi
push dpi
push dph / s a v e dph
aca 1 1 flash en /do first step, enable wiifinq
mov dptr, il f l a s h wr a d d r / l o a d dpt.t w i t h f l a s h wi addr
mov a, II! l a s h wr data / l o a d A f l a s h wr d a I a
movx Pdptr, a / . s e n d 1 l a s h wi i l " e o m m a n d
pop dph / i e s t o r e dph
pop dpi / 1 e s t e t •• d p i
mov a, rU /move data t o w t i t e i n ' o a
movx (•'opta , a / w r i t e 1 h o • la I a
acal 1 f f a s h w .!! ; w.i i t mil. i i i t ' s d< 'tie
clr a /eieat A fa lost
move a, fardptr / i e a d i 1 back
elr <•: /clear C (as tlaql
xt 1 a, ill ;>:•'! A a n d ri)
)~ prgmotii 1 /'•limp i ! d a t a is wt i l t e n i .:• -1 ••>)
setb c ; w ! f n i t - •! s e t o ::>•; '' ( i s II i q )
prqmend:pop ace ; l e s to..-. A
xch a, 1U / •-xchanqe data !•> w r i t e <••• i t h r'. ;

t.et /ietnrn

/ e r a l l e r a s e s a l l t h e f l a s h rom a n d r e t u r n '.:-] i t t a t l u r e , O n i l o l . . i t c a ! ! <.


/ e r b l o c k f o r I d o c k e r a s u r e . Then i f s c a n s a l l I he f l a s h a r e a if they are not
/completely deleted ( d e l e t i o n ••• F'FI t o s i g n a l e i i o r . When d e l e t i o n i s o k a y c---u
/ o t h e r w i s e c=-.l ( e r r o r ) .

eral1:
mov d p i r , III i a s h o r ? a. Idi / p o i nl t. • I 1 isIk-i ac M i .

mov a , ft! l a s h o r ? d a t a ; r e a d addr . c o n t e n t


a call orhlock / u s e o r b . l o e k t.o s e n d erase all.
mov dptr', dbflash /point to back f l a s h -vllr.
erall?: clr a / e l eat A

118
move i, i't.i t ' l p t a - ;r<-.id l.-i'-t: I l a s h I:K m o r y
•-'!51 i ; o- -inj •! .-•I:I<-.|. i i . |,|
JNV. o r a l . I --11 ; c h e c k i I • i ' y. : . - i j I y e i aso.;i
IN. •lot. I ; i ii'-i ,|pt ;
IW'V l , I! i ( o i . l a s l l i I ) >. .15b) ;iiiu7i- Id k I--woi .-,ddi . |-,. A
c j no dpi, ei.a.ll,' / l u m p l - i o i : | - b i t M-.I !. i fi i ::l i. •• i
mov a, S ( ( ( o f i - i s h t t 1 ••'- ti} ''•'S; / n i ' v e i d k l . i ' i i i . o . i d d t . 'i o A
c j no . i , • lp! i, e r..i 1.1..: /jump oack il i l l not finish'-.i
c i r. ;i-Jivii <•'., (1 i n o » ot urn;
ret ; r o t nt n
u a l J nri: :
pot b ; .•••>• t >', ( fa Is o r "tut n j
cot ; i e i 1111!

erblock is i a . s e c-.-mmaii!.!. 1! i s c u l l e d b y o i u l i , a n d i s i n l ' - n d ' - d t.


callable Cfrom t h e P l a s h m e m o r y <:o t h a t c u s t o m b l o c k ni,,<••<. c o . | r . c a n ),,-.
implemented. u s e s f l a s h on subronl i n c .

erbiock:
push •'iCC ;save Acc
push dp] /save dpi
push dpi) ;save dph
aeal 1 f l a s h on /send (lash '-tialdo .-Out!
mov dptr, II f I a s h ••u.l a d d r ;point: to f l a s h blk
mov a , ft !.I.1.-I1 '.,. ; d a t a ;II1OVH f l a s h e r a s e dita
movx 9dpt r, a / s e n d "i:;i;«! e n a b l e
aea 1 ! t l a s h on ;s<--nd 1 l a s h e n a b l e skull
pop dph ,-|e ;(o|e
: dph, dpi and A o o
pop ' dp] ; rest.01 0 dpi
pop ace ; t>.--.-il;i>i e A
movx Gdpt.r, a ; s e n d e r a s e command
ajmp f i a s l p w.-i i 1 ; jump t o w a i t and loiui.n 1

/ f i n d s e a r c h e s f o r h e a d e r i n t h e e x t e r n a l memory i d e n t i f i e d b y t h e sequence
/ A 5 , E 5 , E O , A 5 . T h e m e m o r y r a n g e s e a r c h e d i s d e f i n e d b y bmem a n d e m e m . T h e i n p u t
/ D P T R ' p o i n t i n g t o t h e s t a r t , o f s e a r c h a d d r e s s , ( o n ! y Mob u s e d ) . O u t p u t : i s DPTK
/ l o c a t i o n of next module, c - »| j «t ; header f o u n d , >' - c l e . o i f RI-< m o r e h e a d e r s

find: mov dpi, fid /point, to headei


clr a /cleat A
move a, Pa-tdptr /point, to 1st specifier
cjne a, #0xA5, fjnd3 /jump if Ist s p e c i f i e r not egu.-I i A';
inc dptt: /increment dptr
clr a /clear A
move a, Oa-tdptr /point, t o 2nd s p e c i f i e r .
cjne a , #0xliV->, Jind< / j u m p i f 2 n d s p e c . i 1 i.oi n o t e q u a ! Kl-
inc dptr /increment dptr
clr • a /clear A
move a, Wa+dptr / p o i n t t o 3rd specifier
cjne a, OOxKO, Cind3 /jump if ' r d s p e c . i l r . e e n o r e q u a 1 Kti
inc dpt r /increment dptr
clr a /cleat: A
move a, l-laldpfi. /point to 4th specifier
c j ne a, IIOxAS, fin.;13 / j u m p i f 4 t i i s p o o i f i e - , n o ! o q u a ; A'.
mov dpi, *(> / found one horn I
setb ,~ / s e t (' ( f o u n d f b i g status}
ret. / r e t 11 • 11
find3: m- IV a, li (emem :•'- 0 1 / l o a d A w i t h w i n h i (ill a d d i . b y l •> ( f o i e n d c h e c k )
c jne a, dph, find'! / c o m p a r e a n d j u m p , i l not. c. g u a l (n- .1 t l i e e n d ;
clr c / c l e a r C (the end f l a g status)

1l<>
ret ;return
f irid4: inc •iph ; k e e p on s e a r c h i n g
-
sjmp find ; j u m p h»i' k t o c o n t i n u e soarchinq

; s m a r t w r r o u t i n e t e s t s t h e p i e s e n c o n f f l a s h I i r s t . II. i n I l a s h w a s f o u n d i ' wi i!<


; t o i h e o r d i n a r y PAM. When a I l a s h w a s f o u n d it c h e c k s t h e a d d r e s s t o b o w r i t t e n
;to, i s i t i n t h e f l a s h r a n q o o r o u t . When i t . i s i n s i d e i t u s e s p r q m s u b j o i n i n • - f
/ w r i t e i t ' s c o n t e n t s , o t h e r w i s e it w r i t e s i t ' s c o n t e n t i n t h e n o t r t r t l 1'AM
/ W r i t i n g t o l - ' i a s h ROM o r o r d i n a r y PAM w i l l b e i n d i c a t e d . C n y b i t w i l l indicate
/successfully written (<.'-()), 0 1 n o r w i i f l e n ((' I ) .

smat t w r :
push ac< ; st o i o A
push b ; s l o i e l<

mov i>, a ; in- i v o d a l a t o w r i I e i n l . • H


; Do w e h a v e a t lash | . « ;
mov a, Uh.-is flash /l.l'.ye 1.• cliocl;, i s •lnqe flash:'
j'' wr t am ; i i.im) • i ! t i e | | , , s . l i ( h a s f b a c h • ,-otoi
;There is a ish rom, b u t i s I h i ; 0 ' l d t . e s s in it :
mov dph ;move dph In A t o <iieck, i s i 1 1 he end?
cine a, it ( o f l a s h -••-• » ) , i s f 1 3 ; jump i I n o t e q u a 1 t o f I a s i l e n . 1 i, b l h ! ,y
sjmp w r .1 l a s h ; i nmg i f i ! i ••• t l ; o ••ud
icfl3: jnc w r ram ; iump i i d p t . i s ••flash hiqh byte
cjne a , 8 ( b f l a s h ••» i s i i '1; 'pimp i I. n o l e q u a i ! o | l a s h b o q . i i r h i g h i
s imp wi flash ; jump 1 I i 1 i t he bo-jin
i s f l-l: jnc w1 flash ; iimip i ( d p h i s < b f l a s h h i g h b y t e
;sjmp w r t am
wr r a m : ItlOV a, b ;mov>• . l a 1 a 1 o w r i t o i i i I-. b a c k ! o A
lUOVX fldpf.r, a ; w r i t '.- t h e v a J n o t o m e m o r y
cir a ;c1ea r A
move a, '. i d p f r ; 1 e.-,. 1 i t 1 ,.•)(-1 | i . ,n i e.'-do memory
clr c / c l e a r <\
subb 1/ h ;subl t a d i.o chock is i. i wr i ft '.'ii
jn :>i:it,tro!:
movx (•'dptr ; r e a d i t b a c k f r o mi d a l a m e m o r y
a t ; c l e a t <:
clr e
sub)' a, b ; sul.M r a c t to chock 1s iI w r i t t e n aqa i n
J* smwrok ; lump i f successful
smwrbad : s e t b c / s e t . (.', n o ! s u e . c o s s f u 1
sjmp smwrxiI ; i n m p t o 1 e s t o l e ;> lid 1 e 1 11 t i l
smwrok: c l r e / • d e a r C, s u c c e s s f u l l y written
smwrxit. : pop b / t e s t e r " !<
pop ••to ; resl o i e A
ret / I o l . i n 1,

wr flash:
mov a, b / m o v e d a t a 1 o wi i f e i ; i H b a c k 1 o A
l e a 11 prqm / w r i f e s A i tit o f 1 as h iiioiii"iy a t d p t . i
pop b ; 1 e s l o i e I'

pop aec ;res tor" A


ret ; r e t u i tt

Power-On Initialization cod"-

/ p o w e r o n make t h e h a r d w a r e t o b o i n i t i a l i z e d b y I lie following routine. Description


/ o f poweron r o u t i n e i s embedded i n t h e t e x t .

intr_return:
reti /return from inter!upt
poweron:
clr a /clear A
mov re, a /reset i n t e r nipt enable tog.istei

120
ir.ov ip, a ; i es»l. i n ' o i r n p t p r i o r i t y leqisioi
moy p s w , lipsw i n i . l ; i n.i I i a I. i y.e p i o g : im s t i f . u s w u i d
/ C l e a r a n y i n t e r r u p t s t a t u s , j u s t .in c a s e t h e i i r p i put " P i m p 0 " i n s v i e theii
;interrupt service code.
a c a 1.1 inft rotm n ; c l e a r p t n b a b l e iril e i r i . p l (call
aca.l. 1. int'.r teturn ; c l e a r a g a i n ( ea 1 1 v d d s u b rout ill"]
cp.l i / c o m p l e m e n t A t o r e s e t a 1 i. p. .rt s.
inov pf>, a ; i " s e t port 0 ( a l l poi l s b bin 1
mov P i . a ; r e s e t poit 1
mov p2, a ; I e s e i . noi I /
lllOV Pb a ; I e s e t port <
• niov sp, iistaek ; ! o a d s i a c t . p , ,i n i. • • i w i t h s i a . •!: if-11

B e t o r e vie s t a i 1 d o i iki a n y 1 / ' ,> a s h e : i. . | e l ,i y i:: r o g u i i m j s o l h a t V est na I


/ h a r d w a r e w h i c h m a y b e i n " r e s e t m o d e " c a n i n i t i a l i z e . T h . i s i s I y p •. -a I I y -i f • ol
r
/ w h e n a P2C. >!> . - h i p i s u s e , ) a n d i t s i e s e l l i n e i s d r i v e n I r.-in t h o K - i ' i . . ; - . . | cii<
/ u s e d f o r t h e s n v i . B e c a u s e t h e 02'.:',!.. r e s e t p i n s w i t c h e s t i .,m . - e . . i , r • ,
r
/ h i g h e r v o l t a g e t h a n t h e >.<.').> i., a n y H 2 C ' . . c h i p s w o u l d s i i.! i b e i n t e s . - > t mo.jo > j .
1

/now...
rst_dly:
mov r l , #200 / a p p r o : : lOOOOn c y c l e -
rdly2: mov r2, #249 / bOO c y c l e s
djnz r2, rdly2 / d e c r e m e n t a n d j u m p b a c k if" t.2 i s n o t zero
djnz r l , l.d.lyi! / d e c r e m e n t , a n d jump b - v k i t r l i s not. z e i o
/ C h e c k f o r t h e • E r a s e - o n - s t . a r t u p s i g n a l a n d e r a s e f l a s h KOM i f it's there.
mov a , Dlias f l a s h /Load Mast, i n s t a l l a t i o n f l a g int. A
jz skip erase lump i f h a s f l a s h i s z e r o ( f l a s h n o t installed)
mov a, Heraso_pin / o t h e r w i s e move o i e a s e p i n s t . s l u s i n t o A
jz skip erase /jump if e i a s e pin is z e r o ( e r a s " p i n no' enable'
mov rO, #250 / l o a d 2"SO I n t o r O , t o c h e c k 2 5 0 t i m e s , t o b e s u r
chkerase:
. mov c, e t a s o pin /move r i w pin s t a t u s int.. A
mov r l , 11200" / l o a d rl wilii 200 ( d e l a y t i m e )
chk e r a s l :
d jnz r l , chk e r a s l /doeremetil r I , l o o p in same I i n " , it it s not ze
jc skip erase jump t o s k i p e r a s e if e i a s c - p i n i s h i g h
djnz 0 , .-hi-, o i a s e /decrement r ' l a n d jump l a c ) ; ; f u o i ::•- >.
leal 1 •!i a.I 1 • le.l e t e a l l flash
/ R u n a n y u s e r i u i t i a 1. i z a t i o n p r o g r a m s i n e x t e r n a l memory.
skip_erase:
tnov b , H2-19 / l o a d P w i t h 24'> ( s i a r t u p c o d e )
aca.ll st.code / d o s t a r t up c o d e
/ I n i t i a l i z e t h e s e r i a l p o r t , a u t o ban I d e t . e e » il nece^p.-n y .
acall autobaud / s e t up t h e sot in I pott
/mov a , t.hl / l o a d I im<• • i h i g h b y t e i n t . - A
/lcall phex / d i s p l a y l i m e r l tiigli b y t e
/ R u n t h e s t a r t . - - u p p i o g i a m s In e x t e r n a l memory.
mov b, !!2V r
/ l o a d A w i t h 2 >''. ( s i a r ! u p or- | . I I . p 1 : • • I J. .-I!'l

aca] i steode / c a l l s t a r I up c o d e
/ N o w p r i n t out. w o . l e . e m e m e s s a c i o
sve 1 c o m e :
mov ru, #24 / l o a d i n w i t h X4 (l-|... oi. l i n e s t o d i s p l a y e d )
welcm?!: l e a l new.I. i n e / d i s p l a y new l i n e
d-jn:: i 0, w e 1. cm2 / d e c r e m e n t rO a n d jump b a c k t o d.i s p l a y n e x t l i n t
mov r-0, # l a / l o a d 1 0 w i t h I > ( D o . of: s p a c e s t o b e d i s p l a y e d )
r

mov a , ;!• ' /move s p a c e I o be d i s p l y e d


welcm4: l c a l l cout /display space
djnz r O , weLoro4 / d e c r e m e n t . rO a n d lump b a c k t o d i s p l a y n<\--;. spa*,
mov d p t r , 1' L o g o n ) /point t o logon! message
l e a .11 post r /display it
mov d p t r , S logoti2 / poi.nl t o I o g o u 2 m e s s a g e

121
l e a l 1. pesfcr /display ii
leal 1 dir. /..-.all d i : o o t , , i y i d i s i d y s I f f files and ••.:<••.••
mov r O , 8 ( p g m *. 2'..a) / l o a d i. << w i t h pgm I • >w b y t e
mov rl, 8 ( p g m >> H) / l o a d r 7 w i t h pgm h i g h b y t e
ljmp menu / r e t u r n I o menu

/ s t e o d e r o u t . i n . - i s i n v o k e d a u t o m a t i c a l l y d u r i n g p o w " ! ' . . n a t t h " s t a r ! . '."his r .ui : :


/ w i l l . Look f'oi s l . a i l . u p s p e c i f i e r ( 2 4 1 ) .,m<<ng t i l " i i " a o ' > i s . When i i is success': i , i
/ s a v e i 1 : s r e t u r n l o c a t i o n arid 'pimp l:r.> t h a t s t a r ! u p s u b , o u t i n o . When i l n o n i u s i!
/ c o n t i n u e s s o . n c h i . i i g t o r o t h e r s and rloes ' h e same unt'il a l l s t a r t u p r o u t i n e s a ? e
/ f i n i s h e d . At. t l i i s m o m e n t t h e f . u o f . i o n w i l l i f h u i ; h a c k " o p o w - a o n routine.

stcode:
mov d p i t , !ll'.iiiem / J o a r l hmeiii l u ;••-a i ••!•. i nq s t . i i ' u p toitrin"s
s t c i ' d r v ' : J c a i. 1 l in.I / I i nd h ' - a d o t ••! Mies
jnc slcdo'.'. / j u m p , s i n e a.l i o. . ,,m.i!i. i s so.-, i h o d a n d n o lr-on-
:

mov d p i , l!'l /point t o ( b r u t e onl its type


cl.r a /cleat A
move a, H a l d p t r /load its typo
Cjll" i, p , S I c o d " " ' / j l.llll| '. '• I V| •'• I I " l: - I t . 'h'.S .••tarlllj
1
!' ' . ' I ••
-
push b / s t o i o t h e I yp>-
push dph / s i . ' i . . t t i g h h y t •> , q : y p e a d d i .
mov a , II ( s t r o d e . - ! 4 /:5!>) / m o v e s t o o d " •! a d d ! . l o w b y t e f.o A
push acc / s t : " i o stood".* addr . low b y t e
mov a , II ( s t o o d e S •• 8) / m o » o st..co.lo.< a d d r . h i g h b y t e t o A
push aoo / s t o : e .strode* ad.'h. h i g h byte,
mov d p i , I 1>1
1
/p.iii! to stat tup headoi
clr a /cl«.'ii A
imp tlaldpti. /jump to the s l a t tup code
stcodea:pop dph /hopefully it'll r e t u i n t o h e r e , r e s t o r e dph
pop b /restore b
stcode4:inc dph / i n c r e m e n t dph tot a n o t h e r sear..:h
mov , i , dph /iiii-'Ve d p h t o b e c o m p a r e d
cjno a , Il ( (oiiiem I I ) •• K) *, s t e e d " . : / iiimp back, i ! " m l n o t i " a c h e d
stcode5:ret / n o w u " " x c c i i l 'al a l l

autobaud routine is invoked automatically dining poweien o the si art vii",- > !.•
f o l l o w i n g . i i n o i s •:•••>i o c t o d .
egi.i baud c o n s t , 0 / f l a g for automatic baud iate detection

To d o a u t o m a t i c b a u d r a t e d e f e c t i o n , m e a s u r e m e n t , a n d s o t t i n g . It. i s assumed thai


the u s e r w i l l p r e s s the cari'i.iae return, which w i l l cause th" below bit IMI n u n
t o a p p e a r o n p o r t H p i n 0 ("K ~ a s c i i c o d e o f d e c i m a l I"'. (OlMi),

0 1 ii I 1 0 0 0 0 1
1 I I I
/ start bit i- ^ — I s b msb—i i stop bit
/To s e t the baud i.ate, the f o l l o w i n g t o i m u l i i s a p p l i e d i n " a t e n l a I. i o n .
-
/ baud__const - 2S6 - ( c r y s t a l / (l: *• 1 i> ' b a n d - r a l e ) ) .

/ T i m e r 81 i s s t a r t e d i n 16 b i t mode a t t h e t r a n s i t i o n b e t w e e n t h e s t a r t b i t . and
/ t h e LSB a n d s t o p i t b e t w e e n t h e MBS a n d s t o p b i t . T h i t w i l l g i v e a p p r o x t h e
/ n u m b e r o f c p u c y c l e s f o r 8 b i t s . D i v i d e by 8 f o r o n e b i t a n d b y 16 s i n c e t h e
/ b u i l t - i n UART t a k e s 1 6 t i m e r o v e r f l o w s f o r e a c h b i t . A f t e r d i v i s i o n t h e t e s u i l
/ h a s t o b e i n v e r t e d s i n c e t i m e r 81 c o u n t s u p . Of c o u r s e , t i m e r III g e t s u s e d i n 8 -
; b i t a u t o r e l o a d mode f o r g e n e r a t i n g t h e b u i l t - i n tlART's b a u d r a t e .

autobaud:
• mov a, Hbaiid_const /load supplied baud ran constant
j i t 7. .nit o e u d jmp ; i iintf • TO a n t . . e n - ! imp
mov a , ban.'! S . i v f ' I ; I o a d b a u d "n.l n - I't <M: pi •
x i .1 b a u d s a v e * ; - ! , 110 I 0 1 0 1 0 1b ;xoi baud s,o/OI, and
:<r! baud r a v f t l , fill 0 0 1 1 0 0 b ; x o r baud s»vca i a: • i ' • II
xi: J baud s a v o + O , #0001110.11. ; x o r baud s a v e . a ai
•i 1P!I
o jne a , b a u d s a v e i ;:, auiobi iu:i.p a • MD •
c j tie a , b a u d s a v e i I., a u t o b l lump i T p r . •and s '
cine a, b . . u . i s a v e i-0 au!:...'i.d i IIIP.I - i •and s.
autoend_jiTip:
ajmp aid o e n d jump l 1

;wait for inac tivity


autobf:
inov peon, IIOxRO ; coiif. j g m p.:..n h a I'. s f b a u d (doub •I!
mov soon, If Ox.12 ; c o n f i<iu i'• >n b i I •••it -b.ii... I,
mov tmo.i, II 0 x 1 1 / c o n f i g u r e I inters V I ai a o f b>li '.i BIT
clr /clear A
mov toon, / i e s e t I* iMOT*0 a n d I i m e i l •:••»»! i •
mov ! 10, /clear t i m e t 0 lew b y t e
mov t.hO, / c l e a r timerO high b y t e
mov til, / c l e a r I i n u I L 1 l o w hyi_'-
mov till, / c l e a r t liner 1 h i g h b y t e

; M a k e s u r e t h e r e i s n o a c t i s i t y o n t h e l i n e h e f o i e w e a c t u a l l y f . e g i n 'o,-.l: i n g
;the carriage return.
mov ITT, II . ' 0 0 / l o a d HI w i t h , 0 0 lor d e l a y fact-ui
autoblbtmov r.l, NO /load r I with '.fi I n d e l a y Iact m ^
autoble:jnb p 1. (l, a n t o l l ! / j u m p i I p i n p <. 0 i s • • n-i
djiiK rl, antobfo /decrement d e l a y l a o t o . , : a n d i,., ,p i ! n e t :•••. r e
• d j nr. ri), ant o b i b /decrement d e l a y l a i d a 1 a m i I OOI • i t n e t :-.ero

/Look f o r t h e b i t s oj t bo c a n bine r e l n t n . Wait f.a slait lot- in I HE I j I s ! |


/ u n t i l ! i t i s l e w , . g a i n . T h e n . h e c k i l a LEV; n-..:- t im-.s, in o'LI'-I lines, t ••> v.i
/ S U I E WE DELL'! I : b c | . ' '•(, s o m e l i o i . S E .
a ut ob;':
jb p.i.ti, aui ob /.LOOP I ! P I N P T . ILGH
jb pf.!>, an f o b /
jb P-'.O, nut o b :
jb pM.0, a n l ol>2
jb p . < . 0 , a lit o b i :
autob2b:jnb p.?-.0, a u t o b / b /wait f i . i b i t 110
/ H e r e c o u n t e r L w i l l s t a r t I Lmlng t h e UK d u r a ' i o n d m i n g i t s FT b i t s s h o w n abo
/After bit f i m e r O i s s k a r l - o d t . o o . When t h e s t o p b i t c - m e s (after bil '/) th
/timers are stopped.
setb trl / now w e ' r e t i m i n't i t.
autob2c : jb t f l , autobl. / c h e c k 1 o r t i n i e o i i i wh i 1 o wa.i.t i n g
jb r.2..O, aul.ob2e / w a i t f o r bi!.. * 1 t o b e g i n
autob2d : jb t N , aui o b i / c h o c k l o r r i i i i ' - o n t w h i 1 e wa i I i n g
jnb p-<.n. aui o l v d /wait for bit !I2 1 O b e g i n
autob2e :jb t ; i , an 1ob1 /check loi 1 iiiieout wh i 1 e v.'.i i i i n g
) '
1 pt.O, ante)-:.'.. /wail l o r b i l II-1 l • • b e g i n
? e t:.b i I ('1 / s i a r t 1 i II; i n g I a s t '1 b i l s
a u t o b 2 1 :jf. IN, n i l OBI / '-heck lot 1 i me. >u! w h i 1 e wa i i i n g
jnb P b i t , aui olv'f / wa.i t f • -r s t o p b i 1 t o b e g i n
clr tr I / s t o p 1. i mei 1.
clr trO / s t o p timet 0
jb f f 1, a n l o b i / c h e c k foi I' iin..out o l i o ):n.r,< i lino
/ C o m p u t e t h e b a u d r a t e b a s e d o n t i m e r ! . T h i s i s . l o n e b y d i v i d i n g t h e i i m n r v:
/ b y by 16 and t h e n by H b e c a u s e timet i s in f a s t b a u i ( d o u b l e d ; mode.'''he liv
/ i s d o n e b y c a n o e . ! 1. i rig t i m e r ! low b y t e e x c e p t t h e m o s t s i g n i f.i ••anl b i t which
/ s h i f t e d to fin.oil high byte as least significant byte.
i:,oV '., t '• [ /move I ill'" l ! b >w !<••/><• i •> A
Mt: i / r o t a t e A bo'I w i l d cart-,
mov 1», a r-in'JVfi A , onl out i.- i
n.ov a, I.hi /move I i
-
i I di'ld I •• V' • - ' A.
r l e a / r o t a t e A I" I I wil'n ea t i y
"jo a u t o h ! / o i r o r if timet ! • o'V.Y:'
/After d i v i s i o n b y 1 (> a n d b y l<, wo h a v i « ili«i-lc b y i.S. ' I ' d i :• a ) a o : : i ma I "O i
/adding b i t . " ' wnioh i s e q u i v a l e n t t o b i t . <n o l t !i h . •; • ! • • , . • ! . • • •.
inov o , b . 7 ; p n t b i t . 7 i n '.'
a d d - o #0 ; a d d 7.or<i w i t h e a r l y
c:pl. i /complement A I " in 1 !•.•'• ;
i i i " o a I. i v ' • >.i s n b t i a..:! i >-i
ino .. ; a d d I !•< m . i k o i' ••qaii. |.. ( ..'SO A)
j z aul.obl /jump il baud r a t e !.>•••• f a s t

/AL'l.oi w e q e l I d o r i n • a g o r e t a i l . , k" n " " d i'•• rr.a 1: • • s u r e I h ' o " i o n ' t a n y " c r a p "
;l;)lO s e r i a l M i l " , a s ! h e r e i s i n t h e o a . s e w e t " we q e l l h " i n i !•'>: K ( a n d o o n o l ' l '
; t h e wrung b a u d r a t " ) , l t n t o r l i . m a t e . l y 1 ho s i m p l e a p p i o a e h o! iusi l o o k i n g al I I K
; L i n e d o r . s i l e n c e d o e s n ' t w o i k , b e c a u s e wo h a v I - , . . • - • • e p ' I |t< • e a s e w h e t > • ' I d - •
/ u s e r ' s t o r m i n a I e m u i a i i o n i s e o n i i g m o d ! • • s e n d . l i n o to,...] . n i o , i oairbvi<
/ r e t u r n . T h e b"-st t h i n q s o d o i s l i s . ; H i " n a i l a n d .b-.,k s o - - il i t i o.-o i v e s
/ a n y t h i n g . If. n o t h i n g r e c e i v e d , t h e r e i s a n e i t o r .

antob!): mov thi, a / m o v e a u t o t o t i m e r I h i.qh b y t e ('•• 11i I q : i :r."i i ;


mov til, «2V. / m o v e IK t o t i m e t I l o w b y t e ( i , . g • i . | i i i ! i c i n | i
mov f i n o d , ,10:: 2'! / a n t o r e l o a d m o d e o f ' i.m"r I
setb ton / s e t r e r o i v o e n a b l e o f s e r i a l p,,i i s o n ! r o i
setb 1 ri ; s e . f t i m e ) | o o n l i o i b i t Is. s i a i r
inov a, tli'i /move t.imori h i q h b y i . - i.. A
epl •-, / oompioiiiet A a n d
ine / i n c r e m e n t I o m a t . " it- p o s . i t v
3 /P.IOV l i m o i \ 1 h i g h b y r e t.o j | - i s g o j
mov • rl, a I A- •; I -R
a u t o b 3 b :mov r O , it 2 •".!., / m o v e f'F t o rO a s d e l a y fa.-.i. •: /
autob3c : djnz rO, a i i t o l > U. / d o c r e m e n t f a t " m, I a n d jump i l n o t
1

djnz ri, am ob.il /decrement f a c i e i / ! a n d jump i f u


j rib I i , a n ! o!.,4 / j u m p i l . r o c " . i >.'" jiil . a i ntii is not
/ I f w e g o t h e r o , t h e r e w a s s e n t " s t u f f /if l e t t h e c a i i i a g " r o t u r n , I
/ a n d s e e i f i t w a s I lie l i n o feed.
clr r.i /clear recei.v i i t t o i t n p ! i<> t e c - ; v e m o r e
mov a, sbui. /.load reci.pl cliai.acl.ot into A
anl a , 11011 I. id l i b /mask t h e h i g h e r id I
add a, !!.?4("> / a d d 24.'-. I.o c h o c k i s i ! a l i n e J o e d (1.0 • OA!!)
jz aut.ob4 /jump i f z e r o (ok, l i n o food character)
add a, #5 / a d d 5 (0101B)
iz autob'1 / j u m p i t z e r o , p e r h a p s we m i s s e d s t a r t b i t
autobl_jmp:
/ o t h e r w i s e j u m p a n d r e t u r n t.o s t a c k f o p
ljmp
/Compute t h e baud
outobi
rate b a s e d o n t i m e r O . T h i s i s d o n " b y d i v i d i n g t h e t imor!) , ; ;
i.l

/ b y by 16 a n d t h e n b y 8 a: •ihown i n t i r a e r l a b o v e .
autob4:
mov a, f l u / m o v e I. iinorO l o w b y t e ! <.• A
rlc . a / r o t a t e A lol.t with c a n y
mov rh, a /move A c o n t e n t t o i 0
mov i , !hi i / m o v e I. i me rO h i g h b y t e I n A
r1e / r e l a t e A loll with o n ! i y
mov r1 , a /move A c o n l e n i to i0
jc a u t . o b ! jnip .•••o. r o r i I" I imot 0 <?7C7
:

/ m a k e a m u l t i p l i c a t i o n of. by s h i f t i n g l ' - t l , b o - s m s o t i inert) i s s t a r t e d t o conn


/ j u s t b e f o r e t h e 2nd n i b b l e of t h e r c . - o i p t "H. Tdoi e l o i . " i I i s m e a s u r e m e n t has
/ b e m u l t i p l i e d by 2 .
mov a, rf) / m o v e r U u> A
rle a / l o l . a t e A loft with c a n y

124
1HOV 1., .i /move A ooni e m t , , !•.
mov • i, r i /move rl t o A
rlo •i / r o t a ! e A i ••• tt w i t h -i t y
/After l i v i . i i o n I >y i i. y / v.-. ~ n a to i i V i fie 1
a n d b y i*, a n d m u l t i p l i e . i t b>n i
/This i < .> a p r . :'. imai '••..) •y a d d . r.'i b i t . . 7 w l - . i o II > S e<|,i j ! en! o i 1 i.e. f ' . ' I I •••
/ r o t n t i >n.
mov . : , )... / / p u t I.; i I . 7 i n
addr - 1 , HO / a d d /..-it o v i t h >• 1 1 r y
•j 7. l l l l i li' i imp / j u m p i 1 -.-.<• • r o , e i i >>r i f b a t ! -i : •- e l . - l . - M 1
opl i /oomp1emel A t o make • l i e q it i •• < l o t s u b ' ! ... •
i.no .1 / a d d 1 1 <•• m a k e i | e . | i i .I 1 1 o t t- - A)
/ C h e e k •iga i a: 1 t i t:ier 1 v.-i I ' . l e .
O'jlie .1, O i l , . m l , . ! d imp t ' w. *• I i in'. i I ' - . d i n g s •-! 1 " 1 1 "
;
iutitp
/ A c : li.-i t l i l ••• i i in • . 1 1 : h i . - | . . i n ! .
•llltootld
mov b a n d .'• a V e t '•, • i Jit O I e I j , e | M'1.1 1 ll.- ( .,j • ,<•X I W . I 1 III
mov b a u d .• a v e I , a , / t
mov h a n d r a v e i- 1 , a / 1 I * t • ' 1
mov b a u d sa v e 1 0 , a / I 1 t 1 t/ 1 t
xrl • baud s . i - i v e i •;. a n d '.Ml
avei2, #0J.0l0l01b / xor band <
xrl
xrl
b a u d r a v e i-J., # 1 1 0 0 1 1 0 0 b
baud s a v e + 0 , #00011101b
/ x o i b a u d :ta v e I 1 a n d
/ s " t b a n d : V I V O 1 0 a n . 1 .1 IjII
< :ai
mov t h i , ' •- / m o v e 1 h e i" l i i . n l h i - • ! o ! ,1
mov t :i i , / m o v e t h e r e l o a d v a I : i >> ! . o I i "1
mov t m o d , ilOx.H / n e t I i m e t ill t o r « b i t lilt 1 oad
mov peon. 9 0x80 / c o n f i q u r e d o u b l e b a n 1 r a t e b i l l it — i n u a i 1

mov soon, (fOxfi/ / i : o n f i q u i e . t o r i a 1 p o i 1 • :• >r. t o l


setb t rl / s t a r t t h e b a u d r a t e . i me r
rot /t etuin

Pat.- Mi 11 f i p 1 i. -a I i h i ant 1 11 i '.' ia i.oti

/ p i n t t l t i p r i m s I h e u n s i q n o d !i b i l v a 1 l i e i I A-:.- i n b a n o i n 'I'll i .-: i s '• 1 1 1 i I -1 I


/ d i . v i d i n g t ln> n u i u b o ' >y 1 OO a n d d i :ipl a y i n | t h e q u e l e nl (In l l - l l . •dl 1. d i q i ! ! , !
/ d i v i n g t h e r ein.i i n d e r b y it) a n d d i s p l a y i n g t h e q u e l e 1 1 1 . ' ! < • I l l II • i i q i 1 , a n d 1-
d i s p l a y i n g the remainder (units d i g i t ) ,

pi attiu:
push
push •T'.i* ,- -.1 o | .

s imp p i n ! tlb / 11imp

/ P r i n t - . s t h e .« -. i q n e d H I d | v-l ! l i e i n A'-f i n l-l.-f i n . T|,; • I - ! :

/minus s i g n . II t h e ntimbnt is- n e q . i t i v e , : h o mi t i n s s i g n i •: i i s p i . i y . - i d .no t h e


/ . i s c o m p l e m e n t e d a n d i n c r e m e n t e d ( t w o ' s o .nip I e m o n l ! . In H i " i " s l p a t t I h<- f.
/ i s s i m i l a r t o pi.iitDu.

p i nl: H:
push i. / S t o l o it
push aee /store A
jnb a e o . .', D i m (tb / j 11111)1 il the siqu bit. is not set
mov a, I!'-'' /otherwise move (-) t o A
l e a 1.1 < :ou 1 / d i s p l a y (-) sign
pop aoc / ret r i e v e A
push aer /store A
cp 1 a /complement A
add a , 1! 1 / a d d I t o make t h e I r u e v a l u e
mov b , HI 0 0 .-move 1 0 0 t o B
div ab / d i v i d e A b y 1 0 0 (J i n d 1 0 0 t h l i q i
setb ' to

125
pint He ; jump, i f A g i n >i e n i i s - l i e
oir ft)
add a, 1ft" ;add M l ' ! e A (moke a s , ' i i ,"|'l I "a 1 on; ;
1 e a 1.1 con! /display A
pint.bi.:: muv a, b ; m o v " i ema i i n ! " i in I*, i , A
ItlOV b , HI (i ;ill'>ve 1 ,1 t o \\
d i. v ab ;di vide )\ | , y I (i j i i t : d I ' l l " - 1 ( H ii d i a i t ;•
j rib til, pintHd ;
j >"• . pint «p ; i
pinfHd: add a, I ' d ' ; a d d \ ' i ' ! o A ( m a k e a . s ,i d i e.-p.i i v ; i 1 e n l j
1 oa 1 J • :..HI 1 /display A
pint, tie: mov •i, b ; Hi' a ' " 1' I •> A
add a, » " ! • ; a. i d ' n ' . . . i\ ( m a , ,: i : s i "oil i '•' l 1 ,'T,I '
11 : : i 1 ! •. | i i , i , •• • '••
' '! | O • ' ,
pop ; 1 . ' S i o | ' • .-'.
1. ; i >•s! o : o i;
. p o p
; I .' • 1 n i 11

/ p i n t . l(<u p i i nI s 1 i ) b i l u n s i g n e d
-
i n t e g .>i i n l.it'l'K, u s i n g b a s e I n . I'll" 1unci i o n u s e
/ p i n t x l C> t u n e l i n n t o d i v i d e t i l " n u i u b e t b y I l l O U l l t o d i . g . i a y M i l l ' ! ' . il h diu.i 1, a n d b y
; 1.000 t o d i s p S a y l O f l f l t h d i g i t , a n d b y 10(1 I . . d i s p l a y Itltll h di'li : . Then i 1 u s e s d
; t o d i v i . d o b y 1 !> t o d i s p l a y 1 0 1 1/ d i < | i 1 i isi g i. f .
. List 1y i I displays onei 1

pintl6u:
pin.li a co ;sioi e A
r.iov a , ,.0 / m o v e i 0 to A
push ace /store A
clr psw. S / c l e a r psw.'i
inov r2, dpd / m o v e |ow«->r b y ! " t o 1 •<• p i i n t e d !•<• v','.
mov 1.3, d p i . / m o v e li i g h e r b y l •"• t o : o p r i n t e d t o ) • /
p i n t 1.6a : m o v r.4, #l<i /move l O l i O O e g i i i',• i ' . n < I n H and i
mov r'.>, i ) " > i t i i it

aoa i I p i i d .1 (•:; / d i v i d e b y HlMi'i! 1 • • I 1 !:• ! i '.).).".'l!.|; .) ig j •

jz p i nt. 1 t b ;
; jump i 1 i " s n 11 i s ,.ei o

add a, l!'u' /••|. Id M O i o A (m.!'.-•• .. • • • i i e g u i V a l e n l 1

1 oa 1 i .:..ul / d i s p l a y A
• sot.b psw..'. ; sot 1 I ac s i nee I i i .-1 d i g i I :
s '•i i sp 1 ay.
p i n t 1 6b:mov 1-1, i ; ' t / m o v e 1 1100 oqit i" a I o n ! 1 o i 4 a n d i '•
mov i-'., If 3 i l l i l it

a o a 1.1 p i nl: l ( e : /.li v i d e b y i 0(111 ! o M i id KHHH h d i g i '


jnz p i n t 1.6o / jump '1 ! r
'* n
• !
i ; :

j nb esw.;.', ;•:::•>•••! ; '• •;;:•[ • .1 '. : • . - . } • • i '. • ••••,:> •• • ••••'• ! - e -

pi n t l 6 o : a d d a, S ' 0 ' / a d d M i ' : o A ( m a k e a :t c i i e g g i v a l e n t !


i c a 1! coat: /display
setb psw. 5 /set flag since there is display
pintl6d:mov r4, 8100 /move 100 e q u i v a l e n t t '•> r ' l i n d r'j
mov i:5, 80 l i t it i i

acall p intlfix / d i v i d e b y 1 0 0 t o f i n d1 1 0 0 1 1: d i g i 1
jnz pint. I do / jump i f : o s n ! . j i s n o : .
jnb • p s w . 5 , pin1.1.61" / j 1111111 i f z e r o i s I s t d i g i t t o display
pint16e:add a, 8 ' 0 ' / a d d M " t o A ( m a k e a s c Li. e g u i v a l e n t )
lca.1.1 C Hit /display A
/ 1 1 ;ig s i n e e | h e r e i s d i s p 1 a y
r
setb psw. >
pintlGf:mov a, t /move lowei b y l " t oA
mov i-3, b /sav H in t'l
mov b, 810 / l o a d H w i t h 10
. div ab / d i v i d e A b y P t o i i n d t h o 1 0 t h d i.g i.!.
jnz pi.nt.16g / j u m p .1 f r e s i t 1 ! i s n o t 7 o r o
jnb psw.5, pinti&h / o t h e r w i s e , jump i t n o p r e v i o u s display
pintl6g:add a, # ' 0 ' / a d d M . ) ' t o A ( m a k e a s c.i.i equivalent)
leal! cout /display A

126
p i n t i <<h :inov a, b /ME.'O f ! ' , , , P . • -p-i T • ' h. • .. u.-- II . 1 i a I '
4

mov It, r.< ; i e s t ••> E •-. 1 I -m •


••V id i , if ' f ' / a d d '1!' ' • • N IFL.• !:• • a s - • I ; R • in I v. >:.>!. I
P-.i) ; • •out / d i s p l a y -\
• . . . | • .-. J •./, .
IIIOV T:I, .-i /rest..)., i (;
pop •i"C
ret / r e t urn
, — • -
/ p.i r i t i f . x d i . v b i c s i x - i i b y i •!- i '. iiid
r
l e a v e s roma i n d e i in r .'• T A a n d ;*.*•.! • i: I I.: q u . -I S •
;.in a c e . T h e •. l i v i s i ' I U I r: o a r : b •<! b y s t q i i " n> i a 1 s a l it i i • -n .

p i n t 1 fix : m o v r(!, «0 ; c l e a r rU
p i n t J tiy: i n o Ic ; i n c . i ' - I ' i e n t : LI a t 1 OI o-i.-l, il i .i--i INN { JII. •: '• • -n < i
Cli ; . : 1 e a I •: < • I ! s u b l 1 • ICL i lie I . '...or t 1 i-/i . •
IUO'/ •, T 2 ; m o v o s u b ! r a c t h c n d 1. » > i !>yiII• t o A
subb a , ! •! ; s u i t ! r a c t . S'LL.L 1 a.'t e . | , , « ' . ) I : T >TII A
raov rX, a / m o v e rcan;T. i LIT lo i I N >.;•
mov a, r3 / m o v e s u b ! r a c r h e n d h i g h e r i-..;! o I .. A
subb a, I / s u h t r i o t . .subl i a c t EI HI OHO; ! I • :m A
mov i 3, a / m o v e i e t n a i IKI'S TO r t
jnc p i n f 1 Cy / jump b a c k i I ... • • a • : Y
dec ILL / d e c r e m e n t T ('• ( CI HTPJIISS ' i o n LOT- EYN| s u b t . r a c t i'
mov a , rX / m o v e rema i itdet o . w e : i.• y 1 e I•o A
add a , r'l / a d d s u b t . i a d o r .I.I m e i b y t • • .• o A t o u n p e n s . i t I..inJ
• mov 12, a /move l e s n l t t o r-' ' ! i n a l r< •ma i ink- r)
mov a, 1.3 / m o v e i ema i n d e i l i i g l i e r b y t < t .-. A
/ a d d s u l •! I a c t e r h i g h e r b y l e t o A !' o j t : p e n s a f I o n
1
add< •. a , rf>
mov r3, a /move r e s u l t t o r ! ( I i.na i I ' •TILL i ;I> It- ! >
inov a , rO / p u t q u o ! ! ent I lit) A
ret / ret u r n

Hult.I-I.iyle frequence and ComoI OSSO.J btf.a f t ,•<•< • s e i s e

; o i n f i 1 f o r 1I.il:n <• l o t inn 1 t i - b y > E s o q u . ' i i e . os t o r u p , d>>wn, IO• i t , I iql.I , paq.-UP,


/pagodown, a s >..-o! i a s o r d i n a r y e s c a p e a n d •II d ' na r y •'Irn ac.L a s . '.'. ><i. a i •' i equ.i. t <
;fo arrive s o motif, i u 1 ! Y , ' . ' ' l i e t w i s e t h e cli.a i a d t-i s a r e I | . . ; , l i a s oi d i na: y u s e i
; k o ' y s l ' . i . o k e s . C : I li M l ' ! 1
1 EL 111 li.-: a s i UC| b •b y l •• -.;l"-i: i 1 S. t HO I'M I It i -1 -.'/! • • '-.-.' MJ E
.•sequence, a s .-TIN >wn l i " i " .
; i el. ui n v a 1 lit key e s c a p e SEQIH-L• •••••
II C-K) up 1 n '•!< 1 i
H> ( M S down i i ' ''I'- -I."
Xi ('II) i iqhl i ft !;P .) !
8 CH) l e i t. i f '-.B <bl
2 a (~Y) p a n e up 1.1'. ')!'• !'• /'!•'.
page ,lo |: W IB Ml Ut .'K
. equ esc c'n i, , 2 7
cin filter:
jnb : i, tint ! / jiinij • i 1 | .-<••> i VE i n ' • • I i apt. i s n o ' s o !
leaf 1 •• in / i npui ! 11mi s e t i - i f p o r t
• VILLI' a, lies-.• c h a r , c i n f end ; j u m p i t . i I. i s nc • t IBii c h a r a c t o r .
; I f e s c was a l i f . v l y in s b u f , ins.! if)iiote IT, l o a v o i d peudititi e s c a p e .
cinf 1 : icai! c in / i npnl f t ..MTI n o r i <i- t p o r t
cjne a, 6esc c h a r , e i n f cud / j u m p i f it- i s not. 1 Bh c h a r a c t e r
c.I n f wa.i t / w i i t I'm A o h a r< i d OT l r a n s m i I. 1 ime
1
cinf2: aca!.
jt- L i , O i ! 1 f'T /jump i1 r e c e i v e i nt e r r u p t i s set
mov - i , »•••«••• . ' b a r /move e s c char ' . • A
rot /an ord i naIY e s c
/'If we g e t hot e , i t ' s a I'.mit m ! c o d . . - , s i n - •<•• a c l r o a ..-I • • r IS E i • „ . , ! - h o i I I -.- -.I :
; r e c e i v i n g a n t'.SC e h a t . a o . t . e : .
c i n f4 :

127
.1 c a l l ; input i i "id S O T i a ! p o t I
c j ne- • t, H. ' I. ' , o i n ! ••• itisi.iiii, /jump i f A ••• l i ' . - i i i ! s no;
ar, a 1 ! olnf wail /wait lei "i «'. i i t i i r l . ' M , l i a n s m i ' I : im •
jnb r i , d i n l i l t .•>• /jump if iocoi'->> i n t e r r p l n-.t s - ' O
I o n 1.1 •iii' / i npul ' i on, •:<•> • i a i p . • r I
c i n f b a : eju<- a, N'A ' , ciut:.!. /choc! if n o t b p k e y
m- •'/ / i 1 A, b . a d ! i ird< A".
rot. / i ••' n ' n
o i n ! f i b : i- j n e i, ii'i / • -lie. •!: '• I in., i iv.-ii is
Km > V i, !ilo ; i I A , ! • ..id ! '' into
ret / I "lllll;
c i n t'5e: 0 jn<
:
•i n l !..! /1 ' h o . : ! . i I not i i. | h I Key
iu< <« i, !l ? ! / i I A, I • - i d • ! i III o ' V e
rot ; I " I i n ii
o i n !">.!: in.- -1, » ' I: /olioel: il no! ) • • ! : h-y
m< >v / i ! A , l e a d H i n l " A.-.-
1 oi. / I o I I; | 11
einf5e: ojno a, "•!•, <•! n t ' . I /••I.e. k i ! not •• -|Mp toy bo disc . V I o
sjmp einffi / iili»| •
cinf:it: o jne . 1 , IK'x'H,, dill!"'...!
;
; elioe.K ! not l.'qbp key Jrd eiiarael.
sjmp o.i.n!.!.' / i'liup
c i n f 5 g : sjmp dini eonsumo
/unknown K:t''ape sequence
;Whon we get. b o r e , w e ' v e q m i h-
/ m o r e ine.om.iini b y t e i . . chock... lot p.-i.|onp/p-i!;.'".i..)WN, but (hero's. • •!!•••
einf«:
ptisn fio: / s i o i o A c o n t e n t (.t'-'h or '}i'-h) I't •t urn
a e a l i. o i i i f wai f /wail f"i some niomeni

jnb r.i , e i n f I e s t a 1.1 /ehodi'. 'I'll ' i l . l I •!< ! e |. p r e s e n c e

tea If o in / i itpul i i < .in • •• i n ! p. ii i


c jne a, i!0::7P;, •inf ii'.-tp / i •);.! i n •! e r s II-! I'.ilij- (>| |"|ptl
pop ace / 1 e s t oi o A
add / .!• i d { t ' . h • • I '•'•!!! I • • .,' I i'I.-1 i > •! ;
cinl e n d : t oi ; : e l i , i 11
cin' rest art :
pop / l C S F o r e A

s jir.p I! o / jlllllj • l o i . e g ! |i i 11'.!

einl__notp<):
P'--P / I " S i e l ' - A

/ U n r e c o g n i z e d e s c a p e ? . . . oat. up e v e r y t h i n g t h a t ' s loll, c o m i n g in q u i c k l y , ! hen


/ b e g i n l o o k i no •igai n .
cinf consume:
aca! 1 e t u i wait. /wait t o r s o m e iiv..motn
jnb r i , e.i u _ f i . l f o r /jump t o b e g i n i no ii i i no; el ;

lcall cin / i n p u t from s e r i a l port,


cjne a, Heso c h a r , cinf_consuiiie / loot., l i e r e i ! n o t l ! i b i l i a r a c ' e i
sjmp cinf?. /if. i t i s lump ba.-k
/ T h i s t h i n g w a i t s for a c h a r a c t e r t o bo r e c e i v e d for a p p t o x A c h a r a c t e r transmit
/time periods, i t r e t u r n s i m m e d a t e l y or aft.ei ( h e >~nf. i i e w a i t time. I t d o e s not
/remove the character from t h e b u f f e r , s o ri s h o u l d b e c h e e k e d t o s e e i f somel.h i no
/ a c t u a l l y d i d show up w h i l e i t was w a i t i n g .
.equ ohat:_de)ay, •! /Ilo. s-l eh.t; rmi t I lilies w.-i i ! i n g
cinf_wait:
mov a, r2 move r2 t o A t o s a v " if
push ace s a v e i ? vaI no
mov 1.-2, l l c h a r d ' - l a y ' l o a d 1 2 w i l l . !i t i m e s e h o i delay-
c i n f w 2 : inov a, this l o a d A w i t h t i m e i (l h i q h b y t e
cinfw3: jb ri, cinfwl jump if i " C " i V " i n l or t tip! i s s o !
inc a i ticromen I A
jnz • : I N f H,' j uinp i '•' A i s n o t ::• -r. •
djnz r?, cinfw? d e c ! o m e n ! I ? jump i f it is ik- 1
p r i n t s i. a. • e ' . m p i e s s e , i s i I i l i ' I S . A d i d i o n a i y o | \ v;o:ds i s
; p e s t :t
; p a c k »<1 b i n i i y i o i n.a: . Wlisn p o s l i l i n o, s a h y f " i I i . 1 i n o w i '• >.: 1 i i ' •
; i. V. p r i n t s i h e v i . l . i ! i .Mil 1 h e 1 i ei - : " i i ' i r y . A 1 (••! b y l o s i i a v s p e c i a I I.
;every! iiing e l s;••> p r i nl s . i s i ! i 1 W P I o a n o r . 1 i n.i i y I i i.. i' i.
; S p e e i a .1. . . K i e s
0 •••• EtJI. i)i .•J'i'iUNo
1 .< --' e-R/f..!''
14 = (JR/I.K >, Kill' oi- STi-.III.:
31 NEXT ; : A i ' I T A I , ( n e x t word c o d e siioiil i I h< c a p i 1 a I i :•'.• " ••}

pcs'tr: push nee ;save i. e 1 i s I. o 1


niov a, rO ;move iu 1 . , l,o •• , a .••• i
push a oo ; s . f o i " .a

inov a, i. !. ; in. ' V o • 1 t o b e tl o . e - 1


push ace /.'.-tore 1
mov a, i:4 ;::iove i 4 1, o b e s ! o r o d
push a eo ; s | o j . o r •i
setb psw. i ;sol u s "i d e f itj-'d : l.vi ;
!• a - . b
sel h psw.!. u s e i d"l i n e d t l.iu • ,p: i
pcstrl: el r a ;• i . o a . l A l o i Iu-xi ilis! ••!:.: 1 i o n
1,1. ' V ( • a. Paldpt( ; I o.i' 1 w l i . i l a ! a d . it .
i in: dptt ;i ncrement
p O S 1 !."/ ; •'lump i !: . - e i o ( K M P i . f !•: i ;:<•,)
)y- a c c . 7, deer-nip ; i u m p i 1 h i 1 .' s e |
lb
an 1 a, IfOx.'P / m a s k h i !• •'
p e s I r s i :ojn- a, !!1 •, p.-SfJ ; j urn; • i 1
i e a 1,! :i'--w i i n o / d i s p l a y l . o ' . ' ' '• •!.e

sol b p s w . i ; s . ' ' i ' M ' i i no . 1. i , !• -1 - a ' ! a.|

sjmp pes!i1 ; , ;
u:np h a - • i.
p o . s t r s ? : e;in.- a. M l , post 1 s < ; jump i1 t:ol anil .•:• •(>•. a e , a ;|
• i,l t psw..'. Ji'l'VII c. i p i 1 i o!i;i I .'.el e • I :.. |
simp pest 1 1 ; > inn! -
! >a-:!:
: e j n o 1, 1) 1 4 , ( . C S t I S'l ; jump iI !.•.' ei: i ! ! -••it o - | . . ••!,;.•
p e s t >:•• i
b-.i 1 1 now l i t : " /lisp! ,y n < ! : i i "

s j mi" post.:?. ; '..imp ' ' ••nd


p e s t rs-l
< : l i: p s w . i ; . • i • •, n i- • a . ! i n o • 'In t a - •'.•• - ' i .'i-i
1 I •oil! :-r>r-\ ! iv• - h a i .!• •! . I
s imp posl, i ; iump • o ! on i n' ii'!
pest../I: pe-b ; i ol I i " V •• A
mnv r -1, ,-i ; . e « l o r e J •'!
p o p • >::• • ;rotri"ve A
mov • if ; r e s t «'l e I !
; • . - f r i !•••.> A
P'P •MS-
mov i. 0 , a ; r e s ! o r e 1 >!

pop- acc ; !.'•• t J . i e v --.- A


ret ; i otui.li

; d c o m p a c t u a l l y t a k e s c a r e o i p r i n t i n g a w o r d l i o n , s h e d i c t i o n a r y at d p i , ) p o s i t
/.in p a c k e d w o r d s t a b l e . T h i s f u n c t i o n s c a n s t h e d i c t i o n a r y s e q u e n t i a l l y t i l ! it
/reaches the particular word number. Then i t r e a d s t h e n i b b l e s c o d e d in t h e
/ d i c t i o n a r y l o c a t i o n a n d t r a n s l a t e . " them u s i n g some l a b ! e s . Then liie translated
; c o d e i s p r i n t e d o u t . T h e n i b b l e s a r e m a n a g e d b y i 4 . i. 4 e i ( n o . - d n i b b l e i s •......
;r 4=255 i f next n i b b l e is high. It u s e ; <|el no;-:l n i b b l e I u n c i i o n t o id >i-..-.
/dictionary.

129
dee.'mp: an ! :, S'i-.7K
inov .-(), ••
p s w . i , • lo. :• .iu[ ..I
J!' ; pimi • i i o t i ; . . ,.; J i, t s i . • •• I F M i s ! d
leal I sp,...:.-
/dispb.,y spec
decbmpl:cir p.-:;/. 1.
/ciei! ll-.-.i !>..! i o a . i i t i - ; • -ha r A T S o .
push • dpi
/ s t o r e dpd
P U S H dpli
/ S T " ! e dph
M O V dpci, llwo.ds
/ l o a d dpt t w i t h w o l d s -idol .
mov vA, !!<• / i n i i a l i z e n i b b l e s p e c i I i.er w i t . h
1
an
mov a, T > :

/ b o d wot • i fl->. i n t o A
l r. doomr?
/ 11nut • i I W ' u d Mo . i s ::o , .
/ H e r o w>. mu.'.:!. s e e k p a s 1 o i l !.
'. i - I s . it. the ;.tl.|.. that •.••i|i. • i e l . i . ; h" • ir-
; s u p p o s e d i o f i in!..
mo>' I ! , o / I O.|. i . I w ill! w- ! • I '/' .
dcomp2: act if •!•>•: e t tiibbi
M X ; juiiij • • i. • :• • I [•-.•::i n I i>i i •.
.in 7 • (<-. (ii.i •', / I. >. .p i ! i • lei. t ! ! ! " l I S t|- a -a i i'i' W a •! . n.

/ W h e n we g e l : He t o , a wov.t ha-
; to I;he oor.re.- t o n e .

din? il, .-tcon-ix: •i B. O ( ;;(,! I ! W M I Mo. I S

/Mow W O ' C O po i ] no to • !,.:• .:•• * t - • Il I Ve • • I" * • . • p I I I] 1


IT OIL I

dcomp3:
a c a 1 1 . .;oi , , c x ! u.i b i d
jz d<-omp o n d / i umi • i f i d.-n I i I i •• i i:
cjne a, ! ! ! ' • , dco.up.i

/The citara.;l i s KITE ! :


o. • i.o
•.•• i s I • • .I;L'.-IO:I I \ •e i ! •• I s .

• n:.i i
:
: / i c i a p i •:> -let. t , . n i b b l e Ias r specifier; l

J m :
/ i i s o oitiont t h e i d . - n i i f j o t point t o s l w o i . - l ..i
move a, a.'.'pc ; i i v i . l . :ha i a c t ... i f i . >m I lit: •!•-.•'.!. t a b l e
r
S j RIP dcomp. . / 'pimp
. db " h rw-.iyb/:v!;g i z "

/The c h a r a c t <• i is one o 1. i H E

d c o m p i:
i nc .; :ii,-|'(1!l"li! I h o b i e t ! I. i i i • a i t . p.-.. i i : ' •:a: act •

move a, s , I p e r o a d oha l a c t or fi..m f h " ir-vi tai.b


s jmp deomp.'-. iimio
. d!. " e ! .i i. tt i s o 1 uiitp. 1

/Decide .if .id should he tippet t

dcompS:
mov c P . - W . r Hi. i v e • '.ij.. i I ,11 !"l l(.| I bio !.<. ''

mov ac.-.b, c m o v e . - a p i a l f l a g t •.. A c c . . 5 ( m a k e s m a l l oi. o a p r . a i !


set b psw..'. sol. eip.ila.l f l a g tsmall I e f i e >. s f o > next.;
cjne t O , # 2 0 , ..Icomp j u m p i f woi d N o . i s not: 2 0 ( 2 0 i s s p e c i a l , w o r d !
clr ace.!. c l e a i A c e . ! , ( m a k e let-1 o r capital)
dcompS: cjne r O , 1112, d o o m p ' j u m p i.i w o r d N o . i s n o ! . 1 2 ( 1 2 . i s s p e c i a l w o s d )
clr ace.. 5 c l e a r A. -c.. S (in i k e I et-1 <\r t v . p i t a I.)
:

dcomp7: lealI co-.\t ci t s p i i y i •)>• i r : C t . • • !


sjmp dcoinp3 / jump b a c k
dcomp e n d :
P O P dph / r e s t o r e dpi-,
pop dpi / r e s t o i o dp!
ajmp pcst.r 1 /jump l a c k to calling (miction

130
;.|r.i n j b! . i ' •liurnol s p o . - i I i. •i ui> l-i t e dpi i -ih.i sw i r e
; n i b b l e spe.-; I ••.

ae!. next u i b i '•<•


elr ;c!e,c A
raovc •:•, H-l i d p i ! ;<V\ S p e c i l i.ey f. .
cine ! \, " u , on:...' ; jump ; i ;i i 1.1. i • • I .-• •' or • •l-l-i
IliOV r4, ilXV, ;swi i rh n i b b l e . •. |-T
-ill I HOOOOi I J il> ,-ni-isk ..in iii.ili uibbb-
rel. ; t o ! i n n A a s i > i.•••i! : i i • • 1

gmi2: inov r-'i, Ip.i ;swi.l-c!i n i l . l . l e !,. po


.i n c dpi i ; i i i e r o n i o i i ! d p i i I .. i" • ••-.! I • -
swap .l ; ...::c!i i i h | O 1; i t ; t • . M i d : • - w i . • i -i -
an! a, ii 0 0 0 0 1 mi, /mask out hiijli n i b b l e
ret. ; ; e l il; li a s i d< i:' i ! i o i

; Hot • I -.11." I • I da! ! s b l . in. I :C I : n !:


;
;Th.is i s t:he I.i o r i ( i n n i o f 128 w..nl:i used by p'-sl
words:
OxH.2, Ox 0 0 , OxSH, 0x2 0>:h6, '••;-s:r;, -'rsio,
db Ox-M , OxP.i, OxBO, OxBI , II.V.1H, Ox'.i- , n.xr'i!, Ox 1 :
dr. 0x7F, OxAO, Ox 1 ;">, 0 x 7 F , OX I'.', o;-; ''••-.! d , li;.; ;-s
db Ox-'-A, 0x50, Oxfoi , 0x0 i, Ox!'-!- , O.xBA, OxOC, Ox F
.lb Ox'36, 0x01 , i'.xiib, (»x '.F, Or." '.,
•• • >•;•;, 1
0x01 •, o -;. •-•
:

db 0x5F, Oxl 2 , 0x07, 0 x 7 1 , Os/'K, o x ' . n , •x,' ••!:•:•!'

db 0x31?, 0x62, 0x!.8, 0 x 2 0 , Ox 1 I- , Ox Ox Ox t:


db 0x24, 0x40, i!xB!l, 0 x 4 o , OxFi , e x ' . 1 , , •':;-:•.; '

db 0x34, OxOB, OxCA, 0x«9, 0 x 0 3 , f :•.'.•>!, 0;<A1, flvUI'l


db 0x58, 0x80, 0x04, Oxl-!i. 0 x 0 2 , OxS.5, ox.60, 0x2^
db Ox'U, OxFO, 0x«2, 0x73, Ox 1 F, Ox i 0 , 0x7 F , 0x1/
db 0x54, 0x93, 0x10, 0x44, 0 x 4 H, 0 x 0 7 , Ox 01 , 0x2'.
db 0x56, 0 x 4 F, OxbO, OxKO, Oxl. 1, 0x72, OxKO, Ox. -:!:1

db • 0x3B, 0xO5, OxFO, Ox.l Ox i f , Ox 5 6 , 0x30, Ox.'-F


db 0x4 8, 0x02, 0x5K, OxAii, Ox;- 0 , 0x1 F, 0x01 , Ox 7 0
db 0x30, 0x05, Oy.60, Ox,-'., 0x4 i , o x A 1, • : ••• Ox..""
db 0x05, 0 x 6 F, 0x01 , 0x3F, 0x2 h, O x l 1- , o x <o, I'X.O •'
db OxHK, Ox l b , 0.x F O , Ox'. >., OxFO, -'X-l / , axis'
db 0x20, Ox.l F, 0x2 \, Ox < o , 0xo3, 0 x 7 A, 0x0 i , tiyl.ii
db 0x2f , OxFO, Oxl-'n, 0x0'., Oxe'F, Ox" , :
Oxl A, (IX'iO
db l!x''!l, O.-I'O, o.xic , Oy.u ! , '•.•-•A , ;
•ixOO, OX o
db Ox I F , Ox!) 1 , 0:<4O, 0 x 2 '., 0.-.0 ! , Ox '• , OxO'-, •sx.i •;
db OxO | , 0 x 7 A , 0 x 0 1 . Ox I 7 , •Or.'- I, 0 I, OX '•!), 11::;'/.
db 0xO8, O x B C , 0 x 2 4 , Ox u , , '•'•.•:•'•>, ey.BO, O x F '•, O x i ••
db 0x60, 0x25, 0x4 ! , o.-.r., 'ISl''l, •2---.sK, OX'Xb, Ox I •>
db S v i 2, ;>x.u;, OxO: , Ox 1 F . - i s - i , exlb, iixO l , 0;: i .1
db Ox-lb , 0 x 7 6, 0x12, Ox 0-1, OxAU, 0:<27, Ov'H), Ox'-..
db Oxl.i 1 , 0 x 2 if, 0xA8, Oxt' -, OxFO,
1
OxAA, 0x26, 0x20
db Ox :")!•', Oxl 0 , OxFO, 0xF3, 0x61 , Oxi- F., Oxo i , 0x4 1
db 0 x 7 3, 0x0 I , 0x27, OxCi, 0x00, 0x84, Ox'U: , Ox.is.
db O x o 1 , U>;07, 0x70, o.".!.'., o.x-; !!••;! '1 ( u x 7 0. o x ! I'
db 0xA8, 0x09, OxOO, ox/.;, Oxo,!, 0X1 7 , o x 4 ,-t, Oxi- K
db 0x01 , OxCl, 0x84, oxor-, 0x15, 0>;7 F , 0x02, 0X.8B.
db . Ox ! 4 , 0 x 3 0 , 0 x 8 F, 0 x 6 !, Ox V I , OXi.fc , Ox p i , OxF.'
db Oxl 1 , 0 x 0 9 , Oy.1 0 , 0x60, 0x02, 0x3F, Or.o 1 , 0 x 0 ' .
db Ox 7A, ox4 J , Ox DO, Ox OA, OxOC, Ox i b . i i •.; 2. •':•, o x ' - . -
db 0x07, 0xF2, O x l 1 , O x i 7, 0X2 0, 0x4 I , O x b B , Ox '•'•
db 0x09, 0xF7, 0x75, 0x1 3, OxOB, O.xA.', 0xl'<2, 0x4 u
db 0x02, ox.'.F, 0x64, 0x12, ilxAO, OxOO, o x ; : •>, •i.xF. :
db 0x9F, OxCO, 0x14, 0x77, Ox/0, Oxl i , 0 x 4 0, 0x7' I

131
db 0 x 2 1, OxC-.u, 0x68, 0x25, 0x4 | , OxKO , 0x6?,
db oxb'. Oxno, 0x21, Oxb1, 0x6.!, OX.'H; , 0:;!<O,
db • le-.O'., Oxl, , 0x73, 0x30, ...... *, Oxi'd , t i x i . K ,
db 0x110, Oxl., 0x43, OxKO, 0x5;.-, O x . ' F , OxKO,
db 0x14, OxDO, 0x23, 0x03, Ox KB, 0 x 3 ! , OxK5,
db 0x30, 0x99, OxKo, 0x03, 0x3F, 0::i,/t , '....•.•- ,
db 0x60, 0x23, 0x4.1, 0 x 2 K, 0xF3, 0x0 1 , 0x56,
db 0x93, 0x09, OxFE, 0x11, Ox. K, Ox ? <>, OxISA,
db 0x75, 0x42, OxEA, 0x62, 0x5!5, Ox AO , OxK5,
db 0x5.3, Ox-11:', OxHI, OxCO, 0xA3, OxO'l . u.-'4 2 .
db OxI-'V, 0x12, iixt)4, Oxt-2, f x ! H, o x . 3 0 , o x K'',,
db 0x1.7, 0x65, (5:00, Ox!'., Ox 1 5 , Ox - 0 , Oy/H?, Ox.?!.'
db Ox?,, 0x14, Ox4K, Ox ! 1
, e x ' •(!, O x (el , l exOO
; S'F'R
l o g o n 1: d b "Wo loom.;-" , 1 ?>!, l 4 « , ".! v ? • , b y ' , < ! ,
!

l o g o n 2 : db 5 1 t • ' O O , 1 4 > t , " 2 . I H . c , " , M » , ' ? . K'.i ••" , 1 '••!


db I 4 y , " ? .tin!?", ! MI), ? 1 3 , ! 1 l, " . " , !
abort : db •' " , ' 1 , 1 '"•«, i i , 1 CO, " ! " , 1
prompt I : db 1 4 H , " 2 I,--.:: ", o
prompt 2 : db " •", ICO ;mns! !• ! b - : a t o . oiompl:
prompts : db 1 3 4 , 2 0 2 , ! <(
prompt4 : db " ) , " , ! 4<3, ! 4 0 , l ? H , ? 0 0 , " , ii
prompt 5 : db . 31 , ! 5 i , . 1 3 0 , .1 0 5 , 1 ">., i 6 0 , 1 > i i ti i it
db i i d , , " JUMP" , 1 2 « , 1 3 4 , 1 i d . . . . . , 0 , 1 3 , ! 1
prompt 6 : db 1 3 , i 3 , 3 1 , 1 35 , 1 3 1 , 1 2 ' b " ; " , 0 , ' ft.
prompt"/ : db 31 , ? ? ? ! , ? f , 1, " h e y : ",()
prompt!' : db .1 3 , 1 3 , 3 1 , 1 3 6 , ! 2 » , 1. 11 , i ? ii

p r o m p t s : db 1 ' • , ! . < , 3 i , M (!, -:i,:"" '., e


pron.pt."-lb: d b ii , 1 2 . , 5 2 , 5:, -i,,ei, 1 I ; inn
p r o m p t 1 0 : db ") " , . U , 1 3 - , » , > 7 - ' , " : "
C

beg s t r : db "First",3!, i2'b": ",0


end s t r : db "Last. ", 3 1 , 1 2 0 , ": " , 3 2 / tl
sure: db 31 , 1 P 5 , I f . ! , " s u r e ?",("•
edi t s l : db 1 3 , 1 3 , H , 15'-, 1 5 4 , b i n , ", " , ! 4 0 , 1 2 0 , . ' n o , l i
e d i t s ? : db " • • , 3 3 , 1 3 6 , l.'3 b " , " , ! 4 ? , ! ? ' , , : • • ! / , 1 ! 1
d n l d s i : db 1 3 , 1 3 , 3 1 , 15 '"«, " a s . - i i ! « , ! 5<i,
db " , " , ! 4 - * , .! 4 0, i l o o , l •;, ! 4
d n b l s ? : db ! 3 , 3 1 , 1 3><, 1 6 0 , " e d " , ! :, I 4
;

d n l d s 3 : db 1 3 , 3 ! , 1 3 8 , 1 5 3 , " d " , 1 3 , 14
d n l d s 4 : db " S u m m e r y : " , 1.4
d n l d s 5 : db " " , 1 0 8 , " s ", 1 4 5 , " d " , 1 4
d n l d s 6 a : db " " , ! 3 9 , 1 4 5, " d " , 1 4
d n l d s C b : db " " , I3<>, " w r i t t e n " , 1 4
dnlds'7: db ' 3 1 , 1 ! . ! - , " : " , 14
d n l d s 8 : db " ",139," e n a b l e " , . ! . ? - ! , " i n i t •>"
d n l d s 9 : db 3 2 , 3 2 , " b a d " , 2 4 5 , " s " , )4
d n l d s 1 0 : db " " , 1 1 3 , 1 5 0 , 1 5 0 , 1 5 0 , 14
d n l d s l l : db " " , i 3 3 , 1 3 2 , 1 5 7 , 14
d n l d s 1 2 : db " " , I 3 3 , " n o n " , I 3 2 , 1 5 / , i •!
d n l d s 1 3 : db 3 . 1 , 1:> 1 , 1 5 5 , " d e f e c t e d " , 1 3 , 14
runslr db . 1 3 , 1 3 4 , " n i n g " , 1.30, " : " , 1 1 4
tiplds 3: db 1 3 , ! 3 , " . ' - e n d i n g " , 31 , 1 . 5 / , ! 3 ? , ! 3 7 , 1 7 2 , 3 2 , 3 2 , i
lipids 4: db " ",12ft,32,32,0 IIIUS! i -1. l e i - up b i s
h e l p ! t.xt: db . 1 3 , 1 3 , " S t a n • l a r d " , . 3 1 , 1 5 0 " s " , i1 t<i
help2txt: db 3 1 , 2 1 . 3 , 3 1 , 2 4 4 , "eci",.*•! , 1 .•O• , •" . " , 1 4 S

typel: db 31,154,1.53, 0
type2: db 31,130,0
type4: db 3.1, 1 4 3 , 3 1 , 2 2 6 , 3 1 , 1 7 0 , 0
type5: db "???",0
help__cmd2: db 31,215,0
help_cmd: db 31, 1.42,21.5,209,0 1 h o s e 11 <. ii'd s t . i .

132
dn.ld
Up I d
siloe
jump cmd: . db *'! 136, 128, 1 J I , 1 2 " , 0
dump cmd : .db 3 1 ! 3 2 , 2 1 9 , 1 5 4 , 131 , o
i n t i r . cmd : .db 31 132, 2 1 9 , 1 9 2 , 1 3 1 , 0
e d i t cmd: . db u i ;•>(>, 1 5 4 , 1 4 6 , 0
clrra_ cir.d: .db .'•] :.',3'/, .131,0
e r f r_ c m d : .do .>•} 20 5 , 1 5 3 , 1 4 4 , 0
e r f r_ "ok: . db 3.1 i 5 3 , 144,203, '•!•, 13,
e r f r e r r: .db u 1 3 3 , 155, 13,1 4

You might also like