Getting Started

(lily) #1

Chapter 10: C Structures


Projects


Finite State Machine................................................................................


I in l ate Machines, Lions, Tigers,
and Bears... hat
there are graduate level Computer Science courses taught on this subject, so it can
et very scary indeed. But, fortunately for us, the fundamental concepts that we


he basic ideas behind finite state machines are used to tame systems that seem
imp s er is a finite state machine. At any given moment
the comput stor states, off or on, 0’s and 1’s.
The compu
current state and changes both the current state and the output state based on the
current state and the input state.


Actually yo w my state is ‘typing’.
If my ears te will change to ‘running
like l state isn’t >= the tigers ‘running like hell’
state, my fu lunch’, being digested’, and
‘being tige


When you think about it, the Butterfly, as simple as it is, does a lot of stuff. How
does the software keep track of what it is doing? How does it know to keep doing
it? How does it know when to do something different? And how does it know
what to do


Say the Butterfly is outputting a value on PORTD and you diddle the joystick,
how does i all this switch statement from
Chapter 5.


RTD = ~0x01;
break:

itia ly thought about naming this section “Finite St
Oh My!” because the topic seems a bit scary. And I must admit t

g
will use are fairly easy to grasp, and we don’t need to go to great depths to get
what we need.


T
os ibly complex. A comput
er state is defined by a bunch of transi
ter inputs a set of 0’s and 1’s, from some external source, checks its


u and I can be seen as state machines. Right no
input the sound of a screeching tiger my sta
he l.’ And, if my ‘running like hell’
ture state may sequence through ‘being
r poop.’

next?

t respond to being diddled? You may rec

switch(input){
case KEY_PLUS :
PO
Free download pdf