0
\$\begingroup\$

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.See images and plz tell my why there is a syntax error

where is the asm file?

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

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
\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$
6
  • \$\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\$
    – prog_SAHIL
    Commented Aug 2, 2015 at 12:42
  • \$\begingroup\$ fix error, compile, and you will have .asm file beside .c source file. \$\endgroup\$
    – Junior
    Commented 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\$
    – prog_SAHIL
    Commented Aug 2, 2015 at 13:19
  • \$\begingroup\$ It worked when I wrote " #pragma config CP1=ON " THANKS.... \$\endgroup\$
    – prog_SAHIL
    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\$
    – prog_SAHIL
    Commented Aug 2, 2015 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.