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

STPPT2.2 Hardware and I - O Interfaces and Source Code Components

Uploaded by

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

STPPT2.2 Hardware and I - O Interfaces and Source Code Components

Uploaded by

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

MICROCONTROLLER AND

MICROPROCESSOR SYSTEMS
ECEMICRO/ECE0035
Assembly Language Programming
Building and Microcontroller
System
ECEMICRO Module 2
■ Subtopics: 1) Microcontroller Systems 2) Hardware, I/O
Interfaces and Source Code Components
■ At the end of the chapter, the learner should be able to:
– Discuss terms and concepts of Microcontroller Systems, I/O
Interfaces, Source Code Components and Assembly Language
Subtopic # 2

Hardware, I/O
Interfaces and Source
Code Components
Interfacing Processors and Peripherals
I/O Design affected by
many factors
(expandability, resilience)
• Performance:
— access latency
— throughput
— connection between
devices and the system
— the memory hierarchy
— the operating system
• A variety of different
users (e.g., banks,
supercomputers,
engineers)
I/O
Important but neglected
• “The difficulties in assessing and designing I/O
systems have often relegated I/O to second class
status”
• “courses in every aspect of computing, from
programming to computer architecture often
ignore I/O or give it scanty coverage”
• “textbooks leave the subject to near the end,
making it easier for students and instructors to skip
it!”
I/O Devices
• Very diverse devices
— behavior (i.e., input vs. output vs. both)
— partners (who is at the other end?)
— data rates
I/O Techniques
Three main modes:

– Programmed I/O
• CPU checks and reads and writes device buffers
– Interrupt Mode
• CPU asks devices to let it know when they are read
– DMA
• CPU asks devices to perform directly from memory
• CPU sets the memory buffers
• CPU is informed when I/O is done (or in case of an error)
through an interrupt
I/O Example: Disk Drives

To access data we need the following steps


– Set DMA controller with address and count of
words to be read
– Ask disk to be on the right track and right
position
– Transfer Data to/from memory
DISK I/O Time
– Preparation time: OS prepares/delivers the transaction
controller
• 1-2 ms.
– Seek: position head over the proper track
• On average takes 8 to 10 ms.
– Rotational latency: wait for desired sector (.5 / RPM)
• At 7200 RPM, time for 0.5 revolution is 4.2 ms.
– Transfer time: grab the data and transfer to memory
• At 4MB/sec, 4Kb takes 4KB/(4MB/sec) = 1 ms.
– Total time: 14.2 ms to 17.2ms (min to max)
• Say 15ms on average
– Keeps bus busy for 1 ms out of 15 ms
I/O Example: Buses
• Shared communication link (one or more wires)
• Difficult design:
— may be bottleneck
— length of the bus
— number of devices
— tradeoffs (buffers for higher bandwidth increases latency)
— support for many different devices
— cost
I/O Example: Buses
• Types of buses:
— processor-memory (short high speed, custom design)
— backplane (high speed, often standardized, e.g., PCI)
— I/O (lengthy, different devices, standardized, e.g., SCSI)
• Synchronous vs. Asynchronous
— use a clock and a synchronous protocol, fast and small
but every device must operate at same rate and
clock skew requires the bus to be short
— don’t use a clock and instead use handshaking
Interfacing Digital IO
Each port has an
associated Mode
(R248)
Register that
(R247)
determines the
(R246) port’s functions and
allows dynamic
change in port
functions
during program
execution. Port and
Mode Registers are
mapped
into the Standard
Register File
Port 0
Port 1
Port 2
Digital Output
• This is the basic ‘hello world’ program used to simply
turn something on or off. In this example, an LEDis
connected to pin 13, and is blinked every second. The
resistor may be omitted on this pin since the Arduino
has one built in.
Digital Input
• This is the simplest form of input with only two
possible states: on or off. This example reads a simple
or pushbutton connected to pin2. when the
switch is closed the input pin will read HIGH and
turn on LED.
High Current Output
• Sometimes it is necessary to control more than
40mA from Arduino. In this case a MOSFETor
transistor could be used to switch higher current
loads. The following example quickly turns on and off
the MOSFET5 times every second.

Note: the schematic shows a motor and protection


diode but other non-inductive loads could be used
without the diode.
High Current Output
PWM Output
• Pulsewidth Modulation (PWM) is a way to fake an
analog output by pulsing the output. This could be
used to dim and brighten an LEDor later to control a
servo motor. The following example brightens and
dims an LEDusing for loops.
Servo Output
• Hobby servos are a type of self-contained motor that
can move in a 180 degrees arc. All that is needed is a
pulse sent every 20ms. This example uses a servo Pulse
function to move the servo from 10-170 degrees and
back again.
Interfacing Processors and Peripherals
I/O Design affected by
many factors
(expandability, resilience)
• Performance:
— access latency
— throughput
— connection between
devices and the system
— the memory hierarchy
— the operating system
• A variety of different
users (e.g., banks,
supercomputers,
engineers)
I/O
Important but neglected
• “The difficulties in assessing and designing I/O
systems have often relegated I/O to second class
status”
• “courses in every aspect of computing, from
programming to computer architecture often
ignore I/O or give it scanty coverage”
• “textbooks leave the subject to near the end,
making it easier for students and instructors to skip
it!”
I/O Devices
• Very diverse devices
— behavior (i.e., input vs. output vs. both)
— partners (who is at the other end?)
— data rates
I/O Techniques
Three main modes:

– Programmed I/O
• CPU checks and reads and writes device buffers
– Interrupt Mode
• CPU asks devices to let it know when they are read
– DMA
• CPU asks devices to perform directly from memory
• CPU sets the memory buffers
• CPU is informed when I/O is done (or in case of an error)
through an interrupt
Interfacing Analog IO
The following describes the output data format, Single-
Shot conversion and Continuous conversion techniques.

Output Data Format


In both SINGLE-ENDED and DIFFERENTIAL modes, the
ADC outputs an 11-bit, signed, two’s complement digital
value.

In DIFFERENTIAL mode, the ADC output


ranges from -1024 to +1023. In SINGLE-ENDED mode,
the output ranges from 0 to +1023, but offset errors can
cause small negative values.
The ADC registers return 13 bits of data, but the two least
significant bits (LSB) are intended for compensation use
only. When the compensation routine is
performed on the 13-bit raw ADC value, two bits of
resolution are lost because of rounding error. As a result,
the final value is an 11-bit number.
Single-Shot Conversion
When ADC is configured for Single-Shot conversion, the
ADC performs a single analog-to-digital conversion on the
selected analog input channel. After the completion of
conversion, the ADC will be switched off automatically.

Continuous Conversion
When ADC is configured for Continuous conversion, the
ADC continuously performs an analog to-digital
conversion on the selected analog input. Each new
data value overwrites the previous value stored in the
ADC data registers. An interrupt is generated after each
conversion.
The DMA_ADC Address register points to a block
of the Register File to store ADC conversion values.
This register contains the seven most-significant bits
of the 12-bit Register File addresses.
The five least-significant bits are calculated from
the ADC Analog Input number (5-bit base address
is equal to twice the ADC Analog Input number).
ADC conversion data is stored in two bytes per
ADC Analog Input, with the most significant byte
of the ADC data stored at the even numbered
Register File address.
Potentiometer Input
• Using a potentiometer and one of the Arduino’s
analog-to-digital conversion (ADC) pins it is
possible to read analog values from 0-1024. the
following example uses a potentiometer to control
an LED’s rate of blinking. For others, you need
ADC.
Variable Resistor Input
• Variable resistor include CdS light sensors,
thermistors, flex sensors, and so on. This example
makes use of a function to read the analog value
and set a delay time. This controls the speed at
which an LED brightens and dims.
High-level language
6
• High-Level Language overcomes the limitation
of writing a program in Machine and Assembly
language as it is difficult and time consuming.
• In High-Level Language, the programs can be written
using simple English words. Examples of High-Level
Language are BASIC, Fortran, COBOL, C, C++.
• Programs written in high-level languages are
translated into machine language by a compiler.
7
Assembly languagesyntax
• An assembly language program consists of statements. The
syntax of an assembly language program statement obeys
the following rules:
- Only one statement is written per line.
- Each statement is either an instruction or an assembler
directive.
- Each instruction has an op-code and possibly one, two or
no operands at all.
- An op-code is known as mnemonic.
- Each mnemonic represents a single machine instruction.
- Operands provide the data to work with.
Basic Assembly ProgramStructure
8
 Assembly language is made up of two(2) types of
statements:
Assembler Directive:
Inform the assembler about the program and the
environment and NOT be translated into machine code.
Executable Instruction:
One of the processor's valid instructions which can be
translated into machine code form by the assembler.
Assembler directive
9
• Assembler directives are instructions that are directed to the assembler
to do a specific thing.
• It is not translated into machine code.
(Assembler directives are executed by the assembler at assembly time,
not by the CPUat run time).
• Directives can be used to :
• Link symbolic names to actual values.
• Set up pre-defined constants.
• Allocate storage for data in memory.
• Control the assembly process.
• Include additional source files.
• starting address for the program.
10 Example of assembler directives
• EQU - Equate
Assigns a value to a symbol (same as = ) e.g. TRISA EQU 0x85

• ORG - Origin
Sets the current origin to a new value. This is used to set the program or register address
during assembly. For example, ORG 0x00 tells the assembler to assemble all subsequent
code starting at address 0000H.

• INCLUDE
An assembler include, or header, file is any file containing valid assembly code.
Usually, the file contains device-specific register and bit assignments. This file may be
“included” in the code so that it may be reused bymany programs. As an example, to
add the standard header file for the PIC16F877 device to your assembly code, use:
#INCLUDE P16F877.INC
• END
This directive is the last statement in an assembly language program. The END
directive terminates an assembly language program.
Instruction format – Label
12
• A label is used to represent a line or group of code, or a constant value. It is
needed for branching instructions.
• Labels should start in column 1. They may be followed by a colon (:), space,
tab or the end of line.
• Labels must begin with an alpha character or an under bar (_) and may
contain alphanumeric characters, the under bar and the question mark.
• Labels must not:
• begin with two leading underscores, e.g. temp
• begin with a leading underscore and number.
e.g. _2NDLOOP
• be an assembler reserved word (mnemonic, directive,
etc.).
Instruction format – Label
13
• Labels may be up to 32 characters long.
• By default they are case sensitive, but case
sensitivity may be overridden by a command-
line option (/c).
• If a colon is used when defining a label, it is treated
as a label operator and not part of the label itself.
• Example:
Here NOP
GOTO Here
Instruction format - Opcode
14
• This field consists of a symbolic operation code,
known as op-code.
• The opcode describes the operation.
• Symbolic op-codes (known as mnemonic) are
translated into machine language opcode.
• Mnemonics are not case sensitive.

• Example: BSF (Bit Set f)


CLRW (Clear W)
Instruction format - Operand Field
15
• Operands give information to the instruction on the data that should be
used and the storage location for the instruction.
• Operands must be separated from mnemonics by one or more spaces, or
tabs.
• It may has one, two or no operands at all. Multiple operands
must be separated by commas.
• Examples of instructions with different operand fields
NOP ; Instruction with no operand
ANDLW 0x34 ; Instruction with one operand
ADDWF FSR,1 ; Instruction with two operand
Instruction format – Comment Field
16
• Comments are text explaining the operation of a line or lines of code.
• A semicolon (;) marks the beginning of a comment
• A semicolon in the beginning of a line makes it all a comment line. All
characters following the semicolon are ignored through the end of the
line.
• Good programming practice dictates the use of a comment on almost
every line.
Example:
;Statement line with a comment field
BSF PortA,0 ;set pin 0 of PortA
17
Example MPASM Assembler Source
Code
7
Assembly languagesyntax
• An assembly language program consists of statements. The
syntax of an assembly language program statement obeys
the following rules:
- Only one statement is written per line.
- Each statement is either an instruction or an assembler
directive.
- Each instruction has an op-code and possibly one, two or
no operands at all.
- An op-code is known as mnemonic.
- Each mnemonic represents a single machine instruction.
- Operands provide the data to work with.
Basic Assembly ProgramStructure
8
 Assembly language is made up of two(2) types of
statements:
Assembler Directive:
Inform the assembler about the program and the
environment and NOT be translated into machine code.
Executable Instruction:
One of the processor's valid instructions which can be
translated into machine code form by the assembler.
Assembler directive
9
• Assembler directives are instructions that are directed to the assembler
to do a specific thing.
• It is not translated into machine code.
(Assembler directives are executed by the assembler at assembly time,
not by the CPUat run time).
• Directives can be used to :
• Link symbolic names to actual values.
• Set up pre-defined constants.
• Allocate storage for data in memory.
• Control the assembly process.
• Include additional source files.
• starting address for the program.
10 Example of assembler directives
• EQU - Equate
Assigns a value to a symbol (same as = ) e.g. TRISA EQU 0x85

• ORG - Origin
Sets the current origin to a new value. This is used to set the program or register address
during assembly. For example, ORG 0x00 tells the assembler to assemble all subsequent
code starting at address 0000H.

• INCLUDE
An assembler include, or header, file is any file containing valid assembly code.
Usually, the file contains device-specific register and bit assignments. This file may be
“included” in the code so that it may be reused bymany programs. As an example, to
add the standard header file for the PIC16F877 device to your assembly code, use:
#INCLUDE P16F877.INC
• END
This directive is the last statement in an assembly language program. The END
directive terminates an assembly language program.
REFERENCES
[1] Microprocessor Architecture, Programming, and Applications with the 8085
5th Edition Textbook by Ramesh S. Gaonkar

[2] Dogan, Ibrahim (2014). PIC Microcontroller Projects in C. Newness

[3] Jones, Daniel (2017). Arduino: The Ultimate Beginner’s Guide to Learn Arduino
(Volume 1). CreateSpace Independent Publishing Platform

[4] Kumar, N. Senthil (2012). Microprocessors and interfacing: 8086, 8051, 8096,
and advanced processors. Oxford University
Press
[5] Mazidi, Muhammad Ali (2016). PIC Microcontrollers and Embedded Systems.
Microdigital Ed.
REFERENCES

https://www.webopedia.com/TERM/H/high_level_language.html

Microprocessor Architecture, Programming, and Applications with the


8085
5th Edition Textbook by Ramesh S. Gaonkar

https://www.slideshare.net/shashankputhrran/assembly-language-
53015963

https://www.tutorialspoint.com/microprocessor/microprocessor_quick_guid
e.htm
ASK ANY QUESTION RELATED TO
OUR TOPIC FOR TODAY.

You might also like