CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Code protect not working

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
eskimobob



Joined: 07 Feb 2009
Posts: 40

View user's profile Send private message

Code protect not working
PostPosted: Tue Dec 15, 2009 7:13 am     Reply with quote

Using an 18F6622.

For some reason I cannot get this to work:

#FUSES PROTECT //Code protected from reads

It simply does not generate the right config code to protect the memory from reads. I only noticed because I thought I'd try the feature in the CCS programmer which can check after programming that the code is indeed protected - it wasn't!

I've tried compiling with versions 4.089 onwards to 4.102 but the config fuses remain the same. I definitely don't have the NOPROTECT somewhere else which might be turning it off.

In case it is related, here are the fuses I am using:
Code:
#FUSES HS                  //1.08   HS   High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES put               //2.00   PUT   Power Up Timer
#FUSES nobrownout      //2.01   NOBROWNOUT   No brownout reset
#FUSES nowdt            //2.08   NOWDT   No Watch Dog Timer
#FUSES mclr               //3.15   MCLR   Master Clear pin enabled
#FUSES nolvp            //4.02   NOLVP   No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES nodebug         //4.07   NODEBUG   No Debug mode for ICD
#FUSES PROTECT         //5.00   PROTECT   Code protected from reads
#FUSES wrt               //6.00   WRT   Program Memory Write Protected


I've tried upper and lower case - no difference...

Anyone else spotted this?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 15, 2009 12:32 pm     Reply with quote

Compile a small test such as the one shown below, and look at the Config
bits shown at the end of the .LST file. I did that for vs. 4.099 and it
shows the correct value for code protection in Config word #5. All the
bits in the lower byte are 0's. That means all 8 blocks are protected:
Quote:

Configuration Fuses:
Word 1: 0100 XT NOIESO NOFCMEN
Word 2: 1E1E BROWNOUT NOWDT BORV22 PUT WDT32768
Word 3: 81F3 CCP2C1 NOLPT1OSC MCLR
Word 4: 0081 STVREN NODEBUG NOLVP NOXINST BBSIZ1K
Word 5: C000 PROTECT NOCPD NOCPB
Word 6: E00F NOWRT NOWRTD NOWRTC NOWRTB
Word 7: 400F NOEBTRB NOEBTR


Also, make sure you're not trying to compile code for the ICD debugger.
If you do that, the compiler will automatically disable any fuses that
conflict with the debugger operation.

From the MPLAB help file for the ICD2:
Quote:

Q: Can I use code protection with MPLAB ICD 2?

A: No. Code protection, especially table read protection on any area in
program memory will prevent MPLAB ICD 2 from functioning. Do not use
any code protection or table read protection configuration settings when
debugging with MPLAB ICD 2. Code protection can be enabled when
programming a part for testing without MPLAB ICD 2.




Here's the test program:
Quote:

#include <18F6622.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP, PROTECT
#use delay(clock=4000000)

//======================================
void main(void)
{

while(1);
}
eskimobob



Joined: 07 Feb 2009
Posts: 40

View user's profile Send private message

PostPosted: Mon Jan 04, 2010 5:43 am     Reply with quote

PCM programmer wrote:
Also, make sure you're not trying to compile code for the ICD debugger.
If you do that, the compiler will automatically disable any fuses that
conflict with the debugger operation.


Thank you PCM programmer. I'd not realised I had left the debug condition in - I should have tried a small program Embarassed . All works as expected now.
picj1984



Joined: 01 Mar 2010
Posts: 73

View user's profile Send private message

PostPosted: Wed Apr 06, 2011 6:11 pm     Reply with quote

I'm having the same problem, and I understand that my problem is that I'm programming for the ICD debugger.

what do I need to include in my code so that I'm NOT compiling for the debugger?

Is it just a matter of leaving out "#device ICD=TRUE" if so, I tried commented that out and I'm still having problems.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 06, 2011 6:19 pm     Reply with quote

Post your PIC.

1. Remove "DEBUG" from your #fuses statement.

2. If in MPLAB, set the Release/Debug box at the top of MPLAB for "Release".
picj1984



Joined: 01 Mar 2010
Posts: 73

View user's profile Send private message

PostPosted: Wed Apr 06, 2011 6:53 pm     Reply with quote

Setting that box to "Release" did the trick! Thanks a million PCM programmer!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group