SlideShare a Scribd company logo
PIC
Lecture 03
PIC18 features
• RISC architecture
• On-chip program (code) – ROM
• Data RAM
• Data EEPROM
• Timers
• ADC
• USART and I/O ports
Simple view of PIC
Lecture 03 basics of pic
Program ROM
• ROM is used to store programs (program or code ROM)
• PIC 18 program ROM
• Flash [letter F for this]
• OTP (One Time Programmable) [letter C for this]
• Masked (during fabrication process)
Data RAM and EEPROM
• RAM is for data storage.
• RAM Space = General Purpose Register (GPR) + Special Function
Registers (SFR)
• Microchip website gives only the GPR size (because SFRs are fixed)
• EEPROM:
• To store critical data that does not need to be changed very often
PIC microcontroller pheripherals
• ADC (10 bits)
• Timers
• USART (Universal Synchronous Asynchronous Receiver Transmitter)
PIC architecture and assembly
language programming
The WREG register
• The majority of PIC registers are 8 bits
• Therefore, only one data type: 8 bits
• Any data larger than 8 bits must be broken into 8-bits chunks.
• WREG  working register (only one)
• WREG  similar to accumulator in other microprocessors
• WREG  for all arithmetic and logic instructions
Understanding the WREG register
• MOVLW
• Move 8-bit data into WREG register
• Move a literal (L) value to WREG (W)
•
•
• MOVLW 25H ;move value 25H (25 in hex) into WREG
Understanding the WREG register
• ADDLW
• Add literal value K to WREG and put the result back to WREG
• WREG = WREG + k
Understanding the WREG register
Understanding the WREG register
PIC FILE Register
• File register  data memory space  read/ write (static RAM)
• File register data RAM = SFR + GPR
• SFR
• Dedicated to special functions
• ALU status
• Timers
• Serial communication
• I/O ports
• ADC
• ….Etc.
PIC FILE Register (Contd..)
• PIC SFRs are fixed and 8-bits
• More SFR registers while PIC has more timers, ADCs etc
• GPR (General purpose registers or RAM)
• For data storage and scratch pad
• Large GPR size means more difficulties in managing using assembly language
• C compiler need more registers to handle parameters and perform job faster
PIC FILE Register (Contd..)
PIC FILE Register (Contd..)
PIC FILE Register (Contd..)
PIC FILE Register (Contd..)
Simple instructions with the default access
bank
• MOVWF  (W: WREG, F: file register)
• This instruction tells to the CPU to move the source register of WREG to a
destination in the file register.
Special function registers
Simple instructions with the default access
bank GPR
Example
Example
More instructions
• ADDWF fileReg, D
SFR or GPR
Adding the content of
WREG and a file
register
Destination bit
D=0  destination is WREG
D=1  destination is file register
Example
Example - answer
Example
Example - answer
To make things less confusion
Destination = WREG
Destination = A file register
Try this..
Answer 1
Answer 2
WREG, File Registers and ALU
ALU instructions using both WREG and fileReg
File register instructions using fileReg or
WREG as destination
COMF instruction
How to write a program to toggle the SFR of Port B continuously forever?
COMF instruction
DECF
• Decrement (subtract one) the content of fileReg and place the result
in WREG or fileReg.
• Destination is fileReg
• Destination is WREG
MOVF
• This mnemonic is intended to perform MOVFW.
• MOVF fileReg, D
• If D=0  it copies the content of fileReg to WREG
• If D=1  fileReg is copied to itslef
MOVFF
• Copies data from One
location in fileReg 
another location in
fileReg
• Without going through
the WREG
PIC Status Register
• Flag register (status register)
PIC Status Register
• C (carry flag)
• This is set whenever there is a carry out from D7 bit (8th bit)
• This is affected after 8-bit addition and subtraction
• DC (digital carry flag) [Auxiliary Carry Flag]
• This bit is set whenever if there is a carry from D3 to D4 (during add and sub)
• This is used for BCD arithmetic
• Z (zero flag)
• If the result of arithmetic or logical operation is zero then z=1, otherwise (z=0)
for non-zero result.
PIC Status Register
• OV (overflow flag)
• This is used for signed number arithmetic
• N (Negative flag)
• This is also used for signed number arithmetic
• D7=0  N=0  result is positive
• D7=1  N=1  result is negative
• Not all instructions affect the flags
PIC Status Register
PIC Status Register
Flag bits and decision
• Status flags are also called conditional flags.
• Some instruction will make conditional jump (branch) based on the
status of the flag bits.
PIC data format representation
• Hex numbers
If the value started with hex digit (A-F), then it must
be preceded with zero.
PIC data format representation
• Binary numbers (1 way)
• Decimal numbers (2 ways)
• ASCII character
Assembler Directives
• Instructions  What to do using the CPU
• Directives (pseudo instructions)  Directions to the assembler
• Ex: EQU, SET, ORG and END
• EQU
• This is used to define a constant value or fixed address.
Assembler Directives
• SET
• This is used to define a constant value or fixed address.
• SET and EQU directives are identical.
• The value assigned by the SET directive may be reassigned later.
• ORG
• This is used to indicate the beginning of the address. (For both code and
data).
• The number that comes after ORG must be in hex.
Assembler Directives
• END
• This indicates to the assembler the end of source file (asm).
• Last line of the program
• LIST
• This indicates to the assembler the specific PIC chip
• We use LIST to state the target chip
Assembler Directives
• #include
• This tells the assembler to use the libraries associated with the specific PIC
• _config
• This tells the assembler the configurations bits for the target chip.
• Don’t use incorrect config:  it may meke the chip unusable
• radix
• This indicates whether the numbering system is hexadecimal or decimal.
• Default is hexadecimal
• For decimal
Rules for labels
• Meaningful
• Unique
• Label  consist of
• upper and lower case letters
• digits
• ?
• .
• @
• _
• $
• First character  alphabetic character
• Don’t use reserved words (check the assembler for more details)
Structure of assembly language
• Four fields
Optional fields
Line of the code by
name
Structure of assembly language (Example-
asm file)
Steps to create a program
Steps to create a program
• Sample of PIC err file
Steps to create a program
• Sample of List file
Program counter (PC)
• Another important register in the PIC microcontroller.
• The PC is used by the CPU to point the address of the next instruction
to be executed.
• The PC is incremented automatically.
• The wider the PC  CPU can access more memory locations
• 14-bit PC  214 (16K) code  (from 0000 to 3FFFH)
• 16-bit  216 (64K) code  (0000-FFFFH)
• 21-bit  221 (2M)  (000000-1FFFFFH)
Program counter (PC)
• PIC18 on-chip ROM Size and address space
Program counter (PC)
Program counter (PC)
Executing a program byte by byte
Two bytes
instructions
Four bytes instruction
Executing a program byte by byte
• ROM contents
Why PIC use Harvard architecture?
Instruction size of PIC 18
• MOLW (2 byte instruction)
Opcode (8 bits) Literal
value
Instruction size of PIC 18
• ADDLW
• MOVWF
Instruction size of PIC 18
• MOVFF (4 bytes)
• GOTO (4 bytes)
Because,
instructions are
either 2 bytes or 4
bytes
Ways to increase performance
• There are three ways available to microprocessor designers to
increase the processing power of CPU
• Increase clock frequency  more power and heat dissipation
• Use Harvard architecture  very expensive and unrealistic for x86
architecture
• Use RISC architecture
Microchip used all three methods
Features of RISC
• Feature 1: RISC processors have fixed instruction size.
• Feature 2: Use large number of registers (at least 32 registers).
• Feature 3: RISC processors have a small instruction set.
• Feature 4: more than 95% of instructions are executed with only one
clock cycle.
• Feature 5: RISC processors have separate buses for data and code.
• Feature 6: due to the small set of instructions, they are implemented
using the hardwire method. (no more than 10% of transistors)
• Feature 7: RISC uses load/store architecture. (no direct access to
external memory for arithmetic operations, only via registers)
• Shall we try MPLAB IDE?????
Summary

More Related Content

PDF
3.2 modulation formats bpsk, qpsk, oqpsk,
PDF
Antennas and Wave Propagation
PPT
E.s unit 4 and 5
PPTX
Phase shift keying Presentation
PPTX
Flip Flop | Counters & Registers | Computer Fundamental and Organization
PPTX
Johnson counter
PPTX
8257 DMA Controller
PDF
Comparison of modulation methods
3.2 modulation formats bpsk, qpsk, oqpsk,
Antennas and Wave Propagation
E.s unit 4 and 5
Phase shift keying Presentation
Flip Flop | Counters & Registers | Computer Fundamental and Organization
Johnson counter
8257 DMA Controller
Comparison of modulation methods

What's hot (20)

PPTX
8051 Microcontroller ppt
PPTX
Microcontroller 8051 and its interfacing
PPTX
Multistage amplifier
PDF
8051 microcontroller
PPT
Vestigial side band (vsb)
PPT
Architecture of 8086 Microprocessor
DOCX
Counters In Digital Logic Design
DOCX
Microprocessor Interfacing and 8155 Features
PPT
Microcontroller 8051
PPTX
ADC - Types (Analog to Digital Converter)
PPTX
Double SideBand Suppressed Carrier (DSB-SC)
PPT
Amplitude modulation
PPTX
DIFFERENTIAL AMPLIFIER using MOSFET
PPTX
Microwave oscillator design
PPTX
Isolator & Circulator -FT.pptx
PPTX
Delta modulation
DOC
Chap 5
PPTX
Successive Approximation ADC
PPT
Digital modulation
PPTX
Stacks & subroutines 1
8051 Microcontroller ppt
Microcontroller 8051 and its interfacing
Multistage amplifier
8051 microcontroller
Vestigial side band (vsb)
Architecture of 8086 Microprocessor
Counters In Digital Logic Design
Microprocessor Interfacing and 8155 Features
Microcontroller 8051
ADC - Types (Analog to Digital Converter)
Double SideBand Suppressed Carrier (DSB-SC)
Amplitude modulation
DIFFERENTIAL AMPLIFIER using MOSFET
Microwave oscillator design
Isolator & Circulator -FT.pptx
Delta modulation
Chap 5
Successive Approximation ADC
Digital modulation
Stacks & subroutines 1
Ad

Similar to Lecture 03 basics of pic (20)

PPTX
WINSEM2022-23_BECE204L_TH_VL2022230500861_2023-02-10_Reference-Material-I.pptx
PPTX
Topic 2 ARM Architecture and Programmer's Model.pptx
PPTX
Arm architecture chapter2_steve_furber
PPT
8051.ppt microcontroller full detail explnation
PPTX
Embedded computing platform design
PDF
Introduction to Processor Design in System Verilog
PPT
10 instruction sets characteristics
PPTX
ARM introduction registers architectures
PPTX
ARM-7 ADDRESSING MODES INSTRUCTION SET
PPT
W8_1: Intro to UoS Educational Processor
PPTX
Module 2 ARM CORTEX M3 Instruction Set and Programming
PPT
Processor Design Flow architecture design
PPTX
It322 intro 1
PPTX
lec3-8051microcontrollerarchitecture-230130044236-5c11a082.pptx
PPTX
Architecture of pentium family
PPTX
PDF
introduction to embedded systems part 1
PPTX
Pentium processor
PDF
Introduction to pic microcontroller
PPTX
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
WINSEM2022-23_BECE204L_TH_VL2022230500861_2023-02-10_Reference-Material-I.pptx
Topic 2 ARM Architecture and Programmer's Model.pptx
Arm architecture chapter2_steve_furber
8051.ppt microcontroller full detail explnation
Embedded computing platform design
Introduction to Processor Design in System Verilog
10 instruction sets characteristics
ARM introduction registers architectures
ARM-7 ADDRESSING MODES INSTRUCTION SET
W8_1: Intro to UoS Educational Processor
Module 2 ARM CORTEX M3 Instruction Set and Programming
Processor Design Flow architecture design
It322 intro 1
lec3-8051microcontrollerarchitecture-230130044236-5c11a082.pptx
Architecture of pentium family
introduction to embedded systems part 1
Pentium processor
Introduction to pic microcontroller
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
Ad

More from Vajira Thambawita (20)

PDF
Lecture 4 principles of parallel algorithm design updated
PDF
Lecture 3 parallel programming platforms
PDF
Lecture 2 more about parallel computing
PDF
Lecture 1 introduction to parallel and distributed computing
PDF
Lecture 12 localization and navigation
PDF
Lecture 11 neural network principles
PDF
Lecture 10 mobile robot design
PDF
Lecture 09 control
PDF
Lecture 08 robots and controllers
PDF
Lecture 07 more about pic
PDF
Lecture 06 pic programming in c
PDF
Lecture 05 pic io port programming
PDF
Lecture 04 branch call and time delay
PDF
Lecture 02 mechatronics systems
PDF
Lecture 1 - Introduction to embedded system and Robotics
PDF
Lec 09 - Registers and Counters
PDF
Lec 08 - DESIGN PROCEDURE
PDF
Lec 07 - ANALYSIS OF CLOCKED SEQUENTIAL CIRCUITS
PDF
Lec 06 - Synchronous Sequential Logic
PDF
Lec 05 - Combinational Logic
Lecture 4 principles of parallel algorithm design updated
Lecture 3 parallel programming platforms
Lecture 2 more about parallel computing
Lecture 1 introduction to parallel and distributed computing
Lecture 12 localization and navigation
Lecture 11 neural network principles
Lecture 10 mobile robot design
Lecture 09 control
Lecture 08 robots and controllers
Lecture 07 more about pic
Lecture 06 pic programming in c
Lecture 05 pic io port programming
Lecture 04 branch call and time delay
Lecture 02 mechatronics systems
Lecture 1 - Introduction to embedded system and Robotics
Lec 09 - Registers and Counters
Lec 08 - DESIGN PROCEDURE
Lec 07 - ANALYSIS OF CLOCKED SEQUENTIAL CIRCUITS
Lec 06 - Synchronous Sequential Logic
Lec 05 - Combinational Logic

Recently uploaded (20)

PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Trump Administration's workforce development strategy
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
Complications of Minimal Access Surgery at WLH
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Classroom Observation Tools for Teachers
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
master seminar digital applications in india
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
VCE English Exam - Section C Student Revision Booklet
Trump Administration's workforce development strategy
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Chinmaya Tiranga quiz Grand Finale.pdf
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Supply Chain Operations Speaking Notes -ICLT Program
2.FourierTransform-ShortQuestionswithAnswers.pdf
Computing-Curriculum for Schools in Ghana
Complications of Minimal Access Surgery at WLH
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Classroom Observation Tools for Teachers
Weekly quiz Compilation Jan -July 25.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
O5-L3 Freight Transport Ops (International) V1.pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
master seminar digital applications in india
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS

Lecture 03 basics of pic

  • 2. PIC18 features • RISC architecture • On-chip program (code) – ROM • Data RAM • Data EEPROM • Timers • ADC • USART and I/O ports
  • 5. Program ROM • ROM is used to store programs (program or code ROM) • PIC 18 program ROM • Flash [letter F for this] • OTP (One Time Programmable) [letter C for this] • Masked (during fabrication process)
  • 6. Data RAM and EEPROM • RAM is for data storage. • RAM Space = General Purpose Register (GPR) + Special Function Registers (SFR) • Microchip website gives only the GPR size (because SFRs are fixed) • EEPROM: • To store critical data that does not need to be changed very often
  • 7. PIC microcontroller pheripherals • ADC (10 bits) • Timers • USART (Universal Synchronous Asynchronous Receiver Transmitter)
  • 8. PIC architecture and assembly language programming
  • 9. The WREG register • The majority of PIC registers are 8 bits • Therefore, only one data type: 8 bits • Any data larger than 8 bits must be broken into 8-bits chunks. • WREG  working register (only one) • WREG  similar to accumulator in other microprocessors • WREG  for all arithmetic and logic instructions
  • 10. Understanding the WREG register • MOVLW • Move 8-bit data into WREG register • Move a literal (L) value to WREG (W) • • • MOVLW 25H ;move value 25H (25 in hex) into WREG
  • 11. Understanding the WREG register • ADDLW • Add literal value K to WREG and put the result back to WREG • WREG = WREG + k
  • 14. PIC FILE Register • File register  data memory space  read/ write (static RAM) • File register data RAM = SFR + GPR • SFR • Dedicated to special functions • ALU status • Timers • Serial communication • I/O ports • ADC • ….Etc.
  • 15. PIC FILE Register (Contd..) • PIC SFRs are fixed and 8-bits • More SFR registers while PIC has more timers, ADCs etc • GPR (General purpose registers or RAM) • For data storage and scratch pad • Large GPR size means more difficulties in managing using assembly language • C compiler need more registers to handle parameters and perform job faster
  • 16. PIC FILE Register (Contd..)
  • 17. PIC FILE Register (Contd..)
  • 18. PIC FILE Register (Contd..)
  • 19. PIC FILE Register (Contd..)
  • 20. Simple instructions with the default access bank • MOVWF  (W: WREG, F: file register) • This instruction tells to the CPU to move the source register of WREG to a destination in the file register. Special function registers
  • 21. Simple instructions with the default access bank GPR
  • 24. More instructions • ADDWF fileReg, D SFR or GPR Adding the content of WREG and a file register Destination bit D=0  destination is WREG D=1  destination is file register
  • 29. To make things less confusion Destination = WREG Destination = A file register
  • 34. ALU instructions using both WREG and fileReg
  • 35. File register instructions using fileReg or WREG as destination
  • 36. COMF instruction How to write a program to toggle the SFR of Port B continuously forever?
  • 38. DECF • Decrement (subtract one) the content of fileReg and place the result in WREG or fileReg. • Destination is fileReg • Destination is WREG
  • 39. MOVF • This mnemonic is intended to perform MOVFW. • MOVF fileReg, D • If D=0  it copies the content of fileReg to WREG • If D=1  fileReg is copied to itslef
  • 40. MOVFF • Copies data from One location in fileReg  another location in fileReg • Without going through the WREG
  • 41. PIC Status Register • Flag register (status register)
  • 42. PIC Status Register • C (carry flag) • This is set whenever there is a carry out from D7 bit (8th bit) • This is affected after 8-bit addition and subtraction • DC (digital carry flag) [Auxiliary Carry Flag] • This bit is set whenever if there is a carry from D3 to D4 (during add and sub) • This is used for BCD arithmetic • Z (zero flag) • If the result of arithmetic or logical operation is zero then z=1, otherwise (z=0) for non-zero result.
  • 43. PIC Status Register • OV (overflow flag) • This is used for signed number arithmetic • N (Negative flag) • This is also used for signed number arithmetic • D7=0  N=0  result is positive • D7=1  N=1  result is negative • Not all instructions affect the flags
  • 46. Flag bits and decision • Status flags are also called conditional flags. • Some instruction will make conditional jump (branch) based on the status of the flag bits.
  • 47. PIC data format representation • Hex numbers If the value started with hex digit (A-F), then it must be preceded with zero.
  • 48. PIC data format representation • Binary numbers (1 way) • Decimal numbers (2 ways) • ASCII character
  • 49. Assembler Directives • Instructions  What to do using the CPU • Directives (pseudo instructions)  Directions to the assembler • Ex: EQU, SET, ORG and END • EQU • This is used to define a constant value or fixed address.
  • 50. Assembler Directives • SET • This is used to define a constant value or fixed address. • SET and EQU directives are identical. • The value assigned by the SET directive may be reassigned later. • ORG • This is used to indicate the beginning of the address. (For both code and data). • The number that comes after ORG must be in hex.
  • 51. Assembler Directives • END • This indicates to the assembler the end of source file (asm). • Last line of the program • LIST • This indicates to the assembler the specific PIC chip • We use LIST to state the target chip
  • 52. Assembler Directives • #include • This tells the assembler to use the libraries associated with the specific PIC • _config • This tells the assembler the configurations bits for the target chip. • Don’t use incorrect config:  it may meke the chip unusable • radix • This indicates whether the numbering system is hexadecimal or decimal. • Default is hexadecimal • For decimal
  • 53. Rules for labels • Meaningful • Unique • Label  consist of • upper and lower case letters • digits • ? • . • @ • _ • $ • First character  alphabetic character • Don’t use reserved words (check the assembler for more details)
  • 54. Structure of assembly language • Four fields Optional fields Line of the code by name
  • 55. Structure of assembly language (Example- asm file)
  • 56. Steps to create a program
  • 57. Steps to create a program • Sample of PIC err file
  • 58. Steps to create a program • Sample of List file
  • 59. Program counter (PC) • Another important register in the PIC microcontroller. • The PC is used by the CPU to point the address of the next instruction to be executed. • The PC is incremented automatically. • The wider the PC  CPU can access more memory locations • 14-bit PC  214 (16K) code  (from 0000 to 3FFFH) • 16-bit  216 (64K) code  (0000-FFFFH) • 21-bit  221 (2M)  (000000-1FFFFFH)
  • 60. Program counter (PC) • PIC18 on-chip ROM Size and address space
  • 63. Executing a program byte by byte Two bytes instructions Four bytes instruction
  • 64. Executing a program byte by byte • ROM contents
  • 65. Why PIC use Harvard architecture?
  • 66. Instruction size of PIC 18 • MOLW (2 byte instruction) Opcode (8 bits) Literal value
  • 67. Instruction size of PIC 18 • ADDLW • MOVWF
  • 68. Instruction size of PIC 18 • MOVFF (4 bytes) • GOTO (4 bytes) Because, instructions are either 2 bytes or 4 bytes
  • 69. Ways to increase performance • There are three ways available to microprocessor designers to increase the processing power of CPU • Increase clock frequency  more power and heat dissipation • Use Harvard architecture  very expensive and unrealistic for x86 architecture • Use RISC architecture Microchip used all three methods
  • 70. Features of RISC • Feature 1: RISC processors have fixed instruction size. • Feature 2: Use large number of registers (at least 32 registers). • Feature 3: RISC processors have a small instruction set. • Feature 4: more than 95% of instructions are executed with only one clock cycle. • Feature 5: RISC processors have separate buses for data and code. • Feature 6: due to the small set of instructions, they are implemented using the hardwire method. (no more than 10% of transistors) • Feature 7: RISC uses load/store architecture. (no direct access to external memory for arithmetic operations, only via registers)
  • 71. • Shall we try MPLAB IDE?????