You are on page 1of 36

Microprocessors and Interfacing

ECX4236

Day School 01
(06th March 2016)

N. I Vithanage

Department of Electrical and Computer Engineering


The Open University of Sri Lanka
1
Academic Staff

• CJ Basnayakage – Course coordinator and consultant


• DS Wickramasinghe – Course coordinator and academic
coordinator
• NI Vithanage – Visiting Lecturer

• Demonstrator
• Lab instructors

2
Course Introduction

• This course provides the background knowledge necessary to


build simple microprocessor based system (Microcontroller
Programming and Interfacing)
• 8051 Microprocessor/ Microcontroller (AES51 Development
board)

3
Assessments

• 3 Tutor Marked Assignments (TMA)


• 1 Continues Assessment Test (CAT)
• 3 Laboratory Sessions

• Final Examination
– No Book type
– Not allowed any reference materials
– 3 hour

4
Eligibility Criteria

• Best six of the seven activities will be considered


towards the continuous assessment mark.
• CA Final = Average Best 6 of (3 assignments, 3 lab
sessions, 1 CAT)
• Lab Average = average of (3 lab sessions)

• Eligibility = CA Final ≥ 40% AND Lab Average ≥ 40%

5
Lab Practical Sessions

• Attend all three lab practical sessions.


• Covers what you have done in your TMA’s.
• You will have hands on experiences about
– Assembly programming
– Features of Microprocessor and Development board
– Run the program on simulator and debugging
– Run the program on microcontroller (AES 51 Board)
– Interfacing other components to the microprocessor
(Ex: Sensors, Motors, etc)
6
Recommended Readings
• What Every Engineer should know about Micro-Computers
Hardware/Software Design a Step-by-step Example (William
S. Bennett and Carl F. Evert, Jr.)

• The 8051 Microcontroller and Embedded System Using


Assembly and C, Second Edition, Prentice-Hall
India(Muhammed Ali Mazidi, Junice Gillispie Mazidi, Rolin D.
Mckinlay)

• Embedded Systems & Robots: Projects Using The 8051


Microcontroller, Subrata Ghoshal

7
Moodle Virtual Class

8
Why this Course is important?

• The microprocessor is the core of a computer


system, which can execute instructions (program).
• Today microprocessors can be found almost
anywhere.

9
Course Structure
Microprocessors and Interfacing

Microprocessor Interfacing
- Input
(Switches, Sensors, etc)
- Output
Hardware Assembly (LEDs, Motors/Drivers, etc.)
Architecture Programming
- Memory - Coding
- Registers - Compiling
- I/O - Simulating/ Debugging
- Timers/ Counters - Running on 8051

10
Background Knowledge Needed
• Computer Hardware level operation
– Basic knowledge of computer hardware
– Number Systems
– Read/ Write Operation
– Addressing Modes
– Operations of the Fetch - Execute cycle
Reference: ECX3233- Unit1- Hardware
• Other
– Basic electronics knowledge
– Basic knowledge about Sensors, Transducers and Actuators
11
Microprocessor Vs Microcontroller

Microprocessor Microcontroller
Generally does not have A microcontroller is all in one
RAM, ROM (processor, RAM, IO all on the
one chip)
It is capable of being built Usually used for more
into bigger general purpose dedicated applications.
applications.
Size of ROM, RAM, I/O ports Fixed amount of RAM, ROM,
can be changed I/O Ports.
Expensive Low cost
12
Hardware Architecture

13
Memory Architecture

Internal Memory

Internal RAM SFRs Internal Code


(Optional)

External RAM External Code

14
On-Chip Memory

Register Banks

Bit Memory

Bit Variables that


used to access
certain SFR on a
bit-by-bit basis
Internal RAM
15
Basic Registers
• Accumulator (ACC or A)
• R – Registers
– 4 Banks, 8 Registers in each bank (R0 – R7)
• B – Register
• Data Pointer (DPTR)
• Program Counter (PC)
• Stack Pointer (SP)

16
Pin Description (8051)

• 40 Pins
• 32 Pins are used for I/O
• 24 Pins are Duel purpose
(operates as I/O or control line
or part o addresses or data bus)
• Analog to Digital (ADC)
Input
• External Interrupts

17
IO Ports/ Pins

• Port 0 with pull-up resistors

• Active Low (NOT gate)


• Clear the pin(set in to ‘0’), pin value set in to ‘1’ (Ex: SET
• Set the pin (set in to ‘1’), pin value set in to ‘0’

pin

Microcontroller

Development Board
18
Timers/ Counters - SFR

Timer SFRs

19
Timers/ Counters - Modes

Timer Modes

20
Assembly Programming

21
Compiling

Assembly Language Source File (*.asm)

- Builds a symbol table


Compiling (Assembler)/ Translation - Translates the source file
- Generates the listing

List File(*.lst) Machine


Hardware
Language Object
- Find Errors Architecture
File (*.hex)
- Machine Code
- Use to program the Microcontroller

22
Simulating/ Debugging
• Simulator (Simulating)
– A software application
– Simulates the microcontroller
– Can be run (all or step-by-step) the program on
the simulator

• Debugging
– Find errors by running step-by-step
– Can be able to see all changes in each step

23
Simulators

MCU 8051 IDE


8051 Simulator

24
Addressing Modes

• Immediate Addressing: MOV A,#20h

• Direct Addressing: MOV A,30h

• Indirect Addressing: MOV A,@R0

• External Direct Addressing: MOVX A,@DPTR

• External Indirect Addressing: MOVX @R,A

• Code Indirect Addressing: MOVC A,@A+DPTR

25
Jump Instructions

Command Description
JZ Jump if A=0
JNZ Jump if A/=0
DJNZ Decrement and jump if A/=0
CJNE A, byte Jump if A/=byte
CJNE reg, #data Jump if byte/=#data
JC Jump if CY=1
JNC Jump if CY=0
JB Jump if bit=1
JNB Jump if bit=0
JBC Jump if bit=1 and clear bit

26
Time Calculation

• Crystal Frequency = 11.059 MHz

• 1 Machine Cycle = 12 Crystal Pluses

• Running timer (f) =

• Period (Time for 1 Machine Cycle):

• As a Counter:

27
Software Delays

• Set of Instructions/Loop
• Easy to implement
• Delay created by executing instructions (DJNZ)
• Keep PC busy
• Can be used when timers in use for some other
task (Ex: PWM Generation)

28
Software Delay Calculation
Example:
DELAY_LOOP: MOV R1,#pH
LOOP2: MOV R2,#qH ;Inner-loop
LOOP1: DJNZ R2,LOOP1 ;Outer-loop
DJNZ R1,LOOP2
* p and q are integers
Calculation:
Inner loop:
2 x q = 2q machine cycles
Outer loop:
total machine cycles = (2q+2+1)p–1

Total Time Delay = [(2q+2+1)p–1] x 1 Machine Cycle Time

29
Using Timers

• Timers always counts up.


• When it reaches to the maximum, over flow bit
will set
• Using timers
I. Timer Initialization/ Configure (TCON)
II. Set the Timer Mode (TMOD)
III. Run the timer (TR)
IV. Check the over-flow bit (TF)
V. Stop the timer (TR)

30
More about Hardware

31
Fetch – Execute Cycle
OPCODE OPERANDS
Instruction
Fetch Execute
Program
ORG 7000H
MOV R1, #10H
PC
MOV A, R1
…………………..
Fetch Execute …………………..
…………………..
…………………..
Decode

32
Flags

• Flags are essential in writing assembly


language programs
• Shows current state
Ex: Zero flag – ZF
Sign flag – SF

33
Implementing a Hardware System

Block Diagram
Flow Chart

Testing/ Program
Debugging

Implement

34
Winding Up!
• Refer course materials
• Refer given Reference Books (If you need)
• Search for other resources for more information
(internet, books, etc)
• Discuss with others
• Understand and then write the assignments/ Lab
Reports (Do not copy) by your own words
• Complete all parts of the Assignments
• During the lab sessions, do practical by your own.
– If you don’t understand something, ask form the
demonstrator/instructor.
35
Thank You!

 CJ Basnayakage: cjbas@ou.ac.lk
 DS Wickramasinghe: dswic@ou.ac.lk
Phone: - Direct: 011 288 1437
Ext: 437
 NI Vithanage: nivit@ou.ac.lk

Check your e-mails…..


Check the moodle class, MyOusl, Google Drive…..
Give us your feed back to improve the course…..

36

You might also like