Getting Started

(lily) #1

Chapter 8: C Pointers and Arrays


ory, is much cheaper to make, so there is usually
lot more ROM than RAM. The AVR microcontrollers have a type of memory
etween RAM and ROM called Flash ROM. It
using special hardware and software

for parameters and return addresses and to store arrays,
mong other things. [The AVR is a special case in that it has 32 general purpose

rams for AVR devices with no ‘RAM’, but that’s
nother story.]

hen we define an array of constants we should be able leave it in ROM, since
’t need to change them. But our C compiler
have lots of constant data in arrays,
ing and tone data for songs, we are
t of RAM.

of how to store a string and an array in flash ROM,
nd keep it there:

r RROR_ D[] PROGMEM = "You fouled up beyond

MEM modifier is not C and is specific to the WinAVR compiler. The
VR has special Load Program Memory, LPM, instructions to get data from the

Projects


Messenger................................................................................................


Arrays in RAM and ROM


Microcontrollers have limited memory, especially RAM, Random Access
Memory. ROM, Read Only Mem
a
that is somewhat intermediate b
functions like ROM, but can be rewritten
functions.


RAM is like money and beauty, you can never have too much of it, but in
microcontrollers you can often have too little: alas, microcontrollers are ugly and
poor. C programs require RAM. You can write assembly programs that can be
burned into ROM, and run on microcontrollers that have no RAM, but C requires
RAM to keep a stack
a
registers that can be used as RAM for very tiny and carefully written C programs,
so it is possible to write C prog
a


W
the elements are constants and we won
puts arrays in the data section of RAM. If we
say strings, or conversion factor tables, or tim
going o needlessly lose a lo t


The following is an example
a


const cha E YOUFOOBARE
repair.\r\0";


The PROG
A

Free download pdf