Just wandering, is there any way to protect the code stored in the atmel against reads? I guess that may be needed for commercial projects so it's interesting to know if there's such thing.
Yes, AVRs have "lock bits" that can be used to prevent reading. See page 286 of the mega168 datasheet for more information.
nice. thanks for ur promptly reply. anyway. how can that be set using the arduino IDE?
I don't think the Arduino IDE directly supports this. You would need to use an ICSP programmer and some programming software like AVR Studio or avrdude (which I believe you can access via the Arduino IDE's command line). The avrdude command for setting the lock bits would be something like:
avrdude -p m168 -P COM4 -c avrispv2 -e -U efuse:w:0x00:m -U hfuse:w:0xDC:m -U lfuse:w:0xCF:m -U flash:w:sketch.hex -U lock:w:0x0C:m
The final -U lock:w:0x0C:m sets the lock bits so that further programming and verification of the flash and EEPROM is disabled in parallel and serial programming mode, and prevents SPM and LPM instructions from working on the bootloader section.
If you want to totally lock everything (i.e. also forbid the the SPM or LPM instructions from working on the application section), you would set the lock bits to be 0x00.
I'm sure the info will be useful for more people
Some other things you should know before you use the lock bits:
If you set them strictly enough, the Arduino bootloader will no longer be able to program your mega168 because it won't be able to use the LPM and SPM instructions it uses to write the flash of the application section.
You can clear the lock bits at any time (i.e. fully unlock your mega168) by performing a chip erase. You will need an ICSP programmer to do this. The avrdude command for chip erasing is:
avrdude -p m168 -P COM4 -c avrispv2 -e
Note that this will also erase your Arduino bootloader.