*8-bit, 8-pin Devices Protected by Microchip’s Low Pin Count Patent: U.S. Patent No. 5,847,450. Additional U.S. and
foreign patents and applications may be issued or pending.
Note the following details of the code protection feature on Microchip devices:
•Microchip products meet the specification contained in their particular Microchip Data Sheet.
•Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
•There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
•Microchip is willing to work with the customer who is concerned about the integrity of their code.
•Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digit al Millennium Copyright Act. If suc h a c t s
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Information contained in this publication regarding device
applications and the like is provided only for your convenience
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED,
WRITTEN OR ORAL, STATUTORY OR OTHERWISE,
RELATED TO THE INFORMATION, INCLUDING BUT NOT
LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE,
MERCHANTABILITY OR FITNESS FOR PURPOSE.
Microchip disclaims all liability arising from this information and
its use. Use of M icrochip’s prod ucts as critical components in
life support systems is not authorized except with express
written approval by Microchip. No licenses are conveyed,
implicitly or otherwise, under any Microchip intellectual property
rights.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, K
EELOQ, microID, MPLAB, PIC, PICmicro, PICSTART,
PRO MATE, PowerSmart, rfPIC, and SmartShunt are
registered trademarks of Microchip Technology Incorporated
in the U.S.A. and other countries.
AmpLab, FilterLab, Migratable Memory, MXDEV, MXLAB,
PICMASTER, SEEVAL, SmartSensor and The Embedded
Control Solutions Company are registered trademarks of
Microchip Technology Incorporated in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, dsPICDEM,
dsPICDEM.net, dsPICworks, ECAN, ECONOMONITOR,
FanSense, FlexROM, fuzzyLAB, In-Circuit Serial
Programming, ICSP, ICEPIC, Linear Active Thermistor,
MPASM, MPLIB, MPLINK, MPSIM, PICkit, PICDEM,
PICDEM.net, PICLAB, PICtail, PowerCal, PowerInfo,
PowerMate, PowerTool, rfLAB, rfPICDEM, Select Mode,
Smart Serial, SmartTel, Total Endurance and WiperLock are
trademarks of Microchip Technology Incorporated in the
U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
Microchip received ISO/TS-16949:2002 quality system certification for
its worldwide headquarters, design and wafer fabrication facilities in
Chandler and Tempe, Arizona and Mountain View, California in
October 2003. The Company’s quality system processes and
procedures are for its PICmicro
devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchip’s quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.
6.0TMR0 Module and TMR0 Register.............................................................................................................................................41
8.0Comparator Voltage Reference Module..................................................................................................................................... 51
10.0 Special Features Of The CPU............ ............. ............ ............. ............ ...................................................................................... 57
11.0 Instruction Set Summary ............................................................................................................................................................ 73
12.0 Development Support.................................................................................................................................................................81
14.0 DC and AC Characteristics Graphs and Charts.............................................. .... .... ........... .... .... .... ............................................ 97
Index ..................................................................................................................................................................................................109
The Microchip Web Site........................... .......................................................................................................................................... 111
Customer Change Notification Service .............................................................................................................................................. 111
It is our intention to provide our valued customers with the best documentation possible to ensure successful use of your Microchip
products. To this end, we will continue to improve our publications to better suit your needs. Our publications will be refined and
enhanced as new volumes and updates are introduced.
If you have any questions or c omm ents regarding t his publication, p lease c ontact the M arket ing Co mmunications Department via
E-mail at docerrors@microchip.com or fax the Reader Response Form in the back of this data sheet to (480) 792-4150. We
welcome your feedback.
Most Current Data Sheet
To obtain the most up-to-date version of this data sheet, please register at our Worldwide Web site at:
http://www.microchip.com
You can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page.
The last character of the literature number is the version number, (e.g., DS30000A is version A of document DS30000).
Errata
An errata sheet, describing minor operational differences from the data sheet and recommended workarounds, may exist for current
devices. As device/documentation issues become known to us, we will publish an errata sheet. The errata will specify the revision
of silicon and revision of document to which it applies.
To determine if an errata sheet exists for a particular device, please check with one of the following:
• Microchip’s Worldwide Web site; http://www.microchip.com
• Your local Microchip sales office (see last page)
When contacting a sales office, please specify which device, revision of silicon and data sheet (include literature number) you are
using.
Customer Notification System
Register on our web site at www.microchip.com to receive the most current information on all of our products.
The PIC12F510/16F506 devices from Microchip
T ec hnology are lo w-cost, hig h-performance , 8-bit, fullystatic, Flash-based CMOS microcontrollers. They
employ a RISC architecture with only 33 single-word/
single-cycle instructions. All instructions are singlecycle except for program branches, which take two
cycles. The PIC12F510/16F506 devices deliver
performance in an o rder of m agnitu de hig her than their
competitors in the same pric e category . The 12-bi t wide
instructions are highly symmetrical, resulting in a
typical 2:1 code compression over other 8-bit
microcontrollers in i ts class . The easy-to-use a nd easyto-remember instr ucti on se t reduc es de velop ment time
significantly.
The PIC12F510/16F506 products are equipped with
special features that reduce system cost and power
requirements. The Power-on Reset (POR) and Device
Reset Timer (DRT) eliminate the need for external
reset circuitry. There are four oscillator configurations
to choose from (six on the PIC16F506), including
INTOSC Internal Oscillator mode and the power-saving
LP (Low-pow er) Osci llator mode. Po wer-sa ving Sle ep
mode, Watchdog Timer and code protection features
improve system cost, power and reliability.
The PIC12F510/16 F506 de vi ce s a ll ow th e c us tom er to
take full advantage of Microchip’s price leadership in
Flash programmable microcontrollers, while benefiting
from the Flash programmable flexibi lit y.
The PIC12F510/16F506 products are supported by a
full-featured macr o assembl er , a s oftware simulator, an
in-circuit emulator, a ‘C’ compiler, a low-cost
development programmer and a full featured programmer. All the tools are supported on IBM
compatible machines.
®
PC and
1.1Applications
The PIC12F510/16F506 devices fit in applications
ranging from personal care appliances and security
systems to low-power remote transmitters/receivers.
The Flash technology makes customizing application
programs (transmitter codes, appliance settings,
receiver frequencies, etc.) extremely fast and convenient. The small footpri nt p ackag es, for t hrough h ole or
surface mounting, make these microcontrollers perfect
for applications with space limitations. Low-cost, lowpower, high-performance, ease-of-use and I/O flexibility make the PIC12F510/16F506 devices very versatile, even in areas where no microcontroller use has
been considered b efore (e.g., tim er functions, lo gic and
PLDs in larger system s and co processor applications ).
T ABLE 1-1:PIC12F510/16F506 DEVICES
PIC16F506PIC12F510
ClockMaximum Frequency of Operation (MHz)208
MemoryFlash Program Memory 10241024
Data Memory (bytes)6738
PeripheralsTimer Module(s)TMR0TMR0
Wake-up from Sleep on Pin ChangeYesYes
FeaturesI/O Pins115
Input Only Pin11
Internal Pull-upsYesYes
In-Circuit Serial ProgrammingYesYes
Number of Instructions3333
Packages14-pin PDIP, SOIC,
TSSOP
The PIC12F510/16F506 devices have Power-on Reset, selectable Watchdog Timer, selectable code-protect, high I/O current
capability and precision internal oscillator.
The PIC12F510/16F506 device uses serial programming with data pin RB0/GP0 and clock pin RB1/GP1.
A variety of packaging options are available. Depending on application and production requirements, the
proper device option can be selected using the
information in th is section. Wh en placing orde rs, please
use the PIC12F510/16F506 Product Identification
System at the back of this data sheet to specify the
correct part number.
2.1Quick Turn Programming (QTP)
Devices
Microchip offers a QTP programming service for
factory production orders. This service is made
available for users who choose not to program
medium-to-high quantity units and whose code
patterns have stabilized. The devices are identical to
the Flash devices, bu t w ith all Fla sh l oc ati ons and fus e
options already programmed by the factory. Certain
code and prototype verification procedures do apply
before production shipments are available. Please
contact your loc al Microchi p Techn ology sales office for
more details.
2.2Serialized Quick Turn
Programming
Microchip offers a unique programming service, where
a few user-defined locations in each device are
programmed with different serial numbers. The serial
numbers may be random, pseudo-random or
sequential.
Serial programming allows each device to have a
unique number, which can serve as an entry code,
password or ID number.
The high performance of the PIC12F510/16F506
devices can be attributed to a number of architectural
features commonly found in RISC microprocessors.
The PIC12F510/16F506 devices use a Harvard architecture in which program and data are accessed on
separate buses. This improves bandwidth over traditional von Neumann architectures where program and
data are fetch ed on the sa me bu s. Separating progra m
and data memor y further allow s instructions to be sized
differently than the 8-bit wide data word. Instruction
opcodes are 12 bit s wide, making it p ossible to have all
single-word instructions. A 12-bit wide program memory access bus fetches a 12-bit instruction in a single
cycle. A two-stage pipeline overlaps fetch and execution of instructions. Consequently, all instructions (33)
execute in a si ngle cycle (200 ns @ 20 MHz, 1 μs @
4 MHz) except for program branches.
Table 3-1 lists program memory (Flash) and data
memory (RAM) for the PIC12F510/16F506 devices.
T ABLE 3-1:PIC12F510/16F506 MEMORY
Memory
Device
Program Data
PIC12F5101024 x 1238 x 8
PIC16F5061024 x 1267 x 8
The PIC12F510/16F506 devices can directly or indirectly address its register files and data memory. All
Special Function Registers (SFR), including the PC,
are mapped in the data memory. The PIC12F510/
16F506 devices have a highly orthogonal (symmetrical) instruc tion set that makes it possible to carry ou t
any operat ion, on any regis ter, using any addressing
mode. This symmetrical nature and lack of “special
optimal situations” make programming with the
PIC12F510/16F506 devices simple, yet efficient. In
addition, the learning curve is reduced significantly.
The PIC12F510/16F506 devices contain an 8-bit ALU
and working register. The ALU is a general purpose
arithmetic unit. It performs arithmetic and Boolean
functions between d ata in the worki ng register and an y
register file.
The ALU is 8 bits wide and capable of addition, subtraction, shift and logical operations. Unless otherwise
mentioned, arithmetic operations are two’s complement in nature. In two-operand instructions, one
operand is typica lly t he W (working) regis ter. T he oth er
operand is either a file register or an immediate
constant. In sing le-operand instr uctions, the operan d is
either the W register or a file register.
The W register is an 8-bit workin g register used for ALU
operations. It is not an addressable register.
Depending on the instruction executed, the ALU may
affect the values of the Carry (C), Digit Carry (DC) and
Zero (Z) bits in the ST ATUS register . The C and DC bit s
operate as a borrow
tively, in subtraction. See the SUBWF and ADDWF
instructions for examples.
A simplified block diagram is shown in Figure 3-1 for
PIC12F510 with the corresponding device pins described
in Table 3-2. A simplified block diagram for PIC16F506 is
shown in Figure 3-2 with the corresponding device pins
described in T able 3-3.
The clock input (OSC1/CLKIN pin) is internally divided
by four to generate four non-overlapping quadrature
clocks, namely Q1, Q2, Q3 and Q4. Internally, the PC
is incremented every Q1 and the instruction is fetched
from program memory and latched into the instruction
register in Q4. It is decoded and executed during the
following Q1 through Q4. The clocks and instruction
execution flow is s hown in Figure3-3 and Example 3-1.
FIGURE 3-3:CLOCK/INSTRUCTION CYCLE
Q2Q3Q4
OSC1
Q1
Q2
Q3
Q4
PC
Q1
PC
Q1
3.2Instruction Flow/Pipelining
An instruction cy cle consists of four Q cycles (Q1, Q2,
Q3 and Q4). The instruction fetch and execute are
pipelined such that fetch takes one instruction cycle,
while decode and execute take another instruction
cycle. However, due to the pipelining, each instruction
effectively executes in one cycle. If an instruction
causes the PC to change (e.g ., GOTO), t hen two c yc le s
are required to complete the ins tructi on (Exampl e 3-1).
A fetch cycle begins with the PC incrementing in Q1.
In the execution cy cle, the fetched instruction i s latched
into the Instruction Register (IR) in cycle Q1. This
instruction is then decoded and executed during the
Q2, Q3 and Q4 c ycles. Dat a m emory is read during Q2
(operand read) and written during Q4 (destination
write).
Q2Q3Q4
PC + 1PC + 2
Q1
Q2Q3Q4
Internal
Phase
Clock
Fetch INST (PC)
Execute INST (PC – 1)
Fetch INST (PC + 1)
Execute INST (PC)
Fetch INST (PC + 2)
Execute INST (PC + 1)
EXAMPLE 3-1:INSTRUCTION PIPELINE FLOW
1. MOVLW 03HFetch 1Execute 1
2. MOVWF PORTBFetch 2Execute 2
3. CALL SUB_1Fetch 3Execute 3
4. BSF PORTB, BIT1Fetch 4
All instructions are si ngle cycle, except for any program bra nches. These tak e two cycles, since th e fetch instruction
is “flushed” from the pipeline, while the new instruction is being fetched and then executed.
The PIC12F510/16F506 memories are organized into
program memory and data memory. For devices with
more than 512 bytes of program memory, a paging
scheme is used. Program memory pages are accessed
using one ST A TUS regi ster bit. For the PIC12F510 and
PIC16F506, with data memory register files of more
than 32 registers, a banking scheme is used. Data
memory banks are accessed using the File Select
Register (FSR).
4.1Program Memory Organization for
the PIC12F510/16F506
The PIC12F510/16F506 devices have a 10-bit
Program Counter (PC) c apable o f addressing a 2K x 12
program memory space.
Only the first 1K x 12 (0000 h-03FFh) are physically
implemented (see Figure 4- 1). Accessing a location
above these boundaries will cause a wraparound
within the 1K x 12 space. The effective Reset vector
is a 0000h (see Figure 4-1). Location 03FFh contains
the internal clock oscillator calibration value. This
value should never be overwritten.
FIGURE 4-1:PROGRAM MEMORY MAP
AND STACK FOR THE
PIC12F510/16F506
PC<11:0>
CALL, RETLW
Stack Level 1
Stack Level 2
Reset Vector
On-chip Program
Memory
512 Word
Space
User Memory
On-chip Program
Memory
1024 Word
10
(1)
0000h
01FFh
0200h
03FFh
0400h
7FFh
Note 1:Address 0000h becomes the effective
Reset vector. Location 03FFh contains
the MOVLW XX internal oscillator
calibration value.
Data memory is composed of registers or bytes of
RAM. Therefore, d ata memory for a device is spec ifie d
by its register file. The register file is divided into two
functional groups: Special Function Registers (SFR)
and General Purpose Registers (GPR).
The Special Function Registers include the TMR0
register, the Program Counter (PCL), the STATUS
register, the I/O registers (ports) and the File Select
Register (FSR). In addition, Specia l Function Registe rs
are used to control the I/O port configuration and
prescaler options.
The General Purpose Registers are used for data and
control information under com mand of the instructions .
For the PIC12F510, the register file is composed of 10
Special Function Registers, 6 General Purpose
Registers and 32 General Purpose Registers acces sed
by banking (see Figure 4-5).
For the PIC16F506, the register file is composed of 13
Special Function Registers, 3 General Purpose
Registers and 64 General Purpose Registers acces sed
by banking (see Figure 4-6).
4.2.1GENERAL PURPOSE REGISTER
FILE
The General Pu rpose Registe r file is accessed either
directly or indirectly through the File Select Register
(FSR). See Section 4.8 “Indirect Data Addressing:
The Special Function Registers (SFRs) are registers
used by the CPU and per ipheral functio ns to con trol the
operation of the device (see Table 4-1).
The Special Function Registers can be classified into
two sets. The Special Function Registers associated
with the “core” functions are described in this section.
Those related to the operation of the peripheral
features are described in the section for each
peripheral feature.
TABLE 4-1:SPECIAL FUNCTION REGISTER SUMMARY – PIC12F510
AddressNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2 Bit 1Bit 0
N/ATRISI/O Control Registers (TRISGPIO)--11 1111
N/AOPTIONContains control bits to configure Ti mer0 and Timer0/WDT Prescaler1111 1111
00hINDFUses contents of FSR to address data memory (not a physical register)xxxx xxxx
01hTMR0Timer0 Module Regis t erxxxx xxxx
(1)
02h
03hSTATUSGPWUFCWUFPA0TO
04hFSRIndirect Data Memory Address Pointer
05hOSCCALCAL6CAL5CAL4CAL3CAL2CAL1CAL0
06hGPIO
07hCM1CON0C1OUTC1OUTEN
08hADCON0ANS1ANS0ADCS 1ADCS0CHS1CHS0GO/D ONE
09hADRESADC Conversion Resultxxxx xxxx
Legend:x = unknown, u = unchanged, – = unimplemented, read as '0' (if applicable). Shaded cells = unimplemented or unused.
Note 1:The upper byte of th e Program Counter is not directly accessible. See Section 4.4 “OPTION Register” for an explanation of
PCLLow Order 8 bits of PC1111 1111
PDZDCC0001 1xxx
—1111 111-
——GP5GP4GP3GP2GP1GP0--xx xxxx
C1POLC1T0CSC1ONC1NREFC1PREFC1WU1111 1111
ADON1111 1100
how to access these bits.
Value on
Power-on
Reset
110x xxxx
TABLE 4-2:SPECIAL FUNCTION REGISTER SUMMARY – PIC16F506
AddressNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2 Bit 1Bit 0
N/ATRISI/O Control Registers (TRISB, TRISC)--11 1111
N/AOPTIONContains control bits to configure Timer0 and Timer0/WDT Prescaler1111 1111
00hINDFUses contents of FSR to address data memory (not a physical register)xxxx xxxx
01hTMR0Timer0 Module Registerxxxx xxxx
(1)
02h
03hSTATUSRBWUFCWUFPA0TO
04hFSRIndirect Data Memory Address Pointer100x xxxx
05hOSCCALCAL6CAL5CAL4CAL3CAL2CAL1CAL0
06hPORTB
07hPORTC
Legend:x = unknown, u = unchanged, – = unimplemented, read as '0' (if applicable). Shaded cells = unimplemented or unused.
Note 1:The upper byte of th e Program Counter is not directly accessible. See Section 4.4 “OPTION Register” for an explanation of
This register contains the arithmetic status of the ALU,
the Reset status and the page preselect bit.
The STATUS register can be the destination for any
instruction, as with any other register. If the STATUS
register is the destination for an instruction that affects
the Z, DC or C bits, then the write to these three bits is
disabled. These bit s are set or cleared ac cording to the
device logic. Furthermore, the TO
and PD bits are not
For example, CLRF STATUS, will c lea r the up per three
bits and set the Z bit. This leaves the STATUS register
as 000u u1uu (where u = unchanged).
Therefore, it is recommended that only BCF, BSF andMOVWF instructions be used to alter the STATUS register. The se in structions do not affect the Z, DC or C bits
from the STATUS register. For other instructions which
do affect Status bits, see Section 11.0 “InstructionSet Summary”.
writable. Therefore, the result of an instruction with the
STATUS regis ter as destina tion may be differ ent than
intended.
1 = Reset due to wake-up from Sleep on pin change
0 = After power-up or other Reset
bit 6CWUF: Comparator Reset bit
1 = Reset due to wake-up from Sleep on comparator change
0 = After power-up or other Reset
bit 5PA0: Program Page Preselect bits
1 = Page 1 (200h-3FFh)
0 = Page 0 (000h-1FFh)
Each page is 512 bytes.
Using the PA0 bit as a general purpose read/write bit in devices which do not use it for prog ram page
preselect is not recommended, since this may affect upward compatibility with future products.
bit 4TO
bit 3PD
bit 2Z: Zero bit
bit 1DC: Digit carry/borrow
bit 0C: Carry/borrow
: Time-out bit
1 = After power-up, CLRWDT instruction, or SLEEP instruction
0 = A WDT time-out occurred
: Power-down bit
1 = After power-up or by the CLRWDT instruction
0 = By execution of the SLEEP instructi on
1 = The result of an arithmetic or logic operation is zero
0 = The result of an arithmetic or logic operation is not zero
bit (for ADDWF and SUBWF instructions)
ADDWF:
1 = A carry from the 4th low-order bit of the result occurred
0 = A carry from the 4th low-order bit of the result did not occur
SUBWF:
1 = A borrow from the 4th low-order bit of the result did not occur
0 = A borrow from the 4th low-order bit of the result occurred
bit (for ADDWF, SUBWF and RRF, RLF instructions)
ADDWF:SUBWF:RRF or RLF:
1 = A carry occurred1 = A borrow did not occurLoad bit with LSb or MSb, respectively
0 = A carry did not occur0 = A borrow occurred
PDZDCC
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
1 = Reset due to wake-up from Sleep on pin change
0 = After power-up or other Reset
bit 6CWUF: Comparator Reset bit
1 = Reset due to wake-up from Sleep on comparator change
0 = After power-up or other Reset
bit 5PA0: Program Page Preselect bits
1 = Page 1 (200h-3FFh)
0 = Page 0 (000h-1FFh)
Each page is 512 bytes.
Using the PA0 bit as a general purpose read/write bit in devices which do not use it for program page preselect is not recommended, since this may affect upward compatibility with future products.
bit 4TO
bit 3PD
bit 2Z: Zero bit
bit 1DC: Digit carry/borrow
bit 0C: Carry/borrow
: Time-out bit
1 = After power-up, CLRWDT instruction, or SLEEP instruction
0 = A WDT time-out occurred
: Power-down bit
1 = After power-up or by the CLRWDT instruction
0 = By execution of the SLEEP instructi on
1 = The result of an arithmetic or logic operation is zero
0 = The result of an arithmetic or logic operation is not zero
bit (for ADDWF and SUBWF instructions)
ADDWF:
1 = A carry from the 4th low-order bit of the result occurred
0 = A carry from the 4th low-order bit of the result did not occur
SUBWF:
1 = A borrow from the 4th low-order bit of the result did not occur
0 = A borrow from the 4th low-order bit of the result occurred
bit (for ADDWF, SUBWF and RRF, RLF instructions)
ADDWF:SUBWF:RRF or
1 = A carry occurred1 = A borrow did not occurLoad bit with LSb or MSb, respectively
0 = A carry did not occur0 = A borrow occurred
PDZDCC
RLF:
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
The Oscillator Calibrati on (OSCCAL) register is used to
calibrate the internal precision 4/8 MHz oscillator. It
contains seven bit s for cal ibra tio n
Note:Erasing the device will also erase the pre-
programmed internal calibration value for
the internal oscillator. The calibration
value must be read prior to erasing the
part so it can be reprogramm ed correctly
later.
After you move in the calibration constant, do not change
the value. See Section 10.2.5 “Internal 4/8 MHz RC
Oscillator”.
REGISTER 4-5:OSCCAL REGISTER (ADDRESS: 05h)
R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1U-0
bit 7bit 0
bit 7-1CAL<6:0>: Oscillator Calibration bits
0111111 = Maximum frequency
•
•
•
0000001
0000000 = Center frequency
1111111
•
•
•
1000000 = Minimum frequency
bit 0Unimplemented: Read as ‘0’
.
CAL6CAL5CAL4CAL3CAL2CAL1CAL0
—
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
As a program instruction is executed, the Program
Counter (PC) will contain the address of the next
program instruction to be executed. The PC value is
increased by one every instruction cycle, unless an
instruction changes the PC.
For a GOTO instruction, bits 8:0 of the PC are provided
by the GOTO instruction word. The Program Counter
(PCL) is mapped to PC<7:0>. Bit 5 of the STATUS
register provides page information to bit 9 of the PC
(Figure4-4).
For a CALL instruction, or any instruction where the
PCL is the destination, bits 7:0 of the PC again are
provided by the instruction word. However, PC<8>
does not come from the instruct ion word, but is alway s
cleared (Figure 4-4).
Instructions where t he PCL is the des tinati on or modif y
PCL instructi ons include MOVWF PC, ADDWF PC and
BSF PC, 5.
Note:Because PC<8> is cleared in the CALL
instruction or any modify PCL instruction,
all subroutine calls or computed jumps are
limited to the first 256 locations of any
program me mory page (512 words long).
FIGURE 4-4:LOADING OF PC
BRANCH INSTRUCTIONS
GOTO Instruction
870
9
PC
70
STATUS
PCL
Instruction Word
PA0
4.6.1EFFECTS OF RESET
The PC is set upon a Reset, which means that the PC
addresses the last location in the last page (i.e., the
oscillator calibration instruction). After executing
MOVLW XX, the PC will roll over to location 00h and
begin executing user code.
The STATUS register page preselect bits are cleared
upon a Reset, which m eans that p age0 is preselected.
Therefore, upon a Reset, a GOTO instruction will
automatically c ause the program t o jump to page0 until
the value of the page bits is altered.
4.7Stack
The PIC12F510/16F 506 de vi ce s h av e a 2-d ee p, 12-bit
wide hardware PUSH/POP stack.
A CALL instru ction will PUSH the curre nt value of S t ack
1 into Stack 2 and then PUSH the current PC value,
incremented by one, into Stack Level 1. If more than
two sequential CALLs are executed, only the most
recent two return addresses are stored.
A RETLW instruction will POP the contents of Stack
Level 1 into the PC and then copy Stack Level 2
contents into S t ack Level 1. If more tha n two sequentia l
RETLWs are execute d, the stack will be fi lled with the
address previously stored in Stack Level 2.
Note 1: The W register will be loaded with the lit-
eral value spec ified in the ins truction. This
is particularly useful for the implementation of data look-up tables within the
program memory.
2: There are no Status bits to indicate stack
overflows or stack underflow conditions.
3: There are no instruction mnemonics
called PUSH or POP. These are actions
that occur from the e xecution of the CALL
and RETLW instructions.
The INDF register is not a physi cal register. Addressing
INDF actually address es the reg ister whos e addres s is
contained in the FSR regis ter (FSR is a pointer). This is
indirect addressing.
NEXTCLRFINDF;clear INDF register
4.8.1INDIRECT ADDRESSING EXAMPLE
• Register file 07 contains the value 10h
• Register file 08 contains the value 0Ah
• Load the value 07 into the FSR register
• A read of the INDF regi ster will return the value
of 10h
• Increment the value of the FSR register by one
(FSR = 08)
• A read of the INDR register now will return the
value of 0Ah.
Reading INDF itself indirectly (FSR = 0) will produce
00h. Writing to the INDF register indirectly results in a
no operation (although Status bits may be affected).
A simple program to clear RAM locations 10h-1Fh
using indirect addres sing is shown in Example 4-1.
CONTINUE
The FSR is a 5-bit wide register. It is used in conjunction with the INDF regis ter to indirectly a ddress the dat a
memory area.
The FSR<4:0> bits are used to select data memory
addresses 00h to 1Fh.
PIC16F506 – Uses FSR<6:5>. Selects from Bank 0 to
Bank 3. FSR<7> is unimplemented, read as ‘1’.
PIC12F510 – Uses FSR<5>. Selects from Bank 0 to
Bank 1. FSR<7:6> are unimplemented, read as ‘11’.
FIGURE 4-5:DIRECT/INDIRECT ADDRESSING (PIC12F510)
Direct Addressing
(FSR)
6
5
(opcode)
321
04
MOVLW0x10;initialize pointer
MOVWFFSR;to RAM
INCFFSR,F;inc pointer
BTFSCFSR,4;all done?
GOTONEXT;NO, clear next
As with any other register, the I/O register(s) can be
written and read under pro gram contro l. However, read
instructions (e.g., MOVF PORTB, W) always read th e I/O
pins independent of the pin’s Input/Output modes. On
Reset, all I/O ports are defined as input (inputs are at
high-impedance) since the I/O control registers are all
set.
Note:On the PIC12F510, I/O PORTB is refer-
enced as GPIO. On the PIC16F506, I/O
PORTB is referenced as PORTB.
5.1PORTB/GPIO
PORTB/GPIO is an 8-bit I/O register. Only the loworder 6 bits a re used ( RB/GP<5: 0>). Bits 7 and 6 are
unimplemented and read as ‘0’s. Please note that RB3/
GP3 is an input only pin. The Configuration Word can
set several I/O ’ s t o a lte rnate fu nc tio ns. When acting as
alternate function s, the pins wil l read as ‘0’ during a port
read. Pins RB0/GP0, RB1/GP1, RB3/GP3 and RB4
(PIC16F506 only) can be configured with weak pull-up
and also for wake-up on change. The wake-up on
change and weak pull-up functions are not pin selectable. If RB3/GP3/MCLR
pull-up is always on and wake-u p on change for this pin
is not enabled.
5.2PORTC (PIC16F506 Only)
PORTC is an 8-bit I/O register . Only the lo w-order 6 bits
are used (RC<5:0>). Bits 7 and 6 are unimplemented
and read as ‘0’s.
is configured as MCLR, weak
5.4I/O Interfacing
The equivalent circuit for an I/O port pin is shown in
Figure 5-1. All port pins, except RB3/GP3 which is
input only, may be used for both input and output operations. For input operations, these ports are non-latching. Any input must be present until read by an input
instruction (e.g., MOVF PORTB, W). The outputs are
latched and remain unchanged until the output latch is
rewritten. To use a port pin as output, the corresponding directio n contro l bit in TR IS must be c leared (= 0).
For use as an input, the corresponding TRIS bit must
be set. Any I/O pin (except RB3/GP3) can be
programmed individually as input or output.
FIGURE 5-1:PIC12F510/16F506
Data
Bus
Data
Bus
Interface
D
CK
Reset
EQUIVALENT CIRCUIT
FOR PIN DRIVE
Q
Q
VDD
P
N
V
SS
(2)
VDD
(1)
I/O
pin
VSS
5.3TRIS Registers
The Output Driver Control register is loaded with the
contents of the W register by executing the TRIS f
Note 1: GP3/RB3 has protection diode to V
2: For pin specific information, see Figure 5-2
through Figure 5-1 3.
SS only.
instruction. A ‘1’ from a TRIS register bi t puts the corresponding output driver in a High-Impedance mode. A
‘0’ puts the contents of the output data latch on the
selected pins, e nabling the outp ut buffer . The exception
is RB3/GP3, which are input only, and the T0CKI pin,
which may be controlled by the OPTION register. See
Register 4-3.
Note:A read of the port reads the pins, not the
output data latches. That is, if an output
driver on a pin is enabled and driven high
but the external system is holding it low, a
read of the port will indicate that the pin is
low.