0% found this document useful (0 votes)
48 views

Pic Microcontroller

The document provides an overview of PIC microcontrollers including their architecture, instruction set, families, and application notes. Key details include PICs using Harvard architecture with separate program and data memory, an 8-bit RISC core with one accumulator register, and extensive application notes and example code available from the manufacturer.

Uploaded by

jeyasuthanj
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Pic Microcontroller

The document provides an overview of PIC microcontrollers including their architecture, instruction set, families, and application notes. Key details include PICs using Harvard architecture with separate program and data memory, an 8-bit RISC core with one accumulator register, and extensive application notes and example code available from the manufacturer.

Uploaded by

jeyasuthanj
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

PIC MICROCONTROLLER

Rodolfo Rodriguez Kevin Zhang MJ Gellada


1

Overview
Microcontroller and Architecture Basics Variants among families ISA Programming overview Hardware interface/Developmental boards

Description
PIC Peripheral Interface Controller Made by Microchip Technology Most popular by industry developers and hobbyists
Low cost (cents to dollars) Availability Extensive application notes Serial programming

v
http://www.microchip.com/stellent/images/mchpsiteimages/en537986.jpg
4

8-bit Core Architecture


Harvard (separate code and data space) RISC One accumulator
W Register

Small addressable data space (256 bytes)


Banking

RAM
PC, special purpose registers

http://www.microchip.com/_images/BaselineArch_large.jpg

Advantages & Limitations to 8-bit Architecture


Small ISA to learn Built in oscillator with selectable speeds Development made easy Inexpensive Device variants Wide range of interfaces (I2C, SPI, etc.)

One accumulator Bank switching Hardware call stack unaddressable (no multi-tasking)

16-bit and 32-bit Architecture


More working registers No bank switching Assignable interrupt vector table More flash memory Cache (32-bit architecture)

Application Notes
Very extensive
16758 items

Description of documentation PDF documenation Source code

http://www.microchip.com/TechDoc.aspx?type=appnotes

http://www.microchip.com/TechDoc.aspx?type=appnotes

Baseline Architecture

Mid-Range Architecture

Enhanced Mid-Range Architecture

PIC18 Architecture

Pin Count Interrupts

6-40 No

8-64 Single interrupt capability

8-64

18-100

Single interrupt Multiple interrupt capability capability with with hardware context save hardware context save

Performance
Instructions Program Memory Data Memory Features

5 MIPS
33, 12-bit Up to 3 KB Up to 138 Bytes Comparator 8-bit ADC Data Memory Internal Oscillator

5 MIPS
35, 14-bit Up to 14 KB

8 MIPS
49, 14-bit Up to 28 KB

Up to 16 MIPS
83, 16-bit Up to 128 KB Up to 4 KB In addition to Enhanced Mid-Range: 8x8 Hardware Multiplier CAN CTMU USB Ethernet 12-bit ADC

Up to 368 Bytes Up to 1.5 KB In addition to Baseline: SPI/IC UART PWMs LCD 10-bit ADC Op Amp In addition to Mid-Range: Multiple Communication Peripherals Linear Programming Space PWMs with Independent Time Base
PIC12FXXX, PIC16F1XX

Families

PIC10, PIC12, PIC16

PIC12, PIC16

PIC18

8-bit architecture

INSTRUCTION

DESCRIPTION

OPERATION

PIC16 ISA: 35 Instructions, 14-bit


Data Transfer Instructions
INSTRUCTION MOVLW k MOVWF f MOVF f,d CLRW CLRF f SWAPF f,d DESCRIPTION OPERATION

Data Transfer Instructions MOVLW k MOVWF f MOVF f,d CLRW CLRF f SWAPF f,d Arithmetic-logic Instructions ADDLW k ADDWF f,d SUBLW k SUBWF f,d Add W and constant Add W and f Subtract W from constant Subtract W from f W+k -> W W+f -> d k-W -> W f-W -> d Move constant to W Move W to f Move f to d Clear W Clear f Swap nibbles in f k -> w W -> f f -> d 0 -> W 0 -> f f(7:4),(3:0) -> f(3:0),(7:4)

ANDLW k

Logical AND with W with constant

W AND k -> W

ANDWF f,d ANDWF f,d

Logical AND with W with f Logical AND with W with f

W AND f -> d W AND f -> d

IORLW k

Logical OR with W with constant

W OR k -> W

IORWF f,d

Logical OR with W with f

W OR f -> d

XORWF f,d

Logical exclusive OR with W with constant

W XOR k -> W

XORLW k

Logical exclusive OR with W with f

W XOR f -> d

Move constant to W k -> w Move W to f Move f to d Clear W Clear f Swap nibbles in f W -> f f -> d 0 -> W 0 -> f f(7:4),(3:0) -> f(3:0),(7:4)

INCF f,d DECF f,d

Increment f by 1 Decrement f by 1

f+1 -> f f-1 -> f

RLF f,d

Rotate left f through CARRY bit

RRF f,d

Rotate right f through CARRY bit

COMF f,d Bit-oriented Instructions BCF f,b BSF f,b Program Control Instructions

Complement f

f -> d

Clear bit b in f Clear bit b in f

0 -> f(b) 1 -> f(b)

BTFSC f,b

Test bit b of f. Skip the following instruction if clear.

Skip if f(b) = 0

BTFSS f,b

Test bit b of f. Skip the following instruction if set.

Skip if f(b) = 1

DECFSZ f,d

Decrement f. Skip the following instruction if clear.

f-1 -> d skip if Z = 1

INCFSZ f,d

Increment f. Skip the following instruction if set.

f+1 -> d skip if Z = 0

W: Working register(Accumulator)

GOTO k CALL k RETURN RETLW k RETFIE

Go to address Call subroutine Return from subroutine Return with constant in W Return from interrupt

k -> PC PC -> TOS, k -> PC TOS -> PC k -> W, TOS -> PC TOS -> PC, 1 -> GIE

Registers: Memory locations

Other instructions NOP No operation TOS -> PC, 1 -> GIE

CLRWDT

Clear watchdog timer

0 -> WDT, 1 -> TO, 1 -> PD

SLEEP

Go into sleep mode

0 -> WDT, 1 -> TO, 0 -> PD

INSTRUCTION Data Transfer Instructions MOVLW k MOVWF f MOVF f,d CLRW

DESCRIPTION

OPERATION

Move constant to W Move W to f Move f to d Clear W Clear f Swap nibbles in f

k -> w W -> f f -> d 0 -> W 0 -> f f(7:4),(3:0) -> f(3:0),(7:4)

Arithmetic-logic Instructions (partial)


ADDLW k ADDWF f,d INCF f,d DECF f,d RLF f,d Add W and constant Add W and f Increment f by 1 Decrement f by 1 Rotate left f through CARRY bit Rotate right f through CARRY bit Complement f f -> d W+k -> W W+f -> d f+1 -> f f-1 -> f

CLRF f SWAPF f,d Arithmetic-logic Instructions ADDLW k ADDWF f,d SUBLW k SUBWF f,d

Add W and constant Add W and f Subtract W from constant Subtract W from f

W+k -> W W+f -> d k-W -> W f-W -> d

ANDLW k

Logical AND with W with constant

W AND k -> W

ANDWF f,d ANDWF f,d

Logical AND with W with f Logical AND with W with f

W AND f -> d W AND f -> d

IORLW k

Logical OR with W with constant

W OR k -> W

IORWF f,d

Logical OR with W with f

W OR f -> d

XORWF f,d

Logical exclusive OR with W with constant

W XOR k -> W

XORLW k

Logical exclusive OR with W with f

W XOR f -> d

INCF f,d DECF f,d

Increment f by 1 Decrement f by 1

f+1 -> f f-1 -> f

RLF f,d

Rotate left f through CARRY bit

RRF f,d

Rotate right f through CARRY bit

RRF f,d COMF f,d

COMF f,d Bit-oriented Instructions BCF f,b BSF f,b Program Control Instructions

Complement f

f -> d

Clear bit b in f Clear bit b in f

0 -> f(b) 1 -> f(b)

BTFSC f,b

Test bit b of f. Skip the following instruction if clear.

Skip if f(b) = 0

BTFSS f,b

Test bit b of f. Skip the following instruction if set.

Skip if f(b) = 1

DECFSZ f,d

Decrement f. Skip the following instruction if clear.

f-1 -> d skip if Z = 1

SUBLW, SUBWF ANDLW, ANDWF IORLW, IORWF XORLW, XORWF

INCFSZ f,d

Increment f. Skip the following instruction if set.

f+1 -> d skip if Z = 0

GOTO k CALL k RETURN RETLW k RETFIE Other instructions NOP

Go to address Call subroutine Return from subroutine Return with constant in W Return from interrupt

k -> PC PC -> TOS, k -> PC TOS -> PC k -> W, TOS -> PC TOS -> PC, 1 -> GIE

No operation

TOS -> PC, 1 -> GIE

CLRWDT

Clear watchdog timer

0 -> WDT, 1 -> TO, 1 -> PD

SLEEP

Go into sleep mode

0 -> WDT, 1 -> TO, 0 -> PD

INSTRUCTION Data Transfer Instructions

DESCRIPTION

OPERATION

Program Control Instructions


Test bit b of f. Skip the following instruction if clear. Test bit b of f. Skip the following instruction if set. Decrement f. Skip the following instruction if clear. Increment f. Skip the following instruction if set. Go to address Call subroutine Return from subroutine Return with constant in W Return from interrupt

MOVLW k MOVWF f MOVF f,d CLRW CLRF f SWAPF f,d Arithmetic-logic Instructions ADDLW k

Move constant to W Move W to f Move f to d Clear W Clear f Swap nibbles in f

k -> w W -> f f -> d 0 -> W 0 -> f f(7:4),(3:0) -> f(3:0),(7:4)

Add W and constant Add W and f Subtract W from constant Subtract W from f

W+k -> W W+f -> d k-W -> W f-W -> d

BTFSC f,b

Skip if f(b) = 0

ADDWF f,d SUBLW k SUBWF f,d

ANDLW k

Logical AND with W with constant

W AND k -> W

ANDWF f,d

Logical AND with W with f Logical AND with W with f

W AND f -> d W AND f -> d

BTFSS f,b

Skip if f(b) = 1

ANDWF f,d

IORLW k

Logical OR with W with constant

W OR k -> W

IORWF f,d

Logical OR with W with f

W OR f -> d

XORWF f,d

Logical exclusive OR with W with constant

W XOR k -> W

DECFSZ f,d

f-1 -> d skip if Z = 1

XORLW k

Logical exclusive OR with W with f

W XOR f -> d

INCF f,d DECF f,d

Increment f by 1 Decrement f by 1

f+1 -> f f-1 -> f

RLF f,d

Rotate left f through CARRY bit

INCFSZ f,d GOTO k CALL k RETURN

f+1 -> d skip if Z = 0 k -> PC PC -> TOS, k -> PC

RRF f,d

Rotate right f through CARRY bit

COMF f,d Bit-oriented Instructions BCF f,b BSF f,b Program Control Instructions

Complement f

f -> d

Clear bit b in f Clear bit b in f

0 -> f(b) 1 -> f(b)

BTFSC f,b

Test bit b of f. Skip the following instruction if clear.

Skip if f(b) = 0

BTFSS f,b

Test bit b of f. Skip the following instruction if set.

Skip if f(b) = 1

TOS -> PC
DECFSZ f,d Decrement f. Skip the following instruction if clear. f-1 -> d skip if Z = 1

RETLW k
RETFIE

k -> W, TOS -> PC


TOS -> PC, 1 -> GIE

INCFSZ f,d

Increment f. Skip the following instruction if set.

f+1 -> d skip if Z = 0

GOTO k CALL k RETURN RETLW k RETFIE Other instructions NOP

Go to address Call subroutine Return from subroutine Return with constant in W Return from interrupt

k -> PC PC -> TOS, k -> PC TOS -> PC k -> W, TOS -> PC TOS -> PC, 1 -> GIE

No operation

TOS -> PC, 1 -> GIE

CLRWDT

Clear watchdog timer

0 -> WDT, 1 -> TO, 1 -> PD

SLEEP

Go into sleep mode

0 -> WDT, 1 -> TO, 0 -> PD

INSTRUCTION Data Transfer Instructions MOVLW k MOVWF f MOVF f,d CLRW CLRF f SWAPF f,d Arithmetic-logic Instructions ADDLW k ADDWF f,d SUBLW k

DESCRIPTION

OPERATION

Move constant to W Move W to f Move f to d Clear W Clear f Swap nibbles in f

k -> w W -> f f -> d 0 -> W 0 -> f f(7:4),(3:0) -> f(3:0),(7:4)

Add W and constant Add W and f Subtract W from constant Subtract W from f

W+k -> W W+f -> d k-W -> W f-W -> d

Bit-oriented Instructions
BCF f,b BSF f,b Clear bit b in f Set bit b in f 0 -> f(b) 1 -> f(b)

SUBWF f,d

ANDLW k

Logical AND with W with constant

W AND k -> W

ANDWF f,d ANDWF f,d

Logical AND with W with f Logical AND with W with f

W AND f -> d W AND f -> d

IORLW k

Logical OR with W with constant

W OR k -> W

IORWF f,d

Logical OR with W with f

W OR f -> d

XORWF f,d

Logical exclusive OR with W with constant

W XOR k -> W

XORLW k

Logical exclusive OR with W with f

W XOR f -> d

INCF f,d DECF f,d

Increment f by 1 Decrement f by 1

f+1 -> f f-1 -> f

RLF f,d

Rotate left f through CARRY bit

Other instructions
NOP CLRWDT SLEEP No operation Clear watchdog timer Go into sleep mode TOS -> PC, 1 -> GIE 0 -> WDT, 1 -> TO, 1 -> PD 0 -> WDT, 1 -> TO, 0 -> PD

RRF f,d

Rotate right f through CARRY bit

COMF f,d Bit-oriented Instructions BCF f,b BSF f,b Program Control Instructions

Complement f

f -> d

Clear bit b in f Clear bit b in f

0 -> f(b) 1 -> f(b)

BTFSC f,b

Test bit b of f. Skip the following instruction if clear.

Skip if f(b) = 0

BTFSS f,b

Test bit b of f. Skip the following instruction if set.

Skip if f(b) = 1

DECFSZ f,d

Decrement f. Skip the following instruction if clear.

f-1 -> d skip if Z = 1

INCFSZ f,d

Increment f. Skip the following instruction if set.

f+1 -> d skip if Z = 0

GOTO k CALL k RETURN RETLW k RETFIE Other instructions NOP

Go to address Call subroutine Return from subroutine Return with constant in W Return from interrupt

k -> PC PC -> TOS, k -> PC TOS -> PC k -> W, TOS -> PC TOS -> PC, 1 -> GIE

No operation

TOS -> PC, 1 -> GIE

CLRWDT

Clear watchdog timer

0 -> WDT, 1 -> TO, 1 -> PD

SLEEP

Go into sleep mode

0 -> WDT, 1 -> TO, 0 -> PD

PIC 16F887 layout


Analog I/O PORTA

I2C

UART
http://www.mikroe.com/eng/chapters/view/74/pic-basic-book-chapter-1world-of-microcontrollers/ 14

Programming a PIC
Microchip provides the free MPLAB:
Assembler and linker Application development Hardware emulation Debugging C or assembly compatible
http://www.microchip.com/pagehandler/ en-us/family/mplabx/

Compiler

Can be C-based or Basic A free one is the CCS C Compiler for PIC12/24/26/18 (not compatible with all PICS) or the HI-TECH PICC-Lit

15

Programming Tools
Basic based environments are available, but dont offer the functionality of C Third party IDEs might be preferred due to an enhanced software library or debugging tools

http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dD ocName=en019469&part=SW007002

16

Device Programmer
Need device to store machine code into PICs memory (EEPROM or Flash) Can be external device, but ICSP is easier:
Dont have to remove chip from its circuit Provides interface between computer (USB) and PIC Specific to circuit (due to interconnect scheme and surrounding circuit) Communication protocol requires 5 signals

http://en.wikipedia.org/wiki/PIC_microcontroller

17

Device Programmer

Five Signals: Vpp (programming voltage) Vdd (power) Vss (ground) IC SPCLK (clock) IC SPDAT (data)
http://en.wikipedia.org/wiki/PIC_microcontroller

18

Necessary Connections (PIC16F877A)


PIC can be bread-boarded, with the following important connections:
Power Ground Reset signal Crystal (oscillator)

http://www.mikroe.com/eng/chapters/view/74/pic-basic-book-chapter-1-world-ofmicrocontrollers/

19

LED example: code


//LED example program written for //PIC programming tutorial. From //(http://seniord.ece.iastate.edu/dec0604/index_files/tutorialDec0604.pdf) //standard include files #include <stdlib.h> #include <pic.h> #include delay.h //main function void main() { PORTA = 0x00; //set RA0-RA5 low TRISA = 0x00; //set PORTA to output //superloop while(1) { PORTA = ~PORTA; DelayMs(250); } }

20

Development Boards
Prepackaged boards come with a multitude of peripherals for development and debugging:
Programmer User I/O: buttons, port pinouts, LEDs Displays: LCD and seven segment Power Serial connection interface

21

Easy PIC v7 from MikroElectronika


Programmer

USB Port

Power Supply

PIC

Port Pinouts

LEDs and buttons

http://www.mikroe.com/eng/chapters/view/74/pic-basic-book-chapter-1world-of-microcontrollers/ 22

Additional Peripherals

Touch Screen

ADC converter

23

Questions?

24

References
http://www.microchip.com/ http://en.wikipedia.org/wiki/PIC_microcontroller http://www.mikroe.com/eng/chapters/view/10/chapter-9-instruction-set/ http://www.mikroe.com/eng/chapters/view/74/pic-basic-book-chapter-1world-of-microcontrollers/ http://www.slideshare.net/element14/microchips-16bit-and-32bit-picmcus-7267006 http://www.ladyada.net/library/picvsavr.html http://www.mikroe.com/eng/chapters/view/74/pic-basic-book-chapter-1world-of-microcontrollers/ http://www.slideshare.net/element14/microchips-16bit-and-32bit-picmcus-7267006 http://en.wikipedia.org/wiki/PIC_microcontroller http://www.ladyada.net/library/picvsavr.html

25

You might also like