1.0 General Description ..................................................................................................................................................................... 5
5.0 Self-Writable Flash Data Memory Control................................................................................................................................. 25
6.0 I/O Port ...................................................................................................................................................................................... 29
7.0 Timer0 Module and TMR0 Register .......................................................................................................................................... 35
8.0 Special Features of the CPU..................................................................................................................................................... 41
13.0 Instruction Set Summary........................................................................................................................................................... 75
14.0 Development Support................................................................................................................................................................ 83
16.0 DC and AC Characteristics Graphs and Charts ...................................................................................................................... 105
The Microchip Web Site.................................................................................................................................................................... 131
Customer Change Notification Service ............................................................................................................................................. 131
Customer Support ............................................................................................................................................................................. 131
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 comments regarding this publication, please contact the Marketing Communications Department via
E-mail at docerrors@microchip.com. 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., DS30000000A is version A of document DS30000000).
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.
DS40001652B-page 4 2012-2013 Microchip Technology Inc.
PIC16F527
1.0GENERAL DESCRIPTION
The PIC16F527 device from Microchip Technology is a
low-cost, high-performance, 8-bit, fully-static, Flashbased CMOS microcontroller. It employs a RISC
architecture with only 36 single-word/single-cycle
instructions. All instructions are single cycle except for
program branches, which take two cycles. The
PIC16F527 device delivers performance an order of
magnitude higher than its competitors in the same price
category. The 12-bit wide instructions are highly
symmetrical, resulting in a typical 2:1 code
compression over other 8-bit microcontrollers in its
class. The easy-to-use and easy to remember
instruction set reduces development time significantly.
The PIC16F527 product is 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 several oscillator
configurations to choose from, including INTRC
Internal Oscillator mode and the power-saving LP
(Low-Power) Oscillator mode. Power-Saving Sleep
mode, Watchdog Timer and code protection features
improve system cost, power and reliability.
The PIC16F527 device is available in the cost-effective
Flash programmable version, which is suitable for
production in any volume. The customer can take full
advantage of Microchip’s price leadership in Flash
programmable microcontrollers, while benefiting from
the Flash programmable flexibility.
The PIC16F527 product is supported by a full-featured
macro assembler, a software 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
machines.
®
PC and compatible
1.1Applications
The PIC16F527 device fits in applications ranging from
personal care appliances and security systems to lowpower remote transmitters/receivers. The Flash
technology makes customizing application programs
(transmitter codes, appliance settings, receiver
frequencies, etc.) extremely fast and convenient. The
small footprint packages, for through hole or surface
mounting, make these microcontrollers perfect for
applications with space limitations. Low cost, low
power, high performance, ease of use and I/O flexibility
make the PIC16F527 device very versatile, even in
areas where no microcontroller use has been
considered before (e.g., timer functions, logic and
PLDs in larger systems and coprocessor applications).
DS40001652B-page 6 2012-2013 Microchip Technology Inc.
PIC16F527
2.0PIC16F527 DEVICE VARIETIES
A variety of packaging options are available.
Depending on application and production
requirements, the proper device option can be selected
using the information in this section. When placing
orders, please use the PIC16F527 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 but with all Flash locations and fuse
options already programmed by the factory. Certain
code and prototype verification procedures do apply
before production shipments are available. Please
contact your local Microchip Technology 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.
DS40001652B-page 8 2012-2013 Microchip Technology Inc.
PIC16F527
3.0 ARCHITECTURAL OVERVIEW
The high performance of the PIC16F527 device can
be attributed to a number of architectural features
commonly found in RISC microprocessors. To begin
with, the PIC16F527 device uses 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 fetched on the same bus. Separating
program and data memory further allows instructions
to be sized differently than the 8-bit wide data word.
Instruction opcodes are 12 bits wide, making it
possible 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 execute in a single
cycle (200 ns @ 20 MHz, 1 s @ 4 MHz) except for
program branches.
Table 3-1 below lists memory supported by the
PIC16F527 device.
TABLE 3-1:PIC16F527 MEMORY
Program
Memory
Device
Flash
(words)
PIC16F52710246864
The PIC16F527 device 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 PIC16F527 device
has a highly orthogonal (symmetrical) instruction set
that makes it possible to carry out any operation, on
any register, using any Addressing mode. This symmetrical nature and lack of “special optimal situations”
make programming with the PIC16F527 device simple,
yet efficient. In addition, the learning curve is reduced
significantly.
Data Memory
SRAM
(bytes)
Flash
(bytes)
The PIC16F527 device contains an 8-bit ALU and
working register. The ALU is a general purpose arithmetic unit. It performs arithmetic and Boolean functions
between data in the working register and any register
file.
The ALU is eight 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 typically the W (working) register. The other
operand is either a file register or an immediate
constant. In single operand instructions, the operand is
either the W register or a file register.
The W register is an 8-bit working 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 STATUS register. The C and DC bits
operate as a borrow
respectively, in subtraction. See the SUBWF and ADDWF
instructions for examples.
A simplified block diagram is shown in Figure 3-2, with
the corresponding device pins described in Tabl e 3 - 2.
Legend:I = Input, O = Output, I/O = Input/Output, P = Power, — = Not Used, TTL = TTL input, ST = Schmitt Trigger input,
HV = High Voltage, AN = Analog Voltage
DS40001652B-page 12 2012-2013 Microchip Technology Inc.
PIC16F527
Q1
Q2Q3Q4
Q1
Q2Q3Q4
Q1
Q2Q3Q4
OSC1
Q1
Q2
Q3
Q4
PC
PC
PC + 1PC + 2
Fetch INST (PC)
Execute INST (PC – 1)
Fetch INST (PC + 1)
Execute INST (PC) Fetch INST (PC + 2)
Execute INST (PC + 1)
Internal
Phase
Clock
All instructions are single cycle, except for any program branches. These take two cycles, since the fetch instruction
is “flushed” from the pipeline, while the new instruction is being fetched and then executed.
1. MOVLW 03H
Fetch 1Execute 1
2. MOVWF PORTB
Fetch 2Execute 2
3. CALL SUB_1
Fetch 3Execute 3
4. BSF PORTB, BIT1
Fetch 4Flush
Fetch SUB_1 Execute SUB_1
3.1Clocking Scheme/Instruction
Cycle
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 shown in Figure 3-2 and Example 3-1.
FIGURE 3-2:CLOCK/INSTRUCTION CYCLE
3.2Instruction Flow/Pipelining
An instruction cycle 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 or an interrupt),
then two cycles are required to complete the instruction
(see Example 3-1).
A fetch cycle begins with the PC incrementing in Q1.
In the execution cycle, the fetched instruction is latched
into the Instruction Register (IR) in cycle Q1. This
instruction is then decoded and executed during the
Q2, Q3 and Q4 cycles. Data memory is read during Q2
(operand read) and written during Q4 (destination
write).
DS40001652B-page 14 2012-2013 Microchip Technology Inc.
PIC16F527
005h
1FFh
Reset Vector
On-chip User
Program
Memory (Page 0)
200h
3FFh
3FEh
User ID Locations
Reserved
Configuration Word
400h
443h
444h
7FEh
7FFh
43Fh
440h
Unimplemented
On-chip User
Program
Memory (Page 1)
Data Memory
Self-writable
448h
49Fh
Backup OSCCAL
Locations
447h
4A0h
Configuration Memory
Space
Space
User Memory
Space
Flash Data Memory
Interrupt Vector
000h
004h
4.0MEMORY ORGANIZATION
FIGURE 4-1:MEMORY MAP
The PIC16F527 memories are organized into program
memory and data memory (SRAM).The self-writable
portion of the program memory called self-writable
Flash data memory is located at addresses 400h-43Fh.
All program mode commands that work on the normal
Flash memory, work on the Flash data memory. This
includes bulk erase, row/column/cycling toggles, Load
and Read data commands (Refer to Section 5.0 “Self-
Writable Flash Data Memory Control” for more
details). For devices with more than 512 bytes of
program memory, a paging scheme is used. Program
memory pages are accessed using one STATUS
register bit. For the PIC16F527, 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
PIC16F527
The PIC16F527 device has an 11-bit Program Counter
(PC) capable of addressing a 2K x 12 program memory
space. Program memory is partitioned into user memory,
data memory and configuration memory spaces.
The user memory space is the on-chip user program
memory. As shown in Figure 4-1, it extends from 0x000
to 0x3FF and partitions into pages, including an
Interrupt vector at address 0x004 and a Reset vector at
address 0x3FF.
The data memory space is the self-writable Flash data
memory block and is located at addresses PC = 400h43Fh. All program mode commands that work on the
normal Flash memory, work on the Flash data memory
block. This includes bulk erase, Load and Read data
commands.
The configuration memory space extends from 0x440
to 0x7FF. Locations from 0x448 through 0x49F are
reserved. The user ID locations extend from 0x440
through 0x443. The Backup OSCCAL locations extend
from 0x444 through 0x447. The Configuration Word is
physically located at 0x7FF.
Refer to “PIC16F527 Memory ProgrammingSpecification” (DS41640) for more details.
Note 1: Not a physical register. See Section 4.8 “Direct and Indirect Addressing”.
BSR<1:0>00011011
2Fh4Fh6Fh
PORTC
INTCON0
09h
0Ah
0Bh
ADRES
ADCON0
0Ch
0Fh
INDF
(1)
EECON
PCL
STATUS
FSR
EEDATA
EEADR
CM2CON0
INTCON0
ANSEL
VRCON
INDF
(1)
TMR0
PCL
STATUS
FSR
OSCCAL
PORTA
PORTB
ADRES
ADCON0
INDF
(1)
IW
PCL
STATUS
FSR
INTCON1
ISTATUS
ANSEL
OPACON
PORTC
IBSR
INTCON0
INTCON0
CM1CON0
IFSR
Addresses map back to
addresses in Bank 0.
6Ch4Ch2Ch
4.2Data Memory (SRAM and SFRs)
Data memory is composed of registers or bytes of
SRAM. Therefore, data memory for a device is
specified 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 are registers used by
the CPU and peripheral functions for controlling
desired operations of the PIC16F527. See Section 4.3
“STATUS Register” for details.
FIGURE 4-2:PIC16F527 REGISTER FILE MAP
4.2.1GENERAL PURPOSE REGISTER
FILE
The General Purpose Register file is accessed directly
or indirectly. See Section 4.8 “Direct and Indirect
Addressing”.
4.2.2SPECIAL FUNCTION REGISTERS
The Special Function Registers (SFRs) are registers
used by the CPU and peripheral functions to control the
operation of the device (see Section 4.3 “STATUS
Register”).
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.
DS40001652B-page 16 2012-2013 Microchip Technology Inc.
PIC16F527
TABLE 4-1:SPECIAL FUNCTION REGISTER SUMMARY
AddressNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2 Bit 1Bit 0
Bank 0
N/AW
N/ATRISI/O Control Registers (TRISA, TRISB, TRISC)1111 1111 1111 1111
N/AOPTIONContains control bits to configure Timer0 and Timer0/WDT prescaler1111 1111 1111 1111
N/ABSR
00hINDFUses contents of FSR to address data memory (not a physical register)xxxx xxxx uuuu uuuu
N/ATRISI/O Control Registers (TRISA, TRISB, TRISC)1111 1111 1111 1111
N/AOPTIONContains control bits to configure Timer0 and Timer0/WDT prescaler1111 1111 1111 1111
N/ABSR
(2)
——————BSR1BSR0---- -000 ---- -0uu
60hINDFUses contents of FSR to address data memory (not a physical register)xxxx xxxx uuuu uuuu
61hIW
62hPCL
63hSTATUS
64hFSR
65h
66hISTATUS
67h
68hIBSR
69hOPACON
6BhINTCON0ADIFCWIFT0IFRAIF
(3)
Interrupt Working Register. (Addressed also as W register when within ISR)xxxx xxxx xxxx xxxx
(1)
Low-order eight bits of PC1111 1111 1111 1111
(2)
ReservedReserved
(2)
—Indirect data memory address pointer0xxx xxxx 0uuu uuuu
PA0T O
INTCON1ADIECWIET0IERAIE
(3)
IFSR
ReservedReserved
(3)
(3)
—Indirect data memory address pointer0xxx xxxx 0uuu uuuu
——————BSR1BSR0---- -0xx ---- -0uu
PA0T O
——————OPA2ON OPA1ON ---- --00 ---- --00
PDZDCC-001 1xxx -00q qqqq
———
WUR0000 ---0 0000 ---0
PDZDCC-xxx xxxx -00q qqqq
———
GIE0000 ---0 0000 ---0
Legend:x = unknown, u = unchanged, – = unimplemented, read as '0' (if applicable), q = value depends on condition.
Shaded cells = unimplemented or unused
Note 1: The upper byte of the Program Counter is not directly accessible. See Section 4.6 “Program Counter” for an explanation of how to access
these bits.
2:Registers are implemented as two physical registers. When executing from within an ISR, a secondary register is used at the same logical
location. Both registers are persistent. See Section 8.11 “Interrupts”.
3:These registers show the contents of the registers in the other context: ISR or main line code. See Section 8.11 “Interrupts”.
Value on all
other Resets
DS40001652B-page 18 2012-2013 Microchip Technology Inc.
PIC16F527
4.3STATUS Register
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 bits are set or cleared according to the
device logic. Furthermore, the TO
writable. Therefore, the result of an instruction with the
STATUS register as destination may be different than
intended.
and PD bits are not
For example, CLRF STATUS, will clear the upper 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. These instructions do not affect the Z, DC or C
bits from the STATUS register. For other instructions
which do affect Status bits, see Section 13.0
“Instruction Set Summary”.
REGISTER 4-1:STATUS: STATUS REGISTER
R-0R-0R/W-0R-1R-1R/W-xR/W-xR/W-x
ReservedReservedPA0TOPDZDCC
bit 7bit 0
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
bit 7-6Reserved: Read as ‘0’
bit 5PA0 : Program Page Preselect bit
1 = Page 1 (200h-3FFh)
0 = Page 0 (000h-1FFh)
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 instruction
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 occurred 1 = A borrow did not occur; Load bit with LSb or MSb, respectively
0 = A carry did not occur 0 = A borrow occurred
1 = Increment on high-to-low transition on T0CKI pin
0 = Increment on low-to-high transition on T0CKI pin
bit 3PSA: Prescaler Assignment bit
1 = Prescaler assigned to the WDT
0 = Prescaler assigned to Timer0
bit 2-0PS<2:0>: Prescaler Rate Select bits
(1)
T0SEPSAPS2PS1PS0
(2)
(1)
Note 1: If the T0CS bit is set to ‘1’, it will override the TRIS function on the T0CKI pin.
2: The RAWU bit of the OPTION register must be set to enable the RAIF function in the INTCON0 register.
DS40001652B-page 20 2012-2013 Microchip Technology Inc.
PIC16F527
4.5 OSCCAL Register
The Oscillator Calibration (OSCCAL) register is used
to calibrate the 8 MHz internal oscillator macro. It
contains seven bits of calibration that uses a two’s
complement scheme for controlling the oscillator speed.
See Register 4-3 for details.
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 (see Figure 4-3).
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 instruction word, but is always
cleared (see Figure 4-3).
Instructions where the PCL is the destination, or modify
PCL instructions, include MOVWF PCL, ADDWF PCL
and BSF PCL,5.
FIGURE 4-3:LOADING OF PC
Note:Because bit 8 of the PC 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 memory page
(512 words long).
BRANCH INSTRUCTIONS
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 means that page 0 is pre-selected.
Therefore, upon a Reset, a GOTO instruction will
automatically cause the program to jump to page 0 until
the value of the page bits is altered.
4.7Stack
The PIC16F527 device has a 4-deep, 12-bit wide
hardware PUSH/POP stack.
A CALL instruction or an interrupt will PUSH the current
PC value, incremented by one, into Stack Level 1. If there
was a previous value in the Stack 1 location, it will be
pushed into the Stack 2 location. This process will be
continued throughout the remaining stack locations populated with values. If more than four sequential CALLs
are executed, only the most recent four return addresses
are stored.
A RETLW, RETURN or RETFIE instruction will POP
the contents of Stack Level 1 into the PC. If there was
a previous value in the Stack 2 location, it will be copied
into the Stack Level 1 location. This process will be continued throughout the remaining stack locations populated with values. If more than four sequential RETLWs
are executed, the stack will be filled with the address
previously stored in Stack Level 4. Note that the
W register will be loaded with the literal value specified
in the instruction. This is particularly useful for the
implementation of data look-up tables within the program memory.
Note 1: There are no Status bits to indicate Stack
Overflows or Stack Underflow conditions.
2: There are no instruction mnemonics
called PUSH or POP. These are actions
that occur from the execution of the
CALL, RETURN, RETFIE and RETLW
instructions.
DS40001652B-page 22 2012-2013 Microchip Technology Inc.
4.8Direct and Indirect Addressing
MOVLW0x10;initialize pointer
MOVWFFSR;to RAM
NEXTCLRFINDF;clear INDF
;register
INCFFSR,F;inc pointer
BTFSCFSR,4;all done?
GOTONEXT;NO, clear next
CONTINUE
:;YES, continue
:
4.8.1DIRECT DATA ADDRESSING: BSR
REGISTER
Traditional data memory addressing is performed in
the Direct Addressing mode. In Direct Addressing, the
Bank Select Register bits BSR<1:0>, in the new BSR
register, are used to select the data memory bank. The
address location within that bank comes directly from
the opcode being executed.
BSR<1:0> are the bank select bits and are used to
select the bank to be addressed (00 = Bank 0, 01 =
Bank 1, 10 = Bank 2, 11 = Bank 3).
A new instruction supports the addition of the BSR
register, called the MOVLB instruction. See
Section 13.0 “Instruction Set Summary” for more
information.
4.8.2INDIRECT DATA ADDRESSING:
INDF AND FSR REGISTERS
The INDF Register is not a physical register.
Addressing INDF actually addresses the register
whose address is contained in the FSR Register (FSR
is a pointer). This is indirect addressing.
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).
The FSR is an 8-bit wide register. It is used in
conjunction with the INDF Register to indirectly
address the data memory area.
The FSR<6:0> bits are used to select data memory
addresses 00h to 1Fh.
FSR<7> is unimplemented and read as ‘0’.
A simple program to clear RAM locations 10h-1Fh
using indirect addressing is shown in Example 4-1.
DS40001652B-page 24 2012-2013 Microchip Technology Inc.
5.0SELF-WRITABLE FLASH DATA
MOVLB0x01; Switch to Bank 1
MOVFDATA_EE_ADDR,W ;
MOVWFEEADR; Data Memory
; Address to read
BSFEECON, RD; EE Read
MOVF EEDATA, W; W = EEDATA
MOVLB0x01; Switch to Bank 1
MOVLWEE_ADR_ERASE ; LOAD ADDRESS OF ROW TO
; ERASE
MOVWFEEADR ;
BSFEECON,FREE ; SELECT ERASE
BSFEECON,WREN ; ENABLE WRITES
BSFEECON,WR ; INITITATE ERASE
MEMORY CONTROL
Flash Data memory consists of 64 bytes of selfwritable memory and supports a self-write capability
that can write four bytes of memory at one time. Data
to be written to the self-writable data memory is first
written into four write latches before writing the data to
Flash memory.
Although each Flash data memory location is 12 bits
wide, access is limited to the lower eight bits. The
upper four bits will automatically default to ‘1’ in any
self-write procedure. The lower eight bits are fully
readable and writable during normal operation and
throughout the full V
The self-writable Flash data memory is not directly
mapped in the register file space. Instead, it is
indirectly addressed through the Special Function
Registers, EECON, EEDATA and EEADR.
5.1Reading Flash Data Memory
To read a Flash data memory location the user must:
• Write the EEADR register
• Set the RD bit of the EECON register
The value written to the EEADR register determines
which Flash data memory location is read. Setting the
RD bit of the EECON register initiates the read. Data
from the Flash data memory read is available in the
EEDATA register immediately. The EEDATA register
will hold this value until another read is initiated or it is
modified by a write operation. Program execution is
suspended while the read cycle is in progress.
Execution will continue with the instruction following the
one that sets the WR bit. See Example 5-1 for sample
code.
EXAMPLE 5-1:READING FROM FLASH
DD range.
DATA MEMORY
PIC16F527
Note 1: To prevent accidental corruption of the
Flash data memory, an unlock sequence
is required to initiate a write or erase
cycle. This sequence requires that the bit
set instructions used to configure the
EECON register happen exactly as
shown in Example 5-2 and Example 5-3,
depending on the operation requested.
2: In order to prevent any disruptions of self-
writes or row erases performed on the
self-writable Flash data memory,
interrupts should be disabled prior to
executing those routines.
5.1.1ERASING FLASH DATA MEMORY
A row must be manually erased before writing new
data. The following sequence must be performed for a
single row erase.
1. Load EEADR with an address in the row to be
erased.
2. Set the FREE bit to enable the erase.
3. Set the WREN bit to enable write access to the
array.
4. Disable interrupts.
5. Set the WR bit to initiate the erase cycle.
If the WREN bit is not set in the instruction cycle after
the FREE bit is set, the FREE bit will be cleared in
hardware.
If the WR bit is not set in the instruction cycle after the
WREN bit is set, the WREN bit will be cleared in
hardware.
Sample code that follows this procedure is included in
Example 5-2.
Program execution is suspended while the erase cycle
is in progress. Execution will continue with the
instruction following the one that sets the WR bit.
command normally used by the core.
However, the WREN and WR bits can
only be set using a series of BSF commands, as documented in Example 5-1.
No other sequence of commands will
work, no exceptions.
2: Bits <5:3> of the EEADR register indicate
which row is to be erased.
5.1.2WRITING TO FLASH DATA
MEMORY
Once a cell is erased, new data can be written.
Program execution is suspended during the write cycle.
The self-write operation writes four bytes of data at one
time. The data must first be loaded into four write
latches. Once the write latches are loaded, the data will
be written to Flash data memory.
The self-write sequence is shown below.
The following self-write sequence must be performed
for four bytes to be written.
1. Load EEADR with the address.
2. Load EEDATA with the data to be written.
3. Set the WREN bit to enable write access to the
array.
4.Disable interrupts.
5. Set the WR bit to load the data into the write
latch.
6. Steps 1 through 5 are repeated three more times
to load the remaining write latches.
On the fourth and final loop, the EEADR register will
contain an address in the format of b’00xxxx11.
When the WR bit is set for the final time, the processor
will recognize that this is the last write latch to be
loaded, and will automatically load the write latch and
then, immediately perform the Flash data memory
write of all four bytes.
The specific sequence of setting the WREN bit and
setting the WR bit must be executed to properly initiate
each load of the write latches and the write to Flash
data memory.
If the WR bit is not set in the instruction cycle after the
WREN bit is set, the WREN bit will be cleared in
hardware.
Sample code that follows this procedure is included in
Example 5-3.
DS40001652B-page 26 2012-2013 Microchip Technology Inc.
EXAMPLE 5-3:WRITING TO FLASH DATA
MEMORY
Note 1: Only a series of BSF commands will work
to enable the memory write sequence
documented in Example 5-3. No other
sequence of commands will work, no
exceptions.
2: For reads, erases and writes to the Flash
data memory, there is no need to insert a
NOP into the user code as is done on midrange devices. The instruction
immediately following the “BSFEECON,WR/RD” will be fetched and
executed properly.
5.2Write/Verify
Depending on the application, good programming
practice may dictate that data written to the Flash data
memory be verified. Example 5-4 is an example of a
write/verify.
1 = Allows write cycle to Flash data memory
0 = Inhibits write cycle to Flash data memory
bit 1WR: Write Control bit
1 = Initiate a erase or write cycle
0 = Write/Erase cycle is complete
bit 0RD: Read Control bit
1 = Initiate a read of Flash data memory
0 = Do not read Flash data memory
5.4Code Protection
Code protection does not prevent the CPU from
performing read or write operations on the Flash data
memory. Refer to the code protection chapter for more
information.
DS40001652B-page 28 2012-2013 Microchip Technology Inc.
PIC16F527
6.0I/O PORT
As with any other register, the I/O register(s) can be
written and read under program control. However, read
instructions (e.g., MOVF PORTB,W) always read the I/O
pins independent of the pin’s Input/Output modes. On
Reset, all I/O ports are defined as input (inputs are at highimpedance) since the I/O control registers are all set.
6.1PORTA
PORTA is a 6-bit I/O register. Only the low-order six
bits are used (RA<5:0>). Bits 7 and 6 are
unimplemented and read as ‘0’s. Please note that RA3
is an input-only pin. The Configuration Word can set
several I/Os to alternate functions. When acting as
alternate functions, the pins will read as ‘0’ during a
port read. Pins RA0, RA1, RA3 and RA4 can be
configured with weak pull-ups and also for wake-up on
change. The wake-up on change and weak pull-up
functions are not pin selectable. If RA3/MCLR
configured as MCLR
wake-up on change for this pin is not enabled.
, weak pull-up is always on and
is
6.2PORTB
PORTB is a 4-bit I/O register. Only the high-order four
bits are used (RB<7:4>). Bits 0 through 3 are
unimplemented and read as ‘0’s.
6.3PORTC
PORTC is an 8-bit I/O register.
6.4TRIS Register
The Output Driver Control register is loaded with the
contents of the W register by executing the TRIS
instruction. A ‘1’ from a TRIS register bit puts the
corresponding output driver in a High-Impedance
mode. A ‘0’ puts the contents of the output data latch
on the selected pins, enabling the output buffer. The
exceptions are RA3, which is input-only and the T0CKI
pin, which may be controlled by the OPTION register
(see Register 4-2).
TRIS registers are “write-only”. Active bits in these
registers are set (output drivers disabled) upon Reset.
Note 1: I/O pins have protection diodes to VDD and
V
SS.
2: Pin enabled as analog for ADC or comparator.
D
CK
Q
Pin Change
RxPU
ADC pin Ebl
COMP pin Ebl
ADC
COMP
I/O Pin
(1)
(2)
(2)
6.5I/O Interfacing
The equivalent circuit for an I/O port pin is shown in
Figure 6-1. All port pins, except the MCLR
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 direction control bit in TRIS must be cleared (= 0).
For use as an input, the corresponding TRIS bit must
be set. Any I/O pin (except MCLR
) can be programmed
individually as input or output.
pin which is
FIGURE 6-1:BLOCK DIAGRAM OF I/O
PIN (Example shown of
RA2 with Weak Pull-up
and Wake-up on change)
DS40001652B-page 30 2012-2013 Microchip Technology Inc.
Loading...
+ 105 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.