Fuse Bits : Changing your MCU speed and JTAG

Share

When you begin with micro-controllers, and you are reading the datasheets or tutorials, you are very likely to have come across the term “Fuse Bits” which relate to the MCU speed and JTAG.
Being beginners and not having the slightest idea about both, it is generally left for “later, when I get more experienced” . The fact that even the tutorials promise to come to it later adds to this lack of confidence.

Three days ago, when I was trying to interface my LCD with my ATMEGA16, I found that the display was being printed too slow for my liking , and so I resolved to increase the MCU speed. (though that was not the real problem, as I later found)

So here I am, with no knowledge about fuse bits or JTAG or anything. So what I do ? Read the datasheet, of course !!

Here’s what the datasheet says :

There are two fuse bytes : lfuse (lower fuse byte) and hfuse (higher fuse byte). These represent atributes of the MCU, and can be programmed to change the attributes. See the table below for the attributes :

(Source : ATMEGA16 Datasheet)

For our purpose, in the hfuse byte we need to reset the JTAGEN to disable JTAG, and reset CKOPT to enable us to select a different internal clock. CKOPT, you can understand, but why change the JTAG part ? That’s because four pins of PORTC are JTAG enabled and sometimes give weird unexpected output if not disabled. The other bits can be left unchanged.

Now, we need to change the 4 bits of CKSEL in the lfuse byte to select the internal clock speed.
Here’s the table for different clock speeds.

(Source : ATMEGA16 Datasheet)

Now, how do I program it ? AVRDude or ICCAVR. Its very easy to do so in ICCAVR and you don’t even need to know about the above fuse bits, but I don’t use ICCAVR and find AVRDude better. So here’s how to go about it in AVRDude.

First make the makefile that you generally make for your programs. Then burn a program into your mcu. Keep the MCU and programmer connected during the whole process and never apply a reset until the whole thing is over. Note the first line of the output window below. It looks something like this :

avrdude -p m32 -c -bsd -u programname.hex

Now go over to DOS mode and follow the steps in the picture below.

(Image courtesy : Bibin John’s Ebooks)

Remember though. The above settings were an example. The bits might be different for your device. Just change the ones that you need after consulting the table above, leave the remaining ones unchanged, calculate the resulting hex number and replace it in the appropriate places.

I hope you all find it quite simple, just as I did.
Oh and ya, congratulation !! Your MCU has now become 8 times faster !!!

Share

LCD Interfacing

Share

Often, when you are working with micro-controllers, you might feel the need to see what conditions are being executed or what input the micro-controllers are taking. For that, you can always use LEDs, but then LEDs are a very clumsy and confusing way of going about it.

So, what will I use that shows me what’s going on ?? An LCD, of course !!

Here’s how.

1. Read the datasheet of your LCD.

2. Understand your LCD.

3. Write the code.

4. Burn the code.

5. Make the connections and voila !!

For the purpose of modularizing work ( and for fear of this post becoming too long and boring), I have posted the detailed discussions section-wise as text files. All links are at the bottom of the post.

Step 1 :
Requirements :

I am using a HITACHI JHD162A LCD Display, with a HD44780 LCD Controller, which comes for roundabout Rs. 110. The datasheet of the controller is much more important than that of the module, since its the controller which is going to take in input and print the screen. You need not bother with the datasheet of the LCD itself.

Of course, you will also need a micro-controller with at least 11 usable pins and lots of connectors.

Step 2:
Understand your LCD :

Read the datasheet.
Read a summary.

Step 3:
Write the code:

Easier said than done, eh ?
Well, do the next best thing. Find code on the internet, understand it and tweak it, based on your configuration.
I read Bibin John‘s code and modified it a bit. I have also been recommended Peter Fleury’s library as being easy to use, but I haven’t gont through it as yet.
Here’s my code.

I have used the delay function provided by WinAVR in my code, since Bibin has written his own delay loop in assembly language and it was giving me faulty delays,making the wait too long.

Step 4:
Burn the code:

The easiest part by far. Just make sure your code is syntactically and logically correct ( you need to know the datasheet well for that) and burn it using WinAVR.

Step 5:
Connect :

Quite an important step. Even if the code is correct, your screen will display junk at the most and black boxes usually if the connections are improper.
Here’s the checklist.

Here’s a picture of the output I get :

Shortcomings,problems, general precautions etc.

There are lots of things that can go wrong, implying there are lots of things you must be careful about. Here’s my list.

Happy Printing !!

P.S. Many thanks to Shashank S. for his help.
———————————————————————————————
Links :

1. Datasheets :

a. HITACHI JHD162A LCD Display
b. HD44780 LCD Controller (Courtesy : Sparkfun)

2. Reading

a. Bibin John’s Books
b. Robotics India
c. AVR-Beginners
d. Meteosat’s Tutorial

3. Files

a. Datasheet summary
b. Code
c. Checklist
d. Problems
e. Peter Fleury’s library
————————————————————————————————

Share