By Abdul Rehman
Many time we need to program our atmega with external programmer. This could be for even programming bootloader or to upload hex file in production. Today we are going to explain how to program atmega8 with external programmer. We are going to use AVR Dude which is also part of Arduino development environment. But we are going to use third-party GUI Application for this which is also open source. You can download AVRDUDESS here. You may use command line version if you feel comfortable but I will recommend using this GUI.
Fuse bits are always seems confusing. Lock bits are more confusing when it comes to program atmaga8 using external programmer. Lock bits are very important when we need code protection. In any microcontroller the most important part is how to protect our intellectual property? Which is obviously our written code or the data placed in EEPROM. For any microcontroller to be successful code protection is crucial feature. Mostly all microcontroller provide this feature but process became more and more complex according to the architecture of the microcontroller. Atmega8 provide two type of lock bits to protect code area. One type of bits are to protect code and eeprom data. The other part is to protect Bootloader related data.
According to the datasheet, there are two lock bits for code and EEPROM protection. LB1 and LB2 although they are two bits bit possible combinations are only three. The combination of LB2 programmed and LB1 not programmed is not supported. Please not here that making a bit HIGH(1) mean not programmed. If we make bit zero(0) it mean we had programmed that bit.
So in first mode when we make both bits 1. We left them not programmed. It mean there is no lock feature enabled and no protection is done. If we just program LB1 in second mode by making it zero. It means that we just disabled further programming FLASH and EEPROM. If we make both of these bits zero it means we had also disabled further programming as well as verification of the code through external programmer. One point to remember here is that we can still full erase microcontroller and use it just as before.
The second provided group of protection or lock bits are for protecting boot-loader area. It forces SPM and LPM to stay away from Boot Loader section. It supports 4 modes and here is the table from datasheet explaining the behavior of these bits.
If you press bit selector button on AVRDUDESS GUI then you will see following screen where you can individually select the fuse and lock bits.
Atmega8 have two fuse bytes as you may see in above picture. These bytes are named with high fuse byte and low fuse byte respectively. We can program them accordingly and they specify a specific behavior. Here are tables taken from ATmega8 Datasheet
You may need to program fuse bytes before you program lock bits in microcontroller. You need to be very careful when selecting and programming fuse bits.
FYP Solutions Powered By Impressive Business WordPress Theme