Professional Documents
Culture Documents
8086 Architecture
Introduction to Microprocessors
A microprocessor is a computer processor which incorporates the
functions of a computer's central processing unit (CPU) on a
single integrated circuit (IC), or at most a few integrated circuits
The microprocessor is a multipurpose, clock driven, register based,
digital-integrated circuit which accepts binary data as input, processes it
according to instructions stored in its memory, and provides results as
output. Microprocessors contain both combinational logic and sequential
digital logic. Microprocessors operate on numbers and symbols represented
in the binary numeral system.
Generation of Microprocessors:
INTEL 4004 ( 1971)
4-bit microprocessor
4 KB main memory
45 instructions
PMOS technology
was first programmable device which was used in calculators
INTEL 8008 (1972)
8-bit version of 4004
16 KB main memory
48 instructions
PMOS technology
Slow
Intel 8080 (1973)
8-bit microprocessor
64 KB main memory
2 microseconds clock cycle time
500,000 instructions/sec
10X faster than 8008
NMOS technology
Drawback was that it needed three power supplies.
Small computers (Microcomputers) were designed in mid
1970’s
Using 8080 as CPU.
INTEL 8086/8088
Buses
Register Organization of 8086
8086 has a powerful set of registers containing general purpose and
special purpose registers. All the registers of 8086 are 16-bit registers. The
general purpose registers, can be used either 8-bit registers or 16-bit
registers. The general purpose registers are either used for holding the data,
variables and intermediate results temporarily or for other purpose like
counter or for storing offset address for some particular addressing modes
etc. The special purpose registers are used as segment registers, pointers,
index registers or as offset storage registers for particular addressing
modes. Fig 1.4 shows register organization of 8086. We will categorize the
register set into four groups as follows:
The registers AX, BX, CX, and DX are the general 16-bit registers.
Segment registers:
To complete 1Mbyte memory is divided into 16 logical segments. The
complete 1Mbyte memory segmentation is as shown in fig 1.5. Each
segment contains 64Kbyte of memory. There are four segment registers.
Source Index (SI) is a 16-bit register. SI is used for indexed, based indexed
and register indirect addressing, as well as a source data addresses in string
manipulation instructions.
Flags Register determines the current state of the processor. They are
modified automatically by CPU after mathematical operations, this allows to
determine the type of the result, and to determine conditions to transfer
control to other parts of the program. The 8086 flag register as shown in
the fig 1.6. 8086 has 9 active flags and they are divided into two categories:
1. Conditional Flags
2. Control Flags
Carry Flag (CY): This flag indicates an overflow condition for unsigned
integer arithmetic. It is also used in multiple-precision arithmetic.
Parity Flag (PF):This flag is used to indicate the parity of result. If lower
order 8-bits of the result contains even number of 1’s, the Parity Flag is set
and for odd number of 1’s, the Parity flag is reset.
Zero Flag (ZF):It is set; if the result of arithmetic or logical operation is zero
else it is reset.
Sign Flag (SF):In sign magnitude format the sign of number is indicated by
MSB bit. If the result of operation is negative, sign flag is set.
Control Flags
Control flags are set or reset deliberately to control the operations of the
execution unit. Control flags are as follows:
Trap Flag (TF): It is used for single step control. It allows user to execute one
instruction of a program at a time for debugging. When trap flag is set,
program can be run in single step mode.
Direction Flag (DF):It is used in string operation. If it is set, string bytes are
accessed from higher memory address to lower memory address. When it is
reset, the string bytes are accessed from lower memory address to higher
memory address.
8086 Architecture
The Execution unit tells the BIU where to fetch instructions or data
from
decodes instructions and
Executes instructions
Control Circuitry:
It directs internal operations.
A decoder in the EU translates instructions fetched from memory
Into series of actions which the EU carries out
SUBTRACT
XOR
INCREMENT
DECREMENT
COMPLEMENT
FLAG REGISTERS:
A flag is a flip flop that indicates some condition produced by
execution of an instruction or controls certain operation of the EU.
It is 16 bit
2. Control flags
Conditional Flags
Carry Flag (CY): This flag indicates an overflow condition for unsigned
integer arithmetic. It is also used in multiple-precision arithmetic.
Parity Flag (PF):This flag is used to indicate the parity of result. If lower
order 8-bits of the result contains even number of 1’s, the Parity Flag is set
and for odd number of 1’s, the Parity flag is reset.
Zero Flag (ZF):It is set; if the result of arithmetic or logical operation is zero
else it is reset.
Sign Flag (SF):In sign magnitude format the sign of number is indicated by
MSB bit. If the result of operation is negative, sign flag is set.
Control Flags
Control flags are set or reset deliberately to control the operations of the
execution unit. Control flags are as follows:
Trap Flag (TF): It is used for single step control. It allows user to execute one
instruction of a program at a time for debugging. When trap flag is set,
program can be run in single step mode.
Direction Flag (DF):It is used in string operation. If it is set, string bytes are
accessed from higher memory address to lower memory address. When it is
reset, the string bytes are accessed from lower memory address to higher
memory address.
Instruction Queue:
BIU gets upto 6 bytes of next instructions and stores them in the
instruction queue. When EU executes instructions and is ready for its next
instruction, then it simply reads the instruction from this instruction queue
resulting in increased execution speed. Fetching the next instruction while
the current instruction executes is called pipelining.( based on FIFO) .This is
much faster than sending out an addresses to the system memory and
waiting for memory to send back the next instruction byte or bytes .Here
the Queue will be dumped and then reloaded from the new Address.
Segment Register:
The 8086 20 bit addresses So it can address upto 220 in memory ( 1 Mbyte)
but at any instant it can address upto 4 64 KB segments. This four segments
holds the upper 16 bits of the starting address of four memory segments
that the 8086 is working with it at particular time .The BIU always inserts
zeros for the lowest 4 bits of the 20 bit starting address
Example : If the code segment register contains 348AH then the code
segment starts at 348A0H .In other words a 64Kbyte segment can be
located anywhere within 1MByte address Space but the segment will
always starts at an address with zeros in the lowest 4 bits
Stack: is a section of memory set aside to store addresses and data while
subprogram executes is often called segment base . The stack segment
register always holds the upper 16 bit starting address of program stack.
The extra segment register and data segment register is used to hold the
upper 16 bit starting addresses of two memory segments that are used for
data .
Instruction Pointer holds the 16 bit address or offset of the next code byte
within the code segment. The value contained in the Instruction Pointer
called as Offset because the value must be added to the segment base
address in CS to produce the required 20 bit address.
These three registers are used to store temporary storage of data like
general purpose registers .They hold the 16 bit offset data of the data word
in one of the segment
Programming model
A logical address gives the displacement from the base address of the
segment to the desired location within it, as opposed to its "real" address,
which maps directly anywhere into the 1 MByte memory space. This "real"
address is called the physical address.
What is the difference between the physical and the logical address?
The physical address is 20 bits long and corresponds to the actual binary
code output by the BIU on the address bus lines. The logical address is an
offset from location 0 of a given segment.
You should also be careful when writing addresses on paper to do so
clearly. To specify the logical address XXXX in the stack segment, use the
convention SS:XXXX, which is equal to [SS] * 16 + XXXX.
Logical address is in the form of: Base Address: Offset Offset is the
displacement of the memory location from the starting location of the
segment. To calculate the physical address of the memory, BIU uses the
following formula:
To convert this 16-bit address into 20-bit, the BIU appends 0H to the LSB (by
multiplying with 16) of the address. After appending, the starting address of
the Data Segment becomes 22220H.
Where 0016H is the offset, 2222 H is the value of DS Therefore the physical
address:22220H + 0016H
: 22236 H
The following table describes the default offset values to the corresponding
memory segments.
AD15-AD0:
These are the time multiplexed memory I/O address and data lines.
Address remains on the lines during T1 state, while the data is available on
the data bus during T2, T3, TW and T4. Here T1, T2, T3, T4 and TW are the
clock states of a machine cycle. TW is await state. These lines are active
high and float to a tristate during interrupt acknowledge and local bus hold
acknowledge cycles.
A19/S6, A18/S5, A17/S4, A16/S3:
These are the time multiplexed address and status lines. During T1,
these are the most significant address lines or memory operations. During
I/O operations, these lines are low. During memory or I/O operations, status
information is available on those lines for T2, T3, TW and T4 .The status of
the interrupt enable flag bit(displayed on S5) is updated at the beginning of
each clock cycle. The S4 and S3 combinedly indicate which segment register
is presently being used for memory accesses as shown in Table 1.1.
These lines float to tri-state off (tristated) during the local bus hold
acknowledge. The status line S6 is always low(logical). The address bits are
separated from the status bits using latches controlled by the ALE signal.
Read signal, when low, indicates the peripherals that the processor is
performing a memory or I/O read operation. is active low and shows
the state for T2, T3, TW of any read cycle. The signal remains tristated
during the 'hold acknowledge'.
READY:
This is a level triggered input. This is sampled during the last clock
cycle of each instruction to determine the availability of the request. If any
interrupt request is pending, the processor enters the interrupt
acknowledge cycle. This can be internally masked by resetting the interrupt
enable flag. This signal is active high and internally synchronized.
TEST:
NMI-Non-maskable Interrupt:
RESET:
This input causes the processor to terminate the current activity and
start execution from FFFF0H. The signal is active high and must be active for
at least four clock cycles. It restarts execution when the RESET returns low.
RESET is also internally synchronized.
CLK-Clock Input:
The clock input provides the basic timing for processor operation and
bus control activity. Its an asymmetric square wave with 33% duty cycle.
The range of frequency for different 8086 versions is from 5MHz to 10MHz.
VCC :
+5V power supply for the operation of the internal circuit. GND
ground for the internal circuit.
MN/MX :
The logic level at this pin decides whether the processor is to operate
in either minimum (single processor) or maximum (multiprocessor) mode.
The following pin functions are for the minimum mode operation of 8086.
M/IO -Memory/IO:
-Interrupt Acknowledge:
This output signal indicates the availability of the valid address on the
address/data lines, and is connected to latch enable input of latches. This
signal is active high and is never tristated.
-Data Transmit/Receive:
This output is used to decide the direction of data flow through the
transreceivers (bidirectional buffers). When the processor sends out data,
this signal is high and when the processor is receiving data, this signal is low.
Logically, this is equivalent to S1 in maximum mode. Its timing is the same
as M/I/O. This is tristated during 'hold acknowledge'.
When the HOLD line goes high, it indicates to the processor that
another master is requesting the bus access. The processor, after receiving
the HOLD request, issues the hold acknowledge signal on HLDA pin, in the
middle of the next clock cycle after completing the current bus (instruction)
cycle. At the same time, the processor floats the local bus and control lines.
When the processor detects the HOLD line low, it lowers the HLDA signal.
HOLD is an asynchronous input, and it should be externally synchronized.
These are the status lines which reflect the type of operation, being
carried out by the processor. These become active during T4 of the previous
cycle and remain active during T1 and T2 of the current bus cycle. The
status lines return to passive state during T3 of the current bus cycle so that
they may again become active for the next bus cycle during T4. Any change
in these lines during T3 indicates the starting of a new cycle, and return to
passive state indicates end of the bus cycle. These status lines are encoded
in table 1.3
This output pin indicates that other system bus masters will be
prevented from gaining the system bus, while the signal is low.
The signal is activated by the 'LOCK' prefix instruction and remains
active until the completion of the next instruction. This floats to tri-state
off during "hold acknowledge". When the CPU is executing a critical
instruction which requires the system bus, the LOCK prefix instruction
ensures that other processors connected in the system will not gain the
control of the bus. The 8086, while executing the prefixed instruction,
asserts the bus lock signal output, which may be connected to an
external bus controller.
These pins are used by other local bus masters, in maximum mode, to
force the processor to release the local bus at the end of the processor's
current bus cycle. Each of the pins is bidirectional with having
higher priority than pins have internal pull-up resistors and
may be left unconnected. The request! Grant sequence is as follows:
1. A pulse one clock wide from another bus master requests the bus access
to 8086.
2. During T4 (current) or T1 (next) clock cycle, a pulse one clock wide from
8086 to the requesting master, indicates that the 8086 has allowed the local
bus to float and that it will enter the "hold acknowledge" state at next clock
cycle. The CPU's bus interface unit is likely to be disconnected from the local
bus of the system.
3. A one clock wide pulse from the another master indicates to 8086 that
the 'hold' request is about to end and the 8086 may regain control of the
local bus at the next clock cycle.
Transreceivers
Transreceivers are the bidirectional buffers and some times they are
called as data amplifiers. They are required to separate the valid data from
the time multiplexed address/data signal. They are controlled by two
signals, namely, DEN* and DT/R*. The DEN* signal indicates that the valid
data is available on the data bus, while DT/R indicates the direction of data,
i.e. from or to the processor.
Memory:
The system contains memory for the monitor and users program
storage. Usually, EPROMS are used for monitor storage, while RAMs for
users program storage.
IO Devices:
A system may contain I/O devices for communication with the processor as
well as some special purpose I/O devices.
Clock Generator:
The clock generator generates the clock from the crystal oscillator
and then shapes it and divides to make it more precise so that it can be
used as an accurate timing reference for the system. The clock generator
also synchronizes some external signals with the system clock.
The general system organization is shown in above fig .Since it has 20
address lines and 16 data lines, the 8086 CPU requires three octal address
latches and two octal data buffers for the complete address and data
separation.
The read cycle begins in T1 with the assertion of the address latch
enable (ALE) signal and also M/IO* signal. During the negative going edge of
this signal, the valid address is latched on the local bus. The BHE* and
A0 signals address low, high or both bytes. From Tl to T4, the M/IO* signal
indicates a memory or I/O operation. At T2 the address is removed from the
local bus and is sent to the output. The bus is then tristated. The read (RD*)
control signal is also activated in T2 .
The read (RD) signal causes the addressed device to enable its data
bus drivers. After RD* goes low, the valid data is available on the data bus.
The addressed device will drive the READY line high, when the
processor returns the read signal to high level, the addressed device will
again tristate its bus drivers.
A write cycle also begins with the assertion of ALE and the emission
of the address. The M/IO* signal is again asserted to indicate a memory or
I/O operation. In T2 after sending the address in Tl the processor sends the
data to be written to the addressed location. The data remains on the bus
until middle of T4 state. The WR* becomes active at the beginning of T2.
The BHE* and A0 signals are used to select the proper byte or bytes
of memory or I/O word to be read or written. The M/IO*, RD* and WR*
signals indicate the types of data transfer as specified in Table
The HOLD pin is checked at the end of the each bus cycle. If it is
received active by the processor before T4 of the previous cycle or during
T1 state of the current cycle, the CPU activities HLDA in the next clock cycle
and for the succeeding bus cycles, the bus will be given to another
requesting master The control control of the bus is not regained by the
processor until the requesting master does not drop the HOLD pin low.
When the request is dropped by the requesting master, the HLDA is
dropped by the processor at the trailing edge of the next clock as shown in
fig
Maximum Mode 8086 System and Timings
In the maximum mode, the 8086 is operated by strapping the
MN/MX* pin to ground. In this mode, the processor derives the status
signals S2*, S1* and S0*. Another chip called bus controller derives the
control signals using this status information. In the maximum mode, there
may be more than one microprocessor in the system configuration. The
other components in the system are the same as in the minimum mode
system. The general system organization is as shown in the fig1.1
The maximum mode system timing diagrams are also divided in two
portions as read (input) and write (output) timing diagrams. The
address/data and address/status timings are similar to the minimum mode.
ALE is asserted in T1, just like minimum mode. The only difference lies in
the status signals used and the available control and advanced command
signals. The fig. 1.2 shows the maximum mode timings for the read
operation while the fig. 1.3 shows the same for the write operation.
OPERAND:
The CPU executes the instruction using the information resides in these fields .
There are six general formats of instructions in 8086 instruction set.
The instruction of 8086 vary from 1to 6 bytes length
ONE BYTE INSTRUCTION:
It is only one byte long and may have implied data or register operands.
The least three significant 3 bits of the opcode are used for specifying register
operand if any otherwise all the 8 bits form an opcode and the operands are implied.
REGISTER TO REGISTER
The format is 2 byte long
The first byte of the code specifies the opcode and width
The second byte of the code shows the register operand and R/M field
The Register represented by REG is one of the operands . The R/M field specifies
another register or memory location .ie the other operand
The first two bytes contains the information regarding OPCODE,MOD and R/M fields
The remaining 4 bytes contains 2 bytes of displacement and 2 bytes of data
ADDRESSING MODES OF 8086
According two the flow of instructions may be categorized as
1. Sequential Control flow instructions
2. Control transfer instructions
Sequential control flow instructions are the instructions which after execution
transfer control to the next instruction appearing immediately. The control transfer
instructions transfer control to some predefined address or the address somehow
specified in the instruction after their execution.
What is addressing mode?
The different ways in which a source operand is denoted in an instruction are known
as addressing mode the addressing modes for sequential control flow instructions
are
Example
MOV DL, 08H
The 8-bit data (08H) given in the instruction is moved to DL
(DL) 08H
MOV AX, 0A9FH
The 16-bit data (0A9FH) given in the instruction is moved to AX register
(AX) 0A9FH
The instruction will specify the name of the register which holds the data to be operated by the
instruction. All registers except IP may be used in this mode
Example:
MOV CL, DH
The content of 8-bit register DH is moved to another 8-bit register CL
(CL) (DH)
Example
MOV AX, [BX]; suppose the register BX contains 4895H, then the contents
; 4895H are moved to AX
ADD CX, {BX}
In this addressing mode, the operands offset address is found by adding the contents of
SI or DI register and 8-bit/16-bit displacements. DS and ES are the default segments for
index registers SI and DI respectively. This is the special case of the of register indirect
addressing mode.
Example
Label (optional)
Instruction (required)
Operands (instruction specific)
Comment (optional)
Mov ax, bx
Machine code : may be one , two , three or four bytes in length. The
first byte is actual operation called an opcode ( is short for 'Operation
Code') that tells the processor what should be done, and any other bytes
that present are operand refrenced an immediate value , a register , or a
memory location.
Types of Addressing Modes:
In the above example, 8705 h is the immediate data. The immediate data
may be 8-bit or 16-bit in size.
Example: ADD BL , AL
MOV SI , CX
[BX+SI+displacement] or [BX+DI+displacement] or
[BP+SI+displacement] or [BP+DI+displacement].
Note. Only the registers (BX, SI, DI, BP) can be used inside square
brackets (as memory pointers).
The 80x86 processors have access memory in many different ways. The 80x86
memory addressing modes provide flexible access to memory, allowing us to
easily access variables, arrays, records, pointers, and other complex data types.
Mastery of the 80x86 addressing modes is the first step towards mastering 80x86
assembly language.
When Intel designed the original 8086 processor, they provided it with a flexible,
though limited, set of memory addressing modes. Intel added several new
addressing modes when it introduced the 80386 microprocessor. Note that the
80386 retained all the modes of the previous processors; the new modes are just an
added bonus. If we need to write code that works on 80286 and earlier processors,
We will not be able to take advantage of these new modes. However, if we intend
to run Wer code on 80386sx or higher processors, We can use these new modes.
Since many programmers still need to write programs that run on 80286 and earlier
machines, it's important to separate the discussion of these two sets of addressing
modes to avoid confusing them.
Most 8086 instructions can operate on the 8086's general purpose register set. By
specifying the name of the register as an operand to the instruction, we may access
the contents of that register. Consider the 8086 mov (move) instruction:
mov destination, source
This instruction copies the data from the source operand to the destination operand.
The eight and 16 bit registers are certainly valid operands for this instruction. The
only restriction is that both operands must be the same size. Now let's look at some
actual 8086 mov instructions:
mov ax, bx ;Copies the value from BX into AX
mov dl, al ;Copies the value from AL into DL
mov si, dx ;Copies the value from DX into SI
mov sp, bp ;Copies the value from BP into SP
mov dh, cl ;Copies the value from CL into DH
mov ax, ax ;Yes, this is legal!
Remember, the registers are the best place to keep often used variables. As we'll
see a little later, instructions using the registers are shorter and faster than those
that access memory. Throughout this chapter We'll see the abbreviated operands
reg and r/m (register/memory) used wherever We may use one of the 8086's
general purpose registers.
The 8086 provides 17 different ways to access memory. This may seem like
quite a bit at first, but fortunately most of the address modes are simple variants of
one another so they're very easy to learn. And learn them we should! The key to
good assembly language programming is the proper use of memory addressing
modes.
The most common addressing mode, and the one that's easiest to understand, is the
displacement-only (or direct) addressing mode. The displacement-only
addressing mode consists of a 16 bit constant that specifies the address of the target
location. The instruction mov al,ds:[8088h] loads the al register with a copy of
the byte at memory location 8088h. Likewise, the instruction mov
ds:[1234h],dl stores the value in the dl register to memory location 1234h:
The displacement-only addressing mode is perfect for accessing simple variables.
Of course, We'd probably prefer using names like "I" or "J" rather than
"DS:[1234h]" or "DS:[8088h]". Well, fear not, we'll soon see it's possible to do just
that.
By default, all displacement-only values provide offsets into the data segment. If
We want to provide an offset into a different segment, We must use a segment
override prefix before Wer address. For example, to access location 1234h in the
extra segment (es) We would use an instruction of the form mov
ax,es:[1234h]. Likewise, to access this location in the code segment We would
use the instruction mov ax, cs:[1234h]. The ds: prefix in the previous examples is
not a segment override. The CPU uses the data segment register by default. These
specific examples require ds: because of MASM's syntactical limitations.
The 80x86 CPUs let we access memory indirectly through a register using the
register indirect addressing modes. There are four forms of this addressing mode
on the 8086, best demonstrated by the following instructions:
mov al, [bx]
mov al, [bp]
mov al, [si]
mov al, [di]
As with the x86 [bx] addressing mode, these four addressing modes reference
the byte at the offset found in the bx, bp, si, or di register, respectively.
The [bx], [si], and [di] modes use the ds segment by default.
The [bp] addressing mode uses the stack segment (ss) by default.
We can use the segment override prefix symbols if We wish to access data in
different segments. The following instructions demonstrate the use of these
overrides:
mov al, cs:[bx]
mov al, ds:[bp]
mov al, ss:[si]
mov al, es:[di]
Intel refers to [bx] and [bp] as base addressing modes and bx and bp as base
registers (in fact, bp stands for base pointer). Intel refers to
the [si] and [di] addressing modes as indexed addressing modes (si stands
for source index, di stands for destination index). However, these addressing
modes are functionally equivalent. This text will call these forms register indirect
modes to be consistent.
Note: the [si] and [di] addressing modes work exactly the same way, just
substitute si and di for bx above.
The offsets generated by these addressing modes are the sum of the constant and
the specified register. The addressing modes involving bx, si, and di all use the
data segment, the disp[bp] addressing mode uses the stack segment by default. As
with the register indirect addressing modes, We can use the segment override
prefixes to specify a different segment:
mov al, ss:disp[bx]
mov al, es:disp[bp]
mov al, cs:disp[si]
mov al, ss:disp[di]
Note that Intel still refers to these addressing modes as based addressing and
indexed addressing. Intel's literature does not differentiate between these modes
with or without the constant. If We look at how the hardware works, this is a
reasonable definition. From the programmer's point of view, however, these
addressing modes are useful for entirely different things. Which is why this text
uses different terms to describe them. Unfortunately, there is very little consensus
on the use of these terms in the 80x86 world.
The based indexed addressing modes are simply combinations of the register
indirect addressing modes. These addressing modes form the offset by adding
together a base register (bx or bp) and an index register (si or di). The allowable
forms for these addressing modes are
mov al, [bx][si]
mov al, [bx][di]
mov al, [bp][si]
mov al, [bp][di]
Suppose that bx contains 1000h and si contains 880h. Then the instruction
mov al,[bx][si]
would load al from location DS:1880h. Likewise, if bp contains 1598h
and di contains 1004, mov ax,[bp+di] will load the 16 bits in ax from locations
SS:259C and SS:259D.
The addressing modes that do not involve bp use the data segment by default.
Those that have bp as an operand use the stack segment by default.
There are a total of 17 different legal memory addressing modes on the 8086: disp,
[bx], [bp], [si], [di], disp[bx], disp[bp], disp[si], disp[di], [bx][si], [bx][di], [bp][si],
[bp][di], disp[bx][si], disp [bx][di], disp[bp][si], and disp[bp][di]. We could
memorize all these forms so that We know which are valid (and, by omission,
which forms are invalid). However, there is an easier way besides memorizing
these 17 forms. Consider the chart:
If We choose zero or one items from each of the columns and wind up with at least
one item, We've got a valid 8086 memory addressing mode. Some examples:
Choose disp from column one, nothing from column two, [di] from column
3, We get disp[di].
Choose disp, [bx], and [di]. We get disp[bx][di].
Skip column one & two, choose [si]. We get [si]
Skip column one, choose [bx], then choose [di]. We get [bx][di]
Likewise, if We have an addressing mode that We cannot construct from this table,
then it is not legal. For example, disp[dx][si] is illegal because We cannot
obtain [dx] from any of the columns above.
Not all addressing modes are created equal! Different addressing modes may take
differing amounts of time to compute the effective address. The exact difference
varies from processor to processor. Generally, though, the more complex an
addressing mode is, the longer it takes to compute the effective address.
Complexity of an addressing mode is directly related to the number of terms in the
addressing mode. For example, disp[bx][si] is more complex than [bx]. See the
instruction set reference in the appendices for information regarding the cycle
times of various addressing modes on the different 80x86 processors.
If the effective address calculation produces a value greater than 0FFFFh, the CPU
ignores the overflow and the result wraps around back to zero. For example,
if bx contains 10h, then the instruction mov al,0FFFFh[bx] will load the al register
from location ds:0Fh, not from location ds:1000Fh.
In this discussion We've seen how these addressing modes operate. The preceding
discussion didn't explain what We use them for. That will come a little later. As
long as We know how each addressing mode performs its effective address
calculation, We'll be fine.
UNIT -III
I/O Interface
8255 PPI
Various Modes of Operation and Interfacing to 8086
D/A and A/D Converter
Stepper motor
Interfacing of DMA controller 8257
Interfacing with advanced devices
Memory Interfacing to 8086
Interrupt Structure of 8086
Interrupt Vector Table, Interrupt Service Routine
architecture of 8259.
Communication Interface
Serial Communication Standards
Serial Data Transfer Schemes
8251 USART Architecture and Interfacing.
UNIT-3
I/O Interface
Introduction:
Input port:
It is used to read data from the input device such as keyboard. The simplest form
of input port is a buffer. The input device is connected to the microprocessor through
buffer, as shown in the fig.1. This buffer is a tri-state buffer and its output is available
only when enable signal is active. When microprocessor wants to read data from the
input device (keyboard), the control signals from the microprocessor activates the buffer
by asserting enable input of the buffer. Once the buffer is enabled, data from the input
device is available on the data bus. Microprocessor reads this data by initiating read
command.
Output port:
It is used to send data to the output device such as display from the
microprocessor. The simplest form of output port is a latch. The output device is
connected to the microprocessor through latch, as shown in the fig.2. When
microprocessor wants to send data to the output device is puts the data on the data bus
and activates the clock signal of the latch, latching the data from the data bus at the
output of latch. It is then available at the output of latch for the output device.
The interrupt driven I/O technique allows the CPU to execute its main program
and only stop to service I/O device when it is told to do so by the I/O system as shown in
fig.3. This method provides an external asynchronous input that would inform the
processor that it should complete whatever instruction that is currently being executed
and fetch a new routine that will service the requesting device. Once this servicing is
completed, the processor would resume exactly where it left off.
An analogy to the interrupt concept is in the classroom, where the professor serves
as CPU and the students as I/O ports. The classroom scenario for this interrupt analogy
will be such that the professor is busy in writing on the blackboard and delivering his
lecture.
The student raises his finger when he wants to ask a question (student requesting for
service). The professor then completes his sentence and acknowledges student‟s
request by saying “YES” (professor acknowledges the interrupt request). After
acknowledgement from the professor, student asks the question and professor gives
answer to the question (professor services the interrupt). After that professor continues
its remaining lecture form where it was left.
PIO 8255:
The two groups of I/O pins are named as Group A and Group B. Each of thesetwo
groups contains a subgroup of eight I/O lines called as 8-bit port and anothersubgroup of
four lines or a 4-bit port. Thus Group A contains an 8-bit port Aalong with a 4-bit port C
upper.
The port A lines are identified by symbols PA0-PA7 while the port C lines are
identified as PC4-PC7 similarly. Group B contains an 8-bit port B, containing lines PB0-
PB7 and a 4-bit port C with lower bits PC0-PC3. The port C upper and port C lower can be
used in combination as an 8-bit port C. Both the port Cs is assigned the same address.
Thus one may have either three 8-bit I/O ports or two 8-bit and two 4-bit I/O ports from
8255. All of these ports can function independently either as input or as output ports.
This can be achieved by programming the bits of an internal register of 8255 called as
control word register (CWR). The internal block diagram and the pin configuration of
8255 are shown in figs.
The 8-bit data bus buffer is controlled by the read/write control logic. The read/write
control logic manages all of the internal and external transfer of both data and control
words. RD, WR, A1, A0 and RESET are the inputs, provided by the microprocessor to
READ/WRITE control logic of 8255. The 8-bit, 3-state bidirectional buffer is used to
interface the 8255 internal data bus with the external system data bus. This buffer
receives or transmits data upon the execution of input or output instructions by the
microprocessor. The control words or status information is also transferred through the
buffer.
The port A lines are identified by symbols PA0-PA7 while the port C lines are
Identified as PC4-PC7. Similarly, Group B contains an 8-bit port B, containing
lines PB0-PB7 and a 4-bit port C with lower bits PC0- PC3. The port C upper
and port C lower can be used in combination as an 8-bit port C.
Both the port C is assigned the same address. Thus one may have either three
8-bit I/O ports or two 8-bit and two 4-bit ports from 8255. All of these ports
can function independently either as input or as output ports. This can be
achieved by programming the bits of an internal register of 8255 called as
control word register (CWR).
The 8-bit data bus buffer is controlled by the read/write control logic. The read/write
control logic manages all of the internal and external transfers of both data and
control words.
RD,WR, A1, A0 and RESET are the inputs provided by the microprocessor to the
READ/ WRITE control logic of 8255. The 8-bit, 3-state bidirectional buffer is used to
interface the 8255 internal data bus with the external system data bus.
This buffer receives or transmits data upon the execution of input or output
instructions by the microprocessor. The control words or status information is also
transferred through the buffer.
PA7-PA0: These are eight port A lines that acts as either latched output or buffered
input lines depending upon the control word loaded into the control word register.
PC7-PC4: Upper nibble of port C lines. They may act as either output latches or input
buffers lines.
This port also can be used for generation of handshake lines in mode1 or mode2.
PC3-PC0: These are the lower port C lines; other details are the same as PC7-PC4
lines.
PB0-PB7: These are the eight port B lines which are used as latched output lines or
buffered input lines in the same way as port A.
RD: This is the input line driven by the microprocessor and should be low to indicate
read operation to 8255.
WR: This is an input line driven by the microprocessor. A low on this line indicates
write operation.
CS: This is a chip select line. If this line goes low, it enables the 8255 to respond to RD
and WR signals, otherwise RD and WR signal are neglected.
D0-D7: These are the data bus lines those carry data or control word to/from the
microprocessor.
RESET:Logic high on this line clears the control word register of 8255. All ports are
set as input ports by default after reset.
A1-A0: These are the address input lines and are driven by the microprocessor.
These lines A1-A0 with RD, WR and CS from the following operations for 8255. These
address lines are used for addressing any one of the four registers, i.e. three ports
and a control word register as given in table below.
In case of 8086 systems, if the 8255 is to be interfaced with lower order data bus,
the A0 and A1 pins of 8255 are connected with A1 and A2 respectively.
Modes of Operation of 8255
These are two basic modes of operation of 8255. I/O mode and Bit Set-Reset mode
(BSR).
In I/O mode, the 8255 ports work as programmable I/O ports, while in BSR mode only
port C (PC0-PC7) can be used to set or reset its individual port bits.
Under the I/O mode of operation, further there are three modes of operation of 8255,
so as to support different types of applications, mode 0, mode 1 and mode 2.
BSR Mode: In this mode any of the 8-bits of port C can be set or reset depending on D0
of the control word. The bit to be set or reset is selected by bit select flags D3, D2 and D1
of the CWR as given in table.
I/O Modes:
a) Mode 0 (Basic I/O mode): This mode is also called as basic input/output Mode. This
mode provides simple input and output capabilities using each of the threeports. Data
can be simply read from and written to the input and output portsrespectively, after
appropriate initialization.
The salient features of this mode are as listed below:
1. Two 8-bit ports (port A and port B) and two 4-bit ports (port C upper and lower)
are available. The two 4-bit ports can be combined used as a third 8-bit port.
2. Any port can be used as an input or output port.
3. Output ports are latched. Input ports are not latched.
4. A maximum of four ports are available so that overall 16 I/O configurations
arepossible.
1. Two groups – group A and group B are available for strobed data transfer.
2. Each group contains one 8-bit data I/O port and one 4-bit control/data port.
3. The 8-bit data port can be either used as input and output port. The inputs
andoutputs both are latched.
4. Out of 8-bit port C, PC0-PC2 are used to generate control signals for port B
andPC3-PC5 are used to generate control signals for port A. the lines PC6, PC7
may be used as independent data lines.
The control signals for both the groups in input and output modes areexplained as
follows:
• STB (Strobeinput) – If this lines falls to logic low level, the data available at 8-
bit input port is loaded into input latches.
• IBF (Input buffer full) – If this signal rises to logic 1, it indicates that data
hasbeen loaded into latches, i.e. it works as an acknowledgement. IBF is set
by a lowon STB and is reset by the rising edge of RD input.
• INTR (Interruptrequest) – This active high output signal can be used
tointerrupt the CPU whenever an input device requests the service. INTR is
set by ahigh STBpin and a high at IBF pin. INTE is an internal flag that can be
controlledby the bit set/reset mode of either PC4 (INTEA) or PC2 (INTEB) as
shown in fig.
• INTR is reset by a falling edge of RD input. Thus an external input device can
berequest the service of the processor by putting the data on the bus and
sending thestrobe signal.
• OBF (Output buffer full) – This status signal, whenever falls to low,
indicatesthat CPU has written data to the specified output port. The OBF flip-
flop will beset by a rising edge of WR signal and reset by a low going edge at
the ACKinput.
• ACK (Acknowledgeinput) – ACK signal acts as an acknowledgement to begiven
by an output device. ACK signal, whenever low, informs the CPU that thedata
transferred by the CPU to the output device through the port is received
bythe output device.
• INTR (Interruptrequest) – Thus an output signal that can be used to
interruptthe CPU when an output device acknowledges the data received
from the CPU.INTR is set when ACK, OBF and INTE are 1. It is reset by a
fallingedge on WRinput. The INTEA and INTEB flags are controlled by the bit
set-reset mode ofPC6 and PC2 respectively.
c) Mode 2 (Strobed bidirectional I/O): This mode of operation of 8255 is alsocalled as
strobed bidirectional I/O. This mode of operation provides 8255 with additional features for
communicating with a peripheral device on an 8-bit databus. Handshaking signals are
provided to maintain proper data flow andsynchronization between the data transmitter
and receiver. The interruptgeneration and other functions are similar to mode 1.
In this mode, 8255 is a bidirectional 8-bit port with handshake signals. The Rdand WR signals
decide whether the 8255 is going to operate as an input port oroutput port.
INTR – (Interrupt request) As in mode 1, this control signal is active high and
isused to interrupt the microprocessor to ask for transfer of the next data
byteto/from it. This signal is used for input (read) as well as output (write)
operations.
Control Signals for Output operations:
OBF (Output buffer full) – This signal, when falls to low level, indicates that
theCPU has written data to port A.
ACK (Acknowledge) This control input, when falls to logic low level,
Acknowledges that the previous data byte is received by the destination and
nextbyte may be sent by the processor. This signal enables the internal tristate
buffersto send the next data byte on port A.
INTE1 ( A flag associated with OBF ) This can be controlled by bit set/resetmode
with PC6.
STB (Strobe input)a low on this line is used to strobe in the data into the
inputLatches of 8255.
IBF (Input buffer full) when the data is loaded into input buffer, this signal risesto
logic „1‟. This can be used as an acknowledge that the data has been receivedby
the receiver.
The waveforms in fig show the operation in Mode 2 for output as well as
inputport.
Note: WR must occur before ACK and STB must be activated before RD.
The following fig shows a schematic diagram containing an 8-bit
bidirectionalport, 5-bit control port and the relation of INTR with the control
pins. Port B caneither be set to Mode 0 or 1 with port A( Group A ) is in Mode
2.
Mode 2 is not available for port B. The following fig shows the control word.
The INTR goes high only if IBF, INTE2, STB and RD go high or OBF,
INTE1, ACK and WR go high. The port C can be read to know the status of
theperipheral device, in terms of the control signals, using the normal
I/Oinstructions.
Interfacing Analog to Digital Data Converters:
In most of the cases, the PIO 8255 is used for interfacing the analog to digital
converters with microprocessor.
We have already studied 8255 interfacing with 8086 as an I/O port, in previous section.
This section we will only emphasize the interfacing techniques of analog to digital
converters with 8255.
The analog to digital converters is treated as an input device by the microprocessor
that sends an initializing signal to the ADC to start the analogy to digital data
conversation process. The start of conversation signal is a pulse of a specific duration.
The analog to digital converter chips 0808 and 0809 are 8-bit CMOS,
successive approximation converters. This technique is one of the fast
techniques for analog to digital conversion. The conversion delay is 100µs at a
clock frequency of 640 KHz, which is quite low as compared to other
converters. These converters do not need any external zero or full scale
adjustments as they are already taken care of by internal circuits.
These converters internally have a 3:8 analog multiplexer so that at a time
eight different analog conversion by using address lines - ADD A, ADD B,
ADD C, as shown. Using these address inputs, multichannel data acquisition
system can be designed using a single ADC. The CPU may drive these lines
using output port lines in case of multichannel applications. In case of
single input applications, these may be hardwired to select the proper
input.
There are unipolar analog to digital converters, i.e. they are able to convert
only positive analog input voltage to their digital equivalent. These chips do
not contain any internal sample and hold circuit.
If one needs a sample and hold circuit for the conversion of fast signal into
equivalent digital quantities, it has to be externally connected at each of the
analog inputs.
Fig (1) and Fig (2) show the block diagrams and pin diagrams for ADC 0808/0809.
Table.1
Address lines
Analog I/P selected
C B A
I/P 0 0 0 0
I/P 1 0 0 1
I/P 2 0 1 0
I/P 3 0 1 1
I/P 4 1 0 0
I/P 5 1 0 1
I/P 6 1 1 0
I/P 7 1 1 1
Fig.1 Block Diagram of ADC 0808/0809
Table.2
The digital to analog converters convert binary numbers into their analog
equivalent voltages. The DAC find applications in areas like digitally controlled gains,
motor speed controls, programmable gain amplifiers, etc.
The supply range extends from +5V to +15V , while Vref may be anywhere
between -10V to +10V. The maximum analog output voltage will be +10V,
when all the digital inputs are at logic high state. Usually a Zener is connected
between OUT1 and OUT2 to save the DAC from negative transients.
An operational amplifier is used as a current to voltage converter at the output
of AD 7523 to convert the current output of AD7523 to a proportional output
voltage.
111
It also offers additional drive capability to the DAC output. An external
feedback resistor acts to control the gain. One may not connect any external
feedback resistor, if no gain control is required.
The circuit for interfacing a winding Wn with an I/O port is given in fig.4. Each of
the windings of a stepper motor needs this circuit for its interfacing with the
output port. A typical stepper motor may have parameters like torque 3 Kg-cm,
operating voltage 12V, current rating 0.2 A and a step angle 1.8 0 i.e. 200
steps/revolution (number of rotor teeth).
A simple schematic for rotating the shaft of a stepper motor is called a wave
scheme. In this scheme, the windings Wa, Wb, Wc and Wd are applied with the
required voltages pulses, in a cyclic fashion. By reversing the sequence of
excitation, the direction of rotation of the stepper motor shaft may be reversed.
Table.1 shows the excitation sequences for clockwise and anticlockwise rotations.
Another popular scheme for rotation of a stepper motor shaft applies pulses to
two successive windings at a time but these are shifted only by one position at a
time. This scheme for rotation of stepper motor shaft is shown in table2.
Motion step A B C D
1 1 0 0 0
2 0 1 0 0
Clock wise 3 0 0 1 0
4 0 0 0 1
5 1 0 0 0
1 1 0 0 0
2 0 0 0 1
Anticlock
3 0 0 1 0
wise
4 0 1 0 0
5 1 0 0 0
Table.2 An alternative scheme for rotating stepper motor shaft
Motion step A B C D
1 0 0 1 1
2 0 1 1 0
Clock wise 3 1 1 0 0
4 1 0 0 1
5 0 0 1 1
1 0 0 1 1
2 1 0 0 1
Anticlock
3 1 1 0 0
wise
4 0 1 1 0
5 0 0 0 0
Keyboard Interfacing
In most keyboards, the key switches are connected in a matrix of Rows and Columns.
1. D e t e c t a k e y p r e s s
2. D e b o u n c e t h e k e y p r e s s .
3. Encode the keypress (produce a standard code for the pressed key).
Key Debounce:
If any of the columns are low now, then the assumption is made that it was a
valid key press.
The final task is to determine the row & column of the pressed key &convert this
information to Hex-code for the pressed key.
The 4-bit code from I/P port & the 4-bit code from O/P port (row &column) are
converted to Hex-code.
Display Interface
Interfacing multiplexed 7-segment display
TIST CS 305 MICROPROCESSOR AND MICROCONTROLLERS MODULE IV
• The parallel input-output port chip 8255 is also called as programmable peripheral
input-output port.
• The Intel’s 8255 is designed for use with Intel’s 8-bit, 16-bit and higher capability
microprocessors.
• The two groups of I/O pins are named as Group A and Group B.
• Each of these two groups contains a subgroup of eight I/O lines called as 8-bit port
and another subgroup of four lines or a 4-bit port.
• Thus Group A contains an 8-bit port A along with a 4-bit port. C upper. The port A
lines are identified by symbols PA0-PA7 .While the port C lines are identified as
PC4-PC7.
• Similarly, Group B contains an 8-bit port B, containing lines PB0-PB7 and a 4-bit
port C with lower bits PC0- PC3.
• The port C upper and port C lower can be used in combination as an 8-bit port C.
• All of these ports can function independently either as input or as output ports.
This can be achieved by programming the bits of an internal register of 8255 called as
control word register ( CWR ).
4. Port A, B and C
• Data bus buffer: This is a tristate bidirectional buffer used to interface the 8255 to
system databus. Data is transmitted or received by the buffer on execution of input or
output instruction by the CPU. Control word and status information are also
transferred through this unit.
• Read/Write control logic: This unit accepts control signals ( RD, WR ) and also
inputs from address bus and issues commands to individual group of control blocks(
Group A, Group B).
b) RD (Read) – A low on this pin enables the CPU to read the data in the
ports or the status word through data bus buffer.
c)WR ( Write ) : A low on this pin, the CPU can write data on to the ports or
on to the control register through the data bus buffer.
d) RESET: A high on this pin clears the control register and all ports are set
to the input mode
• Group A and Group B controls : These block receive control from the CPU and
issues commands to their respective ports.
• Control word register can only be written into, no read operation of the CW register
is allowed.
The 8255 contains three 8-bit ports (A, B, and C). All can be configured to a wide
variety of functional characteristics by the system software but each has its own
special features or "personality" to further enhance the power and flexibility of the
8255.
a) Port A: This has an 8 bit latched/buffered O/P and 8 bit input latch. It can be
programmed in 3 modes – mode 0,mode 1, mode 2.
b) Port B: This has an 8 bit latched / buffered O/P and 8 bit input latch. It can be
programmed in mode 0, mode1.
c) Port C : This has an 8 bit latched input buffer and 8 bit output latched/buffer. This
port can be divided into two 4 bit ports and can be used as control signals for port A
and port B. it can be programmed in mode 0.
• PA7-PA0: These are eight port A lines that acts as either latched output or buffered
input lines depending upon the control word loaded into the control word register.
• PC7-PC4 : Upper nibble of port C lines. They may act as either output latches or
input buffers lines. This port also can be used for generation of handshake lines in
mode 1 or mode 2
• PC3-PC0 : These are the lower port C lines, other details are the same as PC7-PC4
lines.
• PB0-PB7 : These are the eight port B lines which are used as latched output lines
or buffered input lines in the same way as port A.
• RD : This is the input line driven by the microprocessor and should be low to
indicate read operation to 8255.
• CS : This is a chip select line. If this line goes low, it enables the 8255 to respond to
RD and WR signals, otherwise RD and WR signal are neglected.
• A1-A0 : These are the address input lines and are driven by the microprocessor.
These lines A1-A0 with RD, WR and CS form the following operations for 8255.
• These address lines are used for addressing any one of the four registers,i.e. three
ports and a control word register as given in table below:-
• In case of 8086 systems, if the 8255 is to be interfaced with lower order data bus, the
A0 and A1 pins of 8255 are connected with A1 and A2 respectively.
1. .I/O mode
2. . Bit Set-Reset mode (BSR).
• In I/O mode, the 8255 ports work as programmable I/Oports, while in BSR mode
only port C (PC0-PC7) can be used to set or reset its individual port bits.
• Under the I/O mode of operation, further there are three modes of operation of
8255, so as to support differenttypes of applications, mode 0, mode 1 and mode 2.
• BSR Mode: In this mode any of the 8-bits of port C can be set or reset depending on
D0 of the control word. The bit to be set or reset is selected by bit select flags D3, D2
and D1 of the CWR as given in table.
I/O Modes :
a) Mode 0 ( Basic I/O mode ): This mode is also called as basic input/output mode. This
mode provides simple input and output capabilities using each of the three ports. Data
can be simply read from and written to the input and output ports respectively, after
appropriate initialisation.
1. Two 8-bit ports ( port A and port B )and two 4-bit ports (port C upper and
lower ) are available. The two 4-bit ports can be combinedly used as a third 8-
bit port.
2. Any port can be used as an input or output port.
3.Output ports are latched. Input ports are not latched.
4. A maximum of four ports are available so that overall 16 I/O configuration
are possible.
• All these modes can be selected by programming a register internal to 8255 known
as CWR.
Now let us consider some interfacing problems so as to elaborate the hardware interfacing
and I/O programming Ideas using 8255 in mode 0.
Problem.1
Problem 2:
Problem.1
1.Two groups – group A and group B are available for strobed data transfer.
2. Each group contains one 8-bit data I/O port and one 4-bit control/data port.
3. The 8-bit data port can be either used as input and output port. The inputs and
outputs both are latched.
4. Out of 8-bit port C, PC0-PC2 are used to generate control signals for port B and
PC3-PC5 are used to generate control signals for port A. the lines PC6, PC7 may
be used as independent data lines.
The control signals for both the groups in input and output modes are explained as
follows:
• STB( Strobe input ) – If this lines falls to logic low level,the data available at 8-bit
input port is loaded into input latches.
• IBF ( Input buffer full ) – If this signal rises to logic 1, it indicates that data has been
loaded into latches, i.e. It works as an acknowledgement. IBF is set by a low on STB
and is reset by the rising edge of RD input.
• INTR ( Interrupt request ) – This active high output signal can be used to interrupt
the CPU whenever an input device requests the service. INTR is set by a high STB
pin and a high at IBF pin. INTE is an internal flag that can be controlled by the bit
set/reset mode of either PC4(INTEA) or PC2(INTEB) as shown in fig.
• INTR is reset by a falling edge of RD input. Thus an external input device can be
request the service of the processor by putting the data on the bus and sending the strobe
signal.
• OBF (Output buffer full ) – This status signal, whenever falls to low, indicates that
CPU has written data to the specified output port. The OBF flip-flop will be set by a
rising edge of WR signal and reset by a low going edge at the ACK input.
• INTR ( Interrupt request ) – Thus an output signal that can be used to interrupt the
CPU when an output device acknowledges the data received from the CPU. INTR is
set
when ACK, OBF and INTE are 1. It is reset by a falling edge on WR input. The
INTEA and INTEB flags are controlled by the bit set-reset mode of PC6 and PC2
respectively.
• This mode of operation of 8255 is also called as strobed bidirectional I/O. This mode
of operation provides 8255 with an additional features for communicating with a
peripheral device on an 8-bit data bus. Handshaking signals are provided to maintain
proper data flow and synchronization between the data transmitter and receiver. The
interrupt generation and other functions are similar to mode 1.
•
• In this mode, 8255 is a bidirectional 8-bit port with handshake signals. The Rd and WR
signals decide whether the 8255 is going to operate as an input port or output port.
5. The 5-bit control port C (PC3-PC7) is used for generating / accepting handshake
signals for the 8-bit data transfer on port A.
• INTR – (Interrupt request) As in mode 1, this control signal is active high and is used to
interrupt the microprocessor to ask for transfer of the next data byte to/from it. This
signal is used for input (read) as well as output (write) operations.
• Control Signals for Output operations:
• OBF (Output buffer full) – This signal, when falls to low level, indicates that the CPU
has written data to port A.
• ACK (Acknowledge) This control input, when falls to logic low level, acknowledges
that the previous data byte is received by the destination and next byte may be sent by
the processor. This signal enables the internal tristate buffers to send the next data
byte on port A.
• INTE1 (A flag associated with OBF) This can be controlled by bit set/reset mode with
PC6.
• The following fig shows a schematic diagram containing an 8-bit bidirectional port,
5-bit control port and the relation of INTR with the control pins. Port B can either be
set to Mode 0 or 1 with port A(Group A) is in Mode 2.
• Mode 2 is not available for port B..
• The INTR goes high only if either IBF, INTE2, STB and RD go high or OBF, INTE1,
ACK and WR go high. The port C can be read to know the status of the peripheral
device, in terms of the control signals, using the normal I/O
Most of devices are parallel in nature. These devices transfer data simultaneously on data
lines. But parallel data transfer process is very complicated and expensive. Hence in some situations
the serial I/O mode is used where one bit is transferred over a single line at a time. In this type of
transmission parallel word is converted into a stream of serial bits which is known as parallel to serial
conversion. The rate of transmission in serial mode is BAUD, i.e., bits per second. The serial data
transmission involves starting, end of transmission, error verification bits along with the data. Any
serial I/O involves the following concepts.
(a) Interfacing requirements (b) Alphanumeric codes (c) Transmission format (d) Error checks in data
communication (e) Data communication over lines (f) Standards in serial I/O
The microprocessor has to identify the port address to perform read or write operation. Serial
I/O uses only one data line, chip select, read, write control signals.
Data transfer takes place using ASCII code (American standard code for Information
Interchange) which is 7 bit code with 128 combinations. The data can be transmitted by taking various
parameters into consideration such as synchronization or asynchronization, direction of data flow
speed, errors, medium of data transmission etc. In synchronous transmission both transmitter and
receiver operate, in synchronous to each other.
Synchronization used for high speed operations. In asynchronous data transmission data is
transmitted between Start and Stop bits with logic 1 as mark logic 0 as space. In asynchronous we get
around 11 bits for data transmission one start, 8 bits of data, 2 stop bits. A synchronous data
transmission is used for less than 20 Kbits /second transmission.
Fig. 5.7 shows the block diagram of 8251 A. The block diagram shows all the elements of a
programmable chip; it includes the interfacing signals, the control register and the status register. The
functions of various blocks are described below:
(A) Data bus buffer: This 3-state, bidirectional buffer is used to interface the 8251A to the system data
bus. Data is transmitted or received by the buffer upon execution of input and output instruction of
the CPU Command words and status information are also transferred through the data bus buffer. The
command, status and data in and data out are separate 8-bit registers to provide double buffering.
The functional block accepts inputs form the control bus and generates control signals for
overall device operation. It contains the control word register and command word register that store
the various control formats for the device functional definition.
For example
If Baud rate equals 220 Baud
TXC equals 220 Hz in the 1x mode.
TXC equals 3.52 KHz in the 16x mode.
TXC equals 14.08 KHz in the 64x mode.
The falling edge of TXC shifts the serial data out of the
8251A.
INTERFACING STANDARDS
(Ref: Interfacing through Microprocessors by K. Subba Rao, Hi-tech publishers, P. 266)
Serial I/O is used to interface various devices or for connecting various equipment to the
system. Common understanding is necessary among various manufacturers such that a standard
notation is followed for interfacing these components. These standards may be provided by IEEE or by
any standard professional organisation. The serial I/O standards must specify clearly voltage levels,
speed of data transfer, length of cables etc. In serial I/O data can be transmitted as either current or
voltage 20 mA or 60 mA current loops are used if data is transmitted using current. Current flow takes
place when the system is at logic 1. The current flow is stopped when the system is at logic 0. In the
current loop method the signals are relatively noise-free and they are best suited for long distance
transmission.
RS-232 is developed long before which is used for communication between terminals and
modems. Using RS-232C data can be transmitted as voltage. The data terminals equipment and data
communication equipment are used to communicate using RS-232C cable. RS-232C is not compatible
with TTL logic and cannot be used for long distance transmission.
The voltage levels for all RS-232C signals are as follows. A logic high, or mark, is a voltage
between -3V and -15 V under load (-25 V no load). A logic low or space is a voltage between +3 V and
+15 V under load (+ 25 V no load). Voltages such as ±12 V are commonly used.
Figure 14-9 shows the signal names, signal direction, and a brief description for each of the 25
pins denned for RS-232C. For most applications only a few of these pins are used.
Note that the signal direction is specified with respect to the DGE, this convention is part of the
standard. Note that there is both a chassis ground (pin 1) and a signal ground (pin 7). To prevent large
ac-induced ground currents in the signal ground, these two should be connected together only at the
power supply in the terminal or the computer.
The TxD, RxD, and handshake signals shown with common names in Figure 14-9 are the ones most often
used for simple systems. These signals control what is called the primary or forward communications
channel of the modem. Some modems allow communication over a secondary or backward channel,
which operates in the reverse direction from the forward channel and at a much lower baud rate. Pins
12, 13, 14, 16, and 19 are the data and handshake lines for this backward channel. Pins 15, 17, 21, and
24 are used for synchronous data communication.
ii)Block move (with and with out overlapping)
Without overlapping
DATA SEGMENT
X DB 01H,02H,03H,04H,05H ;Initialize Data Segments Memory Locations
Y DB 05 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA ; Initialize DS to point to start of the memory
MOV DS,AX ; set aside for storing of data
MOV CX,05H ; Load counter
LEA SI,X+04 ; SI pointer pointed to top of the memory block
LEA DI,X+04+03 ; 03 is displacement of over lapping, DI pointed to
;the top of the destination block
Before execution
00
00
00
00
00 Y,DI
05
04
03
02
01 X, SI
After execution
05
04
03
02
01
05
04
03
02
01
-6-
With Overlapping
DATA SEGMENT
X DB 01H,02H,03H,04H,05H ; Initialize Data Segments Memory Locations
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA ; Initialize DS to point to start of the memory
MOV DS,AX ; set aside for storing of data
MOV CX,05H ; Load counter
LEA SI,X+04 ; SI pointer pointed to top of the memory block
LEA DI,X+04+03 ; 03 is displacement of over lapping, DI pointed to
;the top of the destination block
UP: MOV BL,[SI] ; Move the SI content to BL register
MOV [DI],BL ; Move the BL register to content of DI
DEC SI ; Update SI and DI
DEC DI
DEC CX ; Decrement the counter till it becomes zero
JNZ UP
MOV AH,4CH
INT 21H
CODE ENDS
END START
DS Before execution
xx
xx
xx DI
xx
xx
05 SI
04
03
02
01 X
DS After execution
xx
xx
05
04
03
-7-
02
01
03
02
01
-8-
iii) Block Interchange
DATA SEGMENT
X DB 01H,02H,03H,04H,05H
Y DB 11H,12H,13H,14H,15H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
MOV CX,05H ; Load the counter
LEA SI,X ; SI pointed to the source location x
LEA DI,Y ; DI pointed to the destination location y
UP: MOV BL,[SI] ; Move the SI content to BL register
MOV AL,[DI] ; Move the DI content to AL register
MOV [SI],AL ; Move AL register content to content of SI
MOV [DI],BL ; Move BL register content to content of DI
INC SI ; Update SI and DI
INC DI
DEC CX ; Decrement the counter till it becomes zero
JNZ UP
MOV AH,4CH
INT 21H
CODE ENDS
END START
DS Before execution
15
14
13
12
11
Y,DI
05
04
03
02
01 X, SI
-9-
DS After execution
05
04
03
02
01
15
14
13
12
11
- 10 -
2) Program involving Arithmetic and logic operations like addition and subtraction of
multi precision numbers
i ) 16 Bit Addition
DATA SEGMENT
NUM DW 1234H, 0F234H
SUM DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,NUM ; First number loaded into AX
MOV BX,0H ; For carry BX register is cleared
ADD AX,NUM+2 ; Second number added with AX
JNC DOWN ; Check for carry
INC BX ; If carry generated increment the BX
DOWN: MOV SUM,AX ; Storing the sum value
MOV SUM+2,BX ; Storing the carry value
MOV AH,4CH
INT 21H
CODE ENDS
END START
- 11 -
ii) 32 Bit addition
DATA SEGMENT
NUM1 DW 0FFFFH,0FFFFH
NUM2 DW 1111H,1111H
SUM DW 4 DUP(0)
dATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,NUM1 ;Move LSB of NUM1 to AX
ADD AX,NUM2 ;Add LSB of NUM2 to AX
MOV SUM,AX ;Store the LSB in SUM
MOV AX,NUM1+2 ; Move MSB of NUM1 to AX
ADC AX,NUM2+2 ; Add MSB of NUM2 to AX
- 12 -
iii) 32 Bit addition using DD directive
DATA SEGMENT
NUM1 DW 12345678H
NUM2 DW 12345678H
SUM DW 3 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
LEA SI,NUM1 ; SI pointed to the of LSB of NUM1
LEA DI,NUM2 ; DI pointed to the of LSB of NUM2
MOV AX,[SI] ; Move the content of SI to AX
ADD AX,[DI] ; Add DI content to AX
MOV CX,[SI+2] ; Move the SI to point MSB of NUM1 and move that
;content to CX
ADC CX,[DI+2] ; Move the DI to point MSB of NUM2 and add
;with carry to CX
JNC DOWN ; Check for carry
MOV SUM+4,01H ; Store the carry in SUM+4
DOWN:MOV SUM,AX ; Store the LSB in SUM
INOUT: 12345678H,12345678H
OUTPUT:2468ACF0H
- 13 -
iv) 16 Bit Subtraction
DATA SEGMENT
NUM DW 4567H,2345H
DIF DW 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME
CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX ; Clearing Carry
CLC
INPUT: 4567H,2345H
OUTPUT:2222
- 14 -
v) 32 Bit Subtraction
DATA SEGMENT
NUM1 DW 2345H,6762H
NUM2 DW 1111H,1111H
DIF DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
LEA SI,NUM1 ; SI pointed to the LSB of NUM1
LEA DI,NUM2 ; DI pointed to the LSB of NUM2
MOV AX,[SI] ; Move the content of SI to AX
MOV BX,[DI] ; Move the content of DI to BX
SUB AX,BX ; Subtract from BX to AX
MOV DIF,AX ; Store the LSB result in DIF
INC SI ;Update SI to point the MSB of NUM1(if
INPUT: 23456762,-11111111
OUTPUT:12345651
INPUT:11111111,-23451234
OUTPUT:EDCBFEDD
- 15 -
Multiplication and Division of signed and unsigned Hexadecimal numbers
vi)16 Bit multiplication for unsigned numbers
DATA SEGMENT
NUM DW 1234H,1234H
PROD DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
LEA SI,NUM ; SI pointed to the Multiplicand
MOV AX,[SI] ; Multiplicand has to be in AX register
DATA SEGMENT
NUM DW -2,1
PROD DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
LEA SI,NUM ; SI pointed to the Multiplicand
MOV AX,[SI] ; Multiplicand has to be in AX register
MOV BX,[SI+2] ; SI+2 pointed to the Multiplier and move it to BX
IMUL BX ; Perform the sign multiplication using sign
;Multiplication operator (IMUL)
MOV PROD,AX ; 32 bit product stored in DX-AX registers
MOV PROD+2,DX
MOV AH,4CH
INT 21H
CODE ENDS
END START
- 17 -
viii)8 Bit Division for Unsigned numbers
DATA SEGMENT
NUM1 DB 72H,
NUM2 DB 02H
QUO DB 1 DUP(0)
REM DB 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AL,NUM1 ;Move the Dividend to AL
MOV AH,0H ; Zero extended for 16 bit/8 bit division
DIV NUM2 ; Perform the Division operation
- 18 -
ix)8 Bit Division for Signed numbers
DATA SEGMENT
NUM1 DB -10
NUM2 DB 02
QUO DB 1 DUP(0)
REM DB 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AL,NUM1 ;Move the Dividend to AL
CBW
IDIV NUM2 ; Perform the Sign Division operation using IDIV operator
MOV QUO,AL ; Store the quotient to AL
MOV REM,AH ;Store the reminder to AH
MOV AH,4CH
INT 21H
CODE ENDS
END START
- 19 -
x)16 Bit Division for Unsigned numbers
DATA SEGMENT
NUM1 DW 4567H,2345H
NUM2 DW 4111H
QUO DW 2 DUP(0)
REM DW 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,NUM1 ;Move the lower bit of Dividend to AX
MOV DX,NUM1+2 ; Move the higher bit of Dividend to DX
DIV NUM2 ; Perform the Division operation
MOV QUO,AX ; Store the quotient to AX
MOV REM,DX ; Store the reminder to DX
MOV AH,4CH
INT 21H
CODE ENDS
END START
- 20 -
xi)16 Bit Division for Signed numbers
DATA SEGMENT
NUM1 DW 4567H,2345H
NUM2 DW 4111H
QUO DW 2 DUP(0)
REM DW 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,NUM1 ; Move the lower bit of Dividend to AX
MOV DX,NUM1+2 ; Move the higher bit of Dividend to DX
CWD
IDIV NUM2 ; Perform the sign Division operation using IDIV
MOV QUO,AX ; Store the quotient to AX
MOV REM,DX ; Store the reminder to DX
MOV AH,4CH
INT 21H
CODE ENDS
END START
- 21 -
3.Code Conversion
CODE SEGMENT
ASSUME CS:CODE
START: MOV AX,31H ;Load ASCII 1
ADD AX,39H ;Load ASCII 9
AAA ;ASCII Adjust, AX=0100 UNPACKED BCD
MOV AH,4CH
INT 21H
CODE ENDS
END START
- 22 -
ii)Binary to BCD code conversion
DATA SEGMENT
BIN DW 01A9H
BCD DB 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA ;Load the Data to AX.
MOV DS,AX ;Move the Data AX to DS.
MOV AX,BIN ;Move the Binary Data to AX.
MOV CL,64H ;100 in decimal
DIV CL ;Perform the division by 100.
MOV BCD+1,AL ;Store the quotient in BCD+1.
MOV AL,AH ;Move the Reminder value to AL.
MOV AH,00H ;Initialize the AH.
MOV CL,0AH ;10 in decimal.
DIV CL ;Perform the division by 10.
MOV CL,04
ROR AL,CL ;Perform the Right side rotation 4 times.
ADD AL,AH ;Adding the Reminder in LSB.
MOV AH,4CH
INT 21H
CODE ENDS
END START
Input: binary--------01A9
Output: bcd------------425
- 23 -
iii)BCD to Binary code conversion
DATA SEGMENT
BCD DW 27H
BIN DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA ;Load the Data to AX.
MOV DS,AX ;Move the Data AX to DS.
MOV AX,BCD ;Move the BCD Data to AX.
AND AX,07H ;Perform the AND operation between
;07H and input BCD
MOV BX,AX ;Move data AX to BX
MOV AX,BCD ;Move the BCD Data to AX.
AND AX,0F0H ;Perform the AND with 0F0H for shifting operation.
MOV CX,0AH ;10 in decimal.
MUL CX ;Perform the multiplication by 10.
ADD AX,BX ;Perform the addition operation to get the LSB.
MOV BIN,AX ;Move the result to binary.
MOV AH,4CH
INT 21H
CODE ENDS
END START
Input: BCD-------------27
Output:------------------1B
- 24 -
4. Arithmetic programs to find square, cube, LCM, GCD and factorial
DATA SEGMENT
X DW 04H
SQUARE DW ?
CUBE DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
CODE ENDS
END START
Input: x ----------- 4h
Output: Square ---------10h
Cube -----------40h
- 25 -
ii)Program to find LCM of a given number
DATA SEGMENT
NUM DW 05,04
LCM DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA ;Load the Data to AX.
MOV DS,AX ;Move the Data AX to DS.
MOV DX,0H ;Initialize the DX.
MOV AX,NUM ;Move the first number to AX.
MOV BX,NUM+2 ;Move the second number to BX.
UP: PUSH AX ;Store the quotient/first number in AX.
PUSH DX ;Store the remainder value in DX.
DIV BX ;Divide the first number by second number.
CMP DX,0 ;Compare the remainder.
JE EXIT ;If remainder is zero, go to EXIT label.
;If remainder is non-zero,
POP DX ;Retrieve the remainder.
POP AX ;Retrieve the quotient.
ADD AX,NUM ;Add first number with AX.
JNC DOWN ;If no carry jump to DOWN label.
INC DX ;Increment DX.
DOWN: JMP UP ;Jump to Up label.
EXIT: POP LCM+2 ;If remainder is zero, store the value at LCM+2.
POP LCM
MOV AH,4CH
INT 21H
CODE ENDS
END START
Input: 0A, 04
Output: 02
- 26 -
iii)Program to find GCD of two numbers
DATA SEGMENT
NUM1 DW 000AH
NUM2 DW 0004H
GCD DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA ;Load the Data to AX.
MOV DS,AX ;Move the Data AX to DS.
MOV AX,NUM1 ;Move the first number to AX.
MOV BX,NUM2 ;Move the second number to BX.
UP: CMP AX,BX ;Compare the two numbers.
JE EXIT ;If equal, go to EXIT label.
JB EXCG ;If first number is below than second,
;go to EXCG label.
UP1:MOV DX,0H ;Initialize the DX.
DIV BX ;Divide the first number by second number.
CMP DX,0 ;Compare remainder is zero or not.
JE EXIT ;If zero, jump to EXIT label.
MOV AX,DX ;If non-zero, move remainder to AX.
JMP UP ;Jump to UP label.
EXCG:XCHG AX,BX ;Exchange the remainder and quotient.
JMP UP1 ;Jump to UP1.
EXIT:MOV GCD,BX ;Store the result in GCD.
MOV AH,4CH
INT 21H
CODE ENDS
END START
Input: 0A,04
Output: 02
- 27 -
iv)Program to find factorial of a given number
DATA SEGMENT
X DW 06H
FACT DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,01H ;Set the value of AX as 01H.
MOV CX,X ;Move the i/p number to CX.
UP: MUL CX ;Perform the Loop multiplication operation.
LOOP UP
MOV FACT,AX ;Store the FACT value.
MOV AH,4CH
INT 21H
CODE ENDS
END START
Input: 06
Output: 2D0H
- 28 -
5.Program involving bit manipulation instruction
DATA SEGMENT
NUM DB 12H
MES1 DB 10,13,'DATA IS POSITIVE $'
MES2 DB 10,13,'DATA IS NEGATIVE $'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AL,NUM ;Move the Number to AL.
ROL AL,1 ;Perform the rotate left side for 1 bit position.
JC NEGA ;Check for the negative number.
CODE ENDS
END START
DATA SEGMENT
X DW 27H
MSG1 DB 19,13,'NUMBER IS EVEN$'
MSG2 DB 10,13,'NUMBER IS ODD$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,X
TEST AX,01H ;Test for Even/Odd number.
JNZ EXIT ;If it is Even go to Exit label.
;(alternate logic)
;MOV BL,2
;DIV BL
;CMP AH,0H
;JNZ EXIT
LEA DX,MSG1 ;Declare it is Even number.
MOV AH,09H
INT 21H
JMP LAST
CODE ENDS
END START
- 30 -
iii) Logical ones and zeros in a given data
DATA SEGMENT
X DB 0AAH
ONE DB ?
ZERO DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AH,X
MOV BL,8 ;Initialize BL to 8.
MOV CL,1 ;Initialize CL to 1.
UP: ROR AH,CL ;Perform the single bit rotate operation
;with respect to right.
JNC DOWN ;If no carry go to DOWN label.
INC ONE ;Increment one.
JMP DOWN1 ;Jump to DOWN1.
DOWN: INC ZERO ;Increment ZERO.
DOWN1: DEC BL ;Decrement the BL.
JNZ UP ;If no zero go to UP label.
MOV AH,4CH
INT 21H
CODE ENDS
END START
Output: Ones--------04
Zeros--------04
- 31 -
iv) 2 out of 5 code
DATA SEGMENT
X DW 82H
MES DB 10,13,'VALID 2 OUT OF CODE $'
MES1 DB 10,13,'NOT A VALID 2 OUT OF CODE $'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA ;Load the Data to AX.
MOV DS,AX ;Move the Data AX to DS.
MOV AX,X ;Move the Data word to AX.
MOV BX,0H ;Initialize the BX.
AND AX,0E0H ;Perform the AND operation of first 3 bit.
JNZ DISP ;If no zero jump to DISP label.
MOV CL,05 ;If zero, Initialize the counter for check the last 5 bit.
MOV AX,X ;Move the Data word to AX.
UP: ROR AX,1 ;Rotate right side one time.
JNC DOWN ;If no carry jump to DOWN label.
INC BX ;Increment the BX.
DOWN:DEC C ;Decrement the counter.
JNC UP ;If no carry jump to UP label.
CMP BX,02H ;Compare the BX with 2.
JNZ DISP ;If no zero jump to DISP label.
LEA DX,MES ;Declared as 2 out of 5 code .
MOV AH,09H
INT 21H
JMP EXIT
DISP: LEA DX,MES1 ;Declared as not valid code .
MOV AH,09H
INT 21H
EXIT:MOV AH,4CH
INT 21H
CODE ENDS
END START
- 32 -
v) Bit wise palindrome
DATA SEGMENT
X DW 0FFFFH
MSG1 DB 10,13,'NUMBER IS PALINDROME$'
MSG2 DB 10,13,'NUMBER IS NOT PALINDROME$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA ;Load the Data to AX.
MOV DS,AX ;Move the Data AX to DS.
MOV AX,X ;Move DW to AX.
MOV CL,10H ;Initialize the counter 10.
UP: ROR AX,1 ;Rotate right one time.
RCL DX,1 ;Rotate left with carry one time.
CODE ENDS
END START
- 33 -
vi) Nibble wise palindrome
DATA SEGMENT
X DW 2662H
TEMP DW 0H
MES DB 10,13,'THE WORD IS NIBBLEWISE PALINDROME $'
MES1 DB 10,13,'THE WORD IS NOT NIBBLEWISE PALINDROME $'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,X
MOV BX,X
MOV CL,04 ;Initialize counter.
AND AX,0000FH ;Perform the and operation between
;last nibble of AX and 000FH.
AND BX,0F000H ;Perform the and operation between
;last nibble of BX and 000FH.
ROL BX,CL ;Rotate left side 4 times the BX.
CMP AX,BX ;Compare AX with BX.
JNZ TER ;If no zero go to TER label.
MOV AX,X ;Move the DW to AX.
ROR AX,CL ;Rotate right side 4 times the AX.
MOV BX,AX ;Move AX to BX.
AND AX,000FH ; Perform the and operation with last nibble.
ROR BX,CL ;Rotate right side 4 times the BX.
AND BX,000FH ;Perform the and operation with last nibble of BX.
CMP AX,BX ;Compare AX with BX.
JNZ TER ;If no zero go to TER label.
MOV AH,09H
LEA DX,MES ;Declared as a PALINDROME.
INT 21H
JMP LAST
TER:MOV AH,09H
LEA DX,MES1 ;Declared as a non palindrome.
INT 21H
LAST:MOV AH,4CH
INT 21H
CODE ENDS
END START
- 34 -
6. PROGRAMS INVOLVING BRANCH/LOOP INSTRUCTIONS / PROGRAMS ON
ARRAYS
i)ADDITION OF n NUMBERS
DATA SEGMENT ;start of data segment
ARR DW 0010H,0020H,0030H,0040H,0050H
LEN EQU ($-ARR)/2
SUM DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
LEA SI,ARR
CLC
XOR AX,AX
MOV CX,LEN
INC SI
INC SI
DEC CX
JNZ UP
MOV SUM,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
OUTPUT: 00F0
- 35 -
;end of data segment ARR ;point to the next data word
;add
;start of code segment the ;decrement Cx
numbe ;and check if all numbers are added
;initialize data segment r if no then add
pointe ;store the addition result in user
;SI points to the LSB of data ARR d by SIdefined memory location sum
;clear carry to A ;terminate the process
;clear AX register registe
;load CX with the number of data words in r ;end of code segment
ii)PROGRAM TO SUBTRACT N NUMBERS
OUTPUT: 0005
- 36 -
PROGRAMS TO FIND LARGEST AND SMALLEST NUMBER
- 37 -
iv)PROGRAM TO FIND THE LARGEST NUMBER USING DOS DISPLAY
INTERRUPTS
DATA SEGMENT ;start of data segment
X DW 0010H,0052H,0030H,0040H,0050H
- 39 -
MOV DL,BL
INT 21H
MOV AH,4CH ;terminate the process
INT 21H
CODE ENDS ;end of code segment
END START
- 40 -
vi)PROGRAM TO SORT THE NUMBERS IN ASCENDING/DESCENDING ORDER
OUTPUT: 09 17 26 34 42
- 41 -
PROGRAMS ON STRING MANIPULATION LIKE STRING TRANSFER, STRING
REVERSING, SEARCHING FOR A CHARACTER IN A STRING AND PALINDROME
ASSUME CS:CODE,DS:DATA,ES:DATA
START: MOV AX,DATA ;initialize data segment
MOV DS,AX
MOV ES,AX ;initialize extra segment for string operations
LEA SI,STR1 ;SI points to starting address of string at
;STR1
LEA DI,STR2 ;DI points to starting address of where the
string has to be transferred
MOV CX,LEN ;load CX with length of the string
CLD ;clear the direction flag for auto increment SI
;and DI
REP MOVSB ;the source string is moved to destination
address till CX=0(after every move CX is
;decremented)
MOV AH,4CH ;terminate the process
INT 21H
CODE ENDS ;end of code segment
END START
- 42 -
viii)PROGRAM TO REVERSE A STRING
ASSUME CS:CODE,DS:DATA,ES:DATA
START: MOV AX,DATA ;initialize data segment
MOV DS,AX
MOV ES,AX ;initialize extra segment for string operations
LEA SI,STR1 ;SI points to the starting address of the string
at STR1
LEA DI,STR2+LEN-1 ;DI points to the address of the last character in
the string(here address of '0')
MOV CX,LEN ;load CX with count value equal to number of
characters in the string
UP: CLD ;clear the direction flag to autoincrement SI
register
LODSB ;load AX with the character pointed SI
register
STD ;set the direction flag to autodecrement DI
register
STOSB ;the contents of AX is stored at the address
pointed by DI
LOOP UP ;decrement CX and continue the transfer till
CX is zero
MOV AH,4CH ;terminate the process
INT 21H
CODE ENDS ;end of code segment
END START
OUTPUT: OLLEH
- 43 -
ix)PROGRAM TO SEARCH FOR A CHARACTER IN A STRING
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:DATA
START: MOV AX,DATA
MOV DS,AX
MOV ES,AX
LEA SI,STR1
LEA DI,STR2+LEN-1
MOV CX,LEN
UP: CLD
LODSB
STD
STOSB
LOOP UP
LEA SI,STR1
LEA DI,STR2
CLD
MOV CX,LEN
REPE CMPSB
CMP CX,0H
JNZ NOTPALIN
LEA DX,MES1
MOV AH,09H
- 45
;end of data segment ;store the character in AL at address
pointed by DI
;start of code segment ;decrement CX and continue with
reversing the string till CX=0
;initialize data segment ;SI points to the starting address of
original string
;initialize extra segment for string ;DI points to the starting address of
operations the string reversed
;SI points to starting address of string
;DI points the last character in the ;set CX as counter for checking if
string palindrome
;load CX with count value equal to ;compare the strings pointed by SI
number of characters in the string and DI
;clear the direction flag to ;do the comparison till CX=0(if
auto increment SI palindrome)
;get the character in AL from the ;if CX is not zero then jump to
address pointed by SI display WORD NOT PALINDROME
;set the direction flag equal to ;display the message at MES1 which
auto decrement DI is WORD IS PALINDROME
INT 21H
JMP EXIT ;jump to end of the program
NOTPALIN: LEA DX,MES2 ;display the message WORD NOT
MOV AH,09H PALINDROME using DOS
INT 21H interrupts
EXIT: MOV AH,4CH ;terminate the process
INT 21H
CODE ENDS ;end of code segment
END START
- 46 -
7.1.Program to use DOS interrupt INT 21H function called for reading a character from
keyboard, buffered keyboard input, display of character and string on console.
DATA SEGMENT
INKEY DB ?
BUF DB 20 DUP(0)
MES DB 10,13, 'DAYANANDA SAGAR COLLEGE OF ENGINEERING $'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE , DS:DATA
- 47 -
2.Creation of a new file
DATA SEGMENT
FILENAME DB'HELLO.NEW'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX,DATA ;initialise data segment
MOV DS,AX
MOV AH,3CH ;dos function call to create
;new file
MOV CX,0 ;CX = file attribute
- 48 -
3.Writing to a file
DATA SEGMENT
MES DB 10,13,'ENTER SOME DATA IN THE FILE$'
FILENAME DB 'HELLO.NEW'
BUFFER DB 22 DUP(0)
MES1 DB 10,13, 'ERROR IN FILE HANDLING$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AH,09H
LEA DX,MES
INT 21H
MOV BUFFER,20
MOV AH,0AH
MOV DX,OFFSET BUFFER
INT 21H
MOV AH,3CH
MOV CX,0
MOV DX,OFFSET FILENAME
INT 21H
MOV BX,AX
MOV AH,40H ;function to write in a file
MOV CX,20
MOV DX, OFFSET BUFFER
INT 21H
JC ERROR
JMP EXIT
ERROR: MOV DX,OFFSET MES1
MOV AH,09H
INT 21H
EXIT: MOV AH,4CH
INT 21H
CODE ENDS
END START
- 49 -
4.Read system date
DATA SEGMENT
YY DB
MM DB
D DB
TDAY DW UN,MON,TUE,WED,THU,FRI,SAT
SUN DB'SUNDAY,$'
MON DB'MONDAY,$'
TUE DB'TUESDAY,$'
WED DB'WEDNESDAY,$'
THU DB'THURSDAY,$'
FRI DB FRIDAY,$'
SAT DB'SATURDAY,$'
TMON DW JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC
JAN DB'JANUARY,$'
FEB DB'FEBRUARY,$'
MAR DB'MARCH,$'
APR DB'APRIL,$'
MAY DB'MAY,$'
JUN DB'JUNE,$'
JUL DB'JULY,$'
AUG DB'AUGUST,$'
SEP DB'SEPTEMBER,$'
OCT DB'OCTOBER,$'
NOV DB'NOVEMBER,$'
DEC DB'DECEMBER,$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
DISCHAR MACRO CHAR
PUSH AX
PUSH DX
MOV DL,CHAR
MOV AH,02
INT 21H
POP DX
POP AX
ENDM
START: MOV AX,DATA
MOV DX,AX
CALL PDATE
- 50 -
MOV AH,4CHH
INT 21H
- 51 -
SKIP: AAM
ADD AX,3030H
DISCHAR AH
DISCHAR AL
RET
PDATE ENDP
CODE ENDS
END START
- 52 -
5.Set System Date
DATA SEGMENT
MES DB 10,13,'ENTER THE DATE WITH FORMAT: DD:MM:YY $'
MES1 DB 10,13,"DATE:$"
BUFF DB 10 DUP(0)
DB 0
DB 10 DUP(0)
YY DB ?
MM DB ?
D DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX,DATA
MOV DS,AX
CALL DATEP
MOV AH,4CH
INT 21H
MOV AH,09H
LEA DX,MES1
INT 21H
MOV AH,0AH
LEA DX,BUFF
INT 21H
MOV CL,04
MOV DL,0H
LEA SI,BUFF
ADD SI,02
BACK: MOV AL,[SI]
CMP AL,':'
JZ TER
ROL DL,CL
SUB AL,30H
- 53 -
ADD DL,AL
INC SI
JMP BACK
- 54 -
ROR DL,CL
MOV AL,10
MUL DL
AND DH,0FH
ADD AL,0DH
MOV YY,AL
MOV AH,2BH
MOV CL,YY
MOV CH,00
ADD CX,2000
MOV DH,MM
MOV DL,0DH
INT 21H
RET
DATEP ENDP
CODE ENDS
END START
- 55 -
6.READ SYSTEM TIME
DATA SEGMENT
HOUR DB ?
MIN DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
MOV DS,AX
CALL TIME
MOV AH,4CH
INT21H
- 56 -
ADD AX,3030H
DISCHAR AH
DISCHAR AL
DISCHAR’ ’
CMP HOUR,12
JB AM
DISCHAR ‘P’
JMP DOWN1
AM: DISCHAR’A’
DOWN1: DISCHAR’M’
RET
TIME ENDP
CODE ENDS
END START
- 57 -
7.Set system time
DATA SEGMENT
MES DB 10,13,’ENTER TIME WITH THE FORMAT :HOUR FOLLOWED BY MIN
FOLLOWED BY AM OR PM$’
MES1 DB 10,13 ,’TIME:$’
BUF DB 10
DB 0
DB 10 DUP(0)
HOUR DB?
MIN DB?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX,DATA
MOV DS,AX
CALL TIME
MOV AX,4CH
INT 21H
- 58 -
AND DL,0F0H
ROR DL,CL
MOV AL,10
MUL DL
AND DH,0FH
ADD AL,DH
MOV HOUR,AL
MOV DL,0
INC SI
UP1: MOV AL,[SI]
CMP AL,’ ’
JZ DOWN1
ROL DL,CL
SUB AL,30H
ADD DL,AL
INC SI
JMP UP1
DOWN1: MOV DH,DL
AND DL,0F0H
ROR DL,CL
MOV AL,10
MUL DL
AND DH,0FH
ADD AL,DH
MOV MIN,AL
INC SI
MOV CH,[SI]
CMP CH,’P’
JNZ SKIP
ADD HOUR,0CH
SKIP: MOV AH,2DH
MOV CH,HOUR
MOV CL,MINUTE
MOV CX,0000H
INT 21H
RET
TIME ENDP
CODE ENDS
END START
- 59 -
8.INTERFACING EXPERIMENTS
1)MATRIX KEYBOARD INTERFACING
DATA SEGMENT
PORTA EQU 120H
PORTC EQU 122H
CWRD EQU 123H
ARRAY DB '0123456789.+-*/%ACK=MMMM'
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX ;initialise data segment
MOV AL,90H ;initialise 8255 porta as i/p and portc as o/p
MOV DX,CWRD
OUT DX,AL
REPEAT: MOV DX,PORTC ;make first row of the keyboard high through pc0
MOV AL,01
OUT DX,AL
MOV DX,PORTA
IN AL,DX ; input contents of porta and check if key is pressed-
CMP AL,00 ; in first row.
JZ NEXT
JMP FIRSTROW
NEXT: MOV DX,PORTC ;if key not found in first row, check if key is in
;second row
MOV AL,02
OUT DX,AL
MOV DX,PORTA
IN AL,DX
CMP AL,00
JNZ SECONDROW
MOV AL,04 ; if key not found then check for key closure in
;third row
MOV DX,PORTC
OUT DX,AL
MOV DX,PORTA
IN AL,DX
CMP AL,00H
JNZ THIRDROW
JMP REPEAT
FIRSTROW: CALL DELAY ;check all the keys one by onein first row
LEA SI,ARRAY
- 60 -
UP: SHR AL,1
JC DISPLAY ;if key found jump to the display subroutine
INC SI
JMP UP
JMP DISPLAY
SECONDROW:CALL DELAY
LEA SI,ARRAY+08H ;second row keys from array +08
UP1:SHR AL,1
JC DISPLAY ;if key found jump to the display subroutine
INC SI
JMP UP1
EXIT:MOV AH,4CH
INT 21H
CODE ENDS
END START
- 61 -
DATA SEGMENT
PORTA EQU 120H
PORTB EQU 121H
PORTC EQU 122H
CWRD EQU 123H
TABLE DB 8CH,0C7H,86H,89H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX,DATA ;intialise data segment
MOV DS,AX
MOV AL,80H ;initialise 8255 portb and portc as o/p
MOV DX,CWRD
OUT DX,AL
MOV BH,04 ; BH = no of digitsto be displayed
LEA SI,TABLE ; SI = starting address of lookup table
OUT DX,AL
DEC AL
MOV DX,PORTC
OUT DX,AL
MOV AL,CH ; get the sevensegment code back in al
DEC CL ;send all 8 bits,thus one digit is displayed
JNZ NEXTBIT
DEC BH
INC SI ;display all the four digits
JNZ NEXTDIGIT
- 62 -
3) LOGICAL CONTROLLER INTERFACE
DATA SEGMENT
PA EQU 120H ;INITIALIZE THE ADDRESS OF PORT A OF 8255
PB EQU 121H ;INITIALIZE THE ADDRESS OF PORT B OF 8255
PC EQU 122H ;INITIALIZE THE ADDRESS OF PORT C OF 8255
CR EQU 123H ;INITIALIZE THE ADDRESS OF CONTROL WORD
REGISTER
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
!"#$%"$#&
5$"<*$<"% !"
5%$<-Z[ !"
.++-Z[ !"
7<&*$#+&5 !#
\]'*<".0'/"(*%5 !$
^'5%,#*+.+& !$
:_`'_:'/.+*8'*+,,%&$5 %&
::'.#&%'*+,,%&$5 %&
'(#)(*+&!
4("#(/.%5 %%
4("#(/.%')%*.("($#+& %'
4("#(/.%'5*+-% %(
,("("-.&!
/0$% %)
#&$ %)
.+&= %)
7.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:58:8=-GV18/5&66;!DD!01:/0!8:8=-G!,8=31
!!/1=8M5%&&&6;!!!!!!!!!!!!!!!!!!!DD!483010!N-I!%!01O-:/
<
01I.8=!Q!'$
Arduino search
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Blog » | Forum » | Playground »
Blink
In most programming languages, the first program you write prints "hello world" to the screen. Since an Arduino board
doesn't have a screen, we blink an LED instead.
The boards are designed to make it easy to blink an LED using digital pin 13. Some (like the Diecimila and LilyPad) have the
LED built-in to the board. On most others (like the Mini and BT), there is a 1 KB resistor on the pin, allowing you to connect
an LED directly. (To connect an LED to another digital pin, you should use an external resistor.)
LEDs have polarity, which means they will only light up if you orient the legs properly. The long leg is typically positive, and
should connect to pin 13. The short leg connects to GND; the bulb of the LED will also typically have a flat edge on this side.
If the LED doesn't light up, trying reversing the legs (you won't hurt the LED if you plug it in backwards for a short period of
time).
Circuit
Code
The example code is very simple, credits are to be found in the comments.
/* Blinking LED
* ------------
*
* turns on and off a light emitting diode(LED) connected to a digital
* pin, in intervals of 2 seconds. Ideally we use pin 13 on the Arduino
* board because it has a resistor attached to it, needing only an LED
*
* Created 1 June 2005
* copyleft 2005 DojoDave <http://www.0j0.org>
* http://arduino.berlios.de
*
* based on an orginal by H. Barragan for the Wiring i/o board
*/
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}
Edit Page | Page History | Printable View | All Recent Site Changes
Arduino search
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Blog » | Forum » | Playground »
Code
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
// here is where you'd put code that needs to be running all the time.
// check to see if it's time to blink the LED; that is, is the difference
// between the current time and last time we blinked the LED bigger than
// the interval at which we want to blink the LED.
if (millis() - previousMillis > interval) {
previousMillis = millis(); // remember the last time we blinked the LED
digitalWrite(ledPin, value);
}
}
Edit Page | Page History | Printable View | All Recent Site Changes
Arduino search
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Blog » | Forum » | Playground »
Button
The pushbutton is a component that connects two points in a circuit when you press it. The example turns on an LED when
you press the button.
We connect three wires to the Arduino board. The first goes from one leg of the pushbutton through a pull-up resistor (here
2.2 KOhms) to the 5 volt supply. The second goes from the corresponding leg of the pushbutton to ground. The third
connects to a digital i/o pin (here pin 7) which reads the button's state.
When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is
connected to 5 volts (through the pull-up resistor) and we read a HIGH. When the button is closed (pressed), it makes a
connection between its two legs, connecting the pin to ground, so that we read a LOW. (The pin is still connected to 5 volts,
but the resistor in-between them means that the pin is "closer" to ground.)
You can also wire this circuit the opposite way, with a pull-down resistor keeping the input LOW, and going HIGH when the
button is pressed. If so, the behavior of the sketch will be reversed, with the LED normally on and turning off when you press
the button.
If you disconnect the digital i/o pin from everything, the LED may blink erratically. This is because the input is "floating" -
that is, it will more-or-less randomly return either HIGH or LOW. That's why you need a pull-up or pull-down resister in the
circuit.
Circuit
Code
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inPin, INPUT); // declare pushbutton as input
}
void loop(){
val = digitalRead(inPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, LOW); // turn LED OFF
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
}
}
Edit Page | Page History | Printable View | All Recent Site Changes
Arduino search
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Blog » | Forum » | Playground »
Debounce
This example demonstrates the use of a pushbutton as a switch: each time you press the button, the LED (or whatever) is
turned on (if it's off) or off (if on). It also debounces the input, without which pressing the button once would appear to the
code as multiple presses. Makes use of the millis() function to keep track of the time when the button is pressed.
Circuit
Code
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
void setup()
{
pinMode(inPin, INPUT);
pinMode(outPin, OUTPUT);
}
void loop()
{
reading = digitalRead(inPin);
// if we just pressed the button (i.e. the input went from LOW to HIGH),
// and we've waited long enough since the last press to ignore any noise...
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
// ... invert the output
if (state == HIGH)
state = LOW;
else
state = HIGH;
digitalWrite(outPin, state);
previous = reading;
}
Edit Page | Page History | Printable View | All Recent Site Changes
Arduino search
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Blog » | Forum » | Playground »
Loop
We also call this example "Knight Rider" in memory to a TV-series from the 80's where the famous David Hasselhoff had an
AI machine driving his Pontiac. The car had been augmented with plenty of LEDs in all possible sizes performing flashy
effects.
Thus we decided that in order to learn more about sequential programming and good programming techniques for the I/O
board, it would be interesting to use the Knight Rider as a metaphor.
This example makes use of 6 LEDs connected to the pins 2 - 7 on the board using 220 Ohm resistors. The first code example
will make the LEDs blink in a sequence, one by one using only digitalWrite(pinNum,HIGH/LOW) and delay(time). The
second example shows how to use a for(;;) construction to perform the very same thing, but in fewer lines. The third and
last example concentrates in the visual effect of turning the LEDs on/off in a more softer way.
Circuit
Code
int timer = 100; // The higher the number, the slower the timing.
int pins[] = { 2, 3, 4, 5, 6, 7 }; // an array of pin numbers
int num_pins = 6; // the number of pins (i.e. the length of the array)
void setup()
{
int i;
for (i = 0; i < num pins; i++) // the array elements are numbered from 0 to num pins - 1
pinMode(pins[i], OUTPUT); // set each pin as an output
}
void loop()
{
int i;
Edit Page | Page History | Printable View | All Recent Site Changes
Arduino search
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Blog » | Forum » | Playground »
Analog Input
A potentiometer is a simple knob that provides a variable resistance, which we can read into the Arduino board as an analog
value. In this example, that value controls the rate at which an LED blinks.
We connect three wires to the Arduino board. The first goes to ground from one of the outer pins of the potentiometer. The
second goes from 5 volts to the other outer pin of the potentiometer. The third goes from analog input 2 to the middle pin of
the potentiometer.
By turning the shaft of the potentiometer, we change the amount of resistence on either side of the wiper which is connected
to the center pin of the potentiometer. This changes the relative "closeness" of that pin to 5 volts and ground, giving us a
different analog input. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and we read
0. When the shaft is turned all the way in the other direction, there are 5 volts going to the pin and we read 1023. In
between, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to
the pin.
Circuit
Code
/*
* AnalogInput
* by DojoDave <http://www.0j0.org>
*
* Turns on and off a light emitting diode(LED) connected to digital
* pin 13. The amount of time the LED will be on and off depends on
* the value obtained by analogRead(). In the easiest case we connect
* a potentiometer to analog pin 2.
*/
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
}
void loop() {
val = analogRead(potPin); // read the value from the sensor
digitalWrite(ledPin, HIGH); // turn the ledPin on
delay(val); // stop the program for some time
digitalWrite(ledPin, LOW); // turn the ledPin off
delay(val); // stop the program for some time
}
Edit Page | Page History | Printable View | All Recent Site Changes
Arduino search
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Blog » | Forum » | Playground »
Fading
Demonstrates the use of analog output (PWM) to fade an LED.
Circuit
Code
void setup()
{
// nothing for setup
}
void loop()
{
for(value = 0 ; value <= 255; value+=5) // fade in (from min to max)
{
analogWrite(ledpin, value); // sets the value (range from 0 to 255)
delay(30); // waits for 30 milli seconds to see the dimming effect
}
for(value = 255; value >=0; value-=5) // fade out (from max to min)
{
analogWrite(ledpin, value);
delay(30);
}
}
Edit Page | Page History | Printable View | All Recent Site Changes
Arduino search
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Blog » | Forum » | Playground »
Knock
Here we use a Piezo element to detect sound, what will allow us to use it as a knock sensor. We are taking advantage of the
processors capability to read analog signals through its ADC - analog to digital converter. These converters read a voltage
value and transform it into a value encoded digitally. In the case of the Arduino boards, we transform the voltage into a value
in the range 0..1024. 0 represents 0volts, while 1024 represents 5volts at the input of one of the six analog pins.
A Piezo is nothing but an electronic device that can both be used to play tones and to detect tones. In our example we are
plugging the Piezo on the analog input pin number 0, that supports the functionality of reading a value between 0 and 5volts,
and not just a plain HIGH or LOW.
The other thing to remember is that Piezos have polarity, commercial devices are usually having a red and a black wires
indicating how to plug it to the board. We connect the black one to ground and the red one to the input. We also have to
connect a resistor in the range of the Megaohms in parallel to the Piezo element; in the example we have plugged it directly
in the female connectors. Sometimes it is possible to acquire Piezo elements without a plastic housing, then they will just look
like a metallic disc and are easier to use as input sensors.
The code example will capture the knock and if it is stronger than a certain threshold, it will send the string "Knock!" back to
the computer over the serial port. In order to see this text you can use the Arduino serial monitor.
/* Knock Sensor
* by DojoDave <http://www.0j0.org>
*
* Program using a Piezo element as if it was a knock sensor.
*
* We have to basically listen to an analog pin and detect
* if the signal goes over a certain threshold. It writes
* "knock" to the serial port if the Threshold is crossed,
* and toggles the LED on pin 13.
*
* http://www.arduino.cc/en/Tutorial/Knock
*/
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
Serial.begin(9600); // use the serial port
}
void loop() {
val = analogRead(knockSensor); // read the sensor and store it in the variable "val"
if (val >= THRESHOLD) {
statePin = !statePin; // toggle the status of the ledPin (this trick doesn't use time cycles)
digitalWrite(ledPin, statePin); // turn the led on or off
Serial.println("Knock!"); // send the string "Knock!" back to the computer, followed by newline
delay(10); // short delay to avoid overloading the serial port
}
}
Edit Page | Page History | Printable View | All Recent Site Changes
Arduino search
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Blog » | Forum » | Playground »
Smoothing
Reads repeatedly from an analog input, calculating a running average and printing it to the computer. Demonstrates the use
of arrays.
Circuit
Code
// Define the number of samples to keep track of. The higher the number,
// the more the readings will be smoothed, but the slower the output will
// respond to the input. Using a #define rather than a normal variable lets
// use this value to determine the size of the readings array.
#define NUMREADINGS 10
int inputPin = 0;
void setup()
{
Serial.begin(9600); // initialize serial communication with computer
for (int i = 0; i < NUMREADINGS; i++)
readings[i] = 0; // initialize all the readings to 0
}
void loop()
{
total -= readings[index]; // subtract the last reading
readings[index] = analogRead(inputPin); // read from the sensor
total += readings[index]; // add the reading to the total
index = (index + 1); // advance to the next index
Edit Page | Page History | Printable View | All Recent Site Changes
Arduino search
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Blog » | Forum » | Playground »
ASCII Table
Demonstrates the advanced serial printing functions by generating a table of characters and their ASCII values in decimal,
hexadecimal, octal, and binary.
Circuit
Code
// ASCII Table
// by Nicholas Zambetti <http://www.zambetti.com>
void setup()
{
Serial.begin(9600);
void loop()
{
Serial.print(number, BYTE); // prints value unaltered, first will be '!'
Output
Edit Page | Page History | Printable View | All Recent Site Changes
Arduino search
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Blog » | Forum » | Playground »
Dimmer
Demonstrates the sending data from the computer to the Arduino board, in this case to control the brightness of an LED. The
data is sent in individual bytes, each of which ranges from 0 to 255. Arduino reads these bytes and uses them to set the
brightness of the LED.
Circuit
Code
int ledPin = 9;
void setup()
{
// begin the serial communication
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop()
{
byte val;
Processing Code
import processing.serial.*;
Serial port;
void setup()
{
size(256, 150);
// Uses the first port in this list (number 0). Change this to
// select the port corresponding to your Arduino board. The last
// parameter (e.g. 9600) is the speed of the communication. It
// has to correspond to the value passed to Serial.begin() in your
// Arduino sketch.
port = new Serial(this, Serial.list()[0], 9600);
// If you know the name of the port used by the Arduino board, you
// can specify it directly like this.
//port = new Serial(this, "COM1", 9600);
}
void draw()
{
// draw a gradient from black to white
for (int i = 0; i < 256; i++) {
stroke(i);
line(i, 0, i, 150);
}
Edit Page | Page History | Printable View | All Recent Site Changes