Pic Microcontroller
Pic Microcontroller
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
RAM
PC, special purpose registers
http://www.microchip.com/_images/BaselineArch_large.jpg
One accumulator Bank switching Hardware call stack unaddressable (no multi-tasking)
Application Notes
Very extensive
16758 items
http://www.microchip.com/TechDoc.aspx?type=appnotes
http://www.microchip.com/TechDoc.aspx?type=appnotes
Baseline Architecture
Mid-Range Architecture
PIC18 Architecture
6-40 No
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
PIC12, PIC16
PIC18
8-bit architecture
INSTRUCTION
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
W AND k -> W
IORLW k
W OR k -> W
IORWF f,d
W OR f -> d
XORWF f,d
W XOR k -> W
XORLW k
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)
Increment f by 1 Decrement f by 1
RLF f,d
RRF f,d
COMF f,d Bit-oriented Instructions BCF f,b BSF f,b Program Control Instructions
Complement f
f -> d
BTFSC f,b
Skip if f(b) = 0
BTFSS f,b
Skip if f(b) = 1
DECFSZ f,d
INCFSZ f,d
W: Working register(Accumulator)
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
CLRWDT
SLEEP
DESCRIPTION
OPERATION
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
ANDLW k
W AND k -> W
IORLW k
W OR k -> W
IORWF f,d
W OR f -> d
XORWF f,d
W XOR k -> W
XORLW k
W XOR f -> d
Increment f by 1 Decrement f by 1
RLF f,d
RRF f,d
COMF f,d Bit-oriented Instructions BCF f,b BSF f,b Program Control Instructions
Complement f
f -> d
BTFSC f,b
Skip if f(b) = 0
BTFSS f,b
Skip if f(b) = 1
DECFSZ f,d
INCFSZ f,d
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
CLRWDT
SLEEP
DESCRIPTION
OPERATION
MOVLW k MOVWF f MOVF f,d CLRW CLRF f SWAPF f,d Arithmetic-logic Instructions ADDLW k
Add W and constant Add W and f Subtract W from constant Subtract W from f
BTFSC f,b
Skip if f(b) = 0
ANDLW k
W AND k -> W
ANDWF f,d
BTFSS f,b
Skip if f(b) = 1
ANDWF f,d
IORLW k
W OR k -> W
IORWF f,d
W OR f -> d
XORWF f,d
W XOR k -> W
DECFSZ f,d
XORLW k
W XOR f -> d
Increment f by 1 Decrement f by 1
RLF f,d
RRF f,d
COMF f,d Bit-oriented Instructions BCF f,b BSF f,b Program Control Instructions
Complement f
f -> d
BTFSC f,b
Skip if f(b) = 0
BTFSS f,b
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
INCFSZ f,d
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
CLRWDT
SLEEP
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
Add W and constant Add W and f Subtract W from constant Subtract W from f
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
W AND k -> W
IORLW k
W OR k -> W
IORWF f,d
W OR f -> d
XORWF f,d
W XOR k -> W
XORLW k
W XOR f -> d
Increment f by 1 Decrement f by 1
RLF f,d
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
COMF f,d Bit-oriented Instructions BCF f,b BSF f,b Program Control Instructions
Complement f
f -> d
BTFSC f,b
Skip if f(b) = 0
BTFSS f,b
Skip if f(b) = 1
DECFSZ f,d
INCFSZ f,d
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
CLRWDT
SLEEP
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
http://www.mikroe.com/eng/chapters/view/74/pic-basic-book-chapter-1-world-ofmicrocontrollers/
19
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
USB Port
Power Supply
PIC
Port Pinouts
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