I am working on pic18f4520 using MPLAB C18 compiler. I have just completed a project (Asked questions about it earlier,see my other posts) and now I want to lock the data of the micro-controller so that no one can read or write it any more. Can anyone plz upload sample of a code on how to protect data in pic18f4520.
2 Answers
\$\begingroup\$
\$\endgroup\$
If you want to embed it in your C code you can use the pragma config
directive to set the fuses. From the PIC18 configuration settings addendum it looks like the PIC18F4520 has four code protect blocks so you'd need the following to protect those and the boot block:
#pragma config CP0 = ON
#pragma config CP1 = ON
#pragma config CP2 = ON
#pragma config CP3 = ON
#pragma config CPB = ON
\$\begingroup\$
\$\endgroup\$
6
You can do this by adding one line of code in your assembly file
__CONFIG _CP_ON
More info on this link and this
Read chapter 15.6 from this book
-
\$\begingroup\$ I don't have a assembly file . I have a C source file and when I write this command line into it , compiler gives a syntax error any guess why. \$\endgroup\$ Commented Aug 2, 2015 at 12:42
-
\$\begingroup\$ fix error, compile, and you will have .asm file beside .c source file. \$\endgroup\$– JuniorCommented Aug 2, 2015 at 12:44
-
\$\begingroup\$ see the pics and plz tell me the error. I also tried writing " __CONFIG _CP_ON " as " #pragma config CP = ON " but it gives a different error saying CP unknown @Junior \$\endgroup\$ Commented Aug 2, 2015 at 13:19
-
\$\begingroup\$ It worked when I wrote " #pragma config CP1=ON " THANKS.... \$\endgroup\$ Commented Aug 2, 2015 at 13:23
-
\$\begingroup\$ NOW, do I have to define other two bits CP2 and CP3? second ques. How can I test that it is write or read protected? @Junior \$\endgroup\$ Commented Aug 2, 2015 at 13:25