If after yesterday’s posting you though things were getting ugly (I agree), you will be pleased to learn that since the introduction of MPLAB C30 v3.02 things have improved considerably. After all, performing the unlock sequences should not be an “impossible” task in C requiring super advanced inline assembly programming skills!
Four new builtin functions of the compiler come to our rescue:
- __builtin_write_RTCWEN( void)
- __builtin_write_NVM( void);
- __builtin_write_OSCCONL( unsigned char value);
- __builtin_write_OSCCONH( unsigned char value);
[Note: a double underscore preceeds each function name]
They give us complete access to the RCFGCAL, NVM and OSCCON control registers by performing the proper unlock sequences.
You will find a complete (long) list of builtin functions well documented in Appendix B of the MPLAB C30 compiler.