Getting Started

(lily) #1

Chapter 10: C Structures


he Display state
ystick is clicked down, then I enter the AVR Butterfly

ble
put st
uctures to keep track of it. First we define two generic structures that we will
ter instantiate for each specific state, input, and next state data set.

rfly software was written using an IAR
complier. There are a lot of notes in the code
Thomas who did the porting.
the discussion as they are not
ere.]

nd menu
e three relevant variables:

gned char state; // the current state
_P pText; // pointer to some text in FLASH memory
char (*pFunc)(char input); // pointer to a function
MENU_STATE;

the current state
the input stimulus

} MENU_NEXTSTATE;

need to find the function that
ified state. The MENU_NEXTSTATE structure
state given the present state and an

TE structure first. We see that we can have 256
ame and a function pointer with each. The
character input value and returning a

if the joystick is clicked left, then I enter t
else if the jo
state


For each state, we must know the next state that we must enter for each possi
in ate. That’s going to be a lot of data so lets use what we’ve learned about
str
la


[ASIDE: As mentioned before, the B
AVR


utte
compiler and ported to the Win
that begin // mt. This is a note added by Martin
Kudo’s to Martin, but I’ve removed his notes from
relevant to what we are trying to learn h


In Menu.h we f
ext sta


ind the definitions of data structures for our menu state a
n te that contains th


typedef struct PROGMEM
{
unsi
PGM

}

typedef str
{

uct PROGMEM

unsigned char state; //
unsigned char input; /
unsigned char nextstate; // the resulting next state

The MENU_STATE structure
c


provides the data we
should be run while in the spe
provides the data we need to find the next
input state.


Let’s deal with the MENU_STA
states, and can associate a text n
function pointer is defined as taking a

Free download pdf