Академический Документы
Профессиональный Документы
Культура Документы
(EE-423)
Dr. Muhammad Rauf
Assistant Professor
Electronics Engineering Department
MUHAMMAD RAUF
Master of Engineering in Electronics (2009-2011)
Research Area: Embedded system and optimization
Member of:
IEEE (Karachi Chapter)
Board of Studies (EED, SSUET
FYP committee (EED, SSUET)
Post Graduate Program (SSUET)
Achievements
• 10 Journal papers
• 18 international conference papers
GOLD Medal – SEDEX 31, UTP
IEM best invention award – SEDEX 31, UTP
Most Innovative award- THE CHAMPION for SEDEX 31, UTP
GOLD Medal- MTE, Kuala Lumpur
SILVER Medal- CITREX, UMP
Course Instructor
• Name : Dr. Muhammad Rauf
• Office : GG-07
• Phone : 021-34988000, Ext- 347
• Email : mrauf57@gmail.com
Course Schedule
Lectures
• Monday 12:40–1:30 pm @ Room No. GFT-3
• Thursday 11:50–12:40 pm @ Room No. GF-4
• Friday 8:30–9:15 am @ Room No. GFT-3
Course Learning Outcomes
CLO
Description Level
No.
Comprehend the basic knowledge of embedded
1 system and its architecture included microcontroller C2
and FPGA.
Demonstrate programming interfacing of PIC
2 microcontrollers, Arduino and FPGA with different C3
type of peripherals.
Design an embedded system for engineering C6
3
problem.
Text Books
The PIC Microcontroller And Embedded
Systems: Using Assembly And C for PIC18, ANY
Edition, Muhammad Ali Mazidi, Rolin
McKinlay, Danny Causey
What is Embedded System
Performance
• Overall speed and deadlines
Functionality and user interface
Manufacturing cost
Power consumption
Other requirements (physical size)
Comparison
Comparison
Microcontrollers
PIC Microcontrollers
• Peripheral Interface Controller (PIC) was originally
designed by General Instruments
• In the late 1970s, GI introduced PIC® 1650 and
1655 – RISC with 30 instructions.
• PIC was sold to Microchip
• Features: low-cost, self-contained, 8-bit, Harvard
structure, pipelined, RISC, single accumulator, with
fixed reset and interrupt vectors.
17
Complex instruction set computer Reduce instruction set computer
PIC Families
PIC Family Stack Size Instruction No of Interrupt
Word Size Instructions Vectors
12CX/12FX 2 12- or 14-bit 33 None
16C5X/16F5X 2 12-bit 33 None
16CX/16FX 8 14-bit 35 1
17CX 16 16-bit 58 4
18CX/18FX 32 16-bit 75 2
Example: 16C84 was the first of its kind. It was later reissued as the 16F84,
incorporating Flash memory technology. It was then reissued as 16F84A.
Program
Memory
PIC18F Microcontroller Families
• PIC microcontrollers are designed using the Harvard
Architecture which includes:
• Microprocessor unit (MPU)
• Program memory for instructions
• Data memory for data
• I/O ports
• Support devices such as timers
Microprocessor Unit (1 of 3)
• Includes Arithmetic Logic
Unit (ALU), Registers, and
Control Unit
• Arithmetic Logic Unit (ALU)
• WREG – working register
• Status register that stores
flags
• Instruction decoder – when
the instruction is fetched it
goes into the ID
Microprocessor Unit (2 of 3)
• Registers
• Bank Select Register (BSR)
• 4-bit register used in direct addressing the data memory
• File Select Registers (FSRs)
• 16-bit registers used as memory pointers in indirect addressing data memory
• Program Counter (PC)
• 21-bit register that holds the program memory address while executing programs
Microprocessor Unit (3 of 3)
• Control unit
• Provides timing and control signals to various Read and
Write operations
Summary
• An embedded system is a product that has one or more
computers embedded within it, which exercise primarily
a control function.
• Microcontrollers are designed according to accepted
electronic and computer principles, and are
fundamentally made up of microprocessor core,
memory and peripherals.
• Microchip offers a wide range of microcontrollers,
divided into a number of different families. Each family
has identical central architecture and instruction set.
However, common features also appear across all their
microcontrollers.
26
PIC18F Programming Model
• The understanding of
the internal architecture
of a microprocessor is
necessary to write
assembly language
programs.
Status Register contains the arithmetic status of the ALU (Arithmetic Logic Unit), the RESET
status and the bank select bit for data memory
WREG
• 8-bit Working Register (equivalent to an
accumulator)
• A most widely used register in PIC
• Used for all arithmetic and logic instruction
Any data larger than 8 bit will be broken into 8 bits chunks
before it is processed.
Flags in Status Register
Example: 9F+52 =F1
1001 1111
0101 0010
-------------
1111 0001
N=1,OV=0, Z=0, C=0, DC=1
• C (Carry/Borrow Flag):
• set when an addition generates a carry and a subtraction generates a borrow
• DC (Digit Carry Flag):
• also called Half Carry flag; set when carry generated from Bit3 to Bit4 in an arithmetic
operation
• Z (Zero Flag):
• set when result of an operation is zero
• OV (Overflow Flag):
• set when result of an operation of signed numbers goes beyond seven bits
• N (Negative Flag):
• set when bit B7 is one of the result of an arithmetic /logic operation
File Select Registers (FSR)
• There are three registers:
• FSR0, FSR1, and FSR2
• Each register composed of two 8-bit registers
(FSRH and FSRL)
• Used as pointers for data registers
• Holds 12-bit address of data register
Registrars functionality in PIC Microcontroller
Other Registers
• Program Counter (PC) • Stack
• 21-bit register functions as a • 31 word-sized registers used
pointer to program memory for temporary storage of
during program execution memory addresses during
• Table Pointer execution of a program
• 21-bit register used as a • Special Function Registers
memory pointer to copy bytes (SFRs):
between program memory • Data registers associated
and data registers with I/O ports, support
• Stack Pointer (SP) devices, and processes of
• Register used to point to the data transfer
stack
18f has 16 banks of register
Introduction to
PIC18 Instruction
Set
• Initialization of a variable
• movlw B’11100000’
• movwf TRIST
• Initialize the PORTB data direction register.
41
The movff instruction
• movff PORTB, PORTB_COPY
• movff - a two-word instruction
• Thus source and destination have 12-bit addresses
• Source – instruction bits + BSR
• Destination – instruction 2nd byte
• Moves data from a 1-byte source to a 1-byte
destination.
• For instruction memory as efficient as the regular move
instruction.
42
The movwf
• movwf f(,Banked) – Move WREG to f
44
Example to evaluate the final values of working
register using Mov and add commands
MOVLW and ADDLW
Class assignment
Write instruction to move value 34h into working register then
add values 16H and CDH in the same register
comf
Decf/Incf
TASK: What is the final value in WREG in both of the
codes below;
PIC like many other microcontrollers, supports only
addition and subtraction
• Flag C, Z and DC are set depending on the results of
addition and subtraction.
• Since subtraction is performed like addition of the
negative number, C flag is inverse following a
subtraction.
Looping in PIC
Using DECFSZ Using BNZ
Examples using both ways
target location.
Call and Return Instructions
Op-Code Description
Test and Skip Instructions
Op-Code Description
Loop inside a loop
All locations in a file register is 8 bit. Therefore a
single loop can only go up to 255 times.
Any loop more than 255, would need another
loop.
Unconditional branch
GOTO to itself
Time Delay in PIC: The Calculations
Calculation for machine cycle
Calculation for instructions cycle