SlideShare a Scribd company logo
Introduction to Microcontroller
 Definition
 A microcontroller is a compact integrated circuit designed to govern a specific
operation in an embedded system. A typical microcontroller includes a
processor, memory and input/output (I/O) peripherals on a single chip.
 How Does it Works?
 Microcontrollers are used in a wide array of systems and devices. Devices often
utilize multiple microcontrollers that work together within the device to handle
their respective tasks.
 For Example
 a car might have many microcontrollers that control various individual systems
within, such as the anti-lock braking system, traction control, fuel injection or
suspension control. All the microcontrollers communicate with each other to
inform the correct actions.
Microcontrollers and Embedded
Processors
 General-purpose microprocessors
contains
 No RAM
 No ROM
 No I/O ports
 Microcontroller has
 CPU (microprocessor)
 RAM ROM
 I/O ports
 Timer
 ADC and other peripherals
Continue…
 General-purpose microprocessors
i. Must add RAM, ROM, I/O ports, and timers externally to make them functional
ii. Make the system bulkier and much more expensive
iii. Have the advantage of versatility on the amount of RAM, ROM, and I/O ports
 Microcontroller
i. The fixed amount of on-chip ROM, RAM, and number of I/O ports makes them ideal for many
applications in which cost and space are critical
ii. In many applications, the space it takes, the power it consumes, and the price per unit are
much more critical considerations than the computing power
Continue…
 There is only one application software that is typically burned into ROM
 It has RAM memory and an operating system that loads a variety of
applications into RAM and lets the CPU run them
 A PC contains or is connected to various embedded products
 Each one peripheral has a microcontroller inside it that performs only one task
Applications
 Home
Appliances, intercom, telephones, security
systems,
garage door openers, answering machines, fax
machines, home computers, TVs, cable TV
tuner,
 Office
Telephones, computers, security systems, fax
machines, microwave, copier, laser printer, color
printer, paging
 Auto
Trip computer, engine control, air bag, ABS,
instrumentation, security system, transmission
control
Continue…
 One of the most critical needs of an embedded system is to decrease power
consumption and space
 In high-performance embedded processors, the trend is to integrate more functions
on the CPU chip and let designer decide which features he/she wants to use
 In many cases using x86 PCs for the high-end embedded applications
 Saves money and shortens development time
 A vast library of software already written Windows is a widely used and well
understood platform
Inside the Computer
 Important Terminologies
 The unit of data size
 Bit : a binary digit that can have the value
0 or 1
 Byte : 8 bits
 Nibble : half of a bye, or 4 bits
 Word : two bytes, or 16 bits
 The terms used to describe amounts of
memory in IBM PCs and compatibles
 Kilobyte (K): 210 bytes
 Megabyte (M) : 220 bytes, over 1 million
 Gigabyte (G) : 230 bytes, over 1 billion
 Terabyte (T) : 240 bytes, over 1 trillion
Continue…
 Internal Organization of Computer
 CPU (Central Processing Unit)
 Execute information stored in memory
 I/O (Input/output) devices
Provide a means of communicating with
CPU
 Memory
 RAM (Random Access Memory) – temporary storage of programs that computer
is running
 The data is lost when computer is off ROM (Read Only Memory) – contains
programs and information essential to operation of the computer
 The information cannot be changed by use, and is not lost when power is off
 – It is called nonvolatile memory
Internal Organization of Computer
Continue…
Continue…
The CPU is connected to memory and
I/O through strips of wire called a bus
i. Carries information from place to place
ii. Address bus
iii. Data bus
iv. Control bus
Continue…
 Address bus
i. For a device (memory or I/O) to be recognized by the CPU, it must be assigned an address
ii. The address assigned to a given device must
be unique
iii. The CPU puts the address on the address bus,
and the decoding circuitry finds the device
 Data bus
i. The CPU either gets data from the device or sends data to it
 Control bus
i. Provides read or write signals to the device to indicate if the CPU is asking for information or
sending it information
More About the Data Bus
 The more data buses available, the
better the CPU
i. Think of data buses as highway lanes
 More data buses mean a more
expensive CPU and computer
i. The average size of data buses in CPUs varies between 8 and 64
 Data buses are bidirectional
i. To receive or send data
 The processing power of a computer is related to the size of its buses
Inside the
Computer
 CPU’S Relation to ROM & RAM
 For the CPU to process information,
the data must be stored in RAM or
ROM, which are referred to as primary
memory
 ROM provides information that is fixed
and permanent
i. Tables or initialization program
 RAM stores information that is not
permanent and can change with time
i. Various versions of OS and application
packages
ii. CPU gets information to be processed first
form RAM (or ROM)
iii. if it is not there, then seeks it from a
mass storage device, called secondary
memory, and
transfers the information to RAM
Continue…
 Registers
i. The CPU uses registers to store information temporarily
ii. Values to be processed
iii. Address of value to be fetched from memory
iv. In general, the more and bigger the registers, the better the CPU
v. Registers can be 8-, 16-, 32-, or 64-bit
vi. The disadvantage of more and bigger registers is the increased cost of such a CPU
Inside the CPU’S
 ALU (arithmetic/logic unit)
i. Performs arithmetic functions such as add, subtract, multiply, and divide, and logic
functions such as AND, OR, and NOT
 Program counter
i. Points to the address of the next instruction to be executed
ii. As each instruction is executed, the program counter is incremented to point to the
address of the next instruction to be executed
 Instruction decoder
i. Interprets the instruction fetched into the CPU
ii. A CPU capable of understanding more instructions requires more transistors to design
Choosing a
Microcontrollers
 8-bit microcontrollers
i. Motorola’s 6811
ii. Intel’s 8051
iii. Zilog’s Z8
iv. Microchip’s PIC
 There are also 16-bit and 32-bit
microcontrollers made by various
chip makers
Criteria for Choosing Microcontroller
 Meeting the computing needs of the task at hand efficiently and cost effectively
i. Speed
ii. Packaging
iii. Power consumption
iv. The amount of RAM and ROM on chip
v. The number of I/O pins and the timer on chip
 How easy to upgrade to higher performance or lower power-consumption versions
 Cost per unit
 The 8051 family has the largest number of diversified (multiple source) suppliers
i. Intel (original)
ii. Atmel
iii. Philips/Signetics
Overview of 8051 Family
 Intel introduced 8051, referred as MCS- 51, in 1981
i. The 8051 is an 8-bit processor
ii. The CPU can work on only 8 bits of data at a time
 The 8051 had
i. 128 bytes of RAM
ii. 4K bytes of on-chip ROM
iii. Two timers
iv. One serial port
v. Four I/O ports, each 8 bits wide
vi. 6 interrupt sources
Continue…
 Feature 8051 8052 8031
ROM (on-chip program 4K 8K 0K
space in bytes)
RAM (bytes) 128 256 128
Timers 2 3 2
I/O pins 32 32 32
Serial port 1 1 1
Interrupt sources 6 8 6
Inside the 8051
 Registers
 Register are used to store information
temporarily, while the information
could be
a byte of data to be processed, or
an address pointing to the data to be
fetched
 The vast majority of 8051 register are
8-bit registers
There is only one data type, 8 bits
 The 8 bits of a register are shown from
MSB D7 to the LSB D0
With an 8-bit data type, any data larger
than 8 bits must be broken into 8-bit
chunks before it is processed
Continue…
8051 Assembly Language Programming
Register are used to store
information temporarily, while
the information could be
a byte of data to be processed, or an
address pointing to the data to be
fetched
The vast majority of 8051
register are 8-bit registers
There is only one data type, 8 bits
The 8 bits of a register are
shown from MSB D7 to the LSB
D0
With an 8-bit data type, any data larger
than 8 bits must be broken into 8-bit
chunks before it is processed
MOV Instruction
The instruction tells the CPU to move
(in reality, COPY) the source operand
to the destination operand
Continue…
 If values 0 to F moved into an 8-bit register, the rest of
the bits are assumed all zeros
 “MOV A, #5”, the result will be A=05; i.e., A= 00000101
in binary
 Moving a value that is too large into a register will cause
an error
 MOV A, #7F2H ; ILLEGAL: 7F2H>8 bits (FFH)
ADD Instruction
 The ADD instruction tells the CPU
to add the source byte to register
A and put the result in register A
Assembling and Running an 8051
Program
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
i. Notice that the editor must be able to produce an ASCII file
ii. For many assemblers, the file names follow the usual DOS conventions, but the source file has the extension “asm“ or “src”,
depending on which assembly you are using
2. The “asm” source file containing the program code created in step 1 is fed to an 8051 assembler
i. The assembler converts the instructions into machine code
ii. The assembler will produce an object file and a list file
iii. The extension for the object file is “obj” while the extension for the list file is “lst”
Continue…
3. Assembler require a third step called linking
 The linker program takes one or more object code files and produce an absolute object file
with the extension “abs”
 This abs file is used by 8051 trainers that have a monitor program
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 step 2 through 4 into one step
Steps to Create a Program
8051 Data Types and
Directives
 Data Types
 8051 microcontroller has only one data type - 8 bits
 The size of each register is also 8 bits
 It is the job of the programmer to break down data larger
than 8 bits (00 to FFH,or 0 to 255 in decimal)
 The data types can be positive or negative
Continue…
 Assembler Directives
 The DB directive is the most
widely used data directive in the
assembler
 It is used to define the 8-bit data
 When DB is used to define data,
the numbers can be in decimal,
binary, hex, ASCII formats
Assembler Directives Continue…
 ORG (origin)
i. The ORG directive is used to indicate the beginning of the address
ii. The number that comes after ORG can be either in hex and decimal
iii. If the number is not followed by H, it is decimal and the assembler will convert it to hex
 END
i. This indicates to the assembler the end of the source (asm) file
ii. The END directive is the last line of an 8051 program
iii. Mean that in the code anything after the END directive is ignored by the assembler
Continue…
 EQU (equate)
i. This is used to define a constant without occupying a memory location
ii. The EQU directive does not set aside storage for a data item but associates a
constant value with a data label
iii. When the label appears in the program, its constant value will be substituted
for the label
iv. By the use of EQU, one can change it once and the assembler will change all
of its occurrences
Flag Bits and PSW Register
 PSW (Program status Word)
i. The program status word (PSW) register, also referred to as the flag register, is an 8 bit
register
ii. Only 6 bits are used
iii. These four are CY (carry), AC (auxiliary carry), P(parity), and OV (overflow)
– They are called conditional flags, meaning that they indicate some conditions that
resulted after an instruction was executed
iv. The PSW3 and PSW4 are designed as RS0 and RS1, and are used to change the bank
v. The two unused bits are user-definable
Continue…
Continue…
Flag Bits and PSW Register
 ADD INSTRUCTION AND PSW
 The flag bits affected by the ADD
instruction are CY, P, AC, and OV
Continue…

More Related Content

Similar to lecture 2 coal assembly language lecture (20)

PPT
Introduction to uP-Chadasdffpter I-3.ppt
YAGYABAHADURSHAHI
 
PPTX
Microcontroller overview 1
Sally Salem
 
PDF
Microprocessor note
alokbhatta
 
PPT
Cpu
abinarkt
 
PPTX
COMPUTER ORGANIZATION UNIT-III COMPLETE PPT
sowmyaglwec
 
PDF
Microprocessor System qwefqwgqwgqwgqwgqegew
ObbiHandira
 
PPT
I. Introduction to Microprocessor System.ppt
HAriesOa1
 
PPTX
Microcontrollers and its applications unit 1
DHIVYA S
 
PPT
8051 Microcontroller slides foe electronics
KiranG764628
 
PDF
Challenges in Embedded Computing
Pradeep Kumar TS
 
PPT
MKLecture01eng.ppt
ssuser7a33ea
 
PPTX
unit-2.pptx
KanchanThory
 
PPT
comp. org Chapter 1
Rajat Sharma
 
PPT
Microprocessor Based Systems.ppt
TALHARIAZ46
 
PPTX
Unit 2 - Microprocessor & Microcontroller.pptx
Charunnath S V
 
PPT
Lec 1 Intro to mp.ppt
USMANMALIK57656
 
PPTX
Embedded systems-for-beginners-electro8
Electro 8
 
PPT
Lec MC.ppt
nodov66591
 
PDF
U proc ovw
Brit4
 
Introduction to uP-Chadasdffpter I-3.ppt
YAGYABAHADURSHAHI
 
Microcontroller overview 1
Sally Salem
 
Microprocessor note
alokbhatta
 
COMPUTER ORGANIZATION UNIT-III COMPLETE PPT
sowmyaglwec
 
Microprocessor System qwefqwgqwgqwgqwgqegew
ObbiHandira
 
I. Introduction to Microprocessor System.ppt
HAriesOa1
 
Microcontrollers and its applications unit 1
DHIVYA S
 
8051 Microcontroller slides foe electronics
KiranG764628
 
Challenges in Embedded Computing
Pradeep Kumar TS
 
MKLecture01eng.ppt
ssuser7a33ea
 
unit-2.pptx
KanchanThory
 
comp. org Chapter 1
Rajat Sharma
 
Microprocessor Based Systems.ppt
TALHARIAZ46
 
Unit 2 - Microprocessor & Microcontroller.pptx
Charunnath S V
 
Lec 1 Intro to mp.ppt
USMANMALIK57656
 
Embedded systems-for-beginners-electro8
Electro 8
 
Lec MC.ppt
nodov66591
 
U proc ovw
Brit4
 

Recently uploaded (20)

PPTX
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
PPTX
Evaluation and thermal analysis of shell and tube heat exchanger as per requi...
shahveer210504
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
PPTX
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
PDF
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
PPTX
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
PPTX
Thermal runway and thermal stability.pptx
godow93766
 
PPTX
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
PPTX
Product Development & DevelopmentLecture02.pptx
zeeshanwazir2
 
PDF
Design Thinking basics for Engineers.pdf
CMR University
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
PPTX
Introduction to Design of Machine Elements
PradeepKumarS27
 
PDF
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PDF
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
PDF
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
PPTX
GitOps_Repo_Structure for begeinner(Scaffolindg)
DanialHabibi2
 
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
Evaluation and thermal analysis of shell and tube heat exchanger as per requi...
shahveer210504
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
Thermal runway and thermal stability.pptx
godow93766
 
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
Product Development & DevelopmentLecture02.pptx
zeeshanwazir2
 
Design Thinking basics for Engineers.pdf
CMR University
 
MRRS Strength and Durability of Concrete
CivilMythili
 
Introduction to Design of Machine Elements
PradeepKumarS27
 
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
GitOps_Repo_Structure for begeinner(Scaffolindg)
DanialHabibi2
 
Ad

lecture 2 coal assembly language lecture

  • 1. Introduction to Microcontroller  Definition  A microcontroller is a compact integrated circuit designed to govern a specific operation in an embedded system. A typical microcontroller includes a processor, memory and input/output (I/O) peripherals on a single chip.  How Does it Works?  Microcontrollers are used in a wide array of systems and devices. Devices often utilize multiple microcontrollers that work together within the device to handle their respective tasks.  For Example  a car might have many microcontrollers that control various individual systems within, such as the anti-lock braking system, traction control, fuel injection or suspension control. All the microcontrollers communicate with each other to inform the correct actions.
  • 2. Microcontrollers and Embedded Processors  General-purpose microprocessors contains  No RAM  No ROM  No I/O ports  Microcontroller has  CPU (microprocessor)  RAM ROM  I/O ports  Timer  ADC and other peripherals
  • 3. Continue…  General-purpose microprocessors i. Must add RAM, ROM, I/O ports, and timers externally to make them functional ii. Make the system bulkier and much more expensive iii. Have the advantage of versatility on the amount of RAM, ROM, and I/O ports  Microcontroller i. The fixed amount of on-chip ROM, RAM, and number of I/O ports makes them ideal for many applications in which cost and space are critical ii. In many applications, the space it takes, the power it consumes, and the price per unit are much more critical considerations than the computing power
  • 4. Continue…  There is only one application software that is typically burned into ROM  It has RAM memory and an operating system that loads a variety of applications into RAM and lets the CPU run them  A PC contains or is connected to various embedded products  Each one peripheral has a microcontroller inside it that performs only one task
  • 5. Applications  Home Appliances, intercom, telephones, security systems, garage door openers, answering machines, fax machines, home computers, TVs, cable TV tuner,  Office Telephones, computers, security systems, fax machines, microwave, copier, laser printer, color printer, paging  Auto Trip computer, engine control, air bag, ABS, instrumentation, security system, transmission control
  • 6. Continue…  One of the most critical needs of an embedded system is to decrease power consumption and space  In high-performance embedded processors, the trend is to integrate more functions on the CPU chip and let designer decide which features he/she wants to use  In many cases using x86 PCs for the high-end embedded applications  Saves money and shortens development time  A vast library of software already written Windows is a widely used and well understood platform
  • 7. Inside the Computer  Important Terminologies  The unit of data size  Bit : a binary digit that can have the value 0 or 1  Byte : 8 bits  Nibble : half of a bye, or 4 bits  Word : two bytes, or 16 bits  The terms used to describe amounts of memory in IBM PCs and compatibles  Kilobyte (K): 210 bytes  Megabyte (M) : 220 bytes, over 1 million  Gigabyte (G) : 230 bytes, over 1 billion  Terabyte (T) : 240 bytes, over 1 trillion
  • 8. Continue…  Internal Organization of Computer  CPU (Central Processing Unit)  Execute information stored in memory  I/O (Input/output) devices Provide a means of communicating with CPU  Memory  RAM (Random Access Memory) – temporary storage of programs that computer is running  The data is lost when computer is off ROM (Read Only Memory) – contains programs and information essential to operation of the computer  The information cannot be changed by use, and is not lost when power is off  – It is called nonvolatile memory
  • 9. Internal Organization of Computer Continue…
  • 10. Continue… The CPU is connected to memory and I/O through strips of wire called a bus i. Carries information from place to place ii. Address bus iii. Data bus iv. Control bus
  • 11. Continue…  Address bus i. For a device (memory or I/O) to be recognized by the CPU, it must be assigned an address ii. The address assigned to a given device must be unique iii. The CPU puts the address on the address bus, and the decoding circuitry finds the device  Data bus i. The CPU either gets data from the device or sends data to it  Control bus i. Provides read or write signals to the device to indicate if the CPU is asking for information or sending it information
  • 12. More About the Data Bus  The more data buses available, the better the CPU i. Think of data buses as highway lanes  More data buses mean a more expensive CPU and computer i. The average size of data buses in CPUs varies between 8 and 64  Data buses are bidirectional i. To receive or send data  The processing power of a computer is related to the size of its buses
  • 13. Inside the Computer  CPU’S Relation to ROM & RAM  For the CPU to process information, the data must be stored in RAM or ROM, which are referred to as primary memory  ROM provides information that is fixed and permanent i. Tables or initialization program  RAM stores information that is not permanent and can change with time i. Various versions of OS and application packages ii. CPU gets information to be processed first form RAM (or ROM) iii. if it is not there, then seeks it from a mass storage device, called secondary memory, and transfers the information to RAM
  • 14. Continue…  Registers i. The CPU uses registers to store information temporarily ii. Values to be processed iii. Address of value to be fetched from memory iv. In general, the more and bigger the registers, the better the CPU v. Registers can be 8-, 16-, 32-, or 64-bit vi. The disadvantage of more and bigger registers is the increased cost of such a CPU
  • 15. Inside the CPU’S  ALU (arithmetic/logic unit) i. Performs arithmetic functions such as add, subtract, multiply, and divide, and logic functions such as AND, OR, and NOT  Program counter i. Points to the address of the next instruction to be executed ii. As each instruction is executed, the program counter is incremented to point to the address of the next instruction to be executed  Instruction decoder i. Interprets the instruction fetched into the CPU ii. A CPU capable of understanding more instructions requires more transistors to design
  • 16. Choosing a Microcontrollers  8-bit microcontrollers i. Motorola’s 6811 ii. Intel’s 8051 iii. Zilog’s Z8 iv. Microchip’s PIC  There are also 16-bit and 32-bit microcontrollers made by various chip makers
  • 17. Criteria for Choosing Microcontroller  Meeting the computing needs of the task at hand efficiently and cost effectively i. Speed ii. Packaging iii. Power consumption iv. The amount of RAM and ROM on chip v. The number of I/O pins and the timer on chip  How easy to upgrade to higher performance or lower power-consumption versions  Cost per unit  The 8051 family has the largest number of diversified (multiple source) suppliers i. Intel (original) ii. Atmel iii. Philips/Signetics
  • 18. Overview of 8051 Family  Intel introduced 8051, referred as MCS- 51, in 1981 i. The 8051 is an 8-bit processor ii. The CPU can work on only 8 bits of data at a time  The 8051 had i. 128 bytes of RAM ii. 4K bytes of on-chip ROM iii. Two timers iv. One serial port v. Four I/O ports, each 8 bits wide vi. 6 interrupt sources
  • 19. Continue…  Feature 8051 8052 8031 ROM (on-chip program 4K 8K 0K space in bytes) RAM (bytes) 128 256 128 Timers 2 3 2 I/O pins 32 32 32 Serial port 1 1 1 Interrupt sources 6 8 6
  • 20. Inside the 8051  Registers  Register are used to store information temporarily, while the information could be a byte of data to be processed, or an address pointing to the data to be fetched  The vast majority of 8051 register are 8-bit registers There is only one data type, 8 bits  The 8 bits of a register are shown from MSB D7 to the LSB D0 With an 8-bit data type, any data larger than 8 bits must be broken into 8-bit chunks before it is processed
  • 22. 8051 Assembly Language Programming Register are used to store information temporarily, while the information could be a byte of data to be processed, or an address pointing to the data to be fetched The vast majority of 8051 register are 8-bit registers There is only one data type, 8 bits The 8 bits of a register are shown from MSB D7 to the LSB D0 With an 8-bit data type, any data larger than 8 bits must be broken into 8-bit chunks before it is processed
  • 23. MOV Instruction The instruction tells the CPU to move (in reality, COPY) the source operand to the destination operand
  • 24. Continue…  If values 0 to F moved into an 8-bit register, the rest of the bits are assumed all zeros  “MOV A, #5”, the result will be A=05; i.e., A= 00000101 in binary  Moving a value that is too large into a register will cause an error  MOV A, #7F2H ; ILLEGAL: 7F2H>8 bits (FFH)
  • 25. ADD Instruction  The ADD instruction tells the CPU to add the source byte to register A and put the result in register A
  • 26. Assembling and Running an 8051 Program 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 i. Notice that the editor must be able to produce an ASCII file ii. For many assemblers, the file names follow the usual DOS conventions, but the source file has the extension “asm“ or “src”, depending on which assembly you are using 2. The “asm” source file containing the program code created in step 1 is fed to an 8051 assembler i. The assembler converts the instructions into machine code ii. The assembler will produce an object file and a list file iii. The extension for the object file is “obj” while the extension for the list file is “lst”
  • 27. Continue… 3. Assembler require a third step called linking  The linker program takes one or more object code files and produce an absolute object file with the extension “abs”  This abs file is used by 8051 trainers that have a monitor program 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 step 2 through 4 into one step
  • 28. Steps to Create a Program
  • 29. 8051 Data Types and Directives  Data Types  8051 microcontroller has only one data type - 8 bits  The size of each register is also 8 bits  It is the job of the programmer to break down data larger than 8 bits (00 to FFH,or 0 to 255 in decimal)  The data types can be positive or negative
  • 30. Continue…  Assembler Directives  The DB directive is the most widely used data directive in the assembler  It is used to define the 8-bit data  When DB is used to define data, the numbers can be in decimal, binary, hex, ASCII formats
  • 31. Assembler Directives Continue…  ORG (origin) i. The ORG directive is used to indicate the beginning of the address ii. The number that comes after ORG can be either in hex and decimal iii. If the number is not followed by H, it is decimal and the assembler will convert it to hex  END i. This indicates to the assembler the end of the source (asm) file ii. The END directive is the last line of an 8051 program iii. Mean that in the code anything after the END directive is ignored by the assembler
  • 32. Continue…  EQU (equate) i. This is used to define a constant without occupying a memory location ii. The EQU directive does not set aside storage for a data item but associates a constant value with a data label iii. When the label appears in the program, its constant value will be substituted for the label iv. By the use of EQU, one can change it once and the assembler will change all of its occurrences
  • 33. Flag Bits and PSW Register  PSW (Program status Word) i. The program status word (PSW) register, also referred to as the flag register, is an 8 bit register ii. Only 6 bits are used iii. These four are CY (carry), AC (auxiliary carry), P(parity), and OV (overflow) – They are called conditional flags, meaning that they indicate some conditions that resulted after an instruction was executed iv. The PSW3 and PSW4 are designed as RS0 and RS1, and are used to change the bank v. The two unused bits are user-definable
  • 36. Flag Bits and PSW Register  ADD INSTRUCTION AND PSW  The flag bits affected by the ADD instruction are CY, P, AC, and OV

Editor's Notes

  • #2: Definition: A microcontroller is a small electronic chip that's like the brain of a specialized system. It's designed to handle specific tasks within that system. Components: Inside a microcontroller, there's a tiny processor (like the brain), memory (for storing information), and input/output peripherals (for connecting to other parts of the system). How it works: When a microcontroller is in action, it follows a set of instructions to perform its task. These instructions tell it what to do with the information it receives and how to send out responses. Example - Car: Let's take the example of a car. A car can have many microcontrollers inside, each responsible for managing different functions like brakes, fuel injection, or suspension. These microcontrollers talk to each other to coordinate their actions, making sure everything in the car works smoothly and safely. For instance, if the anti-lock braking system senses a wheel locking up, it communicates with other microcontrollers to adjust the braking pressure and keep the car under control. In simpler terms, microcontrollers are like small computer brains that handle specific tasks in devices like cars, making sure everything runs smoothly by talking to each other and coordinating their actions.
  • #4: Fixed resources: A microcontroller has a set amount of built-in memory (ROM and RAM) and a specific number of input/output ports (for connecting to other devices). These resources cannot be changed or upgraded. Cost and space considerations: Microcontrollers are great for situations where keeping costs low and saving space are really important. Because they have everything integrated into one chip, they're often more affordable and take up less room compared to using separate components. Power consumption: Microcontrollers are designed to use minimal power. This is important because in many devices, especially portable ones like smartphones or battery-operated gadgets, conserving battery life is crucial. Microcontrollers help keep power usage low. Price, space, and power over computing power: When choosing a microcontroller, factors like how much it costs, how much space it takes up, and how much power it uses are often more important than how powerful it is in terms of processing speed or capabilities. This means that even if a microcontroller isn't the fastest or most advanced, it can still be the best choice for certain applications because it meets these critical requirements effectively.
  • #5: Single application software: Microcontrollers typically have one set of software permanently stored in ROM. This software controls how the microcontroller operates. RAM and operating system: Microcontrollers have RAM for temporary data storage, and they can run different applications loaded into RAM by a small operating system. Embedded products in PCs: Many devices connected to or inside a computer, like peripherals, contain microcontrollers. Each microcontroller inside these devices is responsible for performing a single specific task. In simple terms, general-purpose microprocessors need extra parts to work, making them bigger and pricier. Microcontrollers, on the other hand, have everything they need built into one chip, making them ideal for space-saving and cost-effective solutions. They're often used in devices where space, power usage, and cost are more important than raw computing power. In simple terms, microcontrollers usually have one specific set of instructions stored in their memory that tells them how to do their job. This set of instructions is like a rulebook that the microcontroller follows all the time. It's stored in a part of the microcontroller called ROM, and it's always there, kind of like a computer program that's permanently built into the microcontroller. These instructions determine exactly what the microcontroller does and how it does it, governing its behavior and making it perform its intended function. For example, let's say we have a thermostat in a smart home system. The microcontroller inside the thermostat has its instructions (software) stored in ROM, telling it how to read the temperature, compare it to the desired temperature, and control the heating or cooling system accordingly. These instructions remain unchanged, just like the thermostat's behavior stays consistent. So, whenever you adjust the temperature on the thermostat, the microcontroller follows its predefined instructions stored in ROM to make sure your home stays at the right temperature.
  • #7: Embedded System: Definition: An embedded system is a combination of hardware and software specifically designed to perform a dedicated function within a larger system. Example: A washing machine. It has a microcontroller or microprocessor embedded inside it to control the various functions like water intake, washing cycle, and spinning. The software programmed into the embedded system ensures that it performs these tasks efficiently without needing human intervention. Microcontroller: Definition: A microcontroller is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals. Example: A remote-controlled toy car. The microcontroller inside the toy car interprets signals from the remote control and controls the motors to make the car move forward, backward, turn left, or turn right. It has all the necessary components like memory and input/output ports built into a single chip. Microprocessor: Definition: A microprocessor is the central processing unit (CPU) of a computer, which performs arithmetic and logic operations. It requires external components like memory, input/output devices, and support chips to function as a complete system. Example: A personal computer (PC). The microprocessor, like an Intel Core or AMD Ryzen chip, is the brain of the computer. It processes instructions from software and performs tasks like running programs, browsing the internet, and playing games. However, to make a complete PC system, you need additional components like RAM, storage drives, a motherboard, and peripherals such as a monitor, keyboard, and mouse.
  • #10: RAM (Random Access Memory): Definition: RAM is a type of computer memory that is used to temporarily store data that the CPU (central processing unit) needs to access quickly while performing tasks. It is volatile memory, meaning that its contents are lost when the power is turned off. Example: Imagine RAM like a workspace on a desk. When you're working on a project, you might spread out papers and tools on your desk for easy access. RAM works similarly for a computer. For instance, when you open a program like a web browser, the computer loads data from the browser into RAM so that it can quickly access and manipulate this data while you're using the program. However, when you turn off the computer, all the data stored in RAM is erased, just like clearing off your desk at the end of the day. ROM (Read-Only Memory): Definition: ROM is a type of computer memory that stores data permanently and cannot be modified or erased under normal conditions. It holds instructions or data that are essential for the operation of the computer or electronic device. Example: Think of ROM like a factory manual that comes with a piece of equipment. Once printed, the information in the manual cannot be changed. Similarly, ROM contains permanent instructions or data that the computer needs to start up and perform basic functions, such as BIOS (Basic Input/Output System) or firmware. For example, when you turn on your computer, the BIOS stored in ROM initializes the hardware components and starts the operating system loading process. Unlike RAM, ROM retains its data even when the power is turned off because it's non-volatile.
  • #12: A computer has a system bus, possibly a backside bus, and an expansion bus. A system bus connects the processor with main memory Backside bus connects the processor with cache An expansion bus allows the processor to communicate with peripheral devices System bus also known as front side bus