0% found this document useful (0 votes)
9 views

Programming Steps

The document discusses assembly language programming for the 8051 microcontroller. It explains that assembly language provides mnemonics for machine code instructions, making programming faster and less error-prone than binary machine code. An assembly language program consists of instructions with mnemonics and operands. The program must be assembled into machine code before running. The document also covers serial communication using the 8051's built-in UART, including configuring the serial port and timer for different baud rates. It provides examples of programming steps to transmit and receive data by polled and interrupt-driven methods.

Uploaded by

Anirban Mandal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Programming Steps

The document discusses assembly language programming for the 8051 microcontroller. It explains that assembly language provides mnemonics for machine code instructions, making programming faster and less error-prone than binary machine code. An assembly language program consists of instructions with mnemonics and operands. The program must be assembled into machine code before running. The document also covers serial communication using the 8051's built-in UART, including configuring the serial port and timer for different baud rates. It provides examples of programming steps to transmit and receive data by polled and interrupt-driven methods.

Uploaded by

Anirban Mandal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

8051 ASSEMBLY PROGRAMMING

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.

SM0 SM1 Serial Mode Explanation Baud Rate


0 0 0 8-bit shift Register Osc./12
0 1 1 8-bit UART Set by Timer-1*
1 0 2 9-bit UART Osc./64*
1 1 3 9-bit UART Set by Timer-1*
* Baud Rate is doubled if PCON.7 (SMOD) is set.

Reload value in Timer-1 (Timer Mode-2),

Baud Rate SMOD TH1


300 0 A0h
1200 0 D0h
2400 0 FAh
9600 0 FDh
19200 1 FDh
In Modes 2 and 3, if SM2=1, RI is activated when 9th bit received (RB8) is 1.
In Mode 1, if SM2=1, RI is activated when valid stop bit is received and if SM2=0, RI is activated when any
character is received. In Mode 3, SM2 has no rule.
Programming Steps in 8051:
1. Configure serial port mode-1 or 3.
2. Configure Timer-1 to Timer mode-2 (8-bit auto-reload).
3.Load TH1 for appropriate Baud Rate.
4. Set / Reset PCON.7 as required for Baud Rate.
5. For data transmission:
a) write byte to SFR SBUF. b) Check TI bit. If it is 1, transmission OK. clear it.
6. For data reception:
a) Check RI bit. If it is 1, reception OK- clear it. b) Read SBUF.
1. Write a program to transmit the character ‘A’ continuously using the 8051 serial port. Use 9-bit data at 9600
baud. Use polled operation.
2. Write a program to receive a character from serial port and save this character in R7. Use 9-bit data at 9600
baud. The parity bit can be ignored. Use polled operation.
3. Write a program to receive a character from serial port using interrupt driven method and save this character in
R7. Use 9-bit data at 9600 baud. The parity bit can be ignored.
4. Write a program to transmit the block of data stored in internal memory address 40h onwards continuously,
using serial port. Use 8-bit data at 2400 baud. Use polled operation.

You might also like