Lecture 3
Lecture 3
PIC Microcontroller
Peripheral Interface Controller
Microchip introduced an 8 bit microcontroller in 1989 called PIC
PIC family includes 10xxx, 12xxx, 14xxx, 16xxx, 17xxx, 18xxx series
They all are 8 bit processors, i.e. CPU can work 8-bit data at a time.
One majaor problem with PIC family is that they are not completely compatible in terms of
software when going from one family to another family.
Comparison of 8051 and PIC18
family
Feature 8951 (8051 Family) PIC18 (PIC Family)
Architecture 8-bit Harvard 8-bit Harvard
Instruction Set CISC (Complex Instruction Set RISC (Reduced Instruction Set Computing)
Computing)
Clock Speed Typically up to 33 MHz Typically up to 64 MHz
Memory Separate code (ROM) and data (RAM) Separate code (Flash) and data (RAM) memory
memory
Program Memory ROM/Flash (4KB–64KB) Flash (Up to 128KB)
Data Memory Internal SRAM (128B–256B) + External Internal SRAM (Up to 4KB)
RAM
GPIO (I/O Pins) 4 Ports (32 I/O pins) Varies, up to 70 I/O pins
Timers 2 or 3 Timers Multiple Timers with CCP (Capture/Compare/PWM)
Communication Interfaces UART, I²C, SPI (with external modules) Built-in UART, I²C, SPI, USB, CAN (depending on
model)
PIC Microcontroller
⚫ Program ROM
⚫ The ROM use to store program.
PIC18 Features (cont’d)
⦿ Data Memory
The data memory is SRAM and EEPROM.
provides a place to store data as application
executes and is lost when power is removed from
the system.
⦿ EEPROM
also a nonvolatile memory which is used to
store data like values of certain variables.
PIC18F4550 has 256 Bytes of EEPROM.
PIC18 Features (cont’d)
⚫ I/O Ports:
⚫ The I/O ports are used to interface the
microprocessor to the outside world.
• Oscillator
• 8x8 Multiplier
• ADC Interface
• Timers/Counters
• USB
PIC18 Registers
• CPUs use many registers to store data
temporarily.
SFR are dedicated to specific functions such as ALU status, timers, serial communication, I/O
ports, ADC and so on.
The function of each SFR is fixed by the CPU designer at the time of design.
8-bit registers
Memory Organisation of PIC 18
Instruction Set
MOVWF
The MOVWF (Move WREG to File Register) instruction in the PIC18
microcontroller is used to transfer the contents of the WREG (Working
Register) to a specified file register in RAM.
MOVWF Syntax:
MOVWF f, a
f- destination file register (address in RAM)
a- access bank selection bit
Ex.
MOVLW 0x55 ; Load WREG with 0x55
MOVWF 0x20, 0 ; Store WREG content (0x55) into RAM location 0x20
Instruction Set
Example 1
Q. State the content of file register RAM location after the following
program:
MOVLW 99H
MOVWF 12H
?
MOVLW 85H
MOVWF 30H
?
Instruction Set
COMF Instruction
MOVLW 55H
MOVWF PORTB
COMF PORTB, F
Instruction Set
Q. Write a simple program to toggle the SFR of PORT B continuously forever
Ans:
MOVLW 55H
MOVWF PORTB
B1 COMF PORTB, F
GOTO B1
Instruction Set
DECF Instruction
The DECF (Decrement File Register) instruction in the PIC18 microcontroller decrements the
value of a specified file register by 1 and stores the result in either the same file register or the
WREG.
Ex.
MOVLW 0x05 ; Load WREG with 5
MOVWF 0x20 ; Store 5 in register 0x20
DECF 0x20, F ; Decrement register 0x20 and store result in 0x20
Instruction Set
MOVF Instruction
The MOVF (Move File Register) instruction in the PIC18 microcontroller moves the value of
a specified file register to either the WREG or the same file register while affecting status
flags.
Ex.