The flash lock bytes are located at the top of the flash for the 8 bit devices. For example, on some devices the flash lock bytes are located at address 0xFBFF. Please consult the Data Sheet or Reference Manual for the specific device to find the exact lock byte location.
Follow these steps to set the lock bytes at address 0xFBFF using Keil as the compiler:
1) Create a separate file and add it to the build that declares the lock byte value. For example, create a file called LOCKBYTE.c that has the line of code as follows:
unsigned char code FlashLock = 0xEF;
2) Right click the the project in the Project Explorer window and select [Properties] at the bottom. 3) Go to [Settings] under the [C/C++ Build properties]. 4) Select the [Miscellaneous] option under the [Keil 8051 Linker] section. 5) In the [Additional Flags] text box, enter the options
where LOCKBYTE is the name of the file as shown above.
6) Rebuild. 7) Verify that the lock bytes were stored at the proper location via the map file. You can also verify this using the hex file.
Note: The linker may throw an error because it is set to error on warnings. If that is the case: 8) In the same [Miscellaneous] section, uncheck the box [Treat unresolved symbols as errors]. 9) Rebuild and verify.