Getting Started

(lily) #1

Chapter 8: C Pointers and Arrays


sion of the definitions:

le, 0};

actual

fi it and
that I have the time or the skill. In
in C we sometimes have to dance lightly around

: we equate a constant integer pointer pointer to a cast
function pgm_read_word, which takes as a parameter
g element of the Songs[] array. What we are doing is
a function that knows how to extract a pointer to Flash
cated... but so what, it works.

the song table in the Timer1 Input
is case is used to set the counter top value.
taken from the Butterfly code and are based on a cpu clock
of 2 MHz for the USART,
ut do not truly compensate for the difference.

equency for
fo owing a. For

First look at his ver


// pointer-array with pointers to the song arrays
const int *Songs[] PROGMEM = { FurElise, Mozart, Minuet,
AuldLangSyne, Sirene1, Sirene2, Whist
const int *pSong; // mt point to a ram location (pointer array
Songs)

The __flash of the IAR compiler is replaced by the PROGMEM. And the
use is as follows:


// mt pSong = Songs[song]; // point to this song
pSong=(int*)pgm_read_word(&Songs[song]); // looks too
complicated...

Yep, I agree: ‘// looks too complicated', but I have no intention to try to x
make it look more C-like. I doubt seriously
programming microcontrollers
ANSI C and use what works.


What the statement says is
of an integer pointer of the
the address of the son
sending this address to
RAM. Looks too compli


Setting the frequency


Tones are setup by putting an integer from
Capture Register 1, ICR1, which in th
The values are
running at 1 MHz. Since we are using a cpu clock
adjustments are made that help b


We select a base frequency of 220Hz (the A note) and calculate the fr
subsequent notes using the notes position on the musical scale ll
instance, C0 is 3 after A:

Free download pdf