Programming Steps
Programming Steps
Though the CPU can work only in binary, it can do this at a very high speed. For humans, however, it is quite
tedious and slow to deal with 0s and 1s in order to program the computer.
A program that consists of 0s and 1s is called machine language. In the early days of the computer, programmers
used to code programs in machine language. Although the hexadecimal system was used as a more efficient way to
represent binary numbers, the process of working in machine code was still cumbersome for humans. Eventually,
Assembly languages were developed that provided mnemonics for the machine code instructions, plus other
features that made programming faster and less prone to error.
The term mnemonic is frequently used in computer science and engineering literature to refer to codes and
abbreviations that are relatively easy to remember. Assembly language programs must be translated into machine
code by a program called an assembler. Assembly language is referred to as a low-level language because it deals
directly with the internal structure of the CPU. To program in Assembly language, the programmer must know all
the registers of the CPU and the size of each, as well as other details. Today, one can use many different
programming languages, such as BASIC, Pascal, C, C++, Java, and numerous others. These languages are called
high-level languages because the programmer does not have to be concerned with the internal details of the CPU.
Whereas an assembler is used to translate an Assembly language program into machine code (sometimes also
called object code or opcode for operation code), high-level languages are translated into machine code by a
program called a compiler. For instance, to write a program in C, one must use a C compiler to translate the
program into machine language.
Structure of Assembly language
An Assembly language program consists of, among other things, a series of lines of Assembly language
instructions. An Assembly language instruction consists of a mnemonic, optionally followed by one or two
operands. The operands are the data items being manipulated, and the mnemonics are the commands to the CPU,
telling it what to do with those items.
Assembling And Running An 8051 Program
While instructions tell the CPU what to do, directives (also called pseudo-
instructions) give directions to the assembler.
1. First we use an editor to type a program. Many excellent editors or word
processors are available that can be used to create and/or edit the program. A
widely used editor is the MS-DOS EDIT program (or Notepad in Windows),
which comes with all Microsoft operating systems. The editor must be able to
produce an ASCII file. For many assemblers, the file names follow the usual
DOS conventions, but the source file has the extension “asm” or “src”. The
“asm” extension for the source file is used by an assembler in the next step.
2. The “asm” source file containing the program code created in step 1 is fed
to an 8051 assembler. The assembler converts the instructions into machine
code. The assembler will produce an object file and a list file. The extension
for the object file is “obj” while the extension for the list file is “lst”.
3. Assemblers require a third step called linking. The link program takes one
or more object files and produces an absolute object file with the extension
“abs”.
4. Next, the “abs” file is fed into a program called “OH” (object to hex
converter), which creates a file with extension “hex” that is ready to burn into
ROM. This program comes with all 8051 assemblers. Recent Windows-based
assemblers combine steps 2 through 4 into one step.
The “asm” file is also called the source file and for this reason some
assemblers require that this file have the “src” extension.
The lst (list) file, which is optional, is very useful to the programmer because it lists all the opcodes and addresses,
as well as errors that the assembler detected. Many assemblers assume that the list file is not wanted unless we
indicate that we want to produce it. This file can be accessed by an editor such as DOS EDIT and displayed on the
monitor or sent to the printer to produce a hard copy. The programmer uses the list file to find syntax errors. It is
only after fixing all the errors indicated in the lst file that the obj file is ready to be input to the linker program.
Serial Communications in 8051
When a microprocessor communicates with the outside world, it provides the data in byte-sized chunks. In some
cases, such as printers, the information is simply grabbed from the 8-bit data bus and presented to the 8-bit data bus
of the printer. This can work only if the cable is not too long, since long cables diminish and even distort signals.
Furthermore, an 8-bit data path is expensive. For these reasons, serial communication is used for transferring data
between two systems located at distances of hundreds of feet to millions of miles apart. In this method the data is
sent one bit at a time, in contrast to parallel communication, in which the data is sent a byte or more at a time.
For serial data communication to work, the byte of data must be converted to serial bits using a parallel-in-serial-
out shift register; then it can be transmitted over a single data line.
This also means that at the receiving end there must be a serial-in-parallel-out shift register to receive the serial data
and pack them into a byte. Of course, if data is to be transferred on the telephone line, it must be converted to 0s
and 1s from audio tones, which are sinusoidalshaped signals. This conversion is performed by a peripheral device
called a modem, which stands for “modulator/demodulator.”
The synchronous method transfers a block of data (characters) at a time, while the asynchronous method transfers
a single byte at a time. There are special IC chips made by many manufacturers for serial data communications.
These chips are commonly referred to as UART (universal asynchronous receiver-transmitter) and USART
(universal synchronous-asynchronous receiver-transmitter). The 8051 chip has a built-in UART.
In data transmission if the data can be transmitted and received, it is a duplex transmission.
In simplex transmissions, such as with printers, the computer only sends data. Duplex transmissions can be half or
full duplex.
If data is transmitted one way at a time, it is referred to as half duplex. If the data can go both ways at the same
time, it is full duplex.