Sei sulla pagina 1di 21

SYLLABUS

CS 2252 MICROPROCESSORS AND MICROCONTROLLERS L T P C


(Common to CSE & IT) 3 0 0 3
UNIT I THE 8085 AND 8086 MICROPROCESSORS 9
8085 Microprocessor architecture-Addressing modes- Instruction set-Programming the
8085
UNIT II SOFTWARE ASPECTS 9
Intel 8086 microprocessor - Architecture - Signals- Instruction Set-Addressing ModesAssembler
Directives- Assembly Language Programming-Procedures-Macros-Interrupts
And Interrupt Service Routines-BIOS function calls.
UNIT III MULTIPROCESSOR CONFIGURATIONS 9
Coprocessor Configuration Closely Coupled Configuration Loosely Coupled
Configuration 8087 Numeric Data Processor Data Types Architecture 8089 I/O
Processor Architecture Communication between CPU and IOP.
UNIT IV I/O INTERFACING 9
Memory interfacing and I/O interfacing with 8085 parallel communication interface
serial communication interface timer-keyboard/display controller interrupt controller
DMA controller (8237) applications stepper motor temperature control.
UNIT V MICROCONTROLLERS 9
Architecture of 8051 Microcontroller signals I/O ports memory counters and
timers serial data I/O interrupts- Interfacing -keyboard, LCD,ADC & DAC

TOTAL: 45 PERIODS
TEXT BOOKS
1. Ramesh S. Gaonkar ,Microprocessor Architecture, Programming and Applications
with the 8085 Penram International Publisher , 5
th
Ed.,2006
2. Yn-cheng Liu,Glenn A.Gibson, Microcomputer systems: The 8086 / 8088 Family
architecture, Programming and Design, second edition, Prentice Hall of India , 2006
3. Kenneth J.Ayala, The 8051 microcontroller Architecture, Programming and
applications second edition ,Penram international

REFERENCES
1. Douglas V.Hall, Microprocessors and Interfacing : Programming and Hardware,
second edition , Tata Mc Graw Hill ,2006.
2. A.K.Ray & K.M Bhurchandi, Advanced Microprocessor and Peripherals
Architecture, Programming and Interfacing, Tata Mc Graw Hill , 2006.
3. Peter Abel, IBM PC Assembly language and programming , fifth edition, Pearson
education / Prentice Hall of India Pvt.Ltd,2007.
4. Mohamed Ali Mazidi,Janice Gillispie Mazidi, The 8051 microcontroller and
embedded systems using Assembly and C,second edition, Pearson education
/Prentice hall of India , 2007








UNIT V

8051 MICROCONTROLLER
It is a single chip
Consists of Cpu, Memory
I/O ports, timers and other peripherals




Memory Organization
- Logical separation of program and data memory
-Separate address spaces for Program (ROM) and Data (RAM) Memory
-Allow Data Memory to be accessed by 8-bit addresses quickly and manipulated by
8-bit CPU
Program memory
-Only be read, not written to
-The address space is 16-bit, so maximum of 64K bytes
-Up to 4K bytes can be on-chip (internal) of 8051 core
-PSEN (Program Store Enable) is used for access to external Program Memory
Data memory
-Includes 128 bytes of on-chip Data Memory which are more easily accessible
directly by its instructions
-There is also a number of Special Function Registers (SFRs)
-Internal Data Memory contains four banks of eight registers and a special 32-
byte long segment which is bit addressable by 8051 bit-instructions
-External memory of maximum 64K bytes is accessible by movx



Interrupt Structure
The 8051 provides 4 interrupt sources

Two External interrupt
Two timer interrupt



Instruction Format
An instruction is a command to the microprocessor to perform a given task on a specified data.
Each instruction has two parts: one is task to be performed, called the operation code
(opcode),
and the second is the data to be operated on, called the operand. The operand (or data) can be
specified in various ways. It may include 8-bit (or 16-bit ) data, an internal register, a memory
location, or 8-bit (or 16-bit) address. In some instructions, the operand is implicit.
Instruction word size
The 8051 instruction set is classified into the following three groups according to word size:
1. One-word or 1-byte instructions
2. Two-word or 2-byte instructions
3. Three-word or 3-byte instructions
One-Byte Instructions
A 1-byte instruction includes the opcode and operand in the same byte. Operand(s) are internal
register and are coded into the instruction.These instructions are 1-byte instructions performing
three different tasks. In the first instruction, both operand registers are specified. In the second
instruction, the operand B is specified and the accumulator is assumed. Similarly, in the third
instruction, the accumulator is assumed to be the implicit operand. These instructions are stored
in 8-bit binary format in memory; each requires one memory location.
Two-Byte Instructions
In a two-byte instruction, the first byte specifies the operation code and the second byte
specifies
the operand. Source operand is a data byte immediately following the opcode.
Three-Byte Instructions
In a three-byte instruction, the first byte specifies the opcode, and the following two bytes
specify
the 16-bit address. Note that the second byte is the low-order address and the third byte is the
high-order address.

ADDRESSING MODES OF 8051

The 8051 provides a total of five distinct addressing modes.
(1) immediate
(2) register
(3) direct
(4) register indirect
(5) indexed
(1) Immediate Addressing Mode
-code.
y the pound sign, "#".


(2) Register Addressing Mode

manipulated.

(3)Direct Addressing Mode
It is most often used to access RAM locations 30 - 7FH.
This is due to the fact that register bank locations are accessed by the register
names of R0 - R7.
There is no such name for other RAM locations so must use direct addressing
In the direct addressing mode, the data is in a RAM memory location whose
address is known, and this address is given as a part of the instruction



(4)Register Indirect Addressing Mode




(5) Indexed Addressing Mode
up table entries
located in the program ROM space of the 8051.
The instruction used for this purpose is :
MOVC A, @ A+DPTR
-The 16 bit register DPTR and register A are used to form the address of the data element stored

TIMERS

The 8051 comes equipped with two timers, both of which may be controlled, set, read, and
configured individually. The 8051 timers have three general functions: 1) Keeping time and/or
calculating the amount of time between events, 2) Counting the events themselves, or 3)
Generating baud rates for the serial port.
one of the primary uses of timers is to measure time. We will discuss this use of timers first and
will subsequently discuss the use of timers to count events. When a timer is used to measure time
it is also called an "interval timer" since it is measuring the time of the interval between two
events.
Timer SFR
8051 has two timers which each function essentially the same way. One timer is TIMER0 and the
other is TIMER1. The two timers 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).


13-bit Time Mode (mode 0)
Timer mode "0" is a 13-bit timer. This is a relic that was kept around in the 8051 to maintain
compatability with its predecesor, the 8048. Generally the 13-bit timer mode is not used in new
development.
When the timer is in 13-bit mode, TLx will count from 0 to 31. When TLx is incremented from
31, it will "reset" to 0 and increment THx. Thus, effectively, only 13 bits of the two timer bytes
are being used: bits 0-4 of TLx and bits 0-7 of THx. This also means, in essence, the timer can
only contain 8192 values. If you set a 13-bit timer to 0, it will overflow back to zero 8192
machine cycles later.
Again, there is very little reason to use this mode and it is only mentioned so you wont be
surprised if you ever end up analyzing archaeic code which has been passed down
through the generations (a generation in a programming shop is often on the order of
about 3 or 4 months).
16-bit Time Mode (mode 1)
Timer mode "1" is a 16-bit timer. This is a very commonly used mode. It functions just
like 13-bit mode except that all 16 bits are used.
TLx is incremented from 0 to 255. When TLx is incremented from 255, it resets to 0 and
causes THx to be incremented by 1. Since this is a full 16-bit timer, the timer may
contain up to 65536 distinct values. If you set a 16-bit timer to 0, it will overflow back to
0 after 65,536 machine cycles.
8-bit Time Mode (mode 2)
Timer mode "2" is an 8-bit auto-reload mode. When a timer is in mode 2, THx holds the
"reload value" and TLx is the timer itself. Thus, TLx starts counting up. When TLx
reaches 255 and is subsequently incremented, instead of resetting to 0 (as in the case of
modes 0 and 1), it will be reset to the value stored in THx.
Split Timer Mode (mode 3)
Timer mode "3" is a split-timer mode. When Timer 0 is placed in mode 3, it essentially
becomes two separate 8-bit timers. That is to say, Timer 0 is TL0 and Timer 1 is TH0.
Both timers count from 0 to 255 and overflow back to 0. All the bits that are related to
Timer 1 will now be tied to TH0.
While Timer 0 is in split mode, the real Timer 1 (i.e. TH1 and TL1) can be put into
modes 0, 1 or 2 normally--however, you may not start or stop the real timer 1 since the
bits that do that are now linked to TH0. The real timer 1, in this case, will be incremented
every machine cycle no matter what.

USING TIMERS AS EVENT COUNTERS
We've discussed how a timer can be used for the obvious purpose of keeping track of
time. However, the 8051 also allows us to use the timers to count events.How can this be
useful? Let's say you had a sensor placed across a road that would send a pulse every
time a car passed over it. This could be used to determine the volume of traffic on
the road. We could attach this sensor to one of the 8051's I/O lines and constantly
monitor it, detecting when it pulsed high and then incrementing our counter when it went
back to a low state. This is not terribly difficult, but requires some code. Let's say we
hooked the sensor to P1.0; the code to count cars passing would look something like this:
JNB P1.0,$ ;If a car hasn't raised the signal, keep waiting
JB P1.0,$ ;The line is high which means the car is on the sensor right now
INC COUNTER ;The car has passed completely, so we count it

Serial Communication
Some of the external I/0 devices receive only the serial data.Normally serial
communication is used in the Multi Processor environment.8051 has two pins for serial
communication.
(1)SID- Serial Input data.
(2)SOD-Serial Output data.
Instruction Set:
Arithmetic Instructions

Logical Instructions

Data Transfer Instructions that access the Internal Data Memory

Data Transfer Instructions that access the External Data Memory


Jump And Boolean Instructions



INTERFACING KEYBOARD TO 8051 MICROCONTROLLER

The key board here we are interfacing is a matrix keyboard. This key board is designed with a
particular rows and columns. These rows and columns are connected to the microcontroller
through its ports of the micro controller 8051. We normally use 8*8 matrix key board. So only
two ports of 8051 can be easily connected to the rows and columns of the key board.
When ever a key is pressed, a row and a column gets shorted through that pressed key and all the
other keys are left open. When a key is pressed only a bit in the port goes high. Which indicates
microcontroller that the key is pressed. By this high on the bit key in the corresponding column is
identified.
Once we are sure that one of key in the key board is pressed next our aim is to identify that key.
To do this we firstly check for particular row and then we check the corresponding column the
key board.
To check the row of the pressed key in the keyboard, one of the row is made high by making one
of bit in the output port of 8051 high . This is done until the row is found out. Once we get the
row next out job is to find out the column of the pressed key. The column is detected by contents
in the input ports with the help of a counter. The content of the input port is rotated with carry
until the carry bit is set.
The contents of the counter is then compared and displayed in the display. This display is
designed using a seven segment display and a BCD to seven segment decoder IC 7447. The BCD
equivalent number of counter is sent through output part of 8051 displays the number of pressed
key.


Circuit Diagram of Interfacing Keyboard to
8051

Program for Keyboard Interfacing with 8051
Start of main program:
to check that whether any key is pressed
start: mov a,#00h
mov p1,a ;making all rows of port p1 zero
mov a,#0fh
mov p1,a ;making all rows of port p1 high
press: mov a,p2
jz press ;check until any key is pressed
after making sure that any key is pressed
mov a,#01h ;make one row high at a time
mov r4,a
mov r3,#00h ;initiating counter
next: mov a,r4
mov p1,a ;making one row high at a time
mov a,p2 ;taking input from port A
jnz colscan ;after getting the row jump to check
column
mov a,r4
rl a ;rotate left to check next row
mov r4,a
mov a,r3
add a,#08h ;increment counter by 08 count
mov r3,a
sjmp next ;jump to check next row
after identifying the row to check the colomn following steps are followe
colscan: mov r5,#00h
in: rrc a ;rotate right with carry until get the carry
jc out ;jump on getting carry
inc r3 ;increment one count
jmp in
out: mov a,r3
da a ;decimal adjust the contents of counter
before display
mov p2,a
jmp start ;repeat for check next key.

INTERFACING LCD TO 8051:

Liquid Crystal Display also called as LCD is very helpful in providing user
interface as well as for debugging purpose. The most common type of LCD controller is
HITACHI 44780 which provides a simple interface between the controller & an LCD.
These LCD's are very simple to interface with the controller as well as are cost
effective.
The most commonly used ALPHANUMERIC
displays are
1x16 (Single Line & 16 characters),
2x16 (Double Line & 16 character per line),
4x20 (four lines & Twenty characters per line).
The LCD requires 3 control lines (RS, R/W & EN) & 8 (or 4) data lines. The number on
data lines depends on the mode of operation. If operated in 8-bit mode then 8 data lines +
3 control lines i.e. total 11 lines are required. And if operated in 4-bit mode then 4 data
lines + 3 control lines i.e. 7 lines are required. How do we decide which mode to use? Its
simple if you have sufficient data lines you can go for 8 bit mode & if there is a time
constrain i.e. display should be faster then we have to use 8-bit mode because basically 4-
bit mode takes twice as more time as compared to 8-bit mode.

Pin Symbol Function
1 Vss Ground
2 Vdd Supply Voltage
3 Vo Contrast Setting
4 RS Register Select
5 R/W Read/Write Select
6 En Chip Enable Signal
7-14 DB0-DB7 Data Lines
15 A/Vee Gnd for the backlight
16 K Vcc for backlight
When RS is low (0), the data is to be treated as a command. When RS is high (1), the data
being sent is considered as text data which should be displayed on the screen.
When R/W is low (0), the information on the data bus is being written to the LCD. When
RW is high (1), the program is effectively reading from the LCD. Most of the times there
is no need to read from the LCD so this line can directly be connected to Gnd thus saving
one controller line.
The ENABLE pin is used to latch the data present on the data pins. A HIGH - LOW
signal is required to latch the data. The LCD interprets and executes our command at the
instant the EN line is brought low. If you never bring EN low, your instruction will never
be executed.


For Contrast setting a 10K pot should be used as shown in the figure.
Display Data Ram (DDRAM) stores the display data. So when we have to display a
character on LCD we basically write it into DDRAM. For a 2x16 LCD the DDRAM
address for first line is from 80h to 8fh & for second line is 0c0h to 0cfh. So if we want to
display 'H' on the 7th postion of the first line then we will write it at location 87h.
Now as you have noticed two types of data is given to the LCD data to be displayed,
command or special instruction.So now let us write a subroutine for both the type of data
Data to be Displayed
lcd_datadisplay:
SETB RS //Telling the LCD that the data which is being send is to
be displayed
MOV P1,A //Character to be displayed is in Acc
SETB EN
CLR EN //High to Low pulse on EN to latch the data
CALL DELAY //Delay so that LCD finishes its internal operations
ret
Command or Special Instruction
lcd_command:
CLR RS //Telling the LCD that the data which is being send is a
command
MOV P1,A //Character to be displayed is in Acc
SETB EN
CLR EN //High to Low pulse on EN to latch the data
CALL DELAY //Delay so that LCD finishes its internal operations
ret
Here I have used delay at the end of both the subroutines this is done to wait until the
instruction is completely executed by the LCD. This will assure that our program gives
the LCD the time it needs to execute instructions and also makes our program compatible
with any LCD, regardless of how fast or slow it is.

"*" - Not Used/Ignored. This bit can be either "1" or "0"
Set Cursor Move Direction:
ID - Increment the Cursor After Each Byte Written to Display if Set
S - Shift Display when Byte Written to Display Enable Display/Cursor
D - Turn Display On(1)/Off(0) C - Turn Cursor On(1)/Off(0)
B - Cursor Blink On(1)/Off(0)
Set Cursor Move Direction:
ID - Increment the Cursor After Each Byte Written to Display if Set
S - Shift Display when Byte Written to Display Enable Display/Cursor
D - Turn Display On(1)/Off(0) C - Turn Cursor On(1)/Off(0)
B - Cursor Blink On(1)/Off(0)
Move Cursor/Shift Display
SC - Display Shift On(1)/Off(0) RL - Direction of Shift Right(1)/Left(0)
Set Interface Length
DL - Set Data Interface Length 8(1)/4(0)
N - Number of Display Lines 1(0)/2(1)
F - Character Font 5x10(1)/5x7(0)
Poll the "Busy Flag" BF - This bit is set while the LCD is processing
Move Cursor to CGRAM/Display
A - Address
Read/Write ASCII to the Display
D - Data
The above Table shows the different commands for the LCD. I wont go into its details.
Before starting to display on LCD we need to Initialize it. Firstly we must tell the LCD
whether we'll be using 8-bit or 4-bit mode. Also we will be telling the LCD that we need
5x8 character font. Both these options are selected using a single command i.e. 38h. So to
activate both these options we must execute following instructions:

MOV A,#38h
CALL lcd_command
Now that we have to Turn On the display & set the cursor option i.e. cursor ON/OFF &
Cursor blinking ON/OFF for that we will use the command 0Eh i.e. Display On , Cursor
ON but Cursor blinking OFF.
MOV A,#0Eh
CALL lcd_command
And the last command we require is to configure the LCD in such a way that everytime
we send a character to it the cursor position automatically increments by one & moves to
right i.e. 06h.
MOV A,#06h
CALL lcd_command
So the lcd_initialize contains the following instructions
lcd_initialize:
MOV A,#38h
CALL lcd_command
MOV A,#38h
CALL lcd_command
MOV A,#38h
CALL lcd_command
ret
Similarly another important instruction that we require is Clearing the LCD i.e.
lcd_clr:
MOV A,#01h
CALL lcd_command
ret
Now we know all the commands to display on LCD. Let us write a program that will
display 'DNA TECHNOLOGY' on LCD.
ORG 0000h
CALL lcd_initialize
CALL lcd_clr
MOV A,#80h //Location from where Data is to be displayed
CALL lcd_command
MOV A,#'D'
CALL lcd_datadisplay
MOV A,#'N'
CALL lcd_datadisplay
MOV A,#'A'
CALL lcd_datadisplay
MOV A,#20h //Hex value for blank space to be displayed
CALL lcd_datadisplay
MOV A,#'T'
CALL lcd_datadisplay
MOV A,#'E'
CALL lcd_datadisplay
MOV A,#'C'
CALL lcd_datadisplay
MOV A,#'H'
CALL lcd_datadisplay
MOV A,#'N'
CALL lcd_datadisplay
MOV A,#'O'
CALL lcd_datadisplay
MOV A,#'L'
CALL lcd_datadisplay
MOV A,#'O'
CALL lcd_datadisplay
MOV A,#'G'
CALL lcd_datadisplay
MOV A,#'Y'
CALL lcd_datadisplay
stop:
ajmp stop

INTERFACING ADC0808 TO 8051

In lot of embedded systems microcontrollers needs to take analog input. Most of the
sensors & transducers such as temperature, humidity, pressure, are analog. For
interfacing these sensors to microcontrollers we require to convert the analog output of
these sensors to digital so that the controller can read it. Some microcontrollers have built
in Analog to Digital Convertor (ADC) so there is no need of external ADC. For
microcontrollers that dont have internal ADC external ADC is used.
One of the most commonly used ADC is ADC0808. ADC 0808 is a Successive
approximation type with 8 channels i.e. it can directly access 8 single ended analog
signals.
I/O Pins
ADDRESS LINE A, B, C
The device contains 8-channels. A particular channel is selected by using the address
decoder line. The TABLE 1 shows the input states for address lines to select any channel.


Address Latch Enable ALE
The address is latched on the Low High transition of ALE.
START
The ADCs Successive Approximation Register (SAR) is reset on the positive edge i.e.
Low- High of the Start Conversion pulse. Whereas the conversion is begun on the falling
edge i.e. High Low of the pulse.
Output Enable
Whenever data has to be read from the ADC, Output Enable pin has to be pulled high
thus enabling the TRI-STATE outputs, allowing data to be read from the data pins D0-
D7.
End of Conversion (EOC)
This Pin becomes High when the conversion has ended, so the controller comes to know
that the data can now be read from the data pins.
Clock
External clock pulses are to be given to the ADC; this can be given either from LM 555
in Astable mode or the controller can also be used to give the pulses.
ALGORITHM 1. Start. 2. Select the channel. 3. A Low High transition on ALE
to latch in the address. 4. A Low High transition on Start to reset the ADCs SAR.
5. A High Low transition on ALE. 6. A High Low transition on start to start the
conversion. 7. Wait for End of cycle (EOC) pin to become high. 8. Make Output
Enable pin High. 9. Take Data from the ADCs output 10. Make Output Enable pin
Low. 11. Stop
The total numbers of lines required are:
datalines:8
ALE:1
START:1
EOC:1
Output Enable:1
I.e. total 12 lines. You can directly connect the OE pin to Vcc. Moreover instead of
polling for EOC just put some delay so instead of 12 lines you will require 10 lines.
You can also provide the clock through the controller thus eliminating the need of
external circuit for clock.
Calculating Step Size
ADC 0808 is an 8 bit ADC i.e. it divides the voltage applied at Vref+ & Vref- into 28 i.e.
256 steps.
Step Size = (Vref+ - Vref-)/256
Suppose Vref+ is connected to Vcc i.e. 5V & Vref- is connected to the Gnd then the step
size will be
Step size= (5 - 0)/256= 19.53 mv.
Calculating Dout.
The data we get at the D0 - D7 depends upon the step size & the Input voltage i.e. Vin.
Dout = Vin /step Size.
If you want to interface sensors like LM35 which has output 10mv/C then I would
suggest that you set the Vref+ to 2.56v so that the step size will be
Step size= (2.56 - 0)/256= 10 mv.
So now whatever reading that you get from the ADC will be equal to the actual
temperature.
PROGRAM
Here is a program for interfacing the ADC to microcontroller, as stated above I have
assumed that the OE pin is connected to Vcc & the clock is given by the controller.
This program selects channel 0 as input channel reads from it & saves in the accumulator.
adc_a bit p2.0
adc_b bit p2.1
adc_c bit p2.2
adc_start bit p2.3
adc_ale bit p2.4
adc_clk bit P2.5
Org 0000h
clr ale
clr start
clr adc_a
clr adc_b ;Select Channel 0
clr adc_c
call delay_small
setb adc_ale ;ale pin high
call delay_small
setb adc_start ;start pin high
call delay_small
clr adc_ale ;ale pin low
call delay_small
clr adc_start ;start pin low
call delay_long
mov a,P1
loop:
ajmp loop
delay_small:
mov r0,#10
l1_delay_small:
cpl adc_clk
nop
nop
nop
nop
nop
djnz r0,l1_delay_small
ret
delay_long:
mov r0,#40
l1_delay_long:
cpl adc_clk
nop
nop
nop
nop
nop
djnz r0,l1_delay_long
ret
End

Potrebbero piacerti anche