Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
12 views

Cse-213 Microcontroller Programming Kopyası PDF

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

Cse-213 Microcontroller Programming Kopyası PDF

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

CSE-213 MICROCONTROLLER PROGRAMMING

-1-

Introduction
• Overview of Intel microprocessors.
• Discussion of history of computers.
• Function of the microprocessor.
• Terms and jargon (computerese).

HISTORICAL BACKGROUND
Events leading to development of the microprocessor.
80X86, Pentium, Pentium Pro, Pentium III, Pentium 4, and Core2
microprocessors.
While not essential to understand the microprocessor, furnishes:
interesting reading
historical perspective of fast-paced evolution

The Mechanical Age


Idea of computing system is not new.
Calculating with a machine dates to 500 BC.
Babylonians invented the abacus.
first mechanical calculator
strings of beads perform calculations
In 1642, mathematician Blaise Pascal invented a calculator constructed of
gears and wheels.
When moved one complete revolution, a second gear advances one
place.
same principle used in automobile odometer
Basis of all mechanical calculators.
PASCAL programming language is named in honor of Blaise Pascal.
In 1823, Charles Babbage (aided by Augusta Ada Byron) began to create
his Analytical Engine (programmable calculating machine)
Steam-powered mechanical computer
Generated navigational tables
Used punched cards
Stored 1000 20-digit decimal numbers
The Electrical Age
1800s, The advent of electric motor
1889, Herman Hollerith developed a machine that counted, sorted, and
collated data stored on punched cards
1941, Z3 calculating computer by Konrad Zuse
used in aircraft and missile design
1943, Alan Turing, Colossus
broke secret German military codes generated by ENIGMA
used vacuum tubes
not programmable
could not solve other problems (special-purpose computer)
1946, ENIAC, University of Pennsylvania
17,000 vacuum tubes, 500 miles of wires
weighted over 30 tons
100,000 operations per second
The first programmable machine
programmed by rewiring its circuits
1948, Development of the transistor
1958, Invention of the integrated circuit (IC)
1960s, Digital integrated circuits
1971, The first microprocessor by Intel (4004)

Programming Advancements
Once programmable machines developed, programs and programming
languages began to appear.
As early practice of rewiring circuits proved too cumbersome, computer
languages began to appear in order to control the computer.
The first, machine language, was constructed of ones and zeros using
binary codes.
stored in the computer memory system as groups of instructions
called a program
More efficient than rewiring a machine to program it.
still time-consuming to develop a program due to sheer number of
program codes required
Mathematician John von Neumann, first modern person to develop a
system to accept instructions and store them in memory.
Computers are often called von Neumann machines in his honor.
Recall that Babbage also had developed the concept long before
von Neumann.
More efficient than rewiring a machine to program it.
still time-consuming to develop a program due to sheer number of
program codes required
Mathematician John von Neumann, first modern person to develop a
system to accept instructions and store them in memory.
Computers are often called von Neumann machines in his honor.
Recall that Babbage also had developed the concept long before von
Neumann.
Assembly language was then used to simplify entering binary code.
Assembler allows programmer to use mnemonic codes…
such as ADD for addition
In place of a binary number.
such as 0100 0111
Assembly language an aid to programming.
Since early days of programming, additional languages have appeared.
FLOWMATIC-FORTRAN-ALGOL-COBOL-RPG
Some common modern programming languages are BASIC, PASCAL,
C/C++, C#, Java, and ADA.
BASIC and PASCAL languages both designed as teaching languages,
but escaped the classroom.
Scientific community uses primarily C/C++.
Recent survey of embedded system developers showed C was used by
60%.
30% used assembly language
remainder used BASIC and JAVA
These languages allow programmer almost complete control over the
programming environment and computer system.
especially C/C++
Assembly language still plays important role.
many video games written almost exclusively in assembly language
Assembly also interspersed with C/C++ to perform machine control
functions efficiently.
some newer parallel instructions found on Pentium and Core2
microprocessors only programmable in assembly language
Reminder
A bit is a binary digit with a value of one or zero
4-bit-wide memory location is often called a nibble
8-bit-wide memory location is called a byte
A word is a collection of 2 bytes (or 16 bits)
1 KB = 1024 Bytes = 2 10 Bytes(1 KB = 1024 bytes)
1 MB = 1024 KB = 2 20 Bytes
1 GB = 2 30 Bytes, 1 TB = 2 40 Bytes
B is used for byte and b is used for bit
8 Mbps = 8 Megabits per second (ADSL speed)

The Microprocessor Age


World’s first microprocessor the Intel 4004.
A 4-bit microprocessor-programmable controller on a chip.
Addressed 4096, 4-bit-wide memory locations.
The 4004 instruction set contained 45 instructions.
1971, Intel 4004 and 4040
4-bit microprocessors
addressed 4096 (4-bit) memory locations
45 instructions
most calculators and low-end applications such as microwave ovens
still use 4-bit microprocessors
1972, Intel 8008
8-bit microprocessor
addressed 16K memory locations
48 instructions
50,000 instructions per second
1973, Intel 8080 (compatible with TTL)
addressed 64K memory locations
500,000 instructions per second (2 μs per instr.)
1974, Motorola 6800
1974, The first personal computer
(MITS Altair 8800) -> BASIC interpreter by Gates&Allen
1977, Intel 8085 (last 8-bit μp by Intel)
769,230 instructions per second (1.3 μs per instr.)
internal clock generator and system controller
The Modern Microprocessors
1978, Intel 8086 and 8088
16-bit microprocessors
400 ns per instruction
2,5 million instructions per second
addressed 1M memory locations
multiply and divide instructions are added
over 20,000 instruction variations
such microprocessors are called CISC (complex instruction set
computers)
Alternative is RISC (reduced instruction set computers)
1983, Intel 80286
addressed 16M memory locations
increased clock speed (8 MHz)
some instructions took 250 ns. to be executed
1986, Intel 80386
32-bit microprocessor
addressed 4GB memory
1989, Intel 80486
same as 80386 but half of its instructions are executed in one clock
cycle instead of two
8 KB cache
1993, Intel Pentium (P5 or 80586)
Introductory versions operated with a clocking frequency 60 & 66
MHz, and a speed of 110 MIPs
Over-clocked versions operated on 120, 133, and 233 MHz clocking
frequencies
16 KB cache
Full-frame video displays at scan rates of 30 Hz or higher (which is
comparable to commercial television)

Next Processors
Pentium Pro
Pentium II
Pentium III
Pentium IV
Core2
Quad Core
64-bit microprocessors

Some Definitions
Integrated Circuit
a.k.a. IC, microcircuit, microchip, silicon chip, or chip
Integrated Circuit is a miniaturized electronic circuit
consisting mainly of semiconductor devices, as well as
passive components) that has been manufactured in the surface of a
thin substrate of semiconductor material.

Microprocessor
A microprocessor is a programmable digital electronic component
that incorporates the functions of a central processing unit (CPU) on
a single semiconducting integrated circuit (IC).
8-bit, 16-bit, 32-bit, and 64-bit microprocessor: refers to number of
bits manipulated in one operation. It requires external memory to
execute programs. It cannot directly interface to I/O devices,
peripheral chips are needed.
Microcomputer and Microcontroller
A microcomputer is a computer that uses a microprocessor as its
CPU.
A microcontroller (or MCU) is a computer-on-a-chip. It is a type of
microprocessor emphasizing self- sufficiency and cost-effectiveness,
in contrast to a general-purpose microprocessor (the kind used in a
PC).
The only difference between a microcontroller and a microprocessor
is that a microprocessor has three parts - ALU, Control Unit and
registers, while the microcontroller has additional elements like
ROM, RAM, peripherals (timer, I/O ports, etc).
THE MICROPROCESSOR-BASED PERSONAL COMPUTER SYSTEM
Computers have undergone many changes recently.
Machines that once filled large areas reduced to small desktop computer
systems because of the microprocessor.
Figure 1–6 shows block diagram of the personal computer.
Applies to any computer system, from early mainframe computers to the
latest systems.
Diagram composed of three blocks interconnected by buses.
a bus is the set of common connections that carry the same type of
information
The Memory and I/O System
Memory structure of all Intel-based personal computers similar.
Figure 1–7 illustrates memory map of a personal computer system.
This map applies to any IBM personal computer.
also any IBM-compatible clones in existence

Main memory system divided into three parts:


TPA (transient program area)
system area
XMS (extended memory system)
Type of microprocessor present determines whether an extended
memory system exists.
First 1M byte of memory often called the real or conventional memory
system.
Intel microprocessors designed to function in this area using real
mode operation
The TPA
The transient program area (TPA) holds
the DOS (disk operating system) operating
system; other programs that control the
computer system.
the TPA is a DOS concept and not
really applicable in Windows
also stores any currently active or inactive
DOS application programs
length of the TPA is 640K bytes
DOS memory map shows how areas of TPA
are used for system programs, data and drivers.
also shows a large area of memory
available for application programs
hexadecimal number to left of each
area represents the memory addresses that
begin and end each data area

The System Area


Smaller than the TPA; just as important.
The system area contains programs on read-
only (ROM) or flash memory, and areas of read/write
(RAM) memory for data storage.
Figure 1–9 shows the system area of a typical
personal computer system.
As with the map of the TPA, this map also includes
the hexadecimal memory addresses of the various
areas.
First area of system space contains video display
RAM and video control programs on ROM or
flash memory.
area starts at location A0000H and extends
to C7FFFH
size/amount of memory depends on type of
video display adapter attached
Windows Systems
Modern computers use a different memory map
with Windows than DOS memory maps.
The Windows memory map in Figure 1–10 has
two main areas; a TPA and system area.
The difference between it and the DOS
memory map are sizes and locations of these
areas.
TPA is first 2G bytes from locations
00000000H to 7FFFFFFFH.
Every Windows program can use up to
2G bytes of memory located at linear addresses
00000000H through 7FFFFFFFH.
System area is last 2G bytes from 80000000H
to FFFFFFFFH.
I/O Space
I/O devices allow the microprocessor to
communicate with the outside world.
I/O (input/output) space in a computer
system extends from I/O port 0000H
to port FFFFH.
I/O port address is similar to a
memory address
instead of memory, it addresses an
I/O device
Figure 1–11 shows the I/O map found in
many personal computer systems.
Access to most I/O devices should always
be made through Windows, DOS, or
BIOS function calls.
The map shown is provided as a guide to
illustrate the I/O space in the system.
The area below I/O location 0400H is
considered reserved for system devices
Area available for expansion extends from
I/O port 0400H through FFFFH.
Generally, 0000H - 00FFH addresses main
board components; 0100H - 03FFH handles
devices located on plug-in cards or also
on the main board.
The limitation of I/O addresses between
0000 and 03FFH comes from original standards specified by IBM for the
PC standard.
CSE-213 MICROCONTROLLER PROGRAMMING
-2-
Introduction
How data is stored in memory
Numeric data representations
Alphanumeric representations
The Microprocessor
Called the CPU (central processing unit).
The controlling element in a computer system.
Controls memory and I/O through connections called buses.
buses select an I/O or memory device, transfer data between I/O
devices or memory and the microprocessor, control I/O and memory
systems
Memory and I/O controlled via instructions stored in memory, executed
by the microprocessor.
Microprocessor performs three main tasks:
data transfer between itself and the memory or I/O systems
simple arithmetic and logic operations
program flow via simple decisions
Power of the microprocessor is capability to execute billions of millions of
instructions per second from a program or software (group of
instructions) stored in the memory system.
stored programs make the microprocessor and computer system very
powerful devices
Another powerful feature is the ability to make simple decisions based
upon numerical facts.
a microprocessor can decide if a number is zero, positive, and so
forth
These decisions allow the microprocessor to modify the program flow, so
programs appear to think through these simple decisions.

simple arithmetic and logic operations Decisions found in the 8086 through core2 microprocessors
Buses
A common group of wires that interconnect components in a computer
system.
Transfer address, data, & control information between microprocessor,
memory and I/O.
Three buses exist for this transfer of information: address, data, and
control.
Figure 1–12 shows how these buses interconnect various system
components.

The address bus requests a memory location from the memory or an I/O
location from the I/O devices.
if I/O is addressed, the address bus contains a 16-bit I/O address
from 0000H through FFFFH.
if memory is addressed, the bus contains a memory address, varying
in width by type of microprocessor (20-bits for 8086).
64-bit extensions to Pentium provide 40 address pins, allowing up to
byte of memory to be accessed.
The data bus transfers information between the microprocessor and it
memory and I/O address space.
Data transfers vary in size, from 8 bits wide to 64 bits wide in various
Intel microprocessors.
8088 has an 8-bit data bus that transfers 8 bits of data at a time
8086, 80286, 80386SL, 80386SX, and 80386EX transfer 16 bits of
data
80386DX, 80486SX, and 80486DX, 32 bits
Pentium through Core2 microprocessors transfer 64 bits of data
Control bus lines select and cause memory or I/O to perform a read or
write operation.
In most computer systems, there are four control bus connections:
MRDC (memory read control)
MWTC (memory write control)
IORC (I/O read control)
IOWC (I/O write control).
overbar indicates the control signal is active- low; (active when logic zero
appears on control line)
The microprocessor reads a memory location by sending the memory an
address through the address bus.
Next, it sends a memory read control signal to cause the memory to
read data.
Data read from memory are passed to themicroprocessor through the
data bus.
Whenever a memory write, I/O write, or I/O read occurs, the same
sequence ensues.
NUMBER SYSTEMS
Use of a microprocessor requires working knowledge of numbering
systems.
binary, decimal, and hexadecimal
This section provides a background for these numbering systems.
Conversions are described.
decimal and binary
decimal and hexadecimal
binary and hexadecimal
Digits
Before converting numbers between bases, digits of a number system
must be understood.
First digit in any numbering system is always zero.
A decimal (base 10) number is constructed with 10 digits: 0 through 9.
A base 8 (octal) number; 8 digits: 0 through 7.
A base 2 (binary) number; 2 digits: 0 and 1.
If the base exceeds 10, additional digits use letters of the alphabet,
beginning with an A.
a base 12 number contains 11 digits: 0 through 9, followed by A for
10 and B for 11
Note that a base 10 number does not contain a 10 digit.
a base 8 number does not contain an 8 digit
Common systems used with computers are decimal, binary, and
hexadecimal (base 16).
many years ago octal numbers were popular
Posiitional Notation
Once digits are understood, larger numbers are constructed using
positional notation.
position to the left of the units position is the tens position
left of tens is the hundreds position, and so forth
An example is decimal number 132.
this number has 1 hundred, 3 tens, and 2 units
Exponential powers of positions are critical for understanding numbers
in other systems.
Exponential value of each position:
the units position has a weight of 10 0 , or 1
tens position a weight of 10 1 , or 10
hundreds position has a weight of 10 2 , or 100
Position to the left of the radix (number base) point is always the units
position in system.
called a decimal point only in the decimal system
position to left of the binary point always 2 0 , or 1
position left of the octal point is 80 , or 1
Any number raised to its zero power is always one (1), or the units
position.
Position to the left of the units position always the number base raised
to the first power.
in a decimal system, this is 10 1 , or 10
binary system, it is 2 1 , or 2
11 decimal has a different value from 11 binary
11 decimal has different value from 11 binary.
decimal number composed of 1 ten, plus 1 unit; a value of 11 units
binary number 11 is composed of 1 two, plus 1 unit: a value of 3
decimal units
11 octal has a value of 9 decimal units
In the decimal system, positions right of the decimal point have negative
powers.
first digit to the right of the decimal point has a value of 10−1 , or
0.1.
In the binary system, the first digit to the right of the binary point has a
value of 2−1, or 0.5.
Principles applying to decimal numbers also generally apply to those in
any other system.
To convert a binary number to decimal, add weights of each digit to
form its decimal equivalent.
Convert to decimal Examples

Conversion to Decimal
To convert from any number base to decimal, determine the weights or
values of each position of the number.
Sum the weights to form the decimal equivalent.

Conversion from Decimal


Conversions from decimal to other number systems more difficult to
accomplish.
To convert the whole number portion of a number to decimal, divide by
1 radix.
To convert the fractional portion, multiply by the radix.
Whole Number Conversion from Decimal
To convert a decimal whole number to another number system, divide
by the radix and save remainders as significant digits of the result.
An algorithm for this conversion:
divide the decimal number by the radix (number base)
save the remainder (first remainder is the least significant digit)
repeat steps 1 and 2 until the quotient is zero
To convert 10 decimal to binary, divide it by 2.
the result is 5, with a remainder of 0
First remainder is units position of the result.
in this example, a 0
Next, divide the 5 by 2; result is 2, with a remainder of 1.
the 1 is the value of the twos (2 1 ) position
Continue division until the quotient is a zero.
The result is written as 1010 2 from the bottom to the top.
To convert 10 decimal to base 8, divide by 8.
a 10 decimal is a 12 octal.
For decimal to hexadecimal, divide by 16.
remainders will range in value from 0 through 15
any remainder of 10 through 15 is converted to letters A through F
for the hexadecimal number
decimal number 109 converts to a 6DH
Converting from a Decimal Fraction
Conversion is accomplished with multiplication by the radix.
Whole number portion of result is saved as a significant digit of the
result.
fractional remainder again multiplied by the radix
when the fraction remainder is zero, multiplication ends
Some numbers are never-ending (repetend).
a zero is never a remainder
Algorithm for conversion from a decimal fraction:
multiply the decimal fraction by the radix (number base).
save the whole number portion of the result (even if zero) as a digit;
first result is written immediately to the right of the radix point
repeat steps 1 and 2, using the fractional part of step 2 until the
fractional part of step 2 is zero
Same technique converts a decimal fraction into any number base.
Binary-Coded Hexadecimal
Binary-coded hexadecimal (BCH) is a hexadecimal number written each
digit is represented by a 4-bit binary number.
BCH code allows a binary version of a hexadecimal number to be written
in a form easily converted between BCH and hexadecimal.
Hexadecimal represented by converting digits to BCH code with a space
between each digit.

Complements
At times, data are stored in complement form to represent negative
numbers.
Two systems used to represent negative data:
radix
radix − 1 complement (earliest - 1’s complement)
COMPUTER DATA FORMATS
Successful programming requires a precise understanding of data
formats.
Commonly, data appear as ASCII, Unicode, BCD, signed and unsigned
integers, and floating-point numbers (real numbers).
Other forms are available but are not commonly found.

ASCII and Unicode Data


ASCII (American Standard Code for Information Interchange) data
represent alphanumeric characters in computer memory.
Standard ASCII code is a 7-bit code.
eighth and most significant bit used to hold parity
If used with a printer, most significant bits are 0 for alphanumeric
printing; 1 for graphics.

ASCII Codes

In PC, an extended ASCII character set is selected by placing 1 in the


leftmost bit.
Extended ASCII characters store:
some foreign letters and punctuation
Greek & mathematical characters
box-drawing & other special characters
ASCII control characters perform control functions in a computer system.
clear screen, backspace, line feed, etc.
Enter control codes through the keyboard.
hold the Control key while typing a letter
Many Windows-based applications use the Unicode system to store
alphanumeric data.
stores each character as 16-bit data
Codes 0000H–00FFH are the same as standard ASCII code.
Remaining codes, 0100H–FFFFH, store all special characters from many
character sets.
Allows software for Windows to be used in many countries around the
world.
BCD (Binary-Coded Decimal) Data
The range of a BCD digit extends from 0000 2 to 10012 , or 0–9 decimal,
stored in two forms:
Stored in packed form:
packed BCD data stored as two digits per byte;
used for BCD addition and subtraction in the instruction set of the
microprocessor
Stored in unpacked form:
unpacked BCD data stored as one digit per byte
returned from a keypad or keyboard

Packed and Unpacked BCD


Applications requiring BCD data are point-of- sales terminals.
also devices that perform a minimal amount of simple arithmetic
If a system requires complex arithmetic, BCD data are seldom used.
there is no simple and efficient method of performing complex BCD
arithmetic
Byte-Sized Data
Stored as unsigned and signed integers.
Difference in these forms is the weight of the leftmost bit position.
value 128 for the unsigned integer
minus 128 for the signed integer
In signed integer format, the leftmost bit represents the sign bit of the
number.
also a weight of minus 128

Unsigned integers range 00H to FFH (0–255)


Signed integers from −128 to 0 to + 127.
Negative signed numbers represented in this way are stored in the two’s
complement form.
Evaluating a signed number by using weights of each bit position is
much easier than the act of two’s complementing a number to find its
value.
especially true in the world of calculators designed for programmers
(+/-) Conversion practice
Whenever a number is two’s complemented, its sign changes from
negative to positive or positive to negative.
For example, the number 0000 1000 is a +8. Its negative value (-8) is
found by two’s complementing the +8.
1. one’s complement the number
invert each bit of a number from zero to one or from one to zero.
2. add a one to the one’s complement.

(+/-) Simpler conversion practice


Another, and probably simpler, technique for two’s complementing a
number starts with the rightmost digit.
Start by writing down the number from right to left.
Write the number exactly as it appears until the first one.
Write down the first one,
and then invert all bits to its left.
Word-Sized Data
A word (16-bits) is formed with two bytes of data.
The least significant byte always stored in the lowest-numbered memory
location.
Most significant byte is stored in the highest.
This method of storing a number is called the little-endian format.

Alternate method is called the big-endia format.


Numbers are stored with the lowest locatio containing the most
significant data.
Not used with Intel microprocessors.
The big-endian format is used with the Motorola family of
microprocessors.
Doubleword-Sized Data

Real Numbers
Since many high-level languages use Intel microprocessors, real numbers
are often encountered.
A real, or a floating-point number contains two parts:
a mantissa, significand, or fraction
an exponent.
A 4-byte number is called single-precision.
The 8-byte form is called double-precision.

The assembler can be used to define real numbers in single- & double-
precision forms:
use the DD directive for single-precision 32-bit numbers
use define quadword(s), or DQ to define 64-bit double-precision real
numbers
Optional directives are REAL4, REAL8, and REAL10.
for defining single-, double-, and extended precision real numbers

You might also like