[XCSSA] Links from Monday's XCSSA Arduino/AVR Microcontroller Programming Meeting

X-otic Computer Systems of San Antonio xcssa at xcssa.org
Thu May 22 16:16:09 CDT 2008


On May 22, 2008, at 4:01 PM, X-otic Computer Systems of San Antonio  
wrote:

> But now that I look at this site that you listed, I see that in one  
> of their
> projects, the source code calls some support libraries that seem to  
> load up
> said register variables:
> 	(from http://nerdkits.com/videos/musicbox1/musicbox1.c)
> 	[...]
> 	#include <avr/io.h>
> 	#include <avr/interrupt.h>
> 	#include <avr/pgmspace.h>
> 	[...]
>
> Do you have experience with these header files?  Are they for just  
> ONE of the
> ATmel devices?  How do you "switch" between models?  Anyone?

Those come with the AVR port of GCC. When I was using AVR's IDE with  
WinAVR added to it, it set things up automatically based on which  
model you selected. I think the IDE was providing the -march or  
somesuch option to gcc, to set up #define __AVR_ATmega88__ etc. Then  
io.h will call up the appropriate header file based on which model  
defines it finds.

One thing to keep in mind is that AVR uses a Harvard architecture,  
though unlike PIC, it allows you to read from code space (for  
constant strings, etc.) Because of this, constant initialized arrays  
will normally be copied into RAM at startup so that you only have to  
worry about one type of pointer. With psmgpace.h you can use the  
progmem attribute and macros like pgm_read_byte() to explicitly read  
code space, thus saving you a lot of RAM for read-only lookup tables.

Also note that you really shouldn't expect GCC to work very well with  
the AVR Tiny series, since they only have very limited stack, and you  
know how C loves to use the stack.

  - Bruce -


More information about the XCSSA mailing list