Microchip Technology MA330018 Data Sheet

Page of 460
dsPIC33FJ32MC302/304, dsPIC33FJ64MCX02/X04 AND dsPIC33FJ128MCX02/X04
DS70291G-page  168
© 2007-2012 Microchip Technology Inc.
11.6.3
CONTROLLING CONFIGURATION 
CHANGES
Because peripheral remapping can be changed during 
run time, some restrictions on peripheral remapping 
are needed to prevent accidental configuration 
changes. The dsPIC33F devices include three features 
to prevent alterations to the peripheral map:
• Control register lock sequence
• Continuous state monitoring
• Configuration bit pin select lock
11.6.3.1
Control Register Lock
Under normal operation, writes to the RPINRx and 
RPORx registers are not allowed. Attempted writes 
appear to execute normally, but the contents of the 
registers remain unchanged. To change these 
registers, they must be unlocked in hardware. The 
register lock is controlled by the IOLOCK bit 
(OSCCON<6>). Setting IOLOCK prevents writes to the 
control registers; 
 
clearing IOLOCK allows writes.
To set or clear the IOLOCK bit, a specific command 
sequence must be executed:
1.
Write 0x46 to OSCCON<7:0>.
2.
Write 0x57 to OSCCON<7:0>.
3.
Clear (or set) the IOLOCK bit as a single 
operation.
Unlike the similar sequence with the oscillator’s LOCK 
bit, IOLOCK remains in one state until changed. This 
allows all of the peripheral pin selects to be configured 
with a single unlock sequence followed by an update to 
all control registers, then locked with a second lock 
sequence.
11.6.3.2
Continuous State Monitoring
In addition to being protected from direct writes, the 
contents of the RPINRx and RPORx registers are 
constantly monitored in hardware by shadow registers. 
If an unexpected change in any of the registers occurs 
(such as cell disturbances caused by ESD or other 
external events), a configuration mismatch Reset is 
triggered.
11.6.3.3
Configuration Bit Pin Select Lock
As an additional level of safety, the device can be 
configured to prevent more than one write session to 
the RPINRx and RPORx registers. The IOL1WAY 
Configuration bit (FOSC<5>) blocks the IOLOCK bit 
from being cleared after it has been set once. If 
IOLOCK remains set, the register unlock procedure 
does not execute, and the peripheral pin select control 
registers cannot be written to. The only way to clear the 
bit and re-enable peripheral remapping is to perform a 
device Reset.
In the default (unprogrammed) state, IOL1WAY is set, 
restricting users to one write session. Programming 
IOL1WAY allows user applications unlimited access 
(with the proper use of the unlock sequence) to the 
peripheral pin select registers.
Note:
MPLAB
®
 C30 provides built-in C 
language functions for unlocking the 
OSCCON register:
__builtin_write_OSCCONL(value)
__builtin_write_OSCCONH(value)
See MPLAB IDE Help for more 
information.