LCD Menu State Machine

Go To Last Post
2 posts / 0 new
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have written a state machine for my motor controller but have run into writers block. How should I implement functions into the table?

For example On some states I want to clear the screen and write 2 new lines. On other I want to clear only one line and change it. I can call functions but I'm unsure how to call them with parameters and make it all useful.

I'm planning on having a timer that updates the LCD regularly so the only actions the states are going to do is modify an LCD buffer to suit that states data.



I cleaned up the code and modularized the project but now have a multiple structure definition problem while linking as well as an implicit declaration of my step function.

I think I have some multiple inclusions but I want my statemachine, lcd library, and bitmask libraries to be flexable as I use them in different projects so I include all the headers each file needs. Will this cause say the delay.h routines to be in every object or does the linker strip out duplicates?

Compiler/Linker Output (shorted for ease):

avr-gcc ......... -c  ../Menu_Statemachine.c
../Menu_Statemachine.c: In function 'main':
../Menu_Statemachine.c:24: warning: implicit declaration of function 'step'

avr-gcc ......... -o Menu_Statemachine.elf
Statemachine.o:(.data+0x0): multiple definition of `the_table'
Menu_Statemachine.o:(.data+0x0): first defined here


  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have variables defined in Statemachine.h

.h files should only contain declarations while the definition should be in a single .c

It doesn't hurt to have an "extern" declaration in a .h file that is included by the .c file where the definition exists.

If you don't understand what I'm talking about read the thread in the Tutorial Forum about managing large projects.

Bottom line:

#include "shared.h"
// this is the actual definition
char fred;


#include "shared.h"
if (fred==3) {


// this is a declaration...
extern char fred;

Oh and the other way for the step() function. Quite rightly you kept it's definition in a single .c file but you did not make it "visible" to the other .c file. The shred header file should contain a function declaration:

void step(enum states *state, int trigger);

While you can use "extern" on a function declaration it's kind of implied by the fact that the ')' is followed by ';' (declaration) and not '{' (definition)