Microcontrollers and Applications
Microcontrollers and Applications
1.PRE-REQUISITE:
Electronic devices and circuits
Microprocessors
4.COURSE OUTCOMES
Students undergoing this course are able to
Ability to program in assembly language.
Design and implement interfaces between digital and analog hardware.
Understand current applications, trends and new directions in microcontrollers.
Student will be able to apply engineering techniques to real worlds problems by designing solutions
appropriate to the needs.
Ability to design, build and debug systems using combined hardware and software solutions.
5.COURSE CONTENT
UNIT I 8051 Architecture 9
Introduction to 8085 Architecture-Basic organization – 8051 CPU structure – Register file – Interrupts –
Timers – Port circuits – Instruction set – Timing diagram – Addressing modes – Simple Program and Applications-
Introduction to ARM 32 bit controllers.
UNITII Peripherals and Interfacing 9
Typical Bus structure – Bus – memory organization – Timing characteristics – Extended Model and
Memory Interfacing – Polling – Interfacing Basic I/O devices – Analog and Digital interfacing – PWM mode
operation – Serial port application.
UNIT III 8096 Architecture 9
CPU operation – Interrupt structure – Timers – High Speed Input / Output Ports – I/O control and Status
registers – Instruction Set – Addressing Modes – Simple Programming – Queues – Tables and Strings – Stack
Memories – Key Switch – Parsing.
TOTAL : 45periods
MICROCONTROLLERS
It has many instructions to move data between It has few instructions to move data between
memory and CPU memory and CPU
Less number of pins are multifunctional More number of pins are multifunctional
Single memory map for data and code Separate memory map for data and code
(program) (program)
Access time for memory and IO are more Less access time for built in memory and IO.
More flexible in the design point of view Less flexible since the additional circuits which is
residing inside the microcontroller is fixed for a
particular microcontroller
Large number of instructions with flexible Limited number of instructions with few
addressing modes addressing modes
1
RISC AND CISC CPU ARCHITECTURES
Microcontrollers with small instruction set are called reduced instruction set computer (RISC)
machines and those with complex instruction set are called complex instruction set computer
(CISC). Intel 8051 is an example of CISC machine whereas microchip PIC 18F87X is an example of
RISC machine.
RISC CISC
Only load/store instructions are used to access In additions to load and store instructions,
memory memory access is possible with other instructions
also.
2
HARVARD & VON- NEUMANN CPU ARCHITECTURE
Von-Neumann (Princeton architecture) Harvard architecture
Data Program
Data
Memory Memory
Address Bus
Address Bus
It uses single memory space for both It has separate program memory and data
instructions and data. memory
It is not possible to fetch instruction code and Instruction code and data can be fetched
data simultaneously
Execution of instruction takes more machine Execution of instruction takes less machine
cycle cycle
Also known as control flow or control driven Also known as data flow or data driven
computers computers
Simplifies the chip design because of single Chip design is complex due to separate memory
memory space space
3
COMPUTER SOFTWARE
A set of instructions written in a specific sequence for the computer to solve a specific task is called
a program and software is a collection of such programs.
The program stored in the computer memory in the form of binary numbers is called machine
instructions. The machine language program is called object code.
The assembly language program the programmer enters is called source code. The source code
(assembly language) is translated to object code (machine language) using assembler.
Programs can be written in high level languages such as C, C++ etc. High level language will be
converted to machine language using compiler or interpreter. Compiler reads the entire program
and translate into the object code and then it is executed by the processor. Interpreter takes one
statement of the high level language as input and translate it into object code and then executes.
4
The 8051 architecture.
I/O
A0-A7
ALU PSW Port 0
SFR D0-D7
General
A B Purpose I/O
RAM Port 1
I/O
A8-
Port 2 A15
ROM
I/O INT
DPTR CNTR
PC
DPH Port 3 SERIAL
RD/WR
DPL
IE
E
System General IP
ALE Timing purpose PCON
PSEN area SBUF
System SCON
XTAL1 interrupt
Bit addressible TCON
XTAL2 timers area TMOD
RESET Register Bank 3 TL0
Data
Register Bank 2 TH0
buffers
Register Bank 1 TL1
Register Bank 0
Memory TH1
control SFR and
VCC
General Purpose RAM
GND
8051 has 4 K Bytes of internal ROM. The address space is from 0000 to 0FFFh. If the
program size is more than 4 K Bytes 8051 will fetch the code automatically from external
memory.
Accumulator is an 8 bit register widely used for all arithmetic and logical operations.
Accumulator is also used to transfer data between external memory. B register is used along
with Accumulator for multiplication and division. A and B registers together is also called
MATH registers.
5
PSW (Program Status Word). This is an 8 bit register which contains the arithmetic status of
ALU and the bank select bits of register banks.
CY AC F0 RS1 RS0 OV - P
CY - carry flag
AC - auxiliary carry flag
F0 - available to the user for general purpose
RS1,RS0 - register bank select bits
OV - overflow
P - parity
Stack Pointer (SP) – it contains the address of the data item on the top of the stack. Stack
may reside anywhere on the internal RAM. On reset, SP is initialized to 07 so that the default
stack will start from address 08 onwards.
Data Pointer (DPTR) – DPH (Data pointer higher byte), DPL (Data pointer lower byte). This
is a 16 bit register which is used to furnish address information for internal and external
program memory and for external data memory.
Program Counter (PC) – 16 bit PC contains the address of next instruction to be executed.
On reset PC will set to 0000. After fetching every instruction PC will increment by one.
PIN DIAGRAM
Pinout Description
Pins 1-8 PORT 1. Each of these pins can be configured as an input or an output.
Pin 9 RESET. A logic one on this pin disables the microcontroller and clears the contents of
most registers. In other words, the positive voltage on this pin resets the
microcontroller. By applying logic zero to this pin, the program starts execution from
the beginning.
Pins10-17 PORT 3. Similar to port 1, each of these pins can serve as general input or output.
Besides, all of them have alternative functions
6
Pin 10 RXD. Serial asynchronous communication input or Serial synchronous communication
output.
Pin 11 TXD. Serial asynchronous communication output or Serial synchronous
communication clock output.
Pin 12 INT0.External Interrupt 0 input
Pin 13 INT1. External Interrupt 1 input
Pin 14 T0. Counter 0 clock input
Pin 15 T1. Counter 1 clock input
Pin 16 WR. Write to external (additional) RAM
Pin 17 RD. Read from external RAM
Pin 18, 19 XTAL2, XTAL1. Internal oscillator input and output. A quartz crystal which specifies
operating frequency is usually connected to these pins.
Pin 20 GND. Ground.
Pin 21-28 Port 2. If there is no intention to use external memory then these port pins are
configured as general inputs/outputs. In case external memory is used, the higher
address byte, i.e. addresses A8-A15 will appear on this port. Even though memory
with capacity of 64Kb is not used, which means that not all eight port bits are used for
its addressing, the rest of them are not available as inputs/outputs.
Pin 29 PSEN. If external ROM is used for storing program then a logic zero (0) appears on it
every time the microcontroller reads a byte from memory.
Pin 30 ALE. Prior to reading from external memory, the microcontroller puts the lower address
byte (A0-A7) on P0 and activates the ALE output. After receiving signal from the ALE
pin, the external latch latches the state of P0 and uses it as a memory chip address.
Immediately after that, the ALE pin is returned its previous logic state and P0 is now
used as a Data Bus.
Pin 31 EA. By applying logic zero to this pin, P2 and P3 are used for data and address
transmission with no regard to whether there is internal memory or not. It means that
even there is a program written to the microcontroller, it will not be executed. Instead,
the program written to external ROM will be executed. By applying logic one to the EA
pin, the microcontroller will use both memories, first internal then external (if exists).
Pin 32-39 PORT 0. Similar to P2, if external memory is not used, these pins can be used as
general inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when
the ALE pin is driven high (1) or as data output (Data Bus) when the ALE pin is driven
low (0).
Pin 40 VCC. +5V power supply.
10
ADDRESSING MODES
Various methods of accessing the data are called addressing
modes.
1. Immediate addressing.
2. Register addressing.
3. Direct addressing.
4. Indirect addressing.
5. Relative addressing.
6. Absolute addressing.
7. Long addressing.
8. Indexed addressing.
9. Bit inherent addressing.
10. Bit direct addressing.
1. Immediate
addressing.
In this addressing mode the data is provided as a part of instruction itself. In other
words data immediately follows the instruction.
Eg. MOV
A,#30H
ADD A, #83 # Symbol indicates the data is immediate.
2. Register
addressing.
In this addressing mode the register will hold the data. One of the eight general
registers
(R0 to R7) can be used and specified as the operand.
Eg. MOV A,R0
ADD A,R6
R0 – R7 will be selected from the current selection of register bank. The default register bank will be bank
0.
3. Direct addressing
There are two ways to access the internal memory. Using direct address and indirect address.
Using direct addressing mode we can not only address the internal memory but SFRs also. In direct
addressing, an 8 bit internal data memory address is specified as part of the instruction and hence, it can
specify the address only in the range of 00H to FFH. In this addressing mode, data is obtained directly from
the memory.
Eg. MOV A,60h
ADD A,30h
4. Indirect
addressing
The indirect addressing mode uses a register to hold the actual address that will be used in data
movement. Registers R0 and R1 and DPTR are the only registers that can be used as data pointers. Indirect
addressing cannot be used to refer to SFR registers. Both R0 and R1 can hold 8 bit address and DPTR can
hold
16 bit address.
Eg. MOV A,@R0
ADD A,@R1
MOVX A,@DPTR
5. Indexed
addressing.
In indexed addressing, either the program counter (PC), or the data pointer (DTPR)—
is used to hold the base address, and the A is used to hold the offset address. Adding the value of
the base address to the value of the offset address forms the effective address. Indexed addressing
is used with JMP or MOVC instructions. Look up tables are easily implemented with the help of
index addressing.
Eg. MOVC A, @A+DPTR // copies the contents of memory location pointed by the sum of
the
accumulator A and the DPTR into accumulator A.
MOVC A, @A+PC // copies the contents of memory location pointed by the sum
of the accumulator A and the program counter into accumulator A.
6. Relative
Addressing.
Relative addressing is used only with conditional jump instructions. The relative
address, (offset), is an 8 bit signed number, which is automatically added to the PC to make
the address of
the next instruction. The 8 bit signed offset value gives an address range of +127 to —128
locations. The jump destination is usually specified using a label and the assembler calculates
the jump offset accordingly. The advantage of relative addressing is that the program code is
easy to relocate and the address is relative to position in the memory.
Eg. SJMP LOOP1
JC BACK
7. Absolute
addressing
Absolute addressing is used only by the AJMP (Absolute Jump) and ACALL (Absolute
Call) instructions. These are 2 bytes instructions. The absolute addressing mode specifies the
lowest 11 bit of the memory address as part of the instruction. The upper 5 bit of the
destination address are the upper 5 bit of the current program counter. Hence, absolute
addressing allows branching only within the current 2 Kbyte page of the program memory.
Eg. AJMP LOOP1
ACALL LOOP2
8. Long Addressing
The long addressing mode is used with the instructions LJMP and LCALL. These are 3 byte
instructions. The address specifies a full 16 bit destination address so that a jump or a call can be
made to a location within a 64 Kbyte code memory space.
Eg. LJMP FINISH
LCALL DELAY
INSTRUCTION SET.
1. Instruction Timings
The 8051 internal operations and external read/write operations are controlled by the oscillator
clock.
T-state, Machine cycle and Instruction cycle are terms used in instruction timings.
T-state is defined as one subdivision of the operation performed in one clock period. The terms 'T-
state' and 'clock period' are often used synonymously.
Machine cycle is defined as 12 oscillator periods. A machine cycle consists of six states and each
state lasts for two oscillator periods. An instruction takes one to four machine cycles to execute an
instruction. Instruction cycle is defined as the time required for completing the execution of an
instruction. The 8051 instruction cycle consists of one to four machine cycles.
Eg. If 8051 microcontroller is operated with 12 MHz oscillator, find the execution time for the
following four instructions.
1. ADD A, 45H
2. SUBB A, #55H
3. MOV DPTR, #2000H
4. MUL AB
Since the oscillator frequency is 12 MHz, the clock period is, Clock period = 1/12 MHz = 0.08333 µS.
Time for 1 machine cycle = 0.08333 µS x 12 =1 µS.
Instruction No. of machine cycles Execution time
1. ADD A, 45H 1 1 µs
2. SUBB A, #55H 2 2 µs
3. MOV DPTR, #2000H 2 2 µs
4. MUL AB 4 4 µs
2. 8051 Instructions
The instructions of 8051 can be broadly classified under the following headings.
1. Data transfer instructions
2. Arithmetic instructions
3. Logical instructions
4. Branch instructions
5. Subroutine instructions
6. Bit manipulation instructions
d. Move the contents of a memory location to A or A to a memory location using direct and
indirect addressing
i. MOV A, 65H iii. MOV 45H, A
ii. MOV A, @R0 iv. MOV @R1, A
The 8051 can perform addition, subtraction. Multiplication and division operations on 8 bit
numbers.
Addition
In this group, we have instructions to
i. Add the contents of A with immediate data with or without carry.
i. ADD A, #45H
ii. ADDC A, #OB4H
ii. Add the contents of A with register Rn with or without carry.
i. ADD A, R5
ii. ADDC A, R2
iii. Add the contents of A with contents of memory with or without carry using direct and
indirect addressing
i. ADD A, 51H
ii. ADDC A, 75H
iii. ADD A, @R1
iv. ADDC A, @R0
Subtraction
In this group, we have instructions to
i. Subtract the contents of A with immediate data with or without carry.
i. SUBB A, #45H
ii. SUBB A, #OB4H
ii. Subtract the contents of A with register Rn with or without carry.
i. SUBB A, R5
ii. SUBB A, R2
iii. Subtract the contents of A with contents of memory with or without carry using direct and
indirect addressing
i. SUBB A, 51H
ii. SUBB A, 75H
iii. SUBB A, @R1
iv. SUBB A, @R0
Multiplication
MUL AB. This instruction multiplies two 8 bit unsigned numbers which are stored in A and B register.
After multiplication the lower byte of the result will be stored in accumulator and higher byte of result
will be stored in B register.
Eg. MOV A,#45H ;[A]=45H
MOV B,#0F5H ;[B]=F5H
MUL AB ;[A] x [B] = 45 x F5 = 4209
;[A]=09H, [B]=42H
Division
DIV AB. This instruction divides the 8 bit unsigned number which is stored in A by the 8 bit
unsigned number which is stored in B register. After division the result will be stored in
accumulator and remainder will be stored in B register.
Eg. MOV A,#45H ;[A]=0E8H
MOV B,#0F5H ;[B]=1BH
DIV AB ;[A] / [B] = E8 /1B = 08 H with remainder 10H
;[A] = 08H, [B]=10H
When two BCD numbers are added, the answer is a non-BCD number. To get the result in BCD, we
use DA A instruction after the addition. DA A works as follows.
If lower nibble is greater than 9 or auxiliary carry is 1, 6 is added to lower nibble.
If upper nibble is greater than 9 or carry is 1, 6 is added to upper nibble.
Eg 1: MOV A,#23H
MOV R1,#55H
ADD A,R1 // [A]=78
DA A // [A]=78 no changes in the accumulator after da a
Eg 2: MOV A,#53H
MOV R1,#58H
ADD A,R1 // [A]=ABh
DA A // [A]=11, C=1 . ANSWER IS 111. Accumulator data is changed after DA A
INC increments the value of source by 1. If the initial value of register is FFh, incrementing the value
will cause it to reset to 0. The Carry Flag is not set when the value "rolls over" from 255 to 0.
In the case of "INC DPTR", the value two-byte unsigned integer value of DPTR is incremented. If the
initial value of DPTR is FFFFh, incrementing the value will cause it to reset to 0.
DEC decrements the value of source by 1. If the initial value of is 0, decrementing the value will cause
it to reset to FFh. The Carry Flag is not set when the value "rolls over" from 0 to FFh.
Logical Instructions
Logical AND
ANL destination, source: ANL does a bitwise "AND" operation between source and destination,
leaving the resulting value in destination. The value in source is not affected. "AND" instruction
logically AND the bits of source and destination.
ANL A,#DATA ANL A, Rn
ANL A,DIRECT ANL A,@Ri
ANL DIRECT,A ANL DIRECT, #DATA
Logical OR
ORL destination, source: ORL does a bitwise "OR" operation between source and destination,
leaving the resulting value in destination. The value in source is not affected. " OR " instruction
logically OR the bits of source and destination.
ORL A,#DATA ORL A, Rn
ORL A,DIRECT ORL A,@Ri
ORL DIRECT,A ORL DIRECT, #DATA
Logical Ex-OR
XRL destination, source: XRL does a bitwise "EX-OR" operation between source and
destination, leaving the resulting value in destination. The value in source is not affected. " XRL "
instruction logically EX-OR the bits of source and destination.
XRL A,#DATA XRL A,Rn
XRL A,DIRECT XRL A,@Ri
XRL DIRECT,A XRL DIRECT, #DATA
Logical NOT
CPL complements operand, leaving the result in operand. If operand is a single bit then the state of
the bit will be reversed. If operand is the Accumulator then all the bits in the Accumulator will be
reversed.
Rotate Instructions
RR A
This instruction is rotate right the accumulator. Its operation is illustrated below. Each bit is shifted one
location to the right, with bit 0 going to bit 7.
RL A
Rotate left the accumulator. Each bit is shifted one location to the left, with bit 7 going to bit 0
RRC A
Rotate right through the carry. Each bit is shifted one location to the right, with bit 0 going into the carry bit in
the PSW, while the carry was at goes into bit 7
RLC A
Rotate left through the carry. Each bit is shifted one location to the left, with bit 7 going into the carry bit in
the PSW, while the carry goes into bit 0.
Branch (JUMP) Instructions
Relative Jump
Jump that replaces the PC (program counter) content with a new address that is greater than (the
address following the jump instruction by 127 or less) or less than (the address following the jump
by 128 or less) is called a relative jump. Schematically, the relative jump can be shown as follows: -
00 0000 - 07FF
01 0800 - 0FFF
02 1000 - 17FF
03 1800 - 1FFF
.
.
1E F000 - F7FF
1F F800 - FFFF
It can be seen that the upper 5bits of the program counter (PC) hold the page number and the lower
11bits of the PC hold the address within that page. Thus, an absolute address is formed by taking
page numbers of the instruction (from the program counter) following the jump and attaching the
specified 11bits to it to form the 16-bit address.
Applications that need to access the entire program memory from 0000H to FFFFH use long
absolute jump. Since the absolute address has to be specified in the op-code, the instruction length
is 3 bytes (except for JMP @ A+DPTR). This jump is not re-locatable.
Example: -
1. The unconditional jump is a jump in which control is transferred unconditionally to the target location.
a. LJMP (long jump). This is a 3-byte instruction. First byte is the op-code and second and third
bytes represent the 16-bit target address which is any memory location from 0000 to FFFFH
eg: LJMP 3000H
b. AJMP: this causes unconditional branch to the indicated address, by loading the 11 bit address to
0 -10 bits of the program counter. The destination must be therefore within the same 2K blocks.
c. SJMP (short jump). This is a 2-byte instruction. First byte is the op-code and second byte is the
relative target address, 00 to FFH (forward +127 and backward -128 bytes from the current PC
value). To calculate the target address of a short jump, the second byte is added to the PC value
which is address of the instruction immediately below the jump.
2. Conditional Jump instructions.
JBC Jump if bit = 1 and clear bit
JNB Jump if bit = 0
JB Jump if bit = 1
JNC Jump if CY = 0
JC Jump if CY = 1
CJNE reg,#data Jump if byte ≠ #data
CJNE A,byte Jump if A ≠ byte
DJNZ Decrement and Jump if A ≠ 0
JNZ Jump if A ≠ 0
JZ Jump if A = 0
Bit level JUMP instructions will check the conditions of the bit and if condition is true, it jumps to the
address specified in the instruction. All the bit jumps are relative jumps.
JB bit, rel ; jump if the direct bit is set to the relative address specified.
JNB bit, rel ; jump if the direct bit is clear to the relative address specified.
JBC bit, rel ; jump if the direct bit is set to the relative address specified and then clear the bit.
RET instruction
RET instruction pops top two contents from the stack and load it to PC.
g. [PC15-8] = [[SP]] ;content of current top of the stack will be moved to higher byte of PC.
h. [SP]=[SP]-1; (SP decrements)
i. [PC7-0] = [[SP]] ;content of bottom of the stack will be moved to lower byte of PC.
j. [SP]=[SP]-1; (SP decrements again)
8051 has 128 bit addressable memory. Bit addressable SFRs and bit addressable PORT pins. It is possible to
perform following bit wise operations for these bit addressable locations.
1. LOGICAL AND
a. ANL C,BIT(BIT ADDRESS) ; ‘LOGICALLY AND’ CARRY AND CONTENT OF BIT ADDRESS, STORE RESULT IN CARRY
b. ANL C, /BIT; ; ‘LOGICALLY AND’ CARRY AND COMPLEMENT OF CONTENT OF BIT ADDRESS, STORE RESULT IN CARRY
2. LOGICAL OR
a. ORL C,BIT(BIT ADDRESS) ; ‘LOGICALLY OR’ CARRY AND CONTENT OF BIT ADDRESS, STORE RESULT IN CARRY
b. ORL C, /BIT; ; ‘LOGICALLY OR’ CARRY AND COMPLEMENT OF CONTENT OF BIT ADDRESS, STORE RESULT IN CARRY
3. CLR bit
a. CLR bit ; CONTENT OF BIT ADDRESS SPECIFIED WILL BE CLEARED.
b. CLR C ; CONTENT OF CARRY WILL BE CLEARED.
4. CPL bit
a. CPL bit ; CONTENT OF BIT ADDRESS SPECIFIED WILL BE COMPLEMENTED.
b. CPL C ; CONTENT OF CARRY WILL BE COMPLEMENTED.
BASICS OF INTERRUPTS.
During program execution if peripheral devices needs service from microcontroller, device will
generate interrupt and gets the service from microcontroller. When peripheral device activate the
interrupt signal, the processor branches to a program called interrupt service routine. After executing
the interrupt service routine the processor returns to the main program.
ISR will always ends with RETI instruction. The execution of RETI instruction results in the following.
1. IE Register
This is an 8 bit register used for enabling or disabling the interrupts. The structure of IE
register is shown below.
2. IP Register.
This is an 8 bit register used for setting the priority of the interrupts.
TIMERS AND COUNTERS
Timers/Counters are used generally for
Time reference
Creating delay
Wave form properties measurement
Periodic interrupt generation
Waveform generation
8051 has two timers, Timer 0 and Timer 1.
Timer in 8051 is used as timer, counter and baud rate generator. Timer always counts up irrespective
of whether it is used as timer, counter, or baud rate generator: Timer is always incremented by the
microcontroller. The time taken to count one digit up is based on master clock
frequency.
If Master CLK=12 MHz,
Timer Clock frequency = Master CLK/12 = 1 MHz
Timer Clock Period = 1micro second
This indicates that one increment in count will take 1 micro second.
The two timers in 8051 share two SFRs (TMOD and TCON) which control the timers, and each timer
also has two SFRs dedicated solely to itself (TH0/TL0 and TH1/TL1).
TCON Register
Timer/ Counter Control Logic.
TIMER MODES
Timer Mode-1: This mode is similar to mode-0 except for the fact that the Timer operates in 16-bit
mode.
Control bits TR1 and TF1 are used by Timer-0 (higher 8 bits) (TH0) in Mode-3 while TR0 and TF0
are available to Timer-0 lower 8 bits(TL0)
PROGRAMS.
1. Write a program to add the values of locations 50H and 51H and store the result in locations
in 52h and 53H.
2. Write a program to store data FFH into RAM memory locations 50H to 58H using direct
addressing mode
3. Write a program to subtract a 16 bit number stored at locations 51H-52H from 55H-56H and
store the result in locations 40H and 41H. Assume that the least significant byte of data or the
result is stored in low address. If the result is positive, then store 00H, else store 01H in 42H.
ORG 0000H ; Set program counter 0000H
MOV A, 55H ; Load the contents of memory location 55 into A
CLR C ; Clear the borrow flag
SUBB A,51H ; Sub the contents of memory 51H from contents of A
MOV 40H, A ; Save the LSByte of the result in location 40H
MOV A, 56H ; Load the contents of memory location 56H into A
SUBB A, 52H ; Subtract the content of memory 52H from the content A
MOV 41H, ; Save the MSbyte of the result in location 415.
MOV A, #00 ; Load 005 into A
ADDC A, #00 ; Add the immediate data and the carry flag to A
MOV 42H, A ; If result is positive, store00H, else store 0lH in 42H
END
4. Write a program to add two 16 bit numbers stored at locations 51H -52H and 55H-56H and
store the result in locations 40H, 41H and 42H. Assume that the least significant byte of
data and the result is stored in low address and the most significant byte of data or the result
is stored in high address.
5. Write a program to store data FFH into RAM memory locations 50H to 58H using indirect
addressing mode.
ORG 0000H ; Set program counter 0000H
MOV A, #0FFH ; Load FFH into A
MOV RO, #50H ; Load pointer, R0-50H
MOV R5, #08H ; Load counter, R5-08H
Start:MOV @ R O , A ; Copy contents of A to RAM pointed by R0
INC RO ; Increment pointer
DJNZ R5, start ; Repeat until R5 is zero
END
6. Write a program to add two Binary Coded Decimal (BCD) numbers stored at locations 60H
and 61H and store the result in BCD at memory locations 52H and 53H. Assume that the
least significant byte of the result is stored in low address.
13. Write a program to exchange the lower nibble of data present in external memory 6000H and
6001H
OR G 0000H ; Set program counter 00h
MOV DPTR, #6000H ; Copy address 6000H to DP TR
M O V X A , @D P T R ; Copy contents of 60008 to A
M O V R 0 , #4 5 H ; Load pointer, R0=45H
M O V @R O , A ; Copy co nt of A to RAM poi nted by 80
INC D PL ; Increment pointer
M O V X A , @D P T R ; Copy contents of 60018 to A
XC H D A , @R 0 ; Exchange l ower nibbl e of A wit h RAM point ed by RO
14. Write a program to count the number of and o's of 8 bit data stored in location 6000H.
ORG 00008 ; Set program counter 00008
MOV DPTR, #6000h ; Copy address 6000H to DPTR
M O V X A , @D P T R ; Copy number to A
M O V R 0 , #0 8 ; Copy 08 in RO
M O V R 2 , #0 0 ; C o py 00 in R2
M O V R 3 , #0 0 ; C o py 00 in R3
CLR C ; Clear carry flag
BA CK: RLC A ; Rotate A through carry flag
JC N E XT ; If CF = 1, branch to next
I N C R2 ; I f C F = 0 , i n c r e m e n t R 2 AJMP NEXT2
N E XT : I N C R 3 ; If CF = 1, increment R3
N E XT 2 : D JN Z R O , B A C K ; Repeat until RO is zero
END
15. Write a program to shift a 24 bit number stored at 57H-55H to the left logically four places.
Assume that the least significant byte of data is stored in lower address.
ORG 0000H ; Set program counter 0000h
MOV R1,#04 ; Set up loop count to 4
again: MOV A,55H ; Place the least significant byte of data in A
CLR C ; Clear tne carry flag
RLC A ; Rotate contents of A (55h) left through carry
MOV
55H,A
MOV
A,56H
RLC A ; Rotate contents of A (56H) left through carry
MOV
56H,A
MOV
A,57H
RLC A ; Rotate contents of A (57H) left through carry
MOV 57H,A
DJNZ R1,again ; Repeat until R1 is zero
END
Microprocessors and Microcontrollers/Architecture of Microprocessors Lecture Notes
• Computers can be generally classified by size and power as follows, though there
is considerable overlap:
• Personal computer: A small, single-user computer based on a microprocessor.
• In addition to the microprocessor, a personal computer has a keyboard for
entering data, a monitor for displaying information, and a storage device for
saving data.
• Working station: A powerful, single-user computer. A workstation is like a
personal computer, but it has a more powerful microprocessor and a higher-
quality monitor.
• Minicomputer: A multi-user computer capable of supporting from 10 to
hundreds of users simultaneously.
• Mainframe: A powerful multi-user computer capable of supporting many
hundreds or thousands of users simultaneously.
• Supercomputer: An extremely fast computer that can perform hundreds of
millions of instructions per second.
Minicomputer:
• A midsized computer. In size and power, minicomputers lie between workstations
and mainframes.
• A minicomputer, a term no longer much used, is a computer of a size intermediate
between a microcomputer and a mainframe.
• Typically, minicomputers have been stand-alone computers (computer systems
with attached terminals and other devices) sold to small and mid-size businesses
for general business applications and to large enterprises for department-level
operations.
• In recent years, the minicomputer has evolved into the "mid-range server" and is
part of a network. IBM's AS/400e is a good example.
• The AS/400 - formally renamed the "IBM iSeries," but still commonly known as
AS/400 - is a midrange server designed for small businesses and departments in
large enterprises and now redesigned so that it will work well in distributed
networks with Web applications.
• The AS/400 uses the PowerPC microprocessor with its reduced instruction set
computer technology. Its operating system is called the OS/400.
• With multi-terabytes of disk storage and a Java virtual memory closely tied into
the operating system, IBM hopes to make the AS/400 a kind of versatile all-
purpose server that can replace PC servers and Web servers in the world's
businesses, competing with both Wintel and Unix servers, while giving its present
enormous customer base an immediate leap into the Internet.
Workstation:
1) A type of computer used for engineering applications (CAD/CAM), desktop
publishing, software development, and other types of applications that require a
moderate amount of computing power and relatively high quality graphics
capabilities.
• Workstations generally come with a large, high- resolution graphics screen, at
least 64 MB (mega bytes) of RAM, built-in network support, and a graphical user
interface.
• Most workstations also have a mass storage device such as a disk drive, but a
special type of workstation, called a diskless workstation, comes without a disk
drive.
• The most common operating systems for workstations are UNIX and Windows
NT.
• In terms of computing power, workstations lie between personal computers and
minicomputers, although the line is fuzzy on both ends.
• High-end personal computers are equivalent to low-end workstations. And high-
end workstations are equivalent to minicomputers.
• Like personal computers, most workstations are single-user computers. However,
workstations are typically linked together to form a local-area network, although
they can also be used as stand-alone systems.
2) In networking, workstation refers to any computer connected to a local-area
network. It could be a workstation or a personal computer.
• Mainframe: A very large and expensive computer capable of supporting
hundreds, or even thousands, of users simultaneously. In the hierarchy that starts
with a simple microprocessors (in watches, for example) at the bottom and moves
to supercomputer at the top, mainframes are just below supercomputers.
• In some ways, mainframes are more powerful than supercomputers because they
support more simultaneous programs.
• But supercomputers can execute a single program faster than a mainframe. The
distinction between small mainframes and minicomputers is vague, depending
really on how the manufacturer wants to market its machines.
• Microcomputer: The term microcomputer is generally synonymous with
personal computer, or a computer that depends on a microprocessor.
• Microcomputers are designed to be used by individuals, whether in the form of
PCs, workstations or notebook computers.
• A microcomputer contains a CPU on a microchip (the microprocessor), a memory
system (typically ROM and RAM), a bus system and I/O ports, typically housed
in a motherboard.
• Microprocessor: A silicon chip that contains a CPU. In the world of personal
computers, the terms microprocessor and CPU are used interchangeably.
• A microprocessor (sometimes abbreviated µP) is a digital electronic component
with miniaturized transistors on a single semiconductor integrated circuit (IC).
• One or more microprocessors typically serve as a central processing unit (CPU) in
a computer system or handheld device.
• Microprocessors made possible the advent of the microcomputer.
• At the heart of all personal computers and most working stations sits a
microprocessor.
• Microprocessors also control the logic of almost all digital devices, from clock
radios to fuel-injection systems for automobiles.
• Three basic characteristics differentiate microprocessors:
• Instruction set: The set of instructions that the microprocessor can execute.
• Bandwidth: The number of bits processed in a single instruction.
• Clock speed: Given in megahertz (MHz), the clock speed determines how many
instructions per second the processor can execute.
• In both cases, the higher the value, the more powerful the CPU. For example, a 32
bit microprocessor that runs at 50MHz is more powerful than a 16-bit
microprocessor that runs at 25MHz.
• In addition to bandwidth and clock speed, microprocessors are classified as being
either RISC (reduced instruction set computer) or CISC (complex instruction set
computer).
• Supercomputer: A supercomputer is a computer that performs at or near the
currently highest operational rate for computers.
• A supercomputer is typically used for scientific and engineering applications that
must handle very large databases or do a great amount of computation (or both).
• At any given time, there are usually a few well-publicized supercomputers that
operate at the very latest and always incredible speeds.
• The term is also sometimes applied to far slower (but still impressively fast)
computers.
• Most supercomputers are really multiple computers that perform parallel
processing.
• In general, there are two parallel processing approaches: symmetric
multiprocessing (SMP) and massively parallel processing (MPP).
• Microcontroller: A highly integrated chip that contains all the components
comprising a controller.
• Typically this includes a CPU, RAM, some form of ROM, I/O ports, and timers.
• Unlike a general-purpose computer, which also includes all of these components,
a microcontroller is designed for a very specific task - to control a particular
system.
• A microcontroller differs from a microprocessor, which is a general-purpose chip
that is used to create a multi-function computer or device and requires multiple
chips to handle various tasks.
• A microcontroller is meant to be more self-contained and independent, and
functions as a tiny, dedicated computer.
• The great advantage of microcontrollers, as opposed to using larger
microprocessors, is that the parts-count and design costs of the item being
controlled can be kept to a minimum.
• They are typically designed using CMOS (complementary metal oxide
semiconductor) technology, an efficient fabrication technique that uses less power
and is more immune to power spikes than other techniques.
• Microcontrollers are sometimes called embedded microcontrollers, which just
means that they are part of an embedded system that is, one part of a larger device
or system.
• Controller: A device that controls the transfer of data from a computer to a
peripheral device and vice versa.
• For example, disk drives, display screens, keyboards and printers all require
controllers.
• In personal computers, the controllers are often single chips.
• When you purchase a computer, it comes with all the necessary controllers for
standard components, such as the display screen, keyboard, and disk drives.
• If you attach additional devices, however, you may need to insert new controllers
that come on expansion boards.
• Controllers must be designed to communicate with the computer's expansion bus.
• There are three standard bus architectures for PCs - the AT bus, PCI (Peripheral
Component Interconnect ) and SCSI.
• When you purchase a controller, therefore, you must ensure that it conforms to
the bus architecture that your computer uses.
• Short for Peripheral Component Interconnect, a local bus standard developed by
Intel Corporation.
• Most modern PCs include a PCI bus in addition to a more general IAS expansion
bus.
• PCI is also used on newer versions of the Macintosh computer.
• PCI is a 64-bit bus, though it is usually implemented as a 32 bit bus. It can run at
clock speeds of 33 or 66 MHz.
• At 32 bits and 33 MHz, it yields a throughput rate of 133 MBps.
• Short for small computer system interface, a parallel interface standard used by
Apple Macintosh computers, PCs, and many UNIX systems for attaching
peripheral devices to computers.
• Nearly all Apple Macintosh computers, excluding only the earliest Macs and the
recent iMac, come with a SCSI port for attaching devices such as disk drives and
printers.
• SCSI interfaces provide for faster data transmission rates (up to 80 megabytes per
second) than standard serial and parallel ports. In addition, you can attach many
devices to a single SCSI port, so that SCSI is really an I/O bus rather than simply
an interface
• Although SCSI is an ANSI standard, there are many variations of it, so two SCSI
interfaces may be incompatible.
• For example, SCSI supports several types of connectors.
• While SCSI has been the standard interface for Macintoshes, the iMac comes with
IDE, a less expensive interface, in which the controller is integrated into the disk
or CD-ROM drive.
• The following varieties of SCSI are currently implemented:
• SCSI-1: Uses an 8-bit bus, and supports data rates of 4 MBps.
• SCSI-2: Same as SCSI-1, but uses a 50-pin connector instead of a 25-pin
connector, and supports multiple devices. This is what most people mean when
they refer to plain SCSI.
• Wide SCSI: Uses a wider cable (168 cable lines to 68 pins) to support 16-bit
transfers.
• Fast SCSI: Uses an 8-bit bus, but doubles the clock rate to support data rates of 10
MBps.
• Fast Wide SCSI: Uses a 16-bit bus and supports data rates of 20 MBps.
• Ultra SCSI: Uses an 8-bit bus, and supports data rates of 20 MBps.
• Wide Ultra2 SCSI: Uses a 16-bit bus and supports data rates of 80 MBps.
• SCSI-3: Uses a 16-bit bus and supports data rates of 40 MBps. Also called Ultra
Wide SCSI.
• Ultra2 SCSI: Uses an 8-bit bus and supports data rates of 40 MBps.
CP
CPU MEMORY
MEMORY
I/O PORTS
I/O PORTS
Definitions:
• A Digital Signal Processor is a special-purpose CPU (Central Processing Unit)
that provides ultra-fast instruction sequences, such as shift and add, and multiply
and add, which are commonly used in math-intensive signal processing
applications.
• A digital signal processor (DSP) is a specialized microprocessor designed
specifically for digital signal processing, generally in real time.
Digital
– operating by the use of discrete signals to represent data in the form of
numbers.
Signal
– a variable parameter by which information is conveyed through an
electronic circuit.
Processing
– to perform operations on data according to programmed instructions.
Digital Signal processing
– changing or analysing information which is measured as discrete
sequences of numbers.
• Digital signal processing (DSP) is the study of signals in a digital representation
and the processing methods of these signals.
• DSP and analog signal processing are subfields of signal processing.
DAP System
Multiply-accumulate hardware:
• Multiply accumulate is the most frequently used operation in digital signal
processing.
• In order to implement this efficiently, the DSP has an hardware multiplier, an
accumulator with an adequate number of bits to hold the sum of products and at
explicit multiply-accumulate instructions.
• Harvard architecture: in this memory architecture, there are two memory spaces.
Program memory and data memory.
X Y
n n
Multiplier
Product register
2n
ADD / SUB
Accumulator
2n
A MAC
X Y
16 16
Multiplier
32
40
ADD / SUB
40
Guard bits
8 32
Processing Result
unit Data bus
Operands
Status Opcode
Instructions Data / Instructions
Status Opcode
Control unit
Program memory
Instructions
Address
Harvard Architecture
Status Opcode
Control unit
program memory
Instructions
Address
MEMORY Peripheral
Program Data / Data Serial
ROM program DARAM port 1
SARAM Data /
program Serial
DARAM port 2
TDM
Serial port
Program bus Buffered
serial port
Memory Program controller Memory CALU CPU
control Multiplier Timer
Program counter mapped
Multiproc Status/control registers Accumulator Parallel Host
essing registers ACC buffer logic unit port
Auxiliary shifters (PAL) interface
Interrupt Hardware stack Resisters arithmetic
Generation logic Arithmetic
Initialisation logic unit Test /
Oscillator/ Instruction register Unit (ARAU) (ALU) emulation
timer
Data bus
Internal Architecture of the TMS320C5X DSP
• The advantages of DSP are:
Versatility:
• digital systems can be reprogrammed for other applications (at least where
programmable DSP chips are used)
• digital systems can be ported to different hardware (for example a different DSP
chip or board level product)
Repeatability:
• digital systems can be easily duplicated
• digital system responses do not drift with temperature
X1 1 40 Vcc
X2 39 HOLD
2 DMA
RESE OUT 3 38 HLDA
SOD 4 37 CLK ( OUT)
Serial i/p, o/p signals RESET IN
SID 5 36
TRAP 6 35 READY
7
IO / M
RST 7.5 34
RST 6.5 8 33 S1
RST 5.5
9
8085 A 32 RD
INTR 10 31 WR
IN T A 11
30 ALE
AD0 12
29 S0
AD1 13
28 A15
AD2 A14
14 27
AD3 15 26 A13
AD4 25 A12
16
AD5 24 A11
17
AD6 18 23 A10
AD7 19 22 A9
VSS 20 21 A8
INT
SERIAL I / O CONTROL
INTERRUPT CONTROL
8 BIT INTERNAL
DATA BUS
INSTRUCTION
ACCUMU- (8) MULTIPLXER
REGISTER( 8 )
LATOR TEMP REG
(8) R W(8)
E TEMP. REG.
G C REG ( 8 )
B REG ( 8 )
FLAG ( 5) .
S D REG ( 8 )
FLIP FLOPS E REG ( 8 )
E
INSTRUCTION H REG ( 8 ) L REG ( 8 )
ARITHEMETIC L
DECODER AND E
LOGIC UNIT ( ALU) STACK POINTER ( 16 )
MACHINE C
ENCODING PROGRAM COUNTER ( 16 )
(8) T
+5V INCREAMENT / DECREAMENT
ADDRESS LATCH ( 16 )
GND
CLK A 15 – A8
RESET IN
OUT READY RD WR ALE S0 S1 IO / M HOLD HLDA RESET OUT ADDRESS BUS
AD7 – AD0 ADDRESS /
BUFFER BUS
Block Diagram
Flag Registers
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
COMBININATON
B & C, D & E, H&L
Memory
• Program, data and stack memories occupy the same memory space. The total
addressable memory size is 64 KB.
• Program memory - program can be located anywhere in memory. Jump, branch
and call instructions use 16-bit addresses, i.e. they can be used to jump/branch
anywhere within 64 KB. All jump/branch instructions use absolute addressing.
• Data memory - the processor always uses 16-bit addresses so that data can be
placed anywhere.
• Stack memory is limited only by the size of memory. Stack grows downward.
• First 64 bytes in a zero memory page should be reserved for vectors used by RST
instructions.
Interrupts
• The processor has 5 interrupts. They are presented below in the order of their
priority (from lowest to highest):
•
• INTR is maskable 8080A compatible interrupt. When the interrupt occurs the
processor fetches from the bus one instruction, usually one of these instructions:
• One of the 8 RST instructions (RST0 - RST7). The processor saves current
program counter into stack and branches to memory location N * 8 (where N is a
3-bit number from 0 to 7 supplied with the RST instruction).
• CALL instruction (3 byte instruction). The processor calls the subroutine, address
of which is specified in the second and third bytes of the instruction.
• RST5.5 is a maskable interrupt. When this interrupt is received the processor
saves the contents of the PC register into stack and branches to 2CH
(hexadecimal) address.
• RST6.5 is a maskable interrupt. When this interrupt is received the processor
saves the contents of the PC register into stack and branches to 34H
(hexadecimal) address.
• RST7.5 is a maskable interrupt. When this interrupt is received the processor
saves the contents of the PC register into stack and branches to 3CH
(hexadecimal) address.
• TRAP is a non-maskable interrupt. When this interrupt is received the processor
saves the contents of the PC register into stack and branches to 24H
(hexadecimal) address.
• All maskable interrupts can be enabled or disabled using EI and DI instructions.
RST 5.5, RST6.5 and RST7.5 interrupts can be enabled or disabled individually
using SIM instruction.
Reset Signals
• RESET IN: When this signal goes low, the program counter (PC) is set to Zero,
µp is reset and resets the interrupt enable and HLDA flip-flops.
• The data and address buses and the control lines are 3-stated during RESET and
because of asynchronous nature of RESET, the processor internal registers and
flags may be altered by RESET with unpredictable results.
• RESET IN is a Schmitt-triggered input, allowing connection to an R-C network
for power-on RESET delay.
• Upon power-up, RESET IN must remain low for at least 10 ms after minimum
Vcc has been reached.
• For proper reset operation after the power – up duration, RESET IN should be
kept low a minimum of three clock periods.
• The CPU is held in the reset condition as long as RESET IN is applied. Typical
Power-on RESET RC values R1 = 75KΩ, C1 = 1µF.
• RESET OUT: This signal indicates that µp is being reset. This signal can be used
to reset other devices. The signal is synchronized to the processor clock and lasts
an integral number of clock periods.
Serial communication Signal
• SID - Serial Input Data Line: The data on this line is loaded into accumulator bit
7 whenever a RIM instruction is executed.
• SOD – Serial Output Data Line: The SIM instruction loads the value of bit 7 of
the accumulator into SOD latch if bit 6 (SOE) of the accumulator is 1.
DMA Signals
• HOLD: Indicates that another master is requesting the use of the address and data
buses. The CPU, upon receiving the hold request, will relinquish the use of the
bus as soon as the completion of the current bus transfer.
• Internal processing can continue. The processor can regain the bus only after the
HOLD is removed.
• When the HOLD is acknowledged, the Address, Data RD, WR and IO/M lines are
3-stated.
• HLDA: Hold Acknowledge: Indicates that the CPU has received the HOLD
request and that it will relinquish the bus in the next clock cycle.
• HLDA goes low after the Hold request is removed. The CPU takes the bus one
half-clock cycle after HLDA goes low.
• READY: This signal Synchronizes the fast CPU and the slow memory,
peripherals.
• If READY is high during a read or write cycle, it indicates that the memory or
peripheral is ready to send or receive data.
• If READY is low, the CPU will wait an integral number of clock cycle for
READY to go high before completing the read or write cycle.
• READY must conform to specified setup and hold times.
Registers
• Accumulator or A register is an 8-bit register used for arithmetic, logic, I/O and
load/store operations.
• Flag Register has five 1-bit flags.
• Sign - set if the most significant bit of the result is set.
• Zero - set if the result is zero.
• Auxiliary carry - set if there was a carry out from bit 3 to bit 4 of the result.
• Parity - set if the parity (the number of set bits in the result) is even.
• Carry - set if there was a carry during addition, or borrow during
subtraction/comparison/rotation.
General Registers
• 8-bit B and 8-bit C registers can be used as one 16-bit BC register pair. When
used as a pair the C register contains low-order byte. Some instructions may use
BC register as a data pointer.
• 8-bit D and 8-bit E registers can be used as one 16-bit DE register pair. When
used as a pair the E register contains low-order byte. Some instructions may use
DE register as a data pointer.
• 8-bit H and 8-bit L registers can be used as one 16-bit HL register pair. When
used as a pair the L register contains low-order byte. HL register usually contains
a data pointer used to reference memory addresses.
• Stack pointer is a 16 bit register. This register is always
decremented/incremented by 2 during push and pop.
• Program counter is a 16-bit register.
Instruction Set
• 8085 instruction set consists of the following instructions:
• Data moving instructions.
• Arithmetic - add, subtract, increment and decrement.
• Logic - AND, OR, XOR and rotate.
• Control transfer - conditional, unconditional, call subroutine, return from
subroutine and restarts.
• Input/Output instructions.
• Other - setting/clearing flag bits, enabling/disabling interrupts, stack operations,
etc.
Addressing mode
• Register - references the data in a register or in a register pair.
Register indirect - instruction specifies register pair containing address, where
the data is located.
Direct, Immediate - 8 or 16-bit data.
Module 1: learning unit 3
8086 Microprocessor
•It is a 16-bit µp.
•8086 has a 20 bit address bus can access up to 220 memory locations (1 MB).
•It can support up to 64K I/O ports.
•It provides 14, 16 -bit registers.
•It has multiplexed address and data bus AD0- AD15 and A16 – A19.
•It requires single phase clock with 33% duty cycle to provide internal timing.
•8086 is designed to operate in two modes, Minimum and Maximum.
•It can prefetches upto 6 instruction bytes from memory and queues them in order to
speed up instruction execution.
•It requires +5V power supply.
•A 40 pin dual in line package
Minimum and Maximum Modes:
•The minimum mode is selected by applying logic 1 to the MN / MX input pin. This is a
single microprocessor configuration.
•The maximum mode is selected by applying logic 0 to the MN / MX input pin. This is a
multi micro processors configuration.
GND 1 40 VCC
AD14 39 AD15
2
AD13 3 38 A16 / S3
AD12 4 37 A17 / S4
AD11 5 36 A18 / S5
AD10 6 35 A19/S6
AD9 7 34 BHE / S7
____
AD8
AD7
8 8086 33 MN/ MX
AD6
9
10
CPU 32 RD _____ _____
RQ / GT0 ( HOLD)
31 ___ _____
AD5 11 RQ / GT1
AD4
30 ( HLDA)
12 _______ ___
29 LOCK (WR) ____
AD3 13
28 ___ S2 (M / IO )
___
AD2
14 27 S1 (DT / R )
_____
AD1 15 26
AD0 S0 ( DEN )
16 25 ________ QS0 (ALE)
NMI 24 QS1 ( INTA )
17
INTR 18 23 TEST
CLK 19 22
READY
GND 20 21
RESET
Pin Diagram of 8086
VCC GND
INTR
M / IO
MEMORY I
/O
HOLD DMA ____ DT / R
CONTROLS
INTERFACE RD
_____
HLDA
WR
VCC
DEN
MODE
____
SELECT READY
MN / MX
CLK
AH AL
ADDRESS BUS
BH BL ∑
CH CL ( 20 )
GENERAL DH DL BITS
REGISTERS
SP DATA BUS
BP
( 16 )
SI BITS
DI
ES
CS
SS
DS
ALU DATA IP
8
16 BITS 0
BUS 8
6
TEMPORARY REGISTERS CONTR B
OL U
LOGIC S
EU INSTRUCTION QUEUE
ALU CONTROQ BUS
L 1 2 3 4 5 6
SYSTEM
8 BIT
is not requesting it to read or write operands from memory, the BIU is free to look ahead
in the program by prefetching the next sequential instruction.
•These prefetching instructions are held in its FIFO queue. With its 16 bit data bus, the
BIU fetches two instruction bytes in a single memory cycle.
•After a byte is loaded at the input end of the queue, it automatically shifts up through the
FIFO to the empty location nearest the output.
•The EU accesses the queue from the output end. It reads one instruction byte after the
other from the output of the queue. If the queue is full and the EU is not requesting access
to operand in memory.
•These intervals of no bus activity, which may occur between bus cycles are known as
Idle state.
•If the BIU is already in the process of fetching an instruction when the EU request it to
read or write operands from memory or I/O, the BIU first completes the instruction fetch
bus cycle before initiating the operand read / write cycle.
•The BIU also contains a dedicated adder which is used to generate the 20bit physical
address that is output on the address bus. This address is formed by adding an appended
16 bit segment address and a 16 bit offset address.
•For example: The physical address of the next instruction to be fetched is formed by
combining the current contents of the code segment CS register and the current contents
of the instruction pointer IP register.
•The BIU is also responsible for generating bus control signals such as those for memory
read or write and I/O read or write.
EXECUTION UNIT
The Execution unit is responsible for decoding and executing all instructions.
•The EU extracts instructions from the top of the queue in the BIU, decodes them,
generates operands if necessary, passes them to the BIU and requests it to perform the
read or write bys cycles to memory or I/O and perform the operation specified by the
instruction on the operands.
•During the execution of the instruction, the EU tests the status and control flags and
updates them based on the results of executing the instruction.
•If the queue is empty, the EU waits for the next instruction byte to be fetched and shifted
to top of the queue.
•When the EU executes a branch or jump instruction, it transfers control to a location
corresponding to another set of sequential instructions.
•Whenever this happens, the BIU automatically resets the queue and then begins to fetch
instructions from this new location to refill the queue.
Module 1 and learning unit 4:
Signal Description of 8086•The Microprocessor 8086 is a 16-bit CPU available in
different clock rates and packaged in a 40 pin CERDIP or plastic package.
•The 8086 operates in single processor or multiprocessor configuration to achieve high
performance. The pins serve a particular function in minimum mode (single processor
mode) and other function in maximum mode configuration (multiprocessor mode ).
•The 8086 signals can be categorised in three groups. The first are the signal having
common functions in minimum as well as maximum mode.
•The second are the signals which have special functions for minimum mode and third
are the signals having special functions for maximum mode.
• BHE /S7: The bus high enable is used to indicate the transfer of data over the higher
order ( D15-D8 ) data bus as shown in table. It goes low for the data transfer over D15-
D8 and is used to derive chip selects of odd address memory bank or peripherals. BHE is
low during T1 for read, write and interrupt acknowledge cycles, whenever a byte is to be
transferred on higher byte of data bus. The status information is available during T2, T3
and T4. The signal is active low and tristated during hold. It is low during T1 for the first
pulse of the interrupt acknowledges cycle.
BHE A0 Indication
0 0 Whole word
0 1 Upper byte from or to odd
evenaddress
address
1 0 Lower byte from or to even address
1 1 None
• RD Read: This signal on low indicates the peripheral that the processor is performing s
memory or I/O read operation. RD 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 the acknowledgement from the slow device or memory that they have
completed the data transfer. The signal made available by the devices is synchronized by
the 8284A clock generator to provide ready input to the 8086. the signal is active high.
•INTR-Interrupt Request: This is a triggered input. This is sampled during the last
clock cycles 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 resulting the interrupt enable flag. This signal is active
high and internally synchronized.
• TEST This input is examined by a ‘WAIT’ instruction. If the TEST pin goes low,
execution will continue, else the processor remains in an idle state. The input is
synchronized internally during each clock cycle on leading edge of clock.
•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.
•MN/ MX : The logic level at this pin decides whether the processor is to operate in either
minimum or maximum mode.
•The following pin functions are for the minimum mode operation of 8086.
•M/ IO – Memory/IO: This is a status line logically equivalent to S2 in maximum mode.
When it is low, it indicates the CPU is having an I/O operation, and when it is high, it
indicates that the CPU is having a memory operation. This line becomes active high in
the previous T4 and remains active till final T4 of the current cycle. It is tristated during
local bus “hold acknowledge “.
• INTA Interrupt Acknowledge: This signal is used as a read strobe for interrupt
acknowledge cycles. i.e. when it goes low, the processor has accepted the interrupt.
•ALE – Address Latch Enable: 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.
•DT/ R – 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.
•DEN – Data Enable: This signal indicates the availability of valid data over the
address/data lines. It is used to enable the transreceivers ( bidirectional buffers ) to
separate the data from the multiplexed address/data signal. It is active from the middle of
T2 until the middle of T4. This is tristated during ‘ hold acknowledge’ cycle.
•HOLD, HLDA- 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
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 is should be externally synchronized.
•If the DMA request is made while the CPU is performing a memory or I/O cycle, it will
release the local bus during T4 provided:
1.The request occurs on or before T2 state of the current cycle.
2.The current cycle is not operating over the lower byte of a word.
3.The current cycle is not the first acknowledge of an interrupt acknowledge sequence.
•The queue is updated after every byte is read from the queue but the fetch cycle is
initiated by BIU only if at least two bytes of the queue are empty and the EU may be
concurrently executing the fetched instructions.
•The next byte after the instruction is completed is again the first opcode byte of the next
instruction. A similar procedure is repeated till the complete execution of the
program.•The fetch operation of the next instruction is overlapped with the execution of
the current instruction. As in the architecture, there are two separate units, namely
Execution unit and Bus interface unit.
•While the execution unit is busy in executing an instruction, after it is completely
decoded, the bus interface unit may be fetching the bytes of the next instruction from
memory, depending upon the queue status.
QS1 QS0 Indication
0 0 No operation
0 1 First byte of the opcode from the queue
1 0 Empty queue
1 1 Subsequent byte from the queue
• RQ / GT0 , RQ / GT1 – Request/Grant: These pins are used by the other local bus master
in maximum mode, to force the processor to release the local bus at the end of the
processor current bus cycle.
•Each of the pin is bidirectional with RQ/GT0 having higher priority than RQ/GT1.
•RQ/GT pins have internal pull-up resistors and may be left unconnected.
•Request/Grant sequence is as follows:
1.A pulse of 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 cycle. The CPU 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 the 8086 that the hold
request is about to end and the 8086 may regain control of the local bus at the next clock
cycle. Thus each master to master exchange of the local bus is a sequence of 3 pulses.
There must be at least one dead clock cycle after each bus exchange.
•The request and grant pulses are active low.
•For the bus request those are received while 8086 is performing memory or I/O cycle,
the granting of the bus is governed by the rules as in case of HOLD and HLDA in
minimum mode.
General Bus Operation:
•The 8086 has a combined address and data bus commonly referred as a time multiplexed
address and data bus.
•The main reason behind multiplexing address and data over the same pins is the
maximum utilisation of processor pins and it facilitates the use of 40 pin standard DIP
package.
•The bus can be demultiplexed using a few latches and transreceivers, when ever
required.
•Basically, all the processor bus cycles consist of at least four clock cycles. These are
referred to as T1, T2, T3, T4. The address is transmitted by the processor during T1. It is
present on the bus only for one cycle.
•The negative edge of this ALE pulse is used to separate the address and the data or status
information. In maximum mode, the status lines S0, S1 and S2 are used to indicate the
type of operation.
•Status bits S3 to S7 are multiplexed with higher order address bits and the BHE signal.
Address is valid during T1 while status bits S3 to S7 are valid during T2 through T4.
ALE
S2 – S0
A19-A16 S3-S7 A19-A16 S3-S7
Add/stat
BHE Bus reserve BHE
Add/data for Data In Data Out D15 – D0
A0-A15 D15-D0 A0-A15 D15-D0
RD/INTA
Ready
READY Ready
DT/R Wait Wait
DEN
•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 signals.
•They are controlled by two signals namely, DEN and DT/R.
•The DEN signal indicates the direction of data, i.e. from or to the processor. The system
contains memory for the monitor and users program storage.
•Usually, EPROM are used for monitor storage, while RAM for users program storage. A
system may contain I/O devices.
•The working of the minimum mode configuration system can be better described in
terms of the timing diagrams rather than qualitatively describing the operations.
•The opcode fetch and read cycles are similar. Hence the timing diagram can be
categorized in two parts, the first is the timing diagram for read cycle and the second is
the timing diagram for write cycle.
•The read cycle begins in T1 with the assertion of 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 T1 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 address 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 T1, 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 (unlike RD is somewhat delayed in T2 to provide time for floating).
•The BHE and A0 signals are used to select the proper byte or bytes of memory or I/O
word to be read or write.
•The M/IO, RD and WR signals indicate the type of data transfer as specified in table
below.
T1 T2 T3 TW T4 T1
Clk
ALE
BHE S7 – S3
ADD / STATUS A19 – A16
WR
DEN
DT / R
Clk
HOLD
HLDA
Maximum Mode 8086 System •In the maximum mode, the 8086 is operated by
strapping the MN/MX pin to ground.
•In this mode, the processor derives the status signal S2, S1, S0. Another chip called bus
controller derives the control signal using this status information.
•In the maximum mode, there may be more than one microprocessor in the system
configuration.
•The components in the system are same as in the minimum mode system.
•The basic function of the bus controller chip IC8288, is to derive control signals like RD
and WR ( for memory and I/O devices), DEN, DT/R, ALE etc. using the information by
the processor on the status lines.
•The bus controller chip has input lines S2, S1, S0 and CLK. These inputs to 8288 are
driven by CPU.
•It derives the outputs ALE, DEN, DT/R, MRDC, MWTC, AMWC, IORC, IOWC and
AIOWC. The AEN, IOB and CEN pins are specially useful for multiprocessor systems.
•AEN and IOB are generally grounded. CEN pin is usually tied to +5V. The significance
of the MCE/PDEN output depends upon the status of the IOB pin.
•If IOB is grounded, it acts as master cascade enable to control cascade 8259A, else it
acts as peripheral data enable used in the multiple bus configurations.
•INTA pin used to issue two interrupt acknowledge pulses to the interrupt controller or to
an interrupting device.
•IORC, IOWC are I/O read command and I/O write command signals respectively. These
signals enable an IO interface to read or write the data from or to the address port.
•The MRDC, MWTC are memory read command and memory write command signals
respectively and may be used as memory read or write signals.
•All these command signals instructs the memory to accept or send data from or to the
bus.
•For both of these write command signals, the advanced signals namely AIOWC and
AMWTC are available.
•Here the only difference between in timing diagram between minimum mode and
maximum mode is the status signals used and the available control and advanced
command signals.
Clk DEN
S0 DT/ R Control bus
S1 8288 IORC
S2 IOWT
AEN MWTC
Reset Reset S0
Clk IOB
S1 CEN AL MRDC
Generator Clk
S2
RDY 8284 Ready + 5V
8086
CLK
AD6-AD15 A/D Address bus
A16-A19 Latches
A
dd
DT/R bu
BHE A0
DIR
Data CS0H CS0L RD CS WR RD
buffer WR
DEN G Memory Peripheral
Data bus
•R0, S1, S2 are set at the beginning of bus cycle.8288 bus controller will output a pulse
as on the ALE and apply a required signal to its DT / R pin during T1.
•In T2, 8288 will set DEN=1 thus enabling transceivers, and for an input it will activate
MRDC or IORC. These signals are activated until T4. For an output, the AMWC or
AIOWC is activated from T2 to T4 and MWTC or IOWC is activated from T3 to T4.
•The status bit S0 to S2 remains active until T3 and become passive during T3 and T4.
•If reader input is not activated before T3, wait state will be inserted between T3 and T4.
•Timings for RQ/ GT Signals:
The request/grant response sequence contains a series of three pulses. The request/grant
pins are checked at each rising pulse of clock input.
•When a request is detected and if the condition for HOLD request are satisfied, the
processor issues a grant pulse over the RQ/GT pin immediately during T4 (current) or T1
(next) state.
•When the requesting master receives this pulse, it accepts the control of the bus, it sends
a release pulse to the processor using RQ/GT pin.
Clk
ALE
MRDC
DT / R
DEN
Clk
ALE
ADD/STATUS BHE S7 – S3
MWTC or IOWC
DT / R high
DEN
Clk
RQ / GT
•The minimum mode signal can be divided into the following basic groups: address/data
bus, status, control, interrupt and DMA.
•Address/Data Bus: these lines serve two functions. As an address bus is 20 bits long
and consists of signal lines A0 through A19. A19 represents the MSB and A0 LSB. A
20bit address gives the 8086 a 1Mbyte memory address space. More over it has an
independent I/O address space which is 64K bytes in length.
•The 16 data bus lines D0 through D15 are actually multiplexed with address lines A0
through A15 respectively. By multiplexed we mean that the bus work as an address bus
during first machine cycle and as a data bus during next machine cycles. D15 is the MSB
and D0 LSB.
•When acting as a data bus, they carry read/write data for memory, input/output data for
I/O devices, and interrupt type codes from an interrupt controller.
Vcc GND
INTR
A0-A15,A16/S3 – A19/S6
INTA
Interrupt
Address / data bus
interface
TEST
D0 – D15
NMI
8086
MPU ALE
RESET
BHE / S7
M / IO Memory I/O
HOLD controls
DMA DT / R
interface
HLDA RD
WR
Vcc
DEN
Mode select
READY
MN / MX
CLK clock
•Status line S5 reflects the status of another internal characteristic of the 8086. It is the
logic level of the internal enable flag. The last status bit S6 is always at the logic 0 level.
S4 S3 Segment Register
0 0 Extra
0 1 Stack
1 0 Code / none
1 1 Data
•On the other hand, logic 0 at DT/R signals that the bus is in the receive mode. This
corresponds to reading data from memory or input of data from an input port.
•The signal read RD and write WR indicates that a read bus cycle or a write bus cycle is
in progress. The 8086 switches WR to logic 0 to signal external device that valid write or
output data are on the bus.
• On the other hand, RD indicates that the 8086 is performing a read of data of the bus.
During read operations, one other control signal is also supplied. This is DEN ( data
enable) and it signals external devices when they should put data on the bus.
•There is one other control signal that is involved with the memory and I/O interface.
This is the READY signal.
•READY signal is used to insert wait states into the bus cycle such that it is extended by
a number of clock periods. This signal is provided by an external clock generator device
and can be supplied by the memory or I/O sub-system to signal the 8086 when they are
ready to permit the data transfer to be completed.
•Interrupt signals: The key interrupt interface signals are interrupt request (INTR) and
interrupt acknowledge ( INTA).
•INTR is an input to the 8086 that can be used by an external device to signal that it need
to be serviced.
•Logic 1 at INTR represents an active interrupt request. When an interrupt request has
been recognized by the 8086, it indicates this fact to external circuit with pulse to logic 0
at the INTA output.
•The TEST input is also related to the external interrupt interface. Execution of a WAIT
instruction causes the 8086 to check the logic level at the TEST input.
•If the logic 1 is found, the MPU suspend operation and goes into the idle state. The 8086
no longer executes instructions, instead it repeatedly checks the logic level of the TEST
input waiting for its transition back to logic 0.
•As TEST switches to 0, execution resume with the next instruction in the program. This
feature can be used to synchronize the operation of the 8086 to an event in external
hardware.
•There are two more inputs in the interrupt interface: the nonmaskable interrupt NMI and
the reset interrupt RESET.
•On the 0-to-1 transition of NMI control is passed to a nonmaskable interrupt service
routine. The RESET input is used to provide a hardware reset for the 8086. Switching
RESET to logic 0 initializes the internal register of the 8086 and initiates a reset service
routine.
•DMA Interface signals:The direct memory access DMA interface of the 8086
minimum mode consist of the HOLD and HLDA signals.
•When an external device wants to take control of the system bus, it signals to the 8086
by switching HOLD to the logic 1 level. At the completion of the current bus cycle, the
8086 enters the hold state. In the hold state, signal lines AD0 through AD15, A16/S3
through A19/S6, BHE, M/IO, DT/R, RD, WR, DEN and INTR are all in the high Z state.
The 8086 signals external device that it is in this state by switching its HLDA output to
logic 1 level.
Maximum Mode Interface
•When the 8086 is set for the maximum-mode configuration, it provides signals for
implementing a multiprocessor / coprocessor system environment.
•By multiprocessor environment we mean that one microprocessor exists in the system
and that each processor is executing its own program.
•Usually in this type of system environment, there are some system resources that are
common to all processors.
•They are called as global resources. There are also other resources that are assigned to
specific processors. These are known as local or private resources.
•Coprocessor also means that there is a second processor in the system. In this two
processor does not access the bus at the same time.
•One passes the control of the system bus to the other and then may suspend its operation.
•In the maximum-mode 8086 system, facilities are provided for implementing allocation
of global resources and passing bus control to other microprocessor or coprocessor.
INIT
Multi Bus
S0 BUSY
S1 CBRQ
S2 8289 BPRO
LOCK Bus BPRN
CRQLCK
CLK RESB BREQ
Vcc GND SYSB/RESB
ANYREQ CLK AEN IOB BCLK
Status Inputs
CPU Cycles 8288
S2 S1 S0 Command
0 0 0 Interrupt Acknowledge INTA
0 0 1 Read I/O Port IORC
0 1 0 Write I/O Port IOWC, AIOWC
0 1 1 Halt None
1 0 0 Instruction Fetch MRDC
•Base register consists of two 8-bit registers BL and BH, which can be combined together
and used as a 16-bit register BX. BL in this case contains the low-order byte of the word,
and BH contains the high-order byte. BX register usually contains a data pointer used for
based, based indexed or register indirect addressing.
•Count register consists of two 8-bit registers CL and CH, which can be combined
together and used as a 16-bit register CX. When combined, CL register contains the low-
order byte of the word, and CH contains the high-order byte. Count register can be used
in Loop, shift/rotate instructions and as a counter in string manipulation,.
•Data register consists of two 8-bit registers DL and DH, which can be combined
together and used as a 16-bit register DX. When combined, DL register contains the low-
order byte of the word, and DH contains the high-order byte. Data register can be used as
a port number in I/O operations. In integer 32-bit multiply and divide instruction the DX
register contains high-order word of the initial or resulting number.
•The following registers are both general and index registers:
•Stack Pointer (SP) is a 16-bit register pointing to program stack.
•Base Pointer (BP) is a 16-bit register pointing to data in stack segment. BP register is
usually used for based, based indexed or register indirect addressing.
•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 address in string manipulation instructions.
•Destination Index (DI) is a 16-bit register. DI is used for indexed, based indexed and
register indirect addressing, as well as a destination data address in string manipulation
instructions.
Other registers:
•Instruction Pointer (IP) is a 16-bit register.
•Flags is a 16-bit register containing 9 one bit flags.
•Overflow Flag (OF) - set if the result is too large positive number, or is too small
negative number to fit into destination operand.
•Direction Flag (DF) - if set then string manipulation instructions will auto-decrement
index registers. If cleared then the index registers will be auto-incremented.
•Interrupt-enable Flag (IF) - setting this bit enables maskable interrupts.
•Single-step Flag (TF) - if set then single-step interrupt will occur after the next
instruction.
•Sign Flag (SF) - set if the most significant bit of the result is set.
•Zero Flag (ZF) - set if the result is zero.
•Auxiliary carry Flag (AF) - set if there was a carry from or borrow to bits 0-3 in the AL
register.
•Parity Flag (PF) - set if parity (the number of "1" bits) in the low-order byte of the
result is even.
•Carry Flag (CF) - set if there was a carry from or borrow to the most significant bit
during last result calculation.
Addressing Modes
•Implied - the data value/data address is implicitly associated with the instruction.
•Register - references the data in a register or in a register pair.
•Immediate - the data is provided in the instruction.
•Direct - the instruction operand specifies the memory address where data is located.
Memory Organization
The 8051 has two types of memory and these are Program Memory and Data Memory. Program
Memory (ROM) is used to permanently save the program being executed, while Data Memory (RAM)
is used for temporarily storing data and intermediate results created and used during the operation of
the microcontroller. Depending on the model in use (we are still talking about the
8051 microcontroller family in general) at most a few Kb of ROM and 128 or 256 bytes of RAM
is used. However…
All 8051 microcontrollers have a 16-bit addressing bus and are capable of addressing 64 kb memory.
It is neither a mistake nor a big ambition of engineers who were working on basic core development.
It is a matter of smart memory organization which makes these microcontrollers a real “programmers‟
goody“.
Program Memory
The first models of the 8051 microcontroller family did not have internal program memory. It was
added as an external separate chip. These models are recognizable by their label beginning with 803
(for example 8031 or 8032). All later models have a few Kbyte ROM embedded. Even though such an
amount of memory is sufficient for writing most of the programs, there are situations when it is
necessary to use additional memory as well. A typical example are so called lookup tables. They are
used in cases when equations describing some processes are too complicated or when there is no
time for solving them. In such cases all necessary estimates and approximates are executed in
advance and the final results are put in the tables (similar to logarithmic tables).
How does the microcontroller handle external memory depends on the EA pin logic state:
EA=0 In this case, the microcontroller completely ignores internal program memory and executes
only the program stored in external memory.
EA=1 In this case, the microcontroller executes first the program from built-in ROM, then the program
stored in external memory.
In both cases, P0 and P2 are not available for use since being used for data and address
transmission. Besides, the ALE and PSEN pins are also used.
Data Memory
As already mentioned, Data Memory is used for temporarily storing data and intermediate results
created and used during the operation of the microcontroller. Besides, RAM memory built in the
8051 family includes many registers such as hardware counters and timers, input/output ports, serial
data buffers etc. The previous models had 256 RAM locations, while for the later models this number
was incremented by additional 128 registers. However, the first 256 memory
locations (addresses 0-FFh) are the heart of memory common to all the models belonging to the
8051 family. Locations available to the user occupy memory space with addresses 0-7Fh, i.e. first
128 registers. This part of RAM is divided in several blocks.
The first block consists of 4 banks each including 8 registers denoted by R0-R7. Prior to accessing
any of these registers, it is necessary to select the bank containing it. The next memory block (address
20h-2Fh) is bit- addressable, which means that each bit has its own address (0-
7Fh). Since there are 16 such registers, this block contains in total of 128 bits with separate addresses
(address of bit 0 of the 20h byte is 0, while address of bit 7 of the 2Fh byte is 7Fh). The third group
of registers occupy addresses 2Fh-7Fh, i.e. 80 locations, and does not have any special functions or
features.
Additional RAM
In order to satisfy the programmers‟ constant hunger for Data Memory, the manufacturers decided
to embed an additional memory block of 128 locations into the latest versions of the
8051 microcontrollers. However, it‟s not as simple as it seems to be… The problem is that electronics
performing addressing has 1 byte (8 bits) on disposal and is capable of reaching only
the first 256 locations, therefore. In order to keep already existing 8-bit architecture and
compatibility with other existing models a small trick was done.
What does it mean? It means that additional memory block shares the same addresses with
locations intended for the SFRs (80h- FFh). In order to differentiate between these two physically
separated memory spaces, different ways of addressing are used. The SFRs memory locations are
accessed by direct addressing, while additional RAM memory locations are accessed by indirect
addressing.
i.....- ....... ollh&
80l5111llcaoa,,1bCJlej's
(258�,eglill
n)
�···>
Prevloul ...... olthe 805111llcaoa,,.t'OIIIN1
(128� ..
. •
•• ..
c "'
a
...,.
-
ff
• """
"• "-''
. "
""
. ••
•.
• us:e:d:f.o:r
-· SP-eei-al •
.
EU n:cti.o:n
.,
... ----· ·--
egis-ter
•
(SE:Rs:)
"
'
Memory expansion
In case memory (RAM or ROM) built in the microcontroller is not sufficient, it is possible to add two
external memory chips with capacity of 64Kb each. P2 and P3 I/O ports are used for their addressing
and data transmission.
From the user‟s point of view, everything works quite simply when properly connected because most
operations are performed by the microcontroller itself. The 8051 microcontroller has two pins for data
read RD#(P3.7) and PSEN#. The first one is used for reading data from external
data memory (RAM), while the other is used for reading data from external program memory (ROM).
Both pins are active low. A typical example of memory expansion by adding RAM and ROM chips
(Hardward architecture), is shown in figure above.
Even though additional memory is rarely used with the latest versions of the microcontrollers, we
will describe in short what happens when memory chips are connected according to the previous
schematic. The whole process described below is performed automatically.
Similar occurs when it is necessary to read location from external RAM. Addressing is performed
in the same way, while read and write are performed via signals appearing on the control outputs RD
(is short for read) or WR (is short for write).
We have seen that a typical 8051 Microcontroller has 4KB of ROM and 128B of RAM (most modern
8051 Microcontroller variants have 8K ROM and 256B of RAM).
The designer of an 8051 Microcontroller based system is not limited to the internal RAM and ROM
present in the 8051 Microcontroller. There is a provision of connecting both external RAM and ROM i.e.
Data Memory and Program.
The reason for interfacing external Program Memory or ROM is that complex programs written in high –
level languages often tend to be larger and occupy more memory.
Another important reason is that chips like 8031 or 8032, which doesn’t have any internal ROM, have to
be interfaced with external ROM.
A maximum of 64B of Program Memory (ROM) and Data Memory (RAM) each can be interface with the
8051 Microcontroller.
The following image shows the block diagram of interfacing 64KB of External RAM and 64KB of
External ROM with the 8051 Microcontroller.
In this tutorial, we have seen the 8051 Microcontroller Memory Organization, Internal ROM and RAM
and how to interface external ROM and RAM with 8051 Microcontroller.
Aim:
To convert an analog signal to its digital equivalent and read the digital value from one port of AT89C51, write
the same data on to other port to convert it back to analog value.
Components/Software:
1. Atmel 89C51 microcontroller
2. 8051 simulator- Win8051
3. Universal SP3 Programmer
4. Win8051 Simulator and Software to load the code into Universal SP3 Programmer
5. Computer System with Windows 98 or later operating system and RS-232 Cable
6. +5V D.C Power Supply
7. Analog to Digital converter (AD7574), Digital to Analog converter (DAC08)
8. Resistors
9. Capacitors
10. 10 MHz crystal oscillator
11. Signal Generator and CRO
Description:
An analog signal is converted to 8-bit digital value using the ADC chip AD7574. After the conversion is
complete, AD7574 will set pin to high. As (connected to P3.1) pin goes high, chip select pin and
read pin (connected to P3.0) are made low to get valid digital data on to the bus (PORT1).The digital
equivalent data is read from Port 1 and written back to Port 2. Digital data from port 2 is connected to DAC08
to convert it back to analog signal. As soon as data is read from the Port 1, P3.0 is set to start next conversion.
Since analog output of DAC08 is an inverted one, an inverting amplifier (TL081CP) is employed to invert it
back and for the gain adjustment. The details of ICs used are given below.
AD7574:
8-bit resolution Analog to digital converter
Employs successive approximation technique
Microprocessor compatible
Conversion time 15 µ sec
Analog input can vary in between 0 to |-Vref|
DAC08:
8-bit Digital to Analog converter
85 nsec settling time
TL081CP:
Operational amplifier (in present context operating as an inverting amplifier)
Procedure:
1. Write the assembly code in Win8051. Compile and simulate it.
2. Once the code is error free, run it and check output with the Simulator
3. After checking the code in the simulator, the code (file with .HEX extension) is loaded into Atmel 89C51
microcontroller using Universal SP3 Programmer.
4. Now connections are made as shown in the circuit diagram.
5. Switch on the supply and push Reset button.
6. Observe the results.
7. Switch off the supply.
Assembly Code:
Observation:
Both analog signal input and analog output are of same shape with out any distortion with a sampling period
of 15 µ sec.
Conclusion:
An analog signal is converted to digital equivalent using AD7574. Using AT89C51 the resultant digital data is
read from a port and written to other port to convert it back to analog form using DAC08.
Lecture 4
4.1 Introduction
Lectures 2 and 3 have described how a computer’s CPU and memory function indi-
vidually and interact with one another. But as yet no consideration has been given
to methods of getting information in to or out of the computer — without which the
whole exercise is pointless.
Computer Input-Output (I/O) can be described at a number of levels. Layers of soft-
ware protocols build on yet more layers of hardware definition, with the aim, of course,
of isolating those working at one level from (i) having to know detail of what happens
below and (ii) second-guess how the level above will be used. You’ve seen modularity
at work elsewhere to reduce the risk of design error.
Our first aim here is to consider I/O the lowest level in terms of register transfers. We
then move on to consider typical I/O devices in the context of microcontrollers.
The same idea of can be exploited to select a particular device for output or input.
1
4/2 LECTURE 4. INPUT/OUTPUT AND INTERFACING
The idea is sketched in Fig. 4.1(b), which also illustrates that while reading and writing
data to memory is always performed in parallel, I/O to devices can be either parallel or
serial. The former is, of course, has higher bandwidth, but the latter is necessary if the
distance between CPU and device substantial. For many years, such serial communica-
tions were painfully slow, but fast serial links are nowadays available over the Universal
Serial Bus (USB) and IEEE 1394 Firewire.
MAR Decoder
MBR Location
Serial link
MAR Decoder
Serializer Parallelizer
MBR OR IO Register
Parallel link
CPU Device (b)
Figure 4.1: (a) A CPU selecting and transferring data to a particular register in memory shares much in
common with (b) a CPU doing the same with a particular device.
4.3 Buses
In a desktop PC, the bus typically consists of 50 to 100 separate lines in the three
functional groups of address, data and control, and made accessible on the computer’s
motherboard via slots. The example shown in Fig. 4.2(b) is an ISA bus (now obsolete,
but chosen for the clarity of the picture).
A microcontroller will have the same buses, but there is no equivalent motherboard —
buses, memory and i/o devices are usually held within a single IC package.
The design of buses is made awkward by the intricacies of timing. Not only do different
devices have different speeds of operation, but transport delay accumulates from
• logic or propagation delay — the time spent between input and output changes in
a gate, say 3–6 ns.
• capacitive delay√— around 0.08 ns pF−1 , with delays of 5 ns typical.
• transit time — LC where L and C are the inductance and capacitance per unit
length — is around 6 ns m−1 .
4.4. STRATEGIES FOR I/O 4/3
Control Bus
Data Bus
Address Bus
Figure 4.2: (a) Address, Control and Data buses schematically. In many computers the buses are made
accessible using connectors into which cards are slotted.
There are two major design approaches to bus timing. Synchronous design requires
devices to respond within a specified time with no continuous checks of whether the
device did receive the data. This is fast, but not suitable when a mix of fast and slow
devices sit on the bus. In asynchronous design, devices are considered to have their
own clocks, and they a treated as separate RTL modules. The CPU and IO device then
has to negotiate transmission and receipt using two control bus signals that continually
monitor readiness to send and received data.
(It is rather dry material, but if you are interested there is a further note on the course
website.)
Polled Interrupt−
I/O driven I/O
Figure 4.3: Some types of I/O, in something of a hierarchy. Don’t read this too rigidly – some might
put Interrupt-drive as a fourth branch at the top-level.
Consider the set of 8 I/O registers that sit on a special port address bus and special
port data bus, as shown in Fig. 4.4(a). Our special address bus would need just three
lines, and a 3-8 line decoder would determine which register to transfer to or from.
In practice there is no need to group the registers together physically. As illustrated in
Fig. 4.4(b), they can sit separately on the bus — here as registers belonging to three
separate devices occupying three slots.
3 5
Port 3
4
address 3
space
2
1 2 7
0 1 4 6
0 3 5
16 16
24 3 3 3
CS 2 7
1 1 4 6
0 0 3 5
Data 16
USEmem/USEport
Figure 4.5: Port-mapped I/O registers can sit on the main buses, but there must be a control level that
determines whether to use main memory or the ports.
A further requirement is that each IO register is readable and writeable both by the
cpu and by the external peripheral. Such devices are called “dual-ported” registers or,
when grouped in numbers, dual-ported RAM. One might imagine making a Dual-ported
RAM from a Single-ported RAM with multiplexers on both the address and data lines.
Commercial devices are much more sophisticated, allowing simultaneous reading from
the same address, and simultaneous reading and writing from different addresses.
4/6 LECTURE 4. INPUT/OUTPUT AND INTERFACING
Usually a peripheral device will require several port addresses, some for the transfer
of “proper” data, and others for the transfer of status information about the device.
Status information is used inter alia to implement another level of handshaking (see
later). In Fig. 4.6 we assume that 12 address lines (of our usual 24) are used to address
212 ≡4K I/O registers, 2 Bytes wide.
28F
Decoder
Decoder
DP
Main Device
IO
Memory Registers
000000 000
Data
USEmem USEport
Control
IOR
IOW
Figure 4.6: Port address space with 212 locations 0 to FFF in hex.
CPU’s that support port-mapping are equipped with IN and OUT instructions. For
example:
LDA # 0 x9A80 ;; get 9 A80 hex into accumulator
OUT 0 x28F ;; and send it to port with address 0 x28F
In Fig. 4.6, it is assumed that the IN and OUT instruction generate CS Levels IOR and
IOW, respectively, so
R/W by peripherals
I/O registers
Memory
address I/O registers
space
R/W by
peripherals
Main 24 24 24
Memory Main
Memory I/O registers I/O registers
(a) (b)
Figure 4.7: Memory mapped I/O. (a) IO-memory is in the memory address space. The physical layout
in (b) indicates that io memory and main memory are physically distinct, and plug separately into the
address and data buses.
• Microcontrollers typically have a relatively small address space (remember the 218
figure). This can rather easily be filled with physical main memory, leaving no
room for I/O registers.
• More crucial is the cost of decoding. In port-mapped I/O only the port address
lines require decoding, whereas in memory-mapped I/O all the main-memory’s
address lines require decoding.
For example, suppose we just have 8 I/O registers.
– In port-mapped I/O, each IO device only has to decode 3 lines to determine
whether it is being addressed, whereas
4/8 LECTURE 4. INPUT/OUTPUT AND INTERFACING
Peripheral
Emptied
slowly
Filled Slow
quickly part of
...
device
FIFO buffer
Obviously, the buffer must be bigger than the volume of data that might be output in
4.6. SCHEDULING I/O 4/9
one burst, but even this is not robust. To ensure no data is lost the IOdevice must, at
very least, have a bit in its device status word that indicates to the CPU whether it is
READY or NOTREADY to receive data.
This then would seem to require handshaking at, or at least involving, the I/O software
level. We consider two ways of coordinating handshaking at this higher level, Polling
and Interrupts.
4.6.3 Polling
Polling is a simple, but often simplistic, software solution to determine whether a
device is ready to receive (or transmit) data. The CPU regularly check the status of
the device by reading the status bit (or word, if there are several bits).
As an example, the following code transfers 100 word of data from a array in memory
(starting at location 0x200) to a device whose status is checked by polling.
The output device is port-mapped at port 500 and its status bits are at location 501.
LDA #200 ; Load base address into AC
STA 22 ; Loc22 hold address of array element
LOOP : IN 501 ; read device status word
AND #1 ; is the lowest bit equal to 1?
BZ LOOP ; if not , jump to LOOP
LDA (22) ; Load contents of array location
OUT 500 ; write them to device
LDA 22 ; Load and
ADD #1 ; increment the location
STA 22 ; and store it back
SUB #300 ; Have we gone too far ?
BNZ LOOP ; If not , carry on looping
However this is obviously inefficient. Three instructions at the core of the polling loop
get executed over and over.
How wasteful could this be? Suppose the IO device handles some 1000 Bytes per
second. To handle one Byte takes 10−3 s. A 2 GHz CPU taking 4 cycles per instruction
will take (3 ∗ 4)/2 × 109 ≈ 10−8 secs to handle compute the polling loop, and so the
polling loop will execute approx 105 times while waiting for the device to be ready again!
Such inefficiency may be of no concern for an embedded microcontroller performing
the simplest of tasks. For example, no-one cares that the microcontroller in a cash-
dispenser is wasting its time waiting for your next button press — after all, what else
would it do? (No, don’t speculate.) However, if there is serious computation to be
done in a real time system, it matters a great deal.
4/10 LECTURE 4. INPUT/OUTPUT AND INTERFACING
Ready? Ready?
No No
Yes Yes
Transfer data Transfer data
to device to device
(a) (b)
Figure 4.9: (a) Basic polling. (b) An attempt to poll while getting on with other useful tasks.
One way of mitigating the gross waste of Fig. 4.9(a) is to attempt to do something
useful between polls, as in Fig. 4.9(b). However, this relies on the program (and hence
programmer) ensuring that a device is checked sufficiently often — a miserable task
in a system where the various useful tasks take different times, and where there are
several devices with differing I/O rates.
If software alone cannot solve the problem, we must return to hardware. Rather than
one-to-monitoring, a better approach is to allow devices to signal in hardware to the
CPU that they require attention.
This is the basis of interrupt-driven I/O, in which the peripheral literally interrupts
the processor from its usual grind through the programmed instructions.
Elsewhere and already resident in the program memory are a set of interrupt service
subroutines, each of which contains the instructions to handle a particular sort of
interrupt. When the interrupt is detected (on the interrupt request (IRQ) control
line), the processor stops executing its currently programmed instructions, jumps to
execute the appropriate subroutine and, once completed, returns to carry on with the
programmed instructions.
There are various things that need to be done when an interrupt is received.
4.6. SCHEDULING I/O 4/11
Figure 4.10:
Care has to be taken not to get deluged by interrupts. A devices interrupts with
particular “priority” n, and when an interrupt at priority n is being dealt with, interrupts
at priority ≤ n are blocked. This doesn’t cancel the interrupt request, but simply
prevents it getting through. However, the most urgent form of interrupt is “non-
maskable”. These are usually associated with system functions affecting the machine’s
well-being. (Further reading in Clements: Principles of Computer Hardware.)
1
Nobody expects the Spanish Inquisition.
4/12 LECTURE 4. INPUT/OUTPUT AND INTERFACING
4.7 Microcontrollers
We are now in a position to appreciate the architecture of a typical microcontroller
which integrates on a single chip
• CPU,
• Memory (ROM, RAM and (E)EPROM),
• IO Ports (digital and A/D, pulse, serial/parallel comms, etc),
• IO interrupt control,
• Timers, and
• Internal buses to connect the components.
You might like to think about the changes you would need to make to our BSA to use
separate Program and Data Memories.
External bus
Clock
Program Data
CPU Memory Memory
(EPROM) (RAM)
Figure 4.11: A microcontroller with a Harvard architecture, where program and data memory are separate
(as used, eg, in the PIC family of micro-controllers).
Now we consider devices which might be connected to the I/O ports — not printers
and the like (most texts will discuss in some detail devices such as keyboards, printers
and disks), but devices used as part of a general engineering system for data acquisition
and control output.
4.8. INTERFACING FOR REAL-TIME CONTROL 4/13
Output
Plant
Sensors
Enable
Data
Address
Control
Figure 4.12: The plant’s output is sensed and assumed to be turned into a binary (0/1) input.
In Fig. 4.12 the plant’s output is sensed and assumed to be turned into a binary (0/1)
input, which is clocked into a register. Note that as only the peripheral writes to the
register, and only the CPU reads from the register, it does not even need to be Dual
Ported! So a 74273 Octal D-type flip-flop with Clear would do. The CPU reads the
register by putting its PortAddress onto the Address Bus, and clocking its contents
into the MBR. The Enable line is derived from the IOR level mentioned earlier.
4/14 LECTURE 4. INPUT/OUTPUT AND INTERFACING
OR’ing with 0x80 ensures that bit 7 is switched ON, but leaves the other outputs
unchanged.
PLANT
WRITE
Data
Address
Control (a)
8 Q7 +
data
Output −
Select register
Solid
Q0 state
relay
Write D−type
reset (b)
Figure 4.13: (a) Simple digital output. (b) Relay control for switching a large current.
4.8. INTERFACING FOR REAL-TIME CONTROL 4/15
Sample
Analogue
Sensor
Figure 4.14:
Vref Vsh
Vin
Vsh
6
Sample
V
Vin 5 3−bit binary
output
Vsh
4
8−3
priority
encoder
3
t 1
Hold
Track 0
gnd
Figure 4.15:
4/16 LECTURE 4. INPUT/OUTPUT AND INTERFACING
Sample
Select
DAC
Sample
DAC
VZOH
R R R 2R
Vref
10V
2R 2R 2R 2R
8 4 2 1
MSB LSB
Figure 4.16: DAC interface, and R-2R ladder for D/A conversion.
The IO interface merely allows several DACs to be handled easily. The address will
select both the Interface and the particular DAC, and the Digital o/p is written from
the AC to the output port, and thence to the DAC. Within the DAC, the Data bits set
the switches in an R-2R ladder. On the output side of the DAC is a Zero-order-hold,
which is a sample an hold device which ensures the DAC analogue output stays at a
fixed value until the next conversion.
4.9. DIGITAL CONTROL SYSTEM 4/17
Figure 4.17:
Aside from this subtraction, what computations are done in the computer box?
That is the subject of the lectures on control, but, as a foretaste of heaven to come,
consider in the time domain the commonly used (and abused) PID controller.
Its output is the sum of terms which are proportional to the error, the error’s integral
and the error’s derivative.
Z
1
c(t) = K e(t) + e(t)dt + Td ė(t)
Ti
Differentiate both sides to get rid of the integral
1
ċ(t) = K ė(t) + e(t) + Td ë(t)
Ti
4/18 LECTURE 4. INPUT/OUTPUT AND INTERFACING
The constants depend on the problem in hand (as you will learn).
The important thing here is that there is causal recipe for updating the output, using
stored values of
and
Microcontroller
Contents
•Introduction
•Inside 8051
•Instructions
•Interfacing
Introduction
• Definition of a Microcontroller
• Difference with a Microprocessor
• Microcontroller is used where ever
Definition
• It is a single chip
• Consists of Cpu, Memory
• I/O ports, timers and other peripherals
Difference
CPU
CPU MEMORY
MEMORY
Where ever
• Small size
• Low cost
• Low power
Architecture
•Harvard university
The Architecture given by Harvard University has the following advantages:
1: Data Space and Program Space are distinct
2: There is no Data corruption or loss of data
Disadvantage is:
1: The circuitry is very complex.
Features
• 8 bit cpu
• 64k Program memory (4k on chip)
• 64k Data memory
• 128 Bytes on chip
• 32 I/O
• Two 16 bit timers
• Full duplex UART
• 6 Source/5 Vector interrupts with two level priority levels
• On chip clock Oscillator.
Block Diagram
External Interrupts
4k On chip
Interrupt ETC Counter inputs
flash
control
128 Bytes Timer 1
RAM Timer 0
CPU
Memory Architecture
FFFFH:
EXTERNAL
EXTERNAL
INTERNAL
FFH:
EA=0 EA=1
EXTERNAL INTERNAL 0000H:
00
0000
RD WR
PSEN
SFR Map
Internal Memory
7FH
Scratch Pad
30H
Bit Memory
20H
Bank 3 (R0-R7)
18H
Bank 2 (R0-R7)
10H
Bank 1 (R0-R7)
08H
Bank 0 (R0-R7)
00H
Pin connections
T R
SS SS
XX T1T1 T2T2 EPA0-3
Po Po Po Po PoPo Po
CC DD
DD C DI C DI or HSIO
rt rt rt rt rt rt rt
0 L R L R 0 1 2 3 4 5 6
KR Only K K KR
MSC 96 Block Diagram
RALU Memory Controller
Master PC 6-bit loop
counter Bus controller
CPU
Upper word 2nd operand
register Register MUX
Register
File Lower word Constants
register 4 byte Slave Addr Data
Queue PC Reg. Reg.
Program Bit select
Register status word
RAM register
MUX Instruction
reg.
A B Micro code
Code PSW Engine
SFRs Control ALU
CPU control and
Status Signals Interrupt
Controller
16
CPU Buses 8
Block Diagram of Register File, RALU, Memory Controller and Interrupt Controller
Instruction Format
8096 Peripherals
• Standard I/O Ports – The 8096 has five 8 bit I/O ports.
• Port 0 is an input port that is also the analog input for the A/D converter.
• Port 1 is a quasi-bidirectional port.
• Port 2 contains three types of port lines.
• Quasi-Bidirectional, input and output. Other functions on the 8096 share the input
and output lines with Port 2.
• Port 3 and 4 are open-drain bidirectional ports that share their pins with the
address/data bus.
• Timers – The 8096 has two 16 bit timers. Timer 1 and Timer 2.
• An internal clock increments the Timer 1 value every 8 state times. (A state time
is 3 oscillator periods)
• An external clock increments Timer 2 on every positive and negative transition.
• Either an internal or external source can reset Timer 2.
• This two timers can generate an interrupt when crossing the 0FFFFH/0000H
boundary.
• The 8096 includes separate, dedicated timers for serial port baud rate generator
and watchdog timer.
• The watchdog Timer is an internal timer that resets the system if the software fails
to operate properly.
• High Speed Input Unit (HSI) – The 8096 HIS unit can record times of external
events with a 9 state time resolution. It can monitor four independently
configurable HSI lines and captures the value of timer 1 when events takes place.
• The four types of events that can trigger captures include: rising edge only, falling
edge only, rising or falling edges, or every eight rising edge.
• The HSI unit can store upto 8 entries (Timer 1 values ).
• Reading the HSI holding register unloads the earliest entry placed in the FIFO.
• The HSI unit can generate an interrupt when loading an entry into the HSI
holding register or loading the sixth entry into the FIFO.
• High Speed Output Unit (HSO) – The 8096 HSO unit can trigger events at
specified times based on Timer1 or Timer2.
• These programmable events include: starting an A/D conversion, resetting
Timer2, generating upto four software time delays, and setting or clearing one or
more of the six HSO output lines.
• The HSO unit stores pending event and specified times in a Content Addressable
Memory (CAM) file. This file stores upto 8 commands.
• Each command specifies the action time, the nature of the action, whether an
interrupt is to occur, and whether Timer1 or Timer2 is the reference timer.
• Every 8 state times the HSO compares the CAM locations for time matches. The
HSO unit triggers the specified event when it finds a time match.
• A command is cleared from the CAM as soon as it executes.
• Serial Port – The serial port on the 8096 has one synchronous (Mode 0) and
three asynchronous modes (Modes 1, 2 and 3).
• The asynchronous modes are full duplex.
• Mode 0, the synchronous mode, is to expand the I/O capability of the 8096 using
shift register.
• Mode 1 is the standard asynchronous mode used for normal serial
communication.
• Modes 2, 3 are 9-bit modes commonly used for multiprocessor communications.
• Pulse Width Modulator (PWM) – The PWM output waveform is a variable
duty cycle pulse that repeats every 256 state times.
• The PWM output can perform digital to analog conversions and drive several
types of motors that require a PWM waveform for more efficient operation.
• A/D Converter – The 8096 A/D converts an analog input to a 10 bit digital
equivalent.
• The main components of the A/D Converter are: 8 analog inputs, an 8 to 1
multiplexer, a sample and hold capacitor and resistor ladder.
• The A/D Converter can start a conversion immediately or the High Speed Output
unit can trigger a conversion at a preprogrammed time.
• The A/D converter performs a conversion in 88 state times. Upon completion of
each conversion the converter can generate a conversion complete interrupt.
• The 8X9X provides separate VREF and ANGND supply pins to isolate noise on
the Vcc or Vss lines.
• Interrupts – There are 21 interrupts sources and 8 interrupt vector on the 8096.
• When the interrupt controller detects one of the 8 interrupts it sets the
corresponding bit in the interrupt pending register. Individual interrupts are
enabled or disabled by setting or clearing bits in the interrupt mask register.
• When the interrupt controller decides to process an interrupt, it executes a “call”
to an interrupt service routine ISR. The corresponding interrupt vector contains
the address of the ISR. The interrupt controller then clears the associated pending
bit.
7 6 5 4 3 2 1 0
0 0 1 1 Chip configuration byte
CCB (2018H) (ROM or EPROM)
Set to 1 for compatibility with future parts.
Bus width select
If set, then BUSWIDTH pin determines the bus
width. If cleared, then external 8-bit data bus is
selected.
Write strobe mode select
If set, then WRH# / BHE# becomes BHE# and WRL# /
WR# becomes WR#.
If cleared, then WRH# / BHE# becomes WRH# and
WRL# / WR# becomes WRL#.
Address valid strobe select
If set, then ALE / ADV# becomes ALE
If cleared , then ALE / ADV# becomes ADV#
IRC1 IRC0 Internal ready control mode
0 0 Limit to 1 wait state
0 1 Limit to 2 wait state
1 0 Limit to 3 wait state
1 1 Disable internal ready control
LOC1 LOC0 Internal ROM / EPROM lock modes
0 0 Read protected ; EPROM is also write protected.
0 1 Read protected
1 0 EPROM part is write protected
1 1 No operation
Chip configuration byte (CCB)
Configuring the 8096
• The 8096 can be operated in either the single-chip mode, or two of its ports can be
redefined to bring out the internal address bus and data bus.
• For the single chip mode, the internal ROM and EPROM must be accessed. This
choice is made by tying the EA# pin high.
• When EA pin is tied high, the internal ROM or EPROM is accessed during
instruction and data fetches from addresses 2080 to 3FFFH and for interrupt
vectors located at addresses 2000 to 2011H.
8096BH
+5V EA
+ 5V
8096BH READY
(a ) Avoiding wait states entirely, for use with fast external parts.
GND
8096BH READY
8096BH READY
BUSWIDTH A15 A15
(8 bit CCB (Address-dependent wait state)
multiplexed 0 0
bus)
(c ) external accesses to address below 8000H get an extra wait state, where as accesses
above 8000H get no extra wait state.
• When operated in the expanded mode the internal ROM or EPROM can still be
used by tying EA# high.
• Accesses to the addresses 2000 to 2011H and 2080 to 3FFFH can be made to
access off-chip memory by tying the EA# pin low.
• If the EA pin is high, then we have the option of using the internal ROM or
EPROM together with external memory and devices.
• One of the options made available by the BH series over the original 8096 family
is the option to deal with either a 16 bit external data bus or else an 8 bit external
data bus.
• The latter options permits expanding the 8096 with a single byte wide static RAM
chip or with a single byte wide EPROM chip for program memory.
• The latter is particularly convenient for users who can either put their application
program into a single EPROM or who do not have the EPROM programming
capability to separate their object code into even addresses and odd addresses as
required for the two byte wide EPROM used with a 16 bit data bus.
• The choice of bus width is made in two places. When the 8096 comes out of reset,
it reads the content of address 2018H of our ROM or EPROM. This is called the
chip configuration CCB.
• The 8096 stores this byte in a chip configuration register which is unaccessable by
our software.
• Bit 1 works together with the external BUSWIDTH pin to determine the data bus
width (when the EA pin is tied low).
• While the BUSWIDTH pin is tied either high or low, it can actually be changed
during each bus cycle of normal operation.
• If it is tied to the A15 address lines, then accesses to external addresses 8000 to
FFFFH would use a 16-bit data bus while accesses to external addresses below
this would use an 8-bit data bus. In either case, the full 16 bit address bus is
brought out.
• When an 8-bit data bus is brought out, the lines which bring out the upper half of
the address bus do not have to be multiplexed.
• In this case, the designers of the chip have saved users the need for an external
latch for the upper half of the address bus by latching the address internally.
• The original 8096 parts gave the user of the expanded chip an ALE output. This
was used to latch the address. The new option is selected with a 0 in bit 3 of CCB.
The ADV# line remains high during any machine cycles which are not accessing
external memory, but goes low during external accesses. Because of this ADV#
can be used to simplify the decoding to enable external devices.
• In addition to the external access, ADV# drop low at precisely the current time to
latch the multiplexed address. Consequently, it can serve double duty, both
helping with decoding and also latching the multiplexed address.
• Another feature of the original 8096 parts operating in the expanded mode was
the need to decode a BHE# signal.
• This was used during writes to a byte at an odd address so that the lower byte on
the 16-bit data bus could be left unchanged.
• Users of the original 8096 parts had to gate BHE# together with a WR# signal to
generate two write signals.
• One for chips connected to the upper half of the data bus and one for chip
connected to the lower half of the data bus.
(12 MHZ)
250 ns
CLK OUT
(4 MHz)
ADV#
RD#
WRH#
WRL#
(12 MHZ)
250 ns
CLK OUT
(12 MHz)
ADV#
RD#
WRH#
FFFF
Intel 8096 expanded memory map
General Purpose I/O Ports
• Port 0 whose lines can serve as either general purpose inputs or alternatively as
input to the analog-to-digital converter family.
• Port 1 is a quasi-bidirectional I/O port.
• Port 2 includes four input lines, two output lines, and two quasi-bidirectional I/O
lines.
• Port 3 and 4 when used as ports, they have open drain outputs.
• By writing anything but a 1 to a line, it can serve as an input even as other lines
serve as outputs.
• Each output line needs the addition of a pullup resistor having a value of 15kΩ.
• In the expanded mode the bus lines gain the ability to drive both high and low,
forming the expansion bus without the need of pullup resistors.
Port 0
8096 PORT 1
(000F)
7
6
5
4 Not available with 48 pin
3 DIP package.
2
1
0
8096 PORT 2
(0010H)
7
6
Pulse width mode. 5
Out. PWM
T2RST 4
Inputs to timer 2 T2CLK 3
External interrupt EXTINT 2
RXD 1
Serial Port TXD 0
Port 2
Expansion PORT 4 + 5V
8096 15KΩ
bus (1FFF)
AD15 7
AD14 6
AD13 5
AD12 4
AD11 3
AD10 2
AD9 1
AD8 0
Expansion PORT 3 (1FFE)
bus AD7 7
AD6 6
AD5 5
AD4 4
AD3 3
AD2 2
AD1 1
AD0 0
Pullup resistors are only needed on lines to
be used as output port lines
IRA HORDEN
MCO APPLICATIONS ENGINEER
September 1987
Intel retains the right to make changes to these specifications at any time, without notice. Microcomputer
Products may have minor variations to this specification known as errata.
*Other brands and names are the property of their respective owners.
² Since publication of documents referenced in this document, registration of the Pentium, OverDrive and
iCOMP trademarks has been issued to Intel Corporation.
Contact your local Intel sales office or your distributor to obtain the latest specifications before placing your
product order.
Copies of documents which have an ordering number and are referenced in this document, or other Intel
literature, may be obtained from:
Intel Corporation
P.O. Box 7641
Mt. Prospect, IL 60056-7641
or call 1-800-879-4683
COPYRIGHT © INTEL CORPORATION, 1996
Using The 8096 CONTENTS PAGE
APPENDICES
A.6. PWM Using the HSO ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ A-15
Appendix A. Basic Software
Examples ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ A-1 A.7. Serial Port ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ A-19
A.1. Table Lookup 1 ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ A-1 A.8. A to D Converter ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ A-21
A.2. Table Lookup 2 ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ A-3 Appendix B. HSO and A to D Under
A.3. PLM-96 Code with Expansion ÀÀÀÀÀÀÀÀ A-5 Interrupt Control ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ B-1
A.4. Pulse Measurement ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ A-11
Appendix C. Software Serial Port ÀÀÀÀÀÀ C-1
A.5. Enchanced Pulse Measurement ÀÀÀÀ A-13
Appendix D. Motor Control Program ÀÀÀ D-1
Figures Listings
2-1. 8096 Block Diagram ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 1 3-1. Include File DEMO96.INC ÀÀÀÀÀÀÀÀÀÀÀ 19
2-2. Memory Map ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 2 3-2. ASM-96 Code for Table Lookup
2-3. SFR Layout ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 3 Routine 1 ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 20
2-4. Major I/O Functions ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 4 3-3. ASM-96 Code for Table Lookup
Routine 1 ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 21
2-5. Instruction Summary ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 5
3-4. PLM-96 Code for Table Lookup
2-6. Instruction Format ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 7 Routine 1 ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 23
2-7. Interrupt Sources ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 8 3-5. 32-Bit Result Multiply Procedure for
2-8. Interrupt Vectors and Priorities ÀÀÀÀÀÀÀ 8 PLM-96 ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 23
2-9. Interrupt Structure Block 3-6. Measuring Pulses Using the HSI
Diagram ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 9 Unit ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 24
2-10. The PSW Register ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 10 3-7. Enhanced HSI Pulse Measurement
Routine ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 25
2-11. HSI Unit Block Diagram ÀÀÀÀÀÀÀÀÀÀÀÀÀ 11
3-8. Generating a PWM with the HSO ÀÀÀÀ 26
2-12. HSI Mode Register ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 11
3-9. Changes to Declarations for HSO
2-13. HSO Command Register ÀÀÀÀÀÀÀÀÀÀÀÀ 12 Routine ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 27
2-14. HSO Block Diagram ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 12 3-10. Driver Module for HSO PWM
2-15. Serial Port Control/Status Program ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 27
Register ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 13 3-11. Using the Serial Port in Mode 1 ÀÀÀÀÀÀ 29
2-16. Baud Rate Formulas ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 14 3-12. Scanning the A to D Channels ÀÀÀÀÀÀÀ 31
2-17. Baud Rate Values for 10, 11, 12 4-1. Using Multiple I/O Devices ÀÀÀÀÀÀÀÀÀÀ 32
MHz ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 15
4-2. Software Serial Port
2-18. Multiprocessor Communication ÀÀÀÀÀÀ 16 Declarations ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 35
2-19. A to D Result/Command 4-3. Software Serial Port Interface
Register ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 17 Routines ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 36
2-20. PWM Output Waveforms ÀÀÀÀÀÀÀÀÀÀÀÀ 18 4-4. Software Serial Port Initialization
2-21. PWM to Analog Conversion Routine ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 36
Circuitry ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 18 4-5. Software Serial Port Transmit
3-1. Using the HSIO to Monitor Rotating Process ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 37
Machinery ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 28 4-6. Receive Process ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 37
3-2. Serial Port Level Conversion ÀÀÀÀÀÀÀÀ 30 4-7. Motor Control HSO.0 Timer
4-1. 10-Bit Asynchronous Frame ÀÀÀÀÀÀÀÀÀ 35 Routine ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 42
4-2. Optical Encoder and Waveforms ÀÀÀÀ 39 4-8. Motor Control HSI Data Available
Routine ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 44
4-3. Filtered Encoder Waveforms ÀÀÀÀÀÀÀÀ 40
4-9. Motor Control Mode 1 Routines ÀÀÀÀÀ 45
4-4. Schematic of Optical Encoder to
8096 Interface ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 41 4-10. Motor Control Mode 0 Routines ÀÀÀÀÀ 46
4-5. Motor Driver Circuitry ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 41 4-11. Motor Control Software Timer 1
Routine ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 47
4-6. Mode State Diagram ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 44
4-12. Motor Control Next Position
4-7. Motor Control Modes ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 49 Lookup ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 49
5-1. Minimum System Configuration ÀÀÀÀÀ 52 4-13. Motor Control Timer Interrupt
Routine ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 50
4-14. Motor Control Software Timer
Interrupt Handler ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 50
4-15. Motor Control Software Timer 2
Routine ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ 51
AP-248
270061 – 1
1
AP-248
2.1.1. CPU SECTION In the lower 24 bytes of the register file are the register-
mapped I/O control locations, also called Special
The CPU of the 8096 uses a 16-bit ALU which operates Function Registers or SFRs. These registers are used to
on a 256-byte register file instead of an accumulator. control the on-chip I/O features. The remaining 232
Any of the locations in the register file can be used for bytes are general purpose RAM, the upper 16 of which
sources or destinations for most of the instructions. can be kept alive using a low current power-down
This is called a register to register architecture. Many mode.
of the instructions can also use bytes or words from
anywhere in the 64K byte address space as operands. A
memory map is shown in Figure 2-2.
270061 – 2
2
AP-248
Figure 2-3 shows the layout of the register mapped to. More information about the use of these registers is
I/O. Some of these registers serve two functions, one if included in the description of the features which they
they are read from and another if they are written control.
270061 – 3
3
AP-248
2.1.2. I/O FEATURES A symmetric set of byte and word operations make up
the majority of the 8096 instruction set. The assembly
Many of the I/O features on the 8096 are designed to language for the 8096 (ASM-96) uses a ‘‘B’’ suffix on a
operate with little CPU intervention. A list of the major mnemonic to indicate a byte operation, without this
I/O functions is shown in Figure 2-4. The Watchdog suffix a word operation is indicated. Many of these op-
Timer is an internal timer which can be used to reset erations can have one, two or three operands. An exam-
the system if the software fails to operate properly. The ple of a one operand instruction would be:
Pulse-Width-Modulation (PWM) output can be used as
a rough D to A, a motor driver, or for many other NOT Value1 ; Value1 : e 1’s complement (Value1)
purposes. The A to D converter (ADC) has 8 multi-
plexed inputs and 10-bit resolution. The serial port has A two operand instruction would have the form:
several modes and its own baud rate generator. The
High Speed I/O section includes a 16-bit timer, a 16-bit ADD Value2,Value1 ; Value2 : e Value2 a Value1
counter, a 4-input programmable edge detector, 4 soft-
ware timers, and a 6-output programmable event gener- A three operand instruction might look like:
ator. All of these features will be described in section
2.3. MUL Value3,Value2,Value1 ;
Value3 : e Value2* Value1
4
AP-248
Oper- Flags
Mnemonic Operation (Note 1) Notes
ands Z N C V VT ST
ADD/ADDB 2 D wDaA & & & & u Ð
ADD/ADDB 3 D wBaA & & & & u Ð
ADDC/ADDCB 2 D w D a A aC v & & & u Ð
SUB/SUBB 2 DwDbA & & & & u Ð
SUB/SUBB 3 DwBbA & & & & u Ð
SUBC/SUBCB 2 DwDbAaCb1 v & & & u Ð
CMP/CMPB 2 DbA & & & & u Ð
MUL/MULU 2 D, D a 2 wD*A Ð Ð Ð Ð Ð ? 2
MUL/MULU 3 D, D a 2 w B * A Ð Ð Ð Ð Ð ? 2
MULB/MULUB 2 D, D a 1 w D * A Ð Ð Ð Ð Ð ? 3
MULB/MULUB 3 D, D a 1 w B * A Ð Ð Ð Ð Ð ? 3
DIVU 2 D w (D, D a 2)/A, D a 2 w remainder Ð Ð Ð & u Ð 2
DIVUB 2 D w (D, D a 1)/A, D a 1 w remainder Ð Ð Ð & u Ð 3
DIV 2 D w (D, D a 2)/A, D a 2 w remainder Ð Ð Ð ? u Ð 2
DIVB 2 D w (D, D a 1)/A, D a 1 w remainder Ð Ð Ð ? u Ð 3
AND/ANDB 2 D w D and A & & 0 0 Ð Ð
AND/ANDB 3 D w B and A & & 0 0 Ð Ð
OR/ORB 2 D w D or A & & 0 0 Ð Ð
XOR/XORB 2 D w D (excl. or) A & & 0 0 Ð Ð
LD/LDB 2 DwA Ð Ð Ð Ð Ð Ð
ST/STB 2 AwD Ð Ð Ð Ð Ð Ð
LDBSE 2 D w A; D a 1 w SIGN(A) Ð Ð Ð Ð Ð Ð 3, 4
LDBZE 2 D w A; D a 1 w 0 Ð Ð Ð Ð Ð Ð 3, 4
PUSH 1 SP w SP b 2; (SP) w A Ð Ð Ð Ð Ð Ð
POP 1 A w (SP); SP w SP a 2 Ð Ð Ð Ð Ð Ð
PUSHF 0 SP w SP b 2; (SP) w PSW; 0 0 0 0 0 0
PSW w 0000H Iw0
POPF 0 PSW w (SP); SP w SP a 2; I w & & & & & & &
5
AP-248
Oper- Flags
Mnemonic Operation (Note 1) Notes
ands Z N C V VT ST
JNE 1 Jump if Z e 0 Ð Ð Ð Ð Ð Ð 5
JGE 1 Jump if N e 0 Ð Ð Ð Ð Ð Ð 5
JLT 1 Jump if N e 1 Ð Ð Ð Ð Ð Ð 5
JGT 1 Jump if N e 0 and Z e 0 Ð Ð Ð Ð Ð Ð 5
JLE 1 Jump if N e 1 or Z e 1 Ð Ð Ð Ð Ð Ð 5
JH 1 Jump if C e 1 and Z e 0 Ð Ð Ð Ð Ð Ð 5
JNH 1 Jump if C e 0 or Z e 1 Ð Ð Ð Ð Ð Ð 5
JV 1 Jump if V e 1 Ð Ð Ð Ð Ð Ð 5
JNV 1 Jump if V e 0 Ð Ð Ð Ð Ð Ð 5
JVT 1 Jump if VT e 1; Clear VT Ð Ð Ð Ð 0 Ð 5
JNVT 1 Jump if VT e 0; Clear VT Ð Ð Ð Ð 0 Ð 5
JST 1 Jump if ST e 1 Ð Ð Ð Ð Ð Ð 5
JNST 1 Jump if ST e 0 Ð Ð Ð Ð Ð Ð 5
JBS 3 Jump if Specified Bit e 1 Ð Ð Ð Ð Ð Ð 5, 6
JBC 3 Jump if Specified Bit e 0 Ð Ð Ð Ð Ð Ð 5, 6
DJNZ 1 D w D b 1; if D i 0 then
PC w PC a 8-bit offset Ð Ð Ð Ð Ð Ð 5
DEC/DECB 1 D wDb1 & & & & u Ð
NEG/NEGB 1 Dw0bD & & & & u Ð
INC/INCB 1 DwDa1 & & & & u Ð
EXT 1 D w D; D a 2 w Sign (D) & & 0 0 Ð Ð 2
EXTB 1 D w D; D a 1 w Sign (D) & & 0 0 Ð Ð 3
NOT/NOTB 1 D w Logical Not (D) & & 0 0 Ð Ð
CLR/CLRB 1 Dw0 1 0 0 0 Ð Ð
SHL/SHLB/SHLL 2 C w msb Ð Ð Ð Ð Ð Isb w 0 & ? & & u Ð 7
SHR/SHRB/SHRL 2 0 x msb Ð Ð Ð Ð Ð Isb x C & ? & 0 Ð & 7
SHRA/SHRAB/SHRAL 2 msb x msb Ð Ð Ð Ð Ð Isb x C & & & 0 Ð & 7
SETC 0 Cw1 Ð Ð 1 Ð Ð Ð
CLRC 0 Cw0 Ð Ð 0 Ð Ð Ð
CLRVT 0 VT w 0 Ð Ð Ð Ð 0 Ð
RST 0 PC w 2080H 0 0 0 0 0 0 8
DI 0 Disable All Interrupts (I w 0) Ð Ð Ð Ð Ð Ð
EI 0 Enable All Interrupts (I w 1) Ð Ð Ð Ð Ð Ð
NOP 0 PC w PC a 1 Ð Ð Ð Ð Ð Ð
SKIP 0 PC w PC a 2 Ð Ð Ð Ð Ð Ð
NORML 2 Left Shift Till msb e 1; D w shift count & ? 0 Ð Ð Ð 7
TRAP 0 SP w SP b 2; (SP) w PC
PC w (2010H) Ð Ð Ð Ð Ð Ð 9
Figure 2-5. Instruction Summary (Continued)
NOTES:
1. If the mnemonic ends in ‘‘B’’, a byte operation is performed, otherwise a word operation is done. Operands D, B, and A
must conform to the alignment rules for the required operand type. D and B are locations in the register file; A can be
located anywhere in memory.
5. Offset is a 2’s complement number.
6. Specified bit is one of the 2048 bits in the register file.
7. The ‘‘L’’ (Long) suffix indicates double-word operation.
8. Initiates a Reset by pulling RESET low. Software should re-initialize all the necessary registers with code starting at
2080H.
9. The assembler will not accept this mnemonic.
6
AP-248
One operand of most of the instructions can be used mode. In this mode a 16-bit 2’s complement value is
with any one of six addressing modes. These modes added to the contents of a word register to form the
increase the flexibility and overall execution speed of address of the operand. By using the zero register as the
the 8096. The addressing modes are: register-direct, im- index, ASM96 (the assembler) can accept ‘‘direct’’ ad-
mediate, indirect, indirect with auto-increment, and dressing to any location. The zero register is located at
long and short indexed. 0000H and always has a value of zero. A short indexed
mode is also available to save some time and code. This
The fastest instruction execution is gained by using ei- mode uses an 8-bit 2’s complement number as the offset
ther register direct or immediate addressing. Register- instead of a 16-bit number.
direct addressing is similar to normal direct addressing,
except that only addresses in the register file or SFRs
can be addressed. The indexed mode is used to directly 2.2.2. ASSEMBLY LANGUAGE
address the remainder of the 64K address space. Imme-
The multiple addressing modes of the 8096 make it easy
diate addressing operates as would be expected, using
to program in assembly language and provide an excel-
the data following the opcode as the operand.
lent interface to high level languages. The instructions
accepted by the assembler consist of mnemonics fol-
Both of the indirect addressing modes use the value in a
lowed by either addresses or data. A list of the mne-
word register as the address of the operand. If the indi-
monics and their functions are shown in Figure 2-5.
rect auto-increment mode is used then the word register
The addresses or data are given in different formats
is incremented by one after a byte access or by two after
depending on the addressing mode. These modes and
a word access. This mode is particularly useful for ac- formats are shown in Figure 2-6.
cessing lookup tables.
Additional information on 8096 assembly language is
Access to any of the locations in the 64K address space
available in the MCS-96 Macro Assembler Users
can be obtained by using the long indexed addressing Guide, listed in the bibliography.
270061 – B3
7
AP-248
270061 – 4
8
AP-248
source. When the vector is taken the INTÐPENDING The software can make the hardware interrupts work in
bit is cleared. If more than one bit is set in the INTÐ almost any fashion desired by having each routine run
PENDING register with the corresponding bit set in with its own setup in the INTÐMASK register. This
the INTÐMASK register, the Interrupt with the high- will be clearly seen in the examples in section 4 which
est priority shown in Figure 2-8 will be executed. change the priority of the vectors in software. The
270061 – 5
9
AP-248
15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
Z N V VT C Ð I ST INTÐMASK
WHERE:
Z is the zero flag. It is set when the result of an operation is zero.
N is the negative flag. It is set to the algebraically correct sign of the result regardless of overflows.
V is the overflow flag. It is set if an overflow occurs.
VT is the overflow trap flag. It is set when the VT flag is set and cleared by JVT, JNVT, or CLRVT.
C is the carry flag. It is set if a carry was generated by the prior operation.
I is the global interrupt enable bit.
ST is the sticky bit. It is set during a right shift if a one was shifted into and then out of the carry flag.
INTÐMASK is the interrupt mask register and contains bits which individually enable the 8 interrupt vectors.
PSW (shown in Figure 2-10), stores the INTÐMASK struction is executed to restore the old PSW. The RET
register in its lower byte so that the mask register can instruction is executed and the code returns to the de-
be pushed and popped along with the machine status sired location. Although the POPF instruction can en-
when moving in and out of routines. The action of able the interrupts the next instruction will always exe-
pushing flags clears the PSW which includes PSW.9, cute. This prevents unnecessary building of the stack by
the interrupt enable bit. Therefore, after a PUSHF in- ensuring that the RET always executes before another
struction interrupts are disabled. In most cases an inter- interrupt vector is taken.
rupt service routine will have the basic structure shown
below.
2.3. On-Chip I/O Section
INT VECTOR:
All of the on-chip I/O features of the 8096 can be ac-
PUSHF cessed through the special function registers, as shown
LDB INT MASK, #xxxxxxxxB in Figure 2-3. The advantage of using register-mapped
EI I/O is that these registers can be used as the sources or
- destinations of CPU operations. There are seven major
- ;Insert service routine here I/O functions. Each one of these will be considered
- with a section of code to exemplify its usage. The first
POPF section covered will be the High Speed I/O, (HSIO),
RET subsystem. This section includes the High Speed Input
(HSI) unit, High Speed Output (HSO) unit, and the
The PUSHF instruction saves the PSW including the Timer/Counter section.
old INTÐMASK register. The PSW, including the in-
terrupt enable bit are left cleared. If some interrupts
2.3.1. TIMER/COUNTERS
need to be enabled while the service routine runs, the
INTÐMASK is loaded with a new value and inter- The 8096 has two time bases, Timer 1 and Timer 2.
rupts are globally enabled before the service routine Timer 1 is a 16-bit free running timer which is incre-
continues. At the end of the service routine a POPF in- mented every 8 state times. (A state time is 3 oscillator
periods, or 0.25 microseconds with a 12 MHz crystal.)
10
AP-248
270061 – 6
# Pulse measurement with 2.0 msec resolution
# Input transitions trigger the recording of the reference
Timer (16-bit) and triggered input(s) (4-bit)
Its value can be read at any time and used as a refer- 2.3.2. HSI
ence for both the HSI section and the HSO section.
Timer 1 can cause an interrupt when it overflows, and The HSI unit can be thought of as a message taker
cannot be modified or stopped without resetting the which records the line which had an event and the time
entire chip. Timer 2 is really an event counter since it at which the event occurred. Four types of events can
uses an external clock source. Like Timer 1, it is 16-bits trigger the HSI unit, as shown in the HSI block dia-
wide, can be read at any time, can be used with the gram in Figure 2-11. The HSI unit can measure pulse
HSO section, and can generate an interrupt when it widths and record times of events with a 2
overflows. Control of Timer 2 is limited to increment-
ing it and resetting it. Specific values can not be written
to it.
Although the 8096 has only two timers, the timer flexi-
bility is equal to a unit with many timers thanks to the
HSIO unit. The HSI enables one to measure times of
external events on up to four lines using Timer 1 as a
timer base. The HSO unit can schedule and execute
internal events and up to six external events based on 270061 – 7
the values in either Timer 1 or Timer 2. The 8096 also Where each 2-bit mode control field
includes separate, dedicated timers for the baud rate defines one of 4 possible modes:
generator and watchdog timer. 00 8 positive transitions
01 Each positive transition
10 Each negative transition
11 Every transition (positive and negative)
11
AP-248
microsecond resolution. It can look for one of four holding register is loaded or when the FIFO has six or
events on each of four lines simultaneously, based on more entries.
the information in the HSI Mode register, shown in
Figure 2-12. The information is then stored in a seven
level FIFO for later retrieval. Whenever the FIFO con- 2.3.3. HSO
tains information, the earliest entry is placed in the
Just as the HSI can be thought of as a message taker,
holding register. When the holding register is read, the
the HSO can be thought of as a message sender. At
next valid piece of information is loaded into it. Inter-
times determined by the software, the HSO sends mes-
rupts can be generated by the HSI unit at the time the
270061 – 8
270061 – 9
12
AP-248
sages to various devices to have them turn on, turn off, A CAM (Content Addressable Memory) file is the
start processing, or reset. Since the programmed times main component of the HSO. This file stores up to
can be referenced to either Timer 1 or Timer 2, the eight events which are pending to occur. Every state
HSO makes the two timers look like many. For exam- time one location of the CAM is compared with the
ple, if several events have to occur at specific times, the two timers. After 8 state times, (two microseconds with
HSO unit can schedule all of the events based on a a 12 MHz clock), the entire CAM has been searched
single timer. The events that can be scheduled to occur for time matches. If a match occurs the specified event
and the format of the command written to the HSO will be triggered and that location of the CAM will be
Command register are shown in Figure 2-13. made available for another pending event. A block dia-
gram of the HSO unit is shown in Figure 2-14.
The software timers listed in the figure are actually 4
software flags in I/O Status Register 1 (IOS1). These
flags can be set, and optionally cause an interrupt, at 2.3.4. Serial Port
any time based on Timer 1 or Timer 2. In most cases
Controlling a device from a remote location is a simple
these timers are used to trigger interrupt routines which
task that frequently requires additional hardware with
must occur at regular intervals. A multitask process
many processors. The 8096 has an on-chip serial port to
can easily be set up using the software timers.
reduce the total number of chips required in the system.
270061 – 10
NOTE:
TI and RI are cleared when SPÐCON is read.
13
AP-248
The serial port is similar to that on the MCS-51 prod- Baud rates for all of the modes are controlled through
uct line. It has one synchronous and three asynchro- the Baud Rate register. This is a byte wide register
nous modes. In the asynchronous modes baud rates of which is loaded sequentially with two bytes, and inter-
up to 187.5 Kbaud can be used, while in the synchro- nally stores the value as a word. The least significant
nous mode rates up to 1.5 Mbaud are available. The byte is loaded to the register followed by the most sig-
chip has a baud rate generator which is independent of nificant. The most significant bit of the baud value de-
Timer 1 and Timer 2, so using the serial port does not termines the clock source for the baud rate generator. If
take away any of the HSI, HSO or timer flexibility or the bit is a one, the XTAL1 pin is used as the source, if
functionality. it is a zero, the T2 CLK pin is used. The formulas
shown in Figure 2-16 can be used to calculate the baud
Control of the serial port is provided through the rates. The variable ‘‘B’’ is used to represent the least
SPCON/SPSTAT (Serial Port CONtrol/Serial Port significant 15 bits of the value loaded into the baud rate
STATus) register. This register, shown in Figure 2-15, register.
has some bits which are read only and others which are
write only. Although the functionality of the port is The baud rate register values for common baud rates
similar to that of the 8051, the names of some of the are shown in Figure 2-17. These values can be used
modes and control bits are different. The way in which when XTAL1 is selected as the clock source for serial
the port is used from a software standpoint is also modes other than Mode 0. The percentage deviation
slightly different since RI and TI are cleared after each from theoretical is listed to help assess the reliability of
read of the register. a given setup. In most cases a serial link will work if
there is less than a 2.5% difference between the baud
The four modes of the serial port are referred to as rates of the two systems. This is based on the assump-
modes 0, 1, 2 and 3. Mode 0 is the synchronous mode, tion that 10 bits are transmitted per frame and the last
and is commonly used to interface to shift registers for bit of the frame must be valid for at least six-eights of
I/O expansion. In this mode the port outputs a pulse the bit time. If the two systems deviate from theoretical
train on the TXD pin and either transmits or receives by 1.25% in opposite directions the maximum toler-
data on the RXD pin. Mode 1 is the standard asyn- ance of 2.5% will be reached. Therefore, caution must
chronous mode, 8 bits plus a stop and start bit are sent be used when the baud rate deviation approaches
or received. Modes 2 and 3 handle 9 bits plus a stop and 1.25% from theoretical. Note that an XTAL1 frequen-
start bit. The difference between the two is, that in cy of 11.0592 MHz can be used with the table values
Mode 2 the serial port interrupt will not be activated for 11 MHz to provide baud rates that have 0.0 percent
unless the ninth data bit is a one; in Mode 3 the inter- deviation from theoretical. In most applications, how-
rupt is activated whenever a byte is received. These two ever, the accuracy available when using an 11 MHz
modes are commonly used for interprocessor communi- input frequency is sufficient.
cation.
Serial port Mode 1 is the easiest mode to use as there is
little to worry about except initialization and loading
Using XTAL1:
and unloading SBUF, the Serial port BUFfer. If parity
XTAL1 frequency
Mode 0: Baud e ;B i 0 is enabled, (i.e., PEN e 1), 7 bits plus even parity are
Rate 4*(B a 1)
used instead of 8 data bits. The parity calculation is
Baud XTAL1 frequency done in hardware for even parity. Modes 2 and 3 are
Others: Rate e
64*(B a 1) similar to Mode 1, except that the ninth bit needs to be
Using T2CLK: controlled and read. It is also not possible to enable
T2CLK frequency parity in Mode 2. When parity is enabled in Mode 3 the
Mode 0: Baud
Rate
e ;B i 0 ninth bit becomes the parity bit. If parity is not enabled,
B
(i.e., PEN e 0), the TB8 bit controls the state of the
T2CLK frequency
Others: Baud
Rate
e ;B i 0 ninth transmitted bit. This bit must be set prior to each
16*B transmission. On reception, if PEN e 0, the RB8 bit
Note that B cannot equal 0, except when using indicates the state of the ninth received bit. If parity is
XTAL1 in other than mode 0. enabled, (i.e., PEN e 1), the same bit is called RPE
Figure 2-16. Baud Rate Formulas (Receive Parity Error), and is used to indicate a parity
error.
14
AP-248
The software used to communicate between processors receive the message switches to Mode 3 and receives
is simplified by making use of Modes 2 and 3. In a basic the information. Since this information is sent with the
protocol the ninth bit is called the address bit. If it is set ninth bit set to zero, none of the processors set to Mode
high then the information in that byte is either the ad- 2 will be interrupted. By using this scheme the overall
dress of one of the processors on the link, or a com- CPU time required for the serial port is minimized.
mand for all the processors. If the bit is a zero, the byte
contains information for the processor or processors A typical connection diagram for the multi-processor
previously addressed. In standby mode all processors mode is shown in Figure 2-18. This type of communica-
wait in Mode 2 for a byte with the address bit set. ton can be used to connect peripherals to a desk top
When they receive that byte, the software determines if computer, the axis of a multi-axis machine, or any oth-
the next message is for them. The processor that is to er group of microcontrollers jointly performing a task.
15
AP-248
270061 – 11
Mode 0, the synchronous mode, is typically used for input. When doing process control algorithms, it is fre-
interfacing to shift registers for I/O expansion. The quently the changes in inputs that are required, not the
software to control this mode involves the REN (Re- absolute accuracy of the value. For this reason, even if
ceiver ENable) bit, the clearing of the RI bit, and writ- the absolute accuracy of a 10-bit converter is the same
ing to SBUF. To transmit to a shift register, REN is set as that of an 8-bit converter, the 10-bit monotonic con-
to zero and SBUF is loaded with the information. The verter is much more useful.
information will be sent and then the TI flag will be set.
There are two ways to cause a reception to begin. The Since most of the analog inputs which are monitored by
first is by causing a rising edge to occur on the REN a microcontroller change very slowly relative to the 42
bit, the second is by clearing RI with REN e 1. In microsecond conversion time, it is acceptable to use a
either case, RI is set again when the received byte is capacitive filter on each input instead of a sample and
available in SBUF. hold. The 8097 does not have an internal sample and
hold, so it is necessary to ensure that the input signal
does not change during the conversion time. The input
2.3.5. A to D CONVERTER to the A/D must be between ANGND and VREF.
ANGND must be within a few millivolts of VSS and
Analog inputs are frequently required in a microcon-
troller application. The 8097 has a 10-bit A to D con- VREF must be within a few tenths of a volt of VCC.
verter that can use any one of eight input channels. The
conversions are done using the successive approxima- Using the A to D converter on the 8097 can be a very
low software overhead task because of the interrupt and
tion method, and require 168 state times (42 microsec-
HSO unit structure. The A to D can be started by the
onds with a 12 MHz clock.)
HSO unit at a preset time. When the conversion is com-
The results are guaranteed monotonic by design of the plete it is possible to generate an interrupt. By using
these features the A to D can be run under complete
converter. This means that if the analog input voltage
interrupt control. The A to D can also be directly
changes, even slightly, the digital value will either stay
the same or change in the same direction as the analog
16
AP-248
270061 – 12
270061 – 13
controlled by software flags which are located in the takes up much less silicon area than a true D to A. The
ADÐRESULT/ADÐCOMMAND Register, shown signal is a variable duty cycle, fixed frequency wave-
in Figure 2-19. form that can be integrated to provide an approxima-
tion to an analog output. The frequency is fixed at a
period of 64 microseconds for a 12 MHz clock speed.
2.3.6. PWM REGISTER Controlling the PWM simply requires writing the de-
Analog outputs are just as important as analog inputs sired duty cycle value (an 8-bit value) to the PWM
Register. Some typical output waveforms that can be
when connecting to a piece of equipment. True digital
to analog converters are difficult to make on a micro- generated are shown in Figure 2-20.
processor because of all of the digital noise and the
necessity of providing an on chip, relatively high cur- Converting the PWM signal to an analog signal varies
in difficulty, depending upon the requirements of the
rent, rail to rail driver. They also take up a fair amount
system. Some systems, such as motors or switching
of silicon area which can be better used for other fea-
power supplies actually require a PWM signal, not a
tures. The A to D converter does use a D to A, but the
true analog one. For many other cases it is necessary
currents involved are very small.
only to amplify the signal so that it switches rail-to-rail,
and then filter it. Switching rail-to-rail means that the
For many applications an analog output signal can be
output of the amplifier will be a reference value when
replaced by a Pulse Width Modulated (PWM) signal.
the input is a logical one, and the output will
This signal can be easily generated in hardware, and
17
AP-248
be zero when the input is a logical zero. The filter can The RC network determines how quiet the output is,
be a simple RC network or an active filter. If a large but the quieter the output, the slower it can change.
amount of current is needed a buffer is also required. The design of high accuracy voltage followers and ac-
For low output currents, (less than 100 microamps or tive filters is beyond the scope of this paper, however
so), the circuit shown in Figure 2-21 can be used. many books on the subject are available.
270061 – 14
270061 – 15
*This resistor limits Rise Time to reduce spikes and high frequency noise.
18
AP-248
3.0 BASIC SOFTWARE EXAMPLES els in this file are different from those in the file
8096.INC that is provided in the ASM-96 package.
The examples in this section show how to use each I/O
feature individually. Examples of using more than one
feature at a time are described in section 4. All of the 3.1. Using the 8096’s Processing
examples in this ap-note are set up to be used as listed. Section
If run through ASM96 they will load and run on an
SBE-96. In order to insure that the programs work, the
stack pointer is initialized at the beginning of each pro- 3.1.1. TABLE INTERPOLATION
gram. If the programs are going to be used as modules A good way of increasing speed for many processing
of other programs, the stack pointer initialization tasks is to use table lookup with interpolation. This can
should only be used at the beginning of the main pro- eliminate lengthy calculations in many algorithms. Fre-
gram. quently it is used in programs that generate sine wave-
forms, use exponents in calculations, or require some
To avoid repetitive declarations the ‘‘include’’ file ‘‘DE- non-linear function of a given input variable. Table
MO96.INC’’, shown in Listing 3-1, is used. ASM-96 lookup can also be used without interpolation to deter-
will insert this file into the code file whenever the direc- mine the output state of I/O devices for a given state of
tive ‘‘INCLUDE DEMO96.INC’’ is used. The file con- a set of input devices. The procedure is also a good
tains the definitions for the SFRs and other variables. example of 8096 code as it uses many of the software
The include statement has been placed in all of the ex- features. Two ways of making a lookup table are de-
amples. It should be noted that some of the lab- scribed, one way uses more calculation time, the second
way uses more table space.
270061 – 16
19
AP-248
In both methods the procedure is similar. Values of a To make the algorithm easier, (and therefore faster), it
function are stored in memory for specific input values. is appropriate to limit the range and accuracy of the
To compute the output function for an input that is not function to only what is needed. It is also advantageous
listed, a linear approximation is made based on the to make the input step (Upper Input-Lower Input)
nearest inputs and nearest outputs. As an example, con- equal to a power of 2. This allows the substitution of
sider the table below. multiple right shifts for a divide operation, thus speed-
ing up throughput. The 8096 allows multiple arithmetic
If the input value was one of those listed then there right shifts with a single instruction providing a very
would be no problem. Unfortunately the real world is fast divide if the divisor is a power of two.
never so kind. The input number will probably be 259
or something similar. If this is the case linear interpola- For the purpose of an example, a program with a 12-bit
tion would provide a reasonable result. The formula is: output and an 8-bit input has been written. An input
step of 16 (2**4) was selected. To cover the input range
UpperOutput-Lower Output
Delta Out e *(Actual Input-Lower Input) 17 words are needed, 255/16 a 1 word to handle val-
Upper Input-Lower Input
ues in the last 15 bytes of input range. Although only
Actual Output e Lower Output a Delta Out
12 bits are required for the output, the 16-bit architec-
For the value of 259 the solution is:
ture offers no penalty for using 16 instead of 12 bits.
900-400 500
Delta Out e *(259-200) e *59 e 5 * 59 e 295
300-200 100 The program for this example, shown in Listing 3-2,
Actual Output e 400 a 295 e 695
uses the definitions and equates from Listing 3-1, only
the additional equates and definitions are shown in the
code.
270061 – 17
20
AP-248
270061 – 18
If the function is known at the time of writing the soft- lookup table. There are many applications where time
ware it is also possible to calculate in advance the is critical and code space is overly abundant. In these
change in the output function for a given change in the cases the code in Listing 3-3 will work to the same
input. This method can save a divide and a few other specifications as the previous example.
instructions at the expense of doubling the size of the
270061 – 19
21
AP-248
270061 – 20
By making use of the second lookup table, one word of lines of assembly code. This is advantageous to the pro-
RAM was saved and 16 state times. In most cases this grammer, since code can usually be written at a set
time savings would not make much of a difference, but number of lines per hour, so the less lines of code that
when pushing the processor to the limit, microseconds need to be written, the faster the task can be completed.
can make or break a design.
If the first example of interpolation is considered, the
PLM-96 code would be written as shown in Listing 3-4.
3.1.2. PL/M-96 Note that version 1.0 of PLM-96 does not support 32-
bit results of 16 by 16 multiplies, so the ASM-96 proce-
Intel provides high level language support for most of
dure ‘‘DMPY’’ is used. Procedure DMPY, shown in
its micro processors and microcontrollers in the form of
PL/M. Specifically, PL/M refers to a family of lan- Listing 3-5, must be assembled and linked with the
compiled PLM-96 program using RL-96, the relocator
guages, each similar in syntax, but specialized for the
and linker. The command line to be used is:
device for which it generates code. The PL/M syntax is
similar to PL/1, and is easy to learn. PLM-96 is the
RL96 PLMEX1.OBJ, DMPY.OBJ, PLM96.LIB &
version of PL/M used for the 8096. It is very code
to PLMOUT.OBJ ROM (2080H-3FFFH)
efficient as it was written specifically for the MCS-96
family. PLM-96 most closely resembles PLM-86, al-
though it has bit and I/O functions similar to PLM-51.
One line of PL/M-code can take the place of many
22
AP-248
270061 – 21
270061 – 22
23
AP-248
Using PLM, code requires less lines, is much faster to Frequently it is also desired to keep track of the num-
write, and easier to maintain, but may take slightly ber of events which have occurred, as well as how often
longer to run. For this example, the assembly code gen- they are occurring. By using a software counter this
erated by the PLM-96 compiler takes 56.75 microsec- feature can be added to the above code. This code de-
onds to run instead of 30.75 microseconds. If PLM-96 pends on the software responding to the change in line
performed the 32-bit result multiply instead of using state before the line changes again. If this cannot be
the ASM-96 routine the PLM code would take 41.5 guaranteed then it may be necessary to use 2 HSI lines
microseconds to run. The actual code listings are for each incoming line. In this case one HSI line would
shown in Appendix A. look for falling edges while the other looks for rising
edges. The code in Listing 3-7 includes both the counter
feature and the edge detect feature.
3.2. Using the I/O Section
The uses for this type of routine are almost endless. In
instrumentation it can be used to determine frequency
3.2.1. USING THE HSI UNIT
on input lines, or perhaps baud rate for a self adjusting
One of the most frequent uses of the HSI is to measure serial port. Section 4.2 contains an example of making a
the time between events. This can be used for frequency software serial port using the HSI unit. Interfacing to
determination in lab instruments, or speed/acceleration some form of mechanically generated position informa-
information when connected to pulse type encoders. tion is a very frequent use of the HSI. The applications
The code in Listing 3-6 can be used to determine the in this category include motor control, precise position-
high and low times of the signals on two lines. This ing (print heads, disk drives, etc.), engine control and
code can be easily expanded to 4 lines and can also be
modified to work as an interrupt routine.
270061 – 23
24
AP-248
transmission control. The HSI unit is used extensively HSO line not change so quickly that it changes twice
in the example in section 4.3. between consecutive reads of I/O Status Register 0,
(IOS0).
3.2.2. USING THE HSO UNIT A very eye catching example can be made by having the
program output waveforms that vary over time. The
Although the HSO has many uses, the best example is
driver routine in Listing 3-10 can be linked to the above
that of a multiple PWM output. This program, shown
program to provide this function. Linking is accom-
in Listing 3-8, is simple enough to be easily understood,
plished using RL96, the relocatable linker for the 8096.
yet it shows how to use the HSO for a task which can
Information for using RL96 can be found in the
be complex. In order for this program to operate, an-
‘‘MCS-96 Utilities Users Guide’’, listed in the bibliogra-
other program needs to set up the on and off time vari-
phy. In order for the program to link, the register dec-
ables for each line. The program also requires that a
270061 – 24
25
AP-248
270061 – 25
26
AP-248
laration section (i.e., the section between ‘‘RSEG’’ and quency twice that of the first one. A slightly different
‘‘CSEG’’) in Listing 3-8 must be changed to that in driver routine could easily be the basis for a switching
Listing 3-9. power supply or a variable frequency/variable voltage
motor driver. The listing of the driver routine is shown
The driver routine simply changes the duty cycle of the in Listing 3-10.
waveform and sets the second HSO output to a fre-
270061 – 26
270061 – 27
27
AP-248
270061 – 28
Since the 8096 needs to keep track of events which of- Another option available is to use the HSI.1 pin to
ten repeat at set intervals it is convenient to be able to clock Timer 2. By using this approach it is possible to
have Timer 2 act as a programmable modulo counter. use the HSI to measure the period of events on the
There are several ways of doing this. The first is to input to Timer 2. If both of the HSI pins are used
program the HSO to reset Timer 2 when Timer 2 instead of the T2RST and T2CLK pins the HSIO unit
equals a set value. A software timer set to interrupt at can keep track of speed and position of the rotating
Timer 2 equals zero could be used to reload the CAM. device with very little software overhead. This type of
This software method takes up two locations in the setup is ideal for a system like the one shown in Figure
CAM and does not synchronize Timer 2 to the external 3-1, and similar to the one used in section 4.3.
world.
In this system a sequence of events is required based on
To synchronize Timer 2 externally the T2 RST (Timer the position of the gear which represents any piece of
2 ReSeT) pin can be used. In this way Timer 2 will get rotating machinery. Timer 2 holds the count of the
reset on each rising edge of T2 RST. If it is desired to number of tooth edges passed since the index mark. By
have an interrupt generated and time recorded when using HSI.1 as the input to Timer 2, instead of T2
Timer 2 gets reset, the signal for its reset can be taken CLK, it is possible to determine tooth count and time
from HSI.0 instead of T2RST. The HSI.0 pin has its information through the HSI. From this information
own interrupt vector which functions independently of instantaneous velocity and acceleration can be calculat-
the HSI unit. ed. Having the tooth edge count in Timer 2 means
270061 – 29
28
AP-248
that the HSO unit can be used to initiate the desired transmits the same character. The code is set up so that
tasks at the appropriate tooth count. The interrupt rou- minor modifications could make it run on an interrupt
tine initiated by HSI.0 can be used to perform any soft- basis. Note that it is necessary to set up some flags as
ware task required every revolution. In this system, the initial conditions to get the routine to run properly. If it
overhead which would normally require extensive soft- was desired to send 7 bits of data plus parity instead of
ware has been done with the hardware on the 8096, 8 bits of data the PEN bit would be set to a one. Inter-
thus making more software time available for control processor communication, as described in section 2.3.4,
programs. can be set up by simply adding code to change RB8 and
the port mode to the listing below. The hardware
shown in Figure 3-2 can be used to convert the logic
3.2.3. USING THE SERIAL PORT IN MODE 1 level output of the 8096 to g 12 or 15 volt levels to
Mode 1 of the serial port supports the basic asynchro- connect to a CRT. This circuit has been found to work
nous 8-bit protocol and is used to interface to most with most RS-232 devices, although it does not con-
CRTs and printers. The example in Listing 3-11 shows form to strict RS-232 specifications. If true RS-232
a simple routine which receives a character and then conformance is required then any standard RS-232
driver can be used.
270061 – 30
29
AP-248
270061 – 31
270061 – 32
30
AP-248
3.2.4. USING THE A TO D really make use of its full capabilities. The following
examples use some of the code blocks from the previous
The code in Listing 3-12 makes use of the software flags section to show how several I/O features can be used
to implement a non-interrupt driven routine which together to accomplish a practical task. Three examples
scans A to D channels 0 through 3 and stores them as will be shown. The first is simply a combination of sev-
words in RAM. An interrupt driven routine is shown in eral of the section 3 examples run under an interrupt
section 4.1. When using the A to D it is important to system. Next, a software serial port using the HSIO
always read the value using the byte read commands, unit is described. The concluding example is one of in-
and to give the converter 8 state times to start convert- terfacing the HSI unit to an optical encoder to control a
ing before reading the status bit. motor.
270061 – 33
31
AP-248
order, Port 1 output pins are used to indicate the cur- be waited between consecutive loads of the HSO. If this
rent status of each task. The actual code listing is in- is not done it is possible to overwrite the contents of the
cluded in Appendix B. CAM holding register. An A/D interrupt is forced by
setting the bit in the Interrupt Pending register. This
The initialization section, shown in Listing 4-1a, clears causes the first A/D interrupt to occur just after the
a few variables and then loads the first set of on and off Interrupt Mask register is set and interrupts are en-
times to the HSO unit. Note that 8 state times must abled.
270061 – 34
32
AP-248
270061 – 35
270061 – 36
33
AP-248
270061 – 37
The HSO routine shown in Listing 4-1b is slightly dif- has a ten bit output, the most significant 8 bits are
ferent than the one in section 3. All of the HSO lines rounded up or down based on the least significant two
turn on at the same time, only the turn-off-time is var- bits.
ied between lines. This action is what is most common-
ly required for multiple PWM outputs and simplifies
the software. A comparison is made between Timer1 4.2. Software Serial Port Using the
and the next HSO turn on time at the beginning of the HSIO Unit
routine. If the next turn on time has passed, then the
on-times are loaded into the CAM, otherwise the off There are many systems which require more than one
times are loaded. serial port, an example is a system which must commu-
nicate with other computers and have an additional
The maximum number of events in the CAM at any port for a local console. If the on-board UART is being
given time is 7. This occurs when the first line to turn used as an inter-processor link, the HSIO unit can be
off does so, causing the off-times for all of the lines to used to interface the 8096 to an additional asynchro-
be loaded. For two of the lines there will be an offtime, nous line.
an on-time, and the just loaded off-time. The other line
(the one that just turned off) will have only the on-time Figure 4-1 shows the format of a standard 10-bit asyn-
and the just loaded off-time. chronous frame. The start bit is used to synchronize the
receiver to the transmitter; at the leading edge of the
A/D conversions are performed by the code in Listing START bit the receiver must set up its timing logic to
4-1c about every 60 microseconds, 42 for the conver- sample the incoming line in the center of each bit. Fol-
sion, the rest for overhead. The A/D routine sets up the lowing the start bit are the eight data bits which are
HSO and PWM on and off times. Since the A/D transmitted least significant bit first. The STOP bit is
set to the opposite state of the START bit to guar-
34
AP-248
270061 – 38
antee that the leading edge of the START bit will cause 3. Transmit ISR. This routine runs as an ISR (interrupt
a transition on the line; it also provides for a dead time service routine) in response to an HSO interrupt in-
on the line so that the receiver can maintain its syn- terrupt. Its function is to serialize the data passed to
chronization. it by the interface routines.
4. Receive ISRs. There are two ISRs involved in the
The remainder of this section will show how a full-du- receive process. One of them runs in response to an
plex asynchronous port can be built from the HSIO HSI interrupt and is used to synchronize the receive
unit. There are four sections to this code: process at the leading edge of the start bit. The sec-
1. Interface routines. These routines provide a proce- ond receive ISR runs in response to an HSO generat-
dural interface between the interrupt driven core of ed software timer interrupt, this routine is scheduled
the software serial port and the remainder of the ap- to run at the center of each bit and is used to deseri-
plication software. alize the incoming data.
2. Initialization routine. This routine is called during
the initialization of the overall system and sets up the The routines share the set of variables that are shown in
various variables used by the software port. Listing 4-2. These variables should be accessed only by
the routines which make up the software serial port.
270061 – 39
35
AP-248
The table also shows the declarations for the com- stored the START and STOP bits are added to the data
mands issued to the HSO unit. In this example HSI.2 is bits. The routine charÐin is called when the applica-
used for receive data and HSO.5 is used for transmit tion software requires a character from the port. The
data, although other HSI and HSO lines could have data is returned in the ax register in conformance to
been used. PLM 96 calling conventions. The routine csts can be
called to determine if a character is available at the port
The interface routines are shown in Listing 4-3. Data is before calling charÐin. (If no character is available
passed to the port by pushing the eight-bit character charÐin will wait indefinitely).
into the stack and calling charÐout, which waits for
any in-process transmission to complete and stores the The initialization routine is shown in Listing 4-4. This
character into the variable serialÐout. As the data is routine is called with the required baud rate in the
270061 – 40
270061 – 41
36
AP-248
stack; it calculates the bit time from the baud rate and nificant bit is output and the register shifted right one
stores it in the variable baudÐcount in units of TIM- place. The framing information (START and STOP
ER1 ticks. An HSO command is issued which will initi- bits) are appended to the actual data by the interface
ate the transmit process and then the remainder of the routines. Note that this routine will be executed once
variables owned by the port are initialized. The routine per bit time whether or not data is being transmitted. It
initÐreceive is called to setup the HSI unit to look for would be possible to use this routine for additional low
the leading edge of the START bit. resolution timing functions with minimal overhead.
The transmit process is shown in Listing 4-5. The HSO The receive process consists of an initialization routine
unit is used to generate an output command to the and two interrupt service routines, hsiÐisr and soft-
transmit pin once per bit time. If the serialÐout regis- wareÐtimerÐisr. The listings of these routines are
ter is zero a MARK (idle condition) is output. If the shown in Listings 4-6a,4-6b, and 4-6c respectively. The
serialÐout register contains data then the least sig-
270061 – 42
270061 – 43
37
AP-248
270061 – 44
270061 – 45
38
AP-248
start is detected by the hsiÐisr which schedules a soft- Frequently there is a third line which generates one
ware timer interrupt in one-half of a bit time. This first pulse per revolution for indexing purposes. Figure 4-2
sample is used to verify that the START bit has not shows a six line encoder and typical waveforms. As can
ended prematurely (a protection against a noisy line). be seen, the two waveforms provide the ability to deter-
The software timer service routine uses the variable mine both position and direction. Since a microcontrol-
rcveÐstate to determine whether it should check for a ler can perform real time calculations it is possible to
valid START bit, deserialize data, or check for a valid determine velocity and acceleration from the position
STOP bit. When a complete character has been re- and time information.
ceived it is moved to the receive buffer and initÐreceive
is called to set up the receive process for the next char- Interfacing to the encoder can be an interesting prob-
acter. This routine is also called when an error (e.g., lem, as it requires connecting mechanically generated
invalid START bit) is detected. electrical signals to the HSI unit. The problems arise
because it is difficult to obtain the exact nature of the
Appendix C contains the complete listing of the rou- signals under all conditions.
tines and the simple loop which was used to initialize
them and verify their operation. The test was run for The equipment used in the lab was a Pittman 9400 se-
several hours at 9600 baud with no apparent malfunc- ries gearmotor with a 600 line optical encoder from
tion of the port. Vernitech. The encoder has to be carefully attached to
the shaft to minimize any runout or endplay. Fortu-
nately, Pitmann has started marketing their motors
4.3. Interfacing an Optical Encoder to with ball bearings and optical encoders already in-
the HSI Unit stalled. It is recommended that the encoder be mounted
to the motor using the exact specifications of the encod-
Optical encoders are among one of the more popular er manufacturer and/or a good machine shop.
devices used to determine position of rotating equip-
ment. These devices output two pulse trains with edges
that occur from 2 to 4000 times a revolution.
270061 – 46
Inside track generates Phase A. Outside track generates Phase B.
39
AP-248
Digital filtering external to the 8096 is used on the en- If it is desired to determine when each edge occurs be-
coder signals. The idealized signals coming from the fore filtering, the encoder outputs can be attached di-
encoder and after the digital filter are shown in Figure rectly to the 8096. As these would be input signals, Port
4-3. The circuitry connecting the encoder to the 8096 0 is the most likely choice for connection. It would not
requires only two chips. A one-shot constructed of be required to connect these lines to the HSI unit, as
XOR gates generates pulses on each edge of each sig- the information on them would only be needed when
nal. The pulses generated by Phase A are used to clock the motor is going very slowly.
the signal from Phase B and vice versa. The hardware is
shown in Figure 4-4. CMOS parts are used to reduce The motor is driven using the PWM output pin for
loading on the encoder so that buffers are not needed. power control and a port pin for direction control. The
Note that T2CLK is clocked on both edges of both 8096 drives a 7438 which drives 2 opto-isolators. These
filtered phases. in turn drive two VFETs. A MOV (Metal Oxide Varis-
tor, a type of transient absorber) is used to protect the
By using this method repetitive edges on a single phase VFETs, and a capacitor filters the PWM to get the best
without an edge on the other phase will not be passed motor performance. Figure 4-5 shows the driver cir-
on to the 8096. Repetitive edges on a phase can occur cuitry. To avoid noise getting into the 8096 system, the
when the motor is stopped and vibrates or when it is g 15 volt power supply is isolated from the 8096 logic
changing direction. The digital filtering technique caus- power supply.
es a little more delay in the signal at slow speeds than
an analog filter would, but the simplicity trade off is This is the extent of the external circuitry required for
worthwhile. The net effect of digital filtering is losing this example. All of the counting and direction detec-
the ability to determine the first edge after a direction tion are done by the 8096. There are two sections to the
change. This does not affect the count since the first example: driving the motor and interfacing to the en-
edge in both directions is lost. coder. The motor driver uses proportional control with
270061 – 47
NOTES:
Phase AÊ is Phase A clocked by Phase B
Phase BÊ is Phase B clocked by Phase A
40
AP-248
some modifications and a braking algorithm. Since the In order to interface to the encoder it is necessary to
main point of this example is I/O interfacing, the mo- know the types of waveforms that can be expected. The
tor driver will be briefly described at the end of this motor was accelerated and decelerated many times us-
section. ing different maximum voltages. It was found that the
270061 – 48
270061 – 49
41
AP-248
motor would decelerate smoothly until the time be- mode is indicated by the lower 2 bits of Port 1, with the
tween encoder edges was around 100 microseconds. At following coding:
this point the motor would either continue to decelerate
slowly, or would suddenly stop and reverse. The latter P1.0 P1.1 Mode Description
case is the one that was most problematic.
0 0 0 HSI looks at every edge
After a brief overview, each section of the program will 1 0 1 HSI looks at Phase A edges only
be described separately, with the complete listing in- 0 1 2 Timer 2 used instead of HSI
cluded in the Appendix D. In order to make debugging 1 1 2 (alternate form of above)
easier, as well as to provide insight into how the pro-
gram is working, I/O port 1 is used to indicate the The example is easiest to see if mode 2 is described first,
program status. This information consists of which rou- followed by mode 1 then mode 0. In mode 2 Timer 2 is
tine the program is in and under which mode it is oper- used to count edges on the incoming signal. A software
ating. The main program sections are: Main loop, HSI timer routine, which is actually run using HSO.0, uses
interrupt, Timer 2 check, and Motor drive. There are the Timer 2 value to update a LONG (32-bit) software
also minor sections such as initialization, timer over- counter labeled POSITION. The HSO routine runs ev-
flow handling, and software timer handling. Tying ev- ery 260 microseconds. The HSO.0 interrupt is used in-
erything together is some overhead and glue. Where the stead of an actual software timer because of the ability
glue is not obvious it will be discussed, otherwise it can to easily unmask it while other software timer routines
be derived from the listings. are running.
The program is a main loop which does nothing except In the code in Listing 4-7, the mode is first determined.
serve as a place for the program to go when none of the For the first pass ignore the code starting with the label
interrupt routines are being run. All of the processing is inÐmodeÐ1. Starting with inÐmodeÐ2 the counter is
done on an interrupt basis. incremented or decremented based on bit zero of DI-
RECT. If DIRECT.0 e 0 the motor is going back-
There are three basic software modes which are in- ward, if it is a 1 the motor is going forward. Next the
voked depending on the speed of the motor. The modes count difference is checked to see if it is slow enough to
referred to as 0, 1 and 2, in order from slowest to fastest go into mode 1. If not the routine returns to the code it
operation. When the program is running the operating was running when the interrupt occurred.
270061 – 50
42
AP-248
270061 – 51
If the pulse rate is slow enough to go to mode 1, the enable mode 0 after an edge is received. This could
transition is made by enabling HSI.0 and HSI.1. Both cause a problem if the last 2 edges on Phase A before
of these lines are connected to the same encoder line, the encoder stops were too close to enable mode 0. If
with HSI.0 looking for rising edges and HSI.1 looking this happened, mode 0 would not be enabled until after
for falling edges. The HSIÐTIME register is read to the encoder started again, resulting in missed edges on
speed up clearing the HSI FIFO and the LAST1Ð Phase B. Using the HSO routine to switch from mode 1
TIME value is set up so the mode 1 routine does not to mode 0 eliminates this problem.
immediately put the program into another mode. The
HSI FIFO is then cleared, the Timer 2 value used Figure 4-6 shows a state diagram of how the mode
throughout this routine is saved, and the routine re- switching is done. As can be seen, there are two sources
turns. for most of the mode decisions. This helps avoid prob-
lems such as the one mentioned above.
This routine still runs in modes 0 and 1, but in an
abbreviated form. The section of code starting with the When either Mode 1 or Mode 0 is enabled the HSI
label inÐmode1 checks to see if the pulses are coming interrupt routine performs the counting of edges, while
in so slowly that both HSI lines can be checked. If this the HSO routine only ensures that the correct mode is
is the case then all of the HSIs are enabled and the running. The routines for modes 0 and 1 share the same
program returns. This routine is the secondary method initialization and completion sections, with the main
for going from mode 1 to mode 0, the primary method body of code being different.
is by checking the time between edges during the HSI
routine, which will be described later. The initialization routine is similar to many HSI rou-
tines. The flags are checked to ensure that the HSI
The HSO routine will enable mode 0 from mode 1 if FIFO data is valid, and then the FIFO is read. Next,
two edges are not received every 260 microseconds. The the main body of code (for either mode 0 or mode 1) is
primary method, (under the HSI routine), can only
43
AP-248
270061 – 52
NOTES:
Mode 0: HSI Examines edges on Phase A and B
Mode 1: HSI Examines edges on Phase A only
Mode 2: TIMER 2 stores edgecount
270061 – 53
44
AP-248
run. At the end time and count values are saved and the POSITION. The program then returns to the comple-
holding register is checked for another event. Listing 4- tion section of the routine.
8 contains the initialization and completion sections of
the HSI routine. There is a lot more code used in Mode 0 than in Mode
1, most of which is due to the multiple jump statements
Listing 4-9 is the main body of the Mode 1 routine. that determine the current and previous state of the
Before any calculations are done in Mode 1, the incom- HSI pins. In order to save execution time several blocks
ing pulse period is measured to see if it is too fast or too of code are repeated as can be seen in Listing 4-10. The
slow for mode 1. The time period between two edges is first determination is that of which edge had occurred.
used so that the duty cycle of the waveform will not If a Phase A edge was detected the LAST1ÐTIME and
affect mode switching. If it is determined that Mode 2 LAST2ÐTIME variables are updated so a reference to
should be set, Port 1.1 is set, all of the HSI lines are the pulse frequency will be available. These are the
disabled, and the HSI fifo is cleared. If Mode 0 is to be same variables used under Mode 1. A test is also made
set all of the HSI lines are enabled and the variable to see if the edges are coming fast enough to warrant
LASTÐSTAT is cleared. LASTÐSTAT e 0 is used as being in Mode 1, if they are, the switch is made. If the
a flag to indicate the first HSI interrupt in Mode 0 after last edge detected was on Phase B, the information is
Mode 1. After the mode checking and setting are com- used only to determine direction.
plete the incremental value in Timer 2 is used to update
270061 – 54
45
AP-248
270061 – 55
46
AP-248
After mode correctness is confirmed and the LASTxÐ is close enough to the desired location that the power to
TIME values are updated the LASTÐSTAT (Last it should be reversed, (i.e., enter the Braking mode). If
Status) variable is used to determine the current direc- the motor is very close to the position or has slowed to
tion of travel. The POSITION value is then updated in the point that is likely to turn around, the HoldÐPosi-
the direction specified by the last two edges and the tion mode is entered.
status is stored. Note that the first time in Mode 0 after
being in Mode 1, the Mode 1 doneÐchk routine is used The determination of which modes are selected under
to update POSITION, instead of the routines goingÐ what conditions was done empirically. All of the pa-
fwd and goingÐrev from the Mode 0 section of code. rameters used to determine the mode are kept in RAM
The completion section of code is then executed. so they can be easily changed on the fly instead of by
re-assembling the program. The parameters in the list-
Providing the PWM value to drive the motor is done by ing have been selected to make the motor run, but have
a routine running under Software Timer 1. The first not been optimized for speed or stability. A diagram of
section of code, shown in Listing 4-11a, has to do with the modes is shown in Figure 4-7.
calculating the position and timer errors. Listing 4-11b
shows the next section of code where the power to be In the HoldÐPosition mode power is eased onto the
supplied to the motor is calculated. First the direction motor to lock it into position. Since the motor could be
is checked and if the direction is reverse the absolute stopped in this mode, some integral control is needed,
value of the error is taken. If the error is greater than as proportional control alone does not work well when
64K counts, the PWM routine is loaded with the maxi- the error is small and the load is large. The BOOST
mum value. The next check is made to see if the motor variable provides this integral control by increasing the
output a fixed amount every time period in which the
270061 – 56
47
AP-248
270061 – 57
48
AP-248
270061 – 58
error does not get smaller. Once the error does get A sanity check can be performed at this point to double
smaller, usually because the motor starts moving, check that the 8096 has proper control of the motor. In
BOOST is cleared. the example the worst that can happen is the proto-
270061 – 59
49
AP-248
type will need to be reset, so the sanity check was not The remaining sections of the program are relatively
used. If one were desired, it could be as simple as simple, but worth discussing briefly. The initialization
checking a hardware generated direction indicator, or routine initializes the I/O features and places several
as complex as checking motor condition and other en- variables from ROM into RAM. Having these variables
vironmental factors. in RAM makes it easier to tweak the algorithm. Timer
1 is expanded into a 32-bit timer by the interrupt rou-
After all checks have been made, the power value is tine shown in Listing 4-13.
loaded to the RPWR register using a software inversion
to compensate for the hardware inversion. Direction is Software timer overhead is handled by the routine
determined next and the power and direction are shown in Listing 4-14. In this routine the status of each
changed in adjacent instructions with interrupts dis- timer bit is checked in a shadow register. If any of the
abled to prevent changing power without direction and timers have expired the appropriate routine is called.
vice versa.
270061 – 60
270061 – B2
50
AP-248
270061 – 61
The last routine, shown in Listing 4-15, is the Software always operates smoothly and provides at least 200 mi-
Timer 2 routine which outputs some variables to exter- croseconds between the last several edges of Phase A
nal RAM. It also keeps LAST1ÐTime within 1800H before reversing. This idea was originally tried because
of Timer1 to prevent overflows from occurring when the motor was not characterized thoroughly at first,
the Mode 0 and Mode 1 software check this variable. and caused problems because of the motors tendency to
stop suddenly when its speed was low.
A complete listing of the program as it is used in our
lab can be found in Appendix D. For a given motor or If an encoder has a lower line count and therefore more
encoder it will probably be necessary to change some of time between output pulses the two mode solution can
the time constants on the first page of the listing. With be used. The software for the two mode version can be
the motor used in our experimentation, pulses are easily extracted form the three mode version, so it will
missed from time to time when direction changes not be presented.
quickly. If the motor were not as fast to turn around or
the encoder were mounted better these problems should
disappear. The missing pulses occur when switching 5.0 HARDWARE EXAMPLE
from Mode 1 to Mode 0, other than that no anomalies
were found in the lab.
5.1. EPROM Only Minimum System
Prior to the version of code just discussed, several at-
tempts were made, one of which could be used under The diagram in Figure 5-1 illustrates how to connect an
certain constraints. It is possible to use only modes 2 8096 in a minimum configuration system. Either 2764s
and 0 to monitor the encoder, provided the encoder or 27128s can be used in the system. Note that the
lower EPROM contains the even bytes while the upper
51
AP-248
270061 – 62
one contains the odd bytes, and the addressing is not 4K is mapped at 2000H. If the program being loaded is
fully decoded. This means that the addressing on a 16 Kbytes long the first half is loaded into the second
2764 will be such that the lower 4K of each EPROM is half of the 2764s and vice versa. A similar situation
mapped at 0000H and 4000H while the upper exists when using 27128s.
52
AP-248
270061 – 63
53
AP-248
54
AP-248
APPENDIX A
BASIC SOFTWARE EXAMPLES
270061– 64
A-1
AP-248
270061– 65
A-2
AP-248
270061– 66
A-3
AP-248
270061– 67
A-4
AP-248
270061– 69
270061– 70
A-6
AP-248
270061– 71
A-7
AP-248
270061– 72
A-8
AP-248
270061– 73
A-9
AP-248
270061– 74
A-10
AP-248
270061– 75
A-11
AP-248
270061– 76
A-12
AP-248
270061– 77
A-13
AP-248
270061– 78
A-14
AP-248
270061– 79
A-15
AP-248
270061– 80
A-16
AP-248
270061– 81
A-17
AP-248
270061– 82
A-18
AP-248
270061– 83
A-19
AP-248
270061– 84
A-20
AP-248
270061– 85
A.8. A to D Converter
A-21
AP-248
270061– 86
A-22
AP-248
APPENDIX B
HSO AND A TO D UNDER INTERRUPT CONTROL
270061– 87
B-1
B-2
AP-248
270061– 88
270061– 89
B-3
AP-248
B-4
AP-248
270061– 90
AP-248
APPENDIX C
SOFTWARE SERIAL PORT
270061– 91
C-1
C-2
AP-248
270061– 92
270061– 93
C-3
AP-248
C-4
AP-248
270061– 94
270061– 95
C-5
AP-248
C-6
AP-248
270061– 96
AP-248
APPENDIX D
MOTOR CONTROL PROGRAM
270061– 97
D-1
D-2
AP-248
270061– 98
270061– 99
D-3
AP-248
D-4
AP-248
270061– A0
270061– A1
D-5
AP-248
D-6
AP-248
270061– A2
270061– A3
D-7
AP-248
D-8
AP-248
270061– A4
270061– A5
D-9
AP-248
AP-248
270061– A6
D-10
AP-248
270061– A7
D-11
AP-248
270061– A8
D-12
AP-248
270061– A9
D-13
AP-248
270061– B0
D-14
AP-248
270061– B1
D-15
INTEL CORPORATION, 2200 Mission College Blvd., Santa Clara, CA 95052; Tel. (408) 765-8080
INTEL CORPORATION (U.K.) Ltd., Swindon, United Kingdom; Tel. (0793) 696 000
Microcontroller Operation
Printed in U.S.A./xxxx/0296/B10M/RP SM
UNIT V Case Study for 8051 and 8096
Purpose
Although keeping time can be done without an RTC, using one has benefits:
Power Source
RTCs often have an alternate source of power, so they can continue to keep time while the primary
source of power is off or unavailable. This alternate source of power is normally a lithium battery in
older systems, but some newer systems use a super capacitor, because they are rechargeable and
can be soldered. The alternate power source can also supply power to battery backed RAM.
Timing
Most RTCs use a crystal oscillator, but some use the power line frequency. In many cases, the
oscillator's frequency is 32.768 kHz. This is the same frequency used in quartz clocks and watches,
and for the same reasons, namely that the frequency is exactly 215 cycles per second, is a
convenient rate to use with simple binary counter circuits.
Many commercial RTC ICs are accurate to less than 5 parts per million. In practical terms, this is
good enough to perform celestial navigation, the classic task of a chronometer. In 2011, Chip-scale
atomic clocks were invented. Although more expensive, they keep time within 100 nanoseconds.
1. The main advantage of programmable gate pulses is the opportunity to change program
according to the requirements.
2. Same device can be used for different types of gate pulses.
3. Controlling the abnormality of the power devices using feedback.
4. Wide range of control over frequency.
Microcontroller
A microcontroller typically includes-
Application of Microcontroller
• Building control
- Access control
- Temperature sensing
- lighting
• Industrial control
- Process control
• Instrumentation
- Industrial instrumentation
• Metering
- AC motor control
- DC motors
- Steppers
• Automotive
This PIC frequency counter project uses an LCD to display the frequency and PIC timer 1 to measure
the input signal and Timer0 to measure the timing period.
It uses Timer 1 in 16 bit counter mode to count the input signal edges and overflows of the counter
are accumulated to give the total count in multiples of 65536.Adding the current value of the counter
at the end gives the total count.
The crystal oscillator is chosen to be 4MHz (Fosc) so that the processor internal clock is 1MHz
(Fosc/4). All you do is count 1e6 processor clocks (Timer0) to give a 1second count period.
Since the measurement time is 1 second the final count is actually the frequency of the input signal
i.e. number of input periods counted in 1 second is the frequency in Hz.
Using the 1 second measurement time also gives a frequency resolution of 1 Hz.
The hardware is simple and the main blocks are shown in the diagram below.
The LCD is used in 4 bit mode interface so you only need 4 data lines and three control lines and it
then fits into a single 8 bit port.
The crystal oscillator is simply a crystal and two capacitors connected to the PIC oscillator port at
OSC1 and OSC2. The capacitors can both be fixed at the same value unless you want to tune it using
a frequency reference. If you don't have an accurate reference then use fixed capacitors.
The PIC micro can be any type that has Timer 0 and Timer 1 hardware modules and and has enough
memory to hold the program ~1.6k words.
The LED is toggled to indicate that the processor is alive - so if there is no input signal you can tell
that the software is working. Also if there is no input signal the the LCD displays a flashing zero.
You can program the PIC in circuit through the ICSP connector in circuit.
Description
To time a 1 second count Timer0 is used. Since the main clock is running at 4MHz then the processor
clock (Fosc/4) is 1MHz which is the rate that Timer0 is set-up to use i.e. the internal clock. Therefore
we need to get a 1 second count using that timer. Since the timer is only 8 bits long you can use the
fact that an interrupt is generated when it overflows - you can then count these overflows to get near
to 1e6 counts.
Since the overflow occurs every time that the counter passes 256 we need to count 1e6/256
overflows
1e6/256 = 3906.25
We can only count integer overflows so must manipulate the last count to get the exact time. So we
need the modulus of 1e6 and 256:
The interrupt routine starts off after being zeroed by counting 3906 overflows, it then controls a flag
variable (do_TMR0_end_count) that indicates this is the last overflow for which the Timer0 value is
set to overflow after 64 Fosc/4 cycles:
At the end of the last overflow the values of Timer1 are captured to:
st_TMR1L
st_TMR1H
st_TMR1_ovfl
An LCD update request is sent from the interrupt routine to the main routine by setting a flag
(update_LCD) and the main routine then uses ltoa to calculate and output the frequency
measurement to then display on LCD.
There are other files since MikroC version 6.0.4 seems to need a lot more than V5! just keep them in
your project folder.
C Source files.
Frequency_counter_4MHz_LCD_TMR1.c
ltoa.c
Header files.
bit.h
ltoa.h
Output files
Frequency_counter_4MHz_LCD_TMR1.hex
Brief description
frequency_counter...c : contains the code start point (in routine 'main') and the interrupt
routine.
ltoa.c contains a long to ascii converter used for display of the frequency count.
bit.h : contains macros for bit manipulation.
The code uses the built in LCD driver routines which are automatically included by the compiler. Note
automatic include is unusual but it seems to work well in mikroC.
Interrupts are not used only the flags that can be polled (timer overflow) are activated.
frequency_counter_4MHz_LCD_TMR1.c
This file contains the port initialization, interrupt and main routine.
After initialization the code enters an endless loop where it continuously performs a measurement and
display operation. After an accurate 1 second delay the counter result is processed and displayed on
the LCD.
The main operation of this code is within the interrupt routine that both counts the input edges and
obtains an accurate 1s time by counting the edges of the internal oscillator clock (Fosc/4).
Interrupts
The most important part of this counter is the interrupt() routine. This is where all the action and
decisions are made.
The interrupt code for Timer1 is very simple and all it does is increment a long variable for counting
multiple input events.
The more tricky interrupt code, for Timer 0, counts time as described above. It counts 3906 overflows
followed by a single 64 cycle count to reach a time of 1 second after which it captures the event count
and then triggers an update to the LCD to calculate and display the frequency. The update triggers
the actions in main().
bit.h
This contains macros for bit manipulation which should be compiler independent.
ARM Architecture
The 32-bit ARM architecture, such as ARMv7-A, was the most widely used architecture in mobile
devices as of 2011.
Since 1995, the ARM Architecture Reference Manual has been the primary source of documentation
on the ARM processor architecture and instruction set, distinguishing interfaces that all ARM
processors are required to support (such as instruction semantics) from implementation details that
may vary. The architecture has evolved over time, and version seven of the architecture, ARMv7,
defines three architecture "profiles":
A-profile, the "Application" profile, implemented by 32-bit cores in the Cortex-A series and by some
non-ARM cores
R-profile, the "Real-time" profile, implemented by cores in the Cortex-R series
M-profile, the "Microcontroller" profile, implemented by most cores in the Cortex-M series
Although the architecture profiles were first defined for ARMv7, ARM subsequently defined the
ARMv6-M architecture (used by the Cortex M0/M0+/M1) as a subset of the ARMv7-M profile with
fewer instructions.
Instruction Set
The original (and subsequent) ARM implementation was hardwired without microcode, like the much
simpler 8-bit 6502 processor used in prior Acorn microcomputers.
The 32-bit ARM architecture (and the 64-bit architecture for the most part) includes the following RISC
features:
Load/store architecture.
No support for unaligned memory accesses in the original version of the architecture. ARMv6 and
later, except some microcontroller versions, support unaligned accesses for half-word and single-
word load/store instructions with some limitations, such as no guaranteed atomicity.
Uniform 16× 32-bit register file (including the program counter, stack pointer and the link register).
Fixed instruction width of 32 bits to ease decoding and pipelining, at the cost of decreased code
density. Later, the Thumb instruction set added 16-bit instructions and increased code density.
Mostly single clock-cycle execution.
To compensate for the simpler design, compared with processors like the Intel 80286 and Motorola
68020, some additional design features were used:
Conditional execution of most instructions reduces branch overhead and compensates for the
lack of a branch predictor.
Arithmetic instructions alter condition codes only when desired.
32-bit barrel shifter can be used without performance penalty with most arithmetic instructions and
address calculations.
Has powerful indexed addressing modes.
A link register supports fast leaf function calls.
A simple, but fast, 2-priority-level interrupt subsystem has switched register banks.
ARM Cortex M
The ARM Cortex-M is a group of 32-bit RISC ARM processor cores licensed by Arm Holdings. The
cores are intended for microcontroller use. The cores consist of the Cortex-M0, Cortex-M0+, Cortex-
M1, Cortex-M3, Cortex-M4, Cortex-M7, Cortex-M23, Cortex-M33. The Cortex-M4 / M7 / M33 cores
have an FPU option, and these cores are known as "Cortex-Mx with FPU" or Cortex-MxF, where 'x' is
the core number. ARM Cortex-M cores have been shipped in tens of billions of devices.
The ARM Cortex-M family are ARM microprocessor cores which are designed for use in
microcontrollers, ASICs, ASSPs, FPGAs, and SoCs. Cortex-M cores are commonly used as
dedicated microcontroller chips, but also are "hidden" inside of SoC chips as power management
controllers, I/O controllers, system controllers, touch screen controllers, smart battery controllers, and
sensors controllers.
Though 8-bit microcontrollers were very popular in the past, Cortex-M has slowly been chipping away
at the 8-bit market as the prices of low-end Cortex-M chips have moved downward. Cortex-M have
become a popular replacements for 8-bit chips in applications that benefit from 32-bit math
operations, and replacing older legacy ARM cores such as ARM7 and ARM9.
Arm Cortex-M processors provide:
ABSTRACT: The project is proposed to develop a four quadrant speed control system for a DC motor with Pulse
width modulation (PWM). The motor is operated in four quadrants i.e. clockwise, anti clock-wise, forward braking and
reverse braking. Four quadrant operations are suited for industrial applications. DC motor can rotate in clockwise, anti-
clockwise directions. Also we can apply braking for instantaneous stop in both the directions. In case of urgent
operation in industrial field the motor may needs to be stopped immediately. In such a case these systems is very useful
for forward braking and reverse braking. As the reverse voltage is used for running DC motor the braking in both
directions is possible for a small period. PWM pulses generated by microcontroller also control the speed of the motor
Microcontroller used in this project is from the 8051 family. A motor driver IC is provided here for motor speed control
also seven push buttons are interfaced with microcontroller for giving input signal as well as to operate the motor. This
project features the speed control by the push button operation. To operate high capacity DC motors this project can be
enhanced by using high power electronic devices.
KEYWORDS: Four quadrant operation, Pulse width modulation, Hardware model and Softwares, Working
I.INTRODUCTION
DC machines play a very important role in industries and in our daily life as they offer easily controllable
characteristics. This paper is designed to develop a four quadrant speed control system for a DC motor using
microcontroller. The DC motor is operated in four quadrants i.e. clockwise, anti-clockwise, forward braking and
reverses braking. Also it features speed control. There are four possible modes or quadrants of operation [3] using a DC
Motor .When DC motor is operating in the first and third quadrant, the supplied voltage is greater than the back emf
which is forward motoring and reverse motoring flow differs. When the motor operates in the second and fourth
quadrant the value of the back emf generated by the motor should be greater than the supplied voltage which are the
forward braking and reverse braking [4] modes of operation respectively, here again the direction of current flow is
reversed flow differs. When the motor operates in the second and fourth quadrant the value of the back emf generated
by the motor should be greater than the supplied voltage which are the forward braking and reverse braking modes of
operation respectively, here again the direction of current flow is reversed modes respectively, but the direction of
current flow is reversed.
REGULATOR: The output of the bridge rectifier is connected to the regulator [8] which regulates the 12 volt
unregulated dc to regulated 5V supply.
SWITCH ARRAY: Switch array consist of 7 push button switches. Each switch is assigned specific functions,
accordingly control pulses is given to motor driver IC for controlling Motor.
VII. RESULT
Solution
Benefits
Flexibility to Scale
www.arm.com/markets/artificial-intelligence
All brand names or product names are the property of their respective holders. Neither the whole nor any part of the information contained in, or the product described in,
this document may be adapted or reproduced in any material form except with the prior written permission of the copyright holder. The product described in this document
is subject to continuous developments and improvements. All particulars of the product and its use contained in this document are given in good faith. All warranties implied
or expressed, including but not limited to implied warranties of satisfactory quality or fitness for purpose are excluded. This document is intended only to provide information
to the reader about the product. To the extent permitted by local laws Arm shall not be liable for any loss or damage arising from the use of any information in this document
or any error or omission in such information.
© Arm Ltd.2018
Case Study:
Industrial Process Controller
MCU and RTC Power Backup
The Industrial Process Control embedded system design team requirements were:
1. Need to provide power back-up for an MSP430 microcontroller in the event of a main
power failure
2. Need to back-up the MCU RAM memory for 10 days
3. Need to back-up the MCU in Standby Mode (VLO) for 7 days
4. Need to back up the MCU Real-time clock operation for 3 days
5. Battery must be rechargeable
6. Battery must have less than 2% self discharge per year,
7. Must never have to change the battery
8. Control system product with integrated battery must be able to be shipped via air
9. Battery must be RoHS and WEEE compliant
10. Must have a small device footprint
11. Must use surface mount technology and reflow solder for assembly.
Many systems utilizing microcontrollers and/or real time clock chips require non-
volatile date retention and/or real-time clock operation in the event of main power
interruption. Normally, this is accomplished with the use of a supply supervisory
circuit coupled with a backup power source such as a coin cell or supercapacitor.
When main power is interrupted - as during line power outages or when the main
battery is removed for recharging or replacement - the backup power source provides
enough energy to maintain the data in the embedded SRAM or keep the internal real-
time clock operational. Many MCUs have an internal supply supervisor circuit that can
be used to control the switchover function from main power to auxiliary power. When
the supply voltage threshold level is reached during power droop or complete power
loss, the MCU can be programmed to generate an internal interrupt that places the
MCU into a low power state for maximum run time from the backup power source.
TI MSP430
Freescale HC
Atmel PicoPower AVR
Microchip PIC
ST Micro ST62
EM Microelectronics EM
TI BQ32000
Epson RX-8564
Dallas-Maxim DS1340
Dallas-Maxim DS1390
Micro Crystal RV-2123
Microchip MDP79410
NXP PCF8523
This Case Study demonstrates how the design team in this industrial process controls
company used EnerChip Solid State Batteries to improve the capabilities and
competitiveness of their new assembly system. You can use EnerChip devices to
reduce costs and improve the functionality of your products as well. Cymbet provides
a set of evaluation kits that can be utilized to accelerate new product development
schedules. For Power Back-up designs an ideal evaluation kit is the EnerChip CC RTC
Power Back-up CBC-EVAL-06 kit. This easy to use USB based stick as shown in
Figure 3, has a Micro Crystal RV-2123 Real Time Clock chip and an EnerChip CC
CBC3112 solid state battery.