Hello guys,
Just some questions:
1. If i need only to have a read protection in my PIC, i only have to activate the CPn bit protection?
If so,
2. ¿What are the Table read protection bits for?
3. ¿ If i wanted to protect my PIC from others to write to it, then i activate the table write protection bit?
if so,
4. ¿My PIC can never been reprogramed again?
Thanks and sorry if i asked novice quesiton
PIC18F Protection bits
Re: PIC18F Protection bits
Isaac wrote:1. If i need only to have a read protection in my PIC, i only have to activate the CPn bit protection?
The code protection bits serve this purpose.
If somebody erased part of your code (like bootloader) and introduced his own, he would be able to read the rest of your code with table reads.If so,
2. ¿What are the Table read protection bits for?
Or if you wanted to protect your code against accidental overwriting (like by runaway code).3. ¿ If i wanted to protect my PIC from others to write to it, then i activate the table write protection bit?
No, it could be erased and reprogrammed.if so,
4. ¿My PIC can never been reprogramed again?
Thanks janni
So the best way to protect our PIC is to activate all of the protection bits, so that no one could read it and write it before erasing all of the code? And then the only way to program to the PIC is to erase it first and then program it?
I just tried to activate all of them and i got some weird behavior, some images wasnt displayed correctly on my GLCD.. odd
So the best way to protect our PIC is to activate all of the protection bits, so that no one could read it and write it before erasing all of the code? And then the only way to program to the PIC is to erase it first and then program it?
I just tried to activate all of them and i got some weird behavior, some images wasnt displayed correctly on my GLCD.. odd
Not at all. You'll have to take care of constants placement, if you want to have all protection bits on. If table reads are blocked, one may only access the ROM data within a block of flash memory. In other words, both the constants and the code reading them have to fit into the same memory block.Isaac wrote:I just tried to activate all of them and i got some weird behavior, some images wasnt displayed correctly on my GLCD.. odd
I wouldn't be so obsessed with the code protection (unless you have reasons to suspect a serious piracy attack) and leave last block of memory with table read protection off. Just make sure that all the constants are placed there.
Re:
Hello Mr Janni,
I need your help.
I would be grateful for your reply. Thank you
Kind regards,
Toni
I need your help.
Please,Could you let me know the way for storing the constants in last block of memory? I'm using PIC18F67K22 ( Mikro C )leave last block of memory with table read protection off. Just make sure that all the constants are placed there.
I would be grateful for your reply. Thank you
Kind regards,
Toni
Re: PIC18F Protection bits
Hi Toni,
Please don't address me Mr. It makes me feel even older than I am .
You can place constants wherever you like with the 'absolute' directive. Just take into account the note from Help:Note that linker removes constants and variables not used in code (though it counts sizeof operator as code). In other words, if you would not explicitly use any of the constants in my example, a1 and a2 arrays would stay in program memory but a3 would be removed.
Please don't address me Mr. It makes me feel even older than I am .
You can place constants wherever you like with the 'absolute' directive. Just take into account the note from Help:
To avoid overwriting one constant by another, you may use the sizeof operator, likeNote :
If you want to place simple type constant into Flash memory, instead of following declaration:
const short SimpeConstant = 0xAA absolute 0x2000;
use an array consisting of single element :
const short SimpleConstant[] = {0xAA} absolute 0x2000;
In first case, compiler will recognize your attempt, but in order to save Flash space, and boost performance, it will automatically replace all instances of this constant in code with it's literal value.
In the second case your constant will be placed in Flash in the exact location specified.
Code: Select all
const cteOffs=0x2000; // base address of constants
const int a1[5]={1,2,3,4,5} absolute cteOffs;
const int a2[3]={1,2,3} absolute cteOffs+sizeof(a1);
const int a3[6]={1,2,3,4,5,6} absolute cteOffs+sizeof(a1)+sizeof(a2);
Re: PIC18F Protection bits
deleted
Last edited by janni on 10 Feb 2021 17:27, edited 1 time in total.
Re: PIC18F Protection bits
Don't know what I pressed but it multiplied my post .
Re: PIC18F Protection bits
Hi Janni,
Thank you for providing the requested information. I am learning so much now.
I will do what you suggested in your last message. If I need any assistance, I will ask here.
Thanks for your time. Take care
Kind regards,
Toni
Thank you for providing the requested information. I am learning so much now.
Yes you are right Feeling younger than we are may help us in many ways. It will Improve our wellbeing and mental health.Please don't address me Mr. It makes me feel even older than I am
I will do what you suggested in your last message. If I need any assistance, I will ask here.
Thanks for your time. Take care
Kind regards,
Toni
-
- Posts: 3
- Joined: 08 Feb 2021 21:08
Re: PIC18F Protection bits
Hello, while programming the PIC, it writes the CONFIG settings clearly on the data sheet. Whatever you want to do it says bit by bit. This issue is actually very important. It is like the foundation of construction. With the right requests and the right bit routing, you can run the PIC properly. For example I (writing clearly) I designed the CONFIG settings as a standard as follows.
__CONFIG _CONFIG1L, 0x00;B'00000000'
__CONFIG _CONFIG1H, 0x00;B'00000000'
__CONFIG _CONFIG2L, 0x00;B'00000000'
__CONFIG _CONFIG2H, 0x00;B'00000000'
__CONFIG _CONFIG3H, 0x80;B'10000000'------------Used as R3 input or MCLR
__CONFIG _CONFIG4L, 0x80; B'10000000'----------RB6 AND RB7 NORMAL INPUT OUTPUT
__CONFIG _CONFIG5L, 0x00;B'00000000'
__CONFIG _CONFIG5H, 0x00;B'00000000'
__CONFIG _CONFIG6L, 0x00;B'00000000'
__CONFIG _CONFIG6H, 0x00;B'00000000'
__CONFIG _CONFIG7L, 0x00;B'00000000'
__CONFIG _CONFIG7H, 0x00;B'00000000'
By looking at the data sheet, you can see which bit changes to 0 or 1.
Not
What I have written is taken from the 18F4550 data sheet.
__CONFIG _CONFIG1L, 0x00;B'00000000'
__CONFIG _CONFIG1H, 0x00;B'00000000'
__CONFIG _CONFIG2L, 0x00;B'00000000'
__CONFIG _CONFIG2H, 0x00;B'00000000'
__CONFIG _CONFIG3H, 0x80;B'10000000'------------Used as R3 input or MCLR
__CONFIG _CONFIG4L, 0x80; B'10000000'----------RB6 AND RB7 NORMAL INPUT OUTPUT
__CONFIG _CONFIG5L, 0x00;B'00000000'
__CONFIG _CONFIG5H, 0x00;B'00000000'
__CONFIG _CONFIG6L, 0x00;B'00000000'
__CONFIG _CONFIG6H, 0x00;B'00000000'
__CONFIG _CONFIG7L, 0x00;B'00000000'
__CONFIG _CONFIG7H, 0x00;B'00000000'
By looking at the data sheet, you can see which bit changes to 0 or 1.
Not
What I have written is taken from the 18F4550 data sheet.