Talkback for article: 352, November2004

Programming the AVR Microcontroller with GCC, libc 1.0.4

Back to:

From: Mr. nipon gasiprong <ngasiprong(at)> [ date: 2004-11-01 ]
Dear Guido Socher,
I'm your hardware paper follower. Thank you very much for your papers.
I study your hardware papers and use your paper " Programming the AVR Microcontroller with GCC" as the starting point in my electronics class room.
My students can use AVR Microcontroller too.
I need to learn more about making a simple USB interface by using an
AVR-USB chip. Could you please write a paper about this topic.

Thank youvery much.

From: Mike Piety <mrp(at)> [ date: 2004-11-23 ]
Excellent article. Would you please post a picture of the underside of the completed project board showing your connection method?


From: Guido Socher [ date: 2004-11-26 ]
Hi Mike,
well this circuit is so simple that you can just solder a few
wires between the pins.
From: Mike [ date: 2004-12-14 ]

In the parts list for the programmer cable you mention a
200 Ohm resistor and 3 470 Ohmresistors.

The plans call for resistors on pins 2, 3 and 4.

4 470 Ohm
3 220 Ohm
2 470 Ohm

Where does the third 470 Ohm resistor go?
From: Guido Socher [ date: 2004-12-15 ]
Hi Mike,
that is a fault in the article. Thanke for telling me.
You need only two 470 Ohm resistors.
From: Anonymous User [ date: 2004-12-19 ]
I've found your delay_ms to be broken:

void delay_ms(unsigned short ms)
/* delay for a minimum of <ms> */
/* with a 1Mhz clock, the resolution is 1 ms */
unsigned short outer1, outer2;
outer1 = 50;

while (outer1) {
outer2 = 1000;
while (outer2) {
while ( ms ) ms--;

In this code, ms is decreased to 0 only once in the inner-most loop and then remains null.

I use this code :

delay_ms(ushort ms)
while(ms--) {
volatile BYTE i;
for (i=8; i ; i-- ) {
volatile BYTE b;

Thank you for such a valuable work!

From: Andreas [ date: 2004-12-22 ]
Hi there

great article! I am using the AtMega8 for my own project and I was just going to worry about what has changed since AT90S4433 when I discovered your new article.

From: Richard Lechner <richardlechner(at)> [ date: 2005-01-29 ]

I'm an absolute beginner. I read this article and I built this tesenvironment for my microcontroller. And what should I say? It worked.

Thanks Guido,
thanks linux


From: Werner Borchers <werbo(at)> [ date: 2005-02-03 ]
I'm very glad to have found your article. I have build many devices with the C-Control Basic I - Unit from Conrad-Electronics.
The problems :
Only one Distributor
Now changed to Version 2

--> no more programming in assembler (you must not look into the OS)
--> IDE only for WIN

The whole C-Control thing seems to go now the "Microsoft - way"
(my opinion)

I'll try to do my next project (climate regulation, hot water, heating...)
with the AVR.

Solong, Werner

From: Gustav Schindelr <g.schindler(at)> [ date: 2005-02-12 ]
When I try to install AVR gcc-core-2.4.2 or 3.4.3
I get follwing errors
../../gcc/config/avr/libgcc.S:72 Error: sufix or operants invalid vor for `clr`
../../gcc/config/avr/libgcc.S:72 Error: no such instruction ´clear result`
make[2]: *** [libgcc(//.//_mulqi3.o] Fehler 1
make [1} [stmp-multilib] Fehler 2

What shall I do ?????
or what`s wrong ??

From: Mirza Nakicevic <mirza(at)[nospam] - - remove [nospam]> [ date: 2005-02-27 ]

I just want to ask you do you know how to back my at mega8 from dead ? :)
Accidentaly I had short circuit between plus and minus and afer that I can't program my mega8 :(

Thanks anyway,

Mirza N.

From: Ole Robert Hestvik <ole.robert.hestvik(at)> [ date: 2005-03-06 ]
I'm happy to find your article. Several years ago I had an early version of avr-gcc working. Now I will install the system again.
I have installed binutils from binutils-2.15.tar.bz2 and gcc from
However, trying avr-libc from avr-libc-1.2.3.tar.gz doconf says:

configure: error: Wrong C compiler found; check the PATH!

The same happens for avr-libc-1.0.4.tar.bz2. My compiler is gcc
version 3.3.2 20031022 (Red Hat Linux 3.3.2-1).
How shall I proceed?
From: Volker <info(at)[nospam]> [ date: 2005-03-28 ]
Hello Guido,
thanks for this good article.

Let me add one comment: you say "We don't have several tasks and there is no other program running. There is not even an operating system."

In fact, this is true for a "naked" AVR.

I have no experience yet, but I found this while searching for AVR development:

Perhaps you'll find some time to write an article about this "... portable, open source, mini Real Time Kernel - a free to download and royalty free RTOS"

Kind regards
From: Guido Socher [ date: 2005-04-06 ]
A few people asked me how they
could use avrdude (instead of uisp) in combination with the
cable described in the article. Here the /etc/avrdude.conf entry
which you will need:

id = "dapa";
desc = "direct parallel port. uisp compatible.";
type = par;
reset = 16;
sck = 1;
mosi = 2;
miso = 11;

# the command to use this is:
# avrdude -p m8 -c dapa -e -U flash:w:YourHexFile.hex

From: francois schnell <francois.schnell(at){[nospam]}> [ date: 2005-04-07 ]
Hello Guido,

Thank you so much for all your articles around the AVR. I'm a newbie on AVR, I've installed all you said on Ubuntu and it works perfectly (I now can easily program digital I/O on the atmega8).
I'm now trying to use the UART line (and later the ADC) and there I must admit I'm stuck for the programming (MAX232 works fine). Do you advise any ressources on the net ? (I didn't find much help for my newbie level in the lib-c manual)

I also saw you mentionned this:

References * Pascal Stang's AVRlib: or

It looks great with lots of functions for UART and ADC but we didn't install it in the article ... ? Can I use it along side AVR lib-c ? How to install it on Linux, should I modify the makefile too ?

I must admit I'd love an article on serial connection to the PC and ADC in order to transform the atmega in an educational scientific lab. In France, schools have data aquisition board which works only on windows and you've got nothing under 1000 $. With the right quarts with atmega8 we could effectively have a 10 kHz sampling ?

Thanks again for your contributions
From: Guido Socher [ date: 2005-04-07 ]
Hello Francois,
for the libraries from Pascal Stang I would suggest to
just copy the relevant part of the source code. However
I have not looked at his uart code and I can't really comment on it.

What will definitly work is this:
copy the uart code (.c and .h file) from
linuxlcdpanel-1.4.tar.gz (linuxfocus article about the lcd pannel
for a server).
I have recently updated it and the uart code has a number of compatibility
defines which will make it work for both 4433 and atmega8.

The linuxlcdpanel-1.4.tar.gz contains also a little linux program to
initialize the uart in your linux pc with the right setting (speed, parity, etc...)


From: Vladimir Riznic <liquidoo11(at)> [ date: 2005-06-20 ]
hello guido,
i liked your article alot,
i already have a development board, but now i have needs for an in-system programming since dev-board is too big and has no mounts for wheels :)
i think of using your suggested method, but i need an oscillator, which values of capacitors near crystal should i use? same as with 4433 or some other value?
From: Guido Socher [ date: 2005-06-20 ]
Hi Vladimir,
what uC do you use? The atmega8 as described in this article
does not need a crystal.

Otherwise 10-22pf are ok for most crystals.

From: Vladimir Riznic <liquidoo11(at)> [ date: 2005-06-20 ]
hi Guido,
yes it is atmega8, but you mentioned that if UART and timers are needed, crystal should be provided to the uC.
im trying to build general purpose robot-brain-board which i could move from bot to bot when needed, so basically all i need is your board with something like IDC10 connections, but i try to make it complete for anything that i might use with it.
thanks and keep with uC articles, they are great, and your code helped me a lot.
From: Guido Socher [ date: 2005-06-21 ]
Hi Vladimir,
OK, that is true. For sending larger strings of data over
rs232 you should have a crystal. You connect it exactly as for
the 4433 (see my old article). After that you have to modify the
fuse bits (note that you can not undo this unless you have
a working crystal).
From: Vladimir Riznic <liquidoo11(at)> [ date: 2005-06-22 ]
thanx again Guido,
all i needed to know is whether values of capacitors change if crystal speed is different (4433 - 4MHz, Mega8 - 16MHz)
the biggest help to me was that eagle file you posted in "autonomous linux robot" article, because it shed some light for me since i don't have lots of electronics experience.
thanx for great articles and keep them up
From: Vladimir Riznic <liquidoo11(at)> [ date: 2005-06-24 ]
hello Guido,
i see that i am becoming most boring poster here :)
i have a problem, i uploaded my code using avrdude with giveio driver installed (testcode, just to see the led blink) but the led doesn't blink although code is veryfied.
(i built my board without an oscillator, and everything else is up to specs of your article, tested it with multimeter to check voltages, while programming three AA batteries were connected to the uC)
on voltage input i read 4.66V, voltages on PC5 shows something over 3V constantly. i just copied and pasted your test code to KamAVR (WinAVR IDE) so it should work (i even compiled similar program using ICC compiler)
my settings are m8 for the device and 1MHz for the clock, no fuse bits
i wouldnt oppress you in this way :) and went to avrfreaks to post a question there, but since you wrote this great article, you are to pay consequences :))))))))))))))))
thanx, and sorry for inconviniences,

ps yes i use windows for avr, because it has a driver to run my usb devboard, and i have trouble parting with ICC

pps it might be a good idea to put a switch on the + power from the supply, so not to need to plunge batteries from their holders each time you want to stop uC
From: Guido Socher [ date: 2005-06-25 ]
Hello Vladimir,
you have probably soldered the LED with the wrong polarity
onto the board.

From: Vladimir Riznic [ date: 2005-06-26 ]
no, i found the mistake, when i was plugging uC into the IC holder (i bought a cheap one, so i had to use some excessive force) i twisted that pin a little, i guess that some contact inside it broke because all other pins work ok, so for now, i just desoldered the side of the 1K resistor which went to PC5 and soldered it to PC4, i have one pin less, but this board is only first version which is to take heavy lab bashing until i develop a new one which will have 7805 regulated voltage a proper crystal clock, and upgrade pins...
for now im very pleased since this is my first hardware project with uC.
thanx again
From: Frank Zacharias <fzachi [at] gmx [dot]> [ date: 2005-07-23 ]

i bought a complete kit, build the board and it works perfectly. For VCC i cutted an old usb-cable and use the usb_voltage to power the circuit. Unfortunately it works only with the code produced by the tools provided on the Linux AVR Programming CD. With downloaded and self-compiled tools(all have the same version like on cd) it doesn't work.
Anyway, i read on a different page( and in the atmega8-specs that avcc should be connected to vcc even if the ADC is not used. What can happen if avcc isn't connected?

thx and regards, frank
From: Guido Socher [ date: 2005-07-23 ]
Hello Frank,
probably there is something wrong with the installation of the
self-compiled tools. If there is no vcc voltage
on the adc then the adc can not be initialized. That's all.
From: Stefan <stef.wagner(at)> [ date: 2005-08-03 ]
Dear Guido,

when I tried "make avr_led_lcd_test.hex" I go a few errors:
some files (io.h and progmem.h) were not found
and lcd.c caused errors too "invalid lvalue in unary `&`" in the lines where lcd_data_port_in() and lcd_data_port_out() are defined.

I tried it with your CD "GCC AVR Microcontroller programming guide",
but it didn`t work.
The same happened when I configured my other Linux-PC (SuSE 9.1) according the article 352. I only used avr-libc-1.0.5 instead of avr-lib-1.0.4.

What can I do? (I am not expierenced with linux.)

From: Guido Socher [ date: 2005-08-03 ]
Hello Stefan,
to which software and which article does your question actually relate?
There is no make target called avr_led_lcd_test.hex in the software that
belongs to this article (avrm8ledtest-0.2).
From: Stefan <stef.wagner(at)> [ date: 2005-08-03 ]
Hello Guido,

thank you for your quick answer!

Sorry, the file avr_led_lcd_test.c belongs to the article 251 in linuxfocus, from November 2002.
I wanted to build the power supply that you described in article251.
And I tried to compile the software in two ways:

1.) according to your article 352 "Programmieren des AVR Microcontrollers mit GCC, libc 1.0.4"
2.) with your cd "Linux AVR Programming CD"

1.) I tried to set up my Linux-Enviroment on a PC according to article 352.
I got all the files you suggested, but not libc 1.0.4. Instead I used libc 1.0.5.
To setup of the enviroment I followed exactly your instructions. It took a long time to install all the software but it seemed to be successfull.

However when I called make avr_led_lcd_test.hex I got errors.
Unfortunately I can't give the exact output now.
Some header-files (io.h, progmem.h) were not found and I got errormessages related to lcd.c.
(error: invalid lvalue in unary '&' in the lines where lcd_data_port_in() and lcd_data_port_out() were referenced).

2.) Then I tried to use the Linux-AVR-Programming-Cd.
I changed only the entry in the Makefile concerning the processortype. Then I called make avr_led_lcd_test.hex and got the following

avr-gcc -mcall-prologues -Os -mmcu=atmega8 -Wall -Wstrict-prototypes -c avr_led_lcd_test.c
avr_led_lcd_test.c:11:16: io.h: No such file or directory
avr_led_lcd_test.c:12:21: progmem.h: No such file or directory
avr_led_lcd_test.c:13:23: interrupt.h: No such file or directory
avr_led_lcd_test.c:14:24: string-avr.h: No such file or directory
avr_led_lcd_test.c:16:21: sig-avr.h: No such file or directory
In file included from avr_led_lcd_test.c:17:
lcd.h:18:22: pgmspace.h: No such file or directory
In file included from avr_led_lcd_test.c:17:
lcd.h:113: error: parse error before '*' token
lcd.h:113: warning: function declaration isn't a prototype
lcd.h:118: warning: type defaults to `int' in declaration of `prog_char'
lcd.h:118: error: parse error before '*' token
lcd.h:118: warning: function declaration isn't a prototype
In file included from avr_led_lcd_test.c:19:
uart.h:17: warning: type defaults to `int' in declaration of `prog_char'
uart.h:17: error: parse error before '*' token
uart.h:17: warning: function declaration isn't a prototype
avr_led_lcd_test.c:27: warning: return type of 'main' is not `int'
avr_led_lcd_test.c: In function `main':
avr_led_lcd_test.c:35: warning: implicit declaration of function `sbi'
avr_led_lcd_test.c:35: error: `DDRC' undeclared (first use in this function)
avr_led_lcd_test.c:35: error: (Each undeclared identifier is reported only once
avr_led_lcd_test.c:35: error: for each function it appears in.)
avr_led_lcd_test.c:35: error: `PC5' undeclared (first use in this function)
avr_led_lcd_test.c:37: warning: implicit declaration of function `sei'
avr_led_lcd_test.c:41: warning: implicit declaration of function `cbi'
avr_led_lcd_test.c:41: error: `PORTC' undeclared (first use in this function)
make: *** [avr_led_lcd_test.o] Error 1

The cd-programming-enviroment would be a wonderful tool for use in school.

Regards Stefan

From: Stefan <stef.wagner(at)t-online> [ date: 2005-08-04 ]
Dear Guido,

here is what I mentioned before.
It's the result of "make avr_led_lcd_test.hex" from my linux-enviroment that I tried to set up as you discribed it in this article (352).
(The file came with the power supply in article 251 in linux focus.
I only changed the entry for MCU to atmega8)

avr-gcc -mcall-prologues -Os -mmcu=atmega8 -Wall -Wstrict-prototypes -c lcd.c
lcd.c:15:16: io.h: No such file or directory
lcd.c:16:22: pgmspace.h: No such file or directory
In file included from lcd.c:19:
lcd.h:113: error: parse error before '*' token
lcd.h:113: warning: function declaration isn't a prototype
lcd.h:118: warning: type defaults to `int' in declaration of `prog_char'
lcd.h:118: error: parse error before '*' token
lcd.h:118: warning: function declaration isn't a prototype
lcd.c:41: error: parse error before '(' token
lcd.c:41: error: parse error before '(' token
lcd.c:41: error: parse error before '(' token
lcd.c: In function `lcd_out_low':
lcd.c:84: warning: implicit declaration of function `sbi'
lcd.c:84: error: `PORTC' undeclared (first use in this function)
lcd.c:84: error: (Each undeclared identifier is reported only once
lcd.c:84: error: for each function it appears in.)
lcd.c:84: error: `PC3' undeclared (first use in this function)
lcd.c:85: warning: implicit declaration of function `cbi'
lcd.c: In function `lcd_read':
lcd.c:169: error: `PORTD' undeclared (first use in this function)
lcd.c:169: error: `PD4' undeclared (first use in this function)
lcd.c:176: warning: implicit declaration of function `bit_is_set'
lcd.c:296: error: parse error before '*' token
lcd.c:296: warning: function declaration isn't a prototype
lcd.c: In function `rolltext_lcd_p':
lcd.c:300: warning: implicit declaration of function `PRG_RDB'
lcd.c:300: error: `text' undeclared (first use in this function)
lcd.c:303: error: `shiftlen' undeclared (first use in this function)
lcd.c: In function `lcd_read':
lcd.c:336: warning: type defaults to `int' in declaration of `prog_char'
lcd.c:336: error: parse error before '*' token
lcd.c:338: warning: function declaration isn't a prototype
lcd.c: In function `lcd_puts_p':
lcd.c:341: error: `progmem_s' undeclared (first use in this function)
lcd.c: In function `lcd_read':
lcd.c:403: error: parse error at end of input
make: *** [lcd.o] Fehler 1

From: Guido Socher [ date: 2005-08-04 ]
Hello Stefan,
ok, that is normal. The libc has changed a lot. You will
not be able to compile out of the box software which is
3 years old.
The basic idea will still work but header file names have
changed and remember that this old code was written for a
different microcontroller. The rs232 interface code is e.g
different. You can re-use ideas but the code needs major
Do you really want to build this old power supply?
There is a new one:
It is easier to build and better. This is why I did not
maintain the old code for the power supply from 3 years ago.
If you really want the old ciruit then I can help you to re-write
the code but it can not be done in a few minutes. It needs time.
From: Stefan <stef.wagner(at)> [ date: 2005-08-06 ]
Dear Guido,

thank you for offering your help!
The new one looks nice and I decided to built it.

From: philius [ date: 2005-08-07 ]
Hello Guido,
how can I programm the fuse bits?
I´m still a beginner.
From: cskao <joegtw(at)> [ date: 2005-08-18 ]
Dear Guido,

Thank you for sharing such a nice idea. I got a problem about that is this ISP programmer competible to ATmega128? Or where can I find an alternative for a cheaper version of an ATmega128 competible programmer? Thank you for your help.
From: Matthias <ratzl(at)> [ date: 2005-09-10 ]
Hi Guido,

in the article 352 you write to download the "avr-libc-1.0.4.tar.bz2.tar"
file from
But this file is not available.Where can I download it?

From: Guido Socher [ date: 2005-09-11 ]
Hi Matthias,
just take the latest version.
From: Jason [ date: 2005-11-01 ]
Hey everybody - I think there's a tiny mistake in the article. When compiling GCC, I think the language option in the configure line should have be "--enable-languages=c" instead of "--enable-language=c"

Thanks for the help with AVR - I'm just learning how to play with them and looking forward to making some exciting applications!
From: Hans [ date: 2006-02-02 ]
Jason is right.
It must be "--enable-languages=c"
From: Michael <michael(at)> [ date: 2006-03-02 ]
We had a product in development, which was done by a programmer who died. The firmware was in assembler, we employed an engineer to take over the project.

After six months (not full time, but a lot of time) the project was un-reliable, and full of bugs.

At the time I had no experience with Atmel chips, or unix based operating systems. I had about 1 year experience programming the msp430 with C using the imagecraft compiler.

Using your page as a starting point, I was able to set up avrgcc on a system running debian. debian's package installer made it a bit easier.

Using C I was able to re-write the whole project in 5 days. It is bug free and bulletproof.

Thankyou very much Guido for your help.

P.S. I would like to put 'modprobe ppdev' and 'chmod 666 /dev/parport0' into a startup script, but havn't figured it out yet.

From: Doug [ date: 2006-03-25 ]
Thanks, Guido! This article rocks!

Wish there were more linuxfocus articles on the way!

One comment: My low-voltage ATMEGA8 continues to run even if the power supply is disconnected (but programmer cable is still attached.) Apparently enough current leaks through the 10K resistor from the RESET line to keep the MC going....

The ATMEGA8L only needs about 2.7V.

Anyway--great job!
From: John <bersig(at)> [ date: 2006-04-05 ]
This article looks promising Guido. I downloaded and compiled everything without a hitch, now I just need the hardware. Thanks!

A few questions still remain however. First is, what about other electronics-related tools? I'm thinking about such things as circuit drawing (layout & artwork for PCB creation) and other misc. tools that would help with the rest of an electronics project. I'm also particularly interested in Linux software for interfacing with AVR tools such as the JTAGICE debugger. Maybe future articles could address some of these topics?

Also, with all the software that is needed to dl/compile to get this stuff to work, has anyone considered getting one of the major distros such as Debian or SuSE to integrate at least some of this? Maybe there should even be a distro dedicated to this stuff... kind of a linux-based engineering workstation thing. It would be awesome to have a system that not only came pre-configured to be able to build uC projects (not just the AVR, but also other microcontrollers too.. the PIC, 6811, and 8051 come immediately to mind, and there are probably others I don't know of yet) but also had tools for circuit layout, PCB artwork generation, etc.

I realize that's probably beyond the scope of your articles Guido. :) Just a thought I had to get out there.

BTW, Olimex ( ) seems to have some decent-looking prototype boards that come pre-populated with things like a serial port, sockets for a crystal oscillator and an AVR chip, a JTAG port, a reset button, etc., plus a few square inches of pre-drilled prototype area. Anyone tried these? I'd gladly pay a few $$ if it means one less thing to build/compile/install before I can start -my- project.

Anyway, thanks again for the article(s). I'm just starting out with AVRs so I'm finding it very informative. I've messed around with the Basic Stamp from Parallax, and I build a complete (4-bit) CPU out of NAND gates as a college project so I'm not a complete electronics noob. Still, I can use whatever help I can get. :) I'm planning to start out with a couple simple projects to get some experience, eventually building up to an AVR-based AC/DC power monitoring gizmo for a solar power (pv) system we have installed at our house. ( will have details of the project if/when I get that far. )

From: Nils [ date: 2006-05-28 ]
Just wanna thank you.
I am a µC beginner but with this article it worked out of the box...

From: ken <ken_lutchu82> [ date: 2006-11-07 ]
hi sir,i want ask about my my project when i compile with avr gcc i found text say that "PRG_RDB"was undifine,what that mean and what is PRG_RDB? thanx

43 talkbacks

Due to the increased amount of web spam we have deciced to removed the talkback posting possibility. You can read old talkbacks but you can no longer post new ones.

Back to

Please contact webmaster(at) if you have any questions with regards to this talkback

lftalkback version 3.10