/* Moore FSM filename MOORE11.C Simulator program of a Moore Finite State Machine This example accompanies the book "Embedded Microcomputer Systems: Real Time Interfacing", Brooks-Cole, copyright (c) 2000, Jonathan W. Valvano 7/6/99 Interface between the TExaS simulator running a MC68HC11 EVB with ICC11 freeware compiler TExaS Copyright 1999 by Jonathan W. Valvano for more information about ICC11 see http://www.imagecraft.com You may use this file without restrictions */ /* PortC bits 1,0 are input, Port B bits 1,0 are output */ #include "HC11.h" const struct State{ unsigned char Out; /* Output to Port B */ unsigned int Time; /* Time in cycles to wait in this state */ const struct State *Next[4]; /* Next state if input=0,1,2,3 */ }; typedef const struct State StateType; typedef StateType * StatePtr; #define SA &fsm[0] #define SB &fsm[1] #define SC &fsm[2] StateType fsm[3]={ {0x01,500,{SB,SA,SB,SC}}, {0x02,100,{SC,SA,SB,SC}}, {0x03,200,{SA,SA,SB,SA}} }; void Wait(unsigned int delay){ int Endt; Endt=TCNT+delay; /* Time (500ns cycles) to wait */ while((Endt-(int)TCNT)>0); /* wait */ }; StatePtr Pt; /* Current State */ unsigned char Input; void main(void){ Pt=SA; /* Initial State */ DDRC=0x00; /* PortC are inputs, PortB is output */ while(1){ PORTB=Pt->Out; Wait(Pt->Time); /* Time to wait in this state */ Input=PORTC&0x03; /* Input=0,1,2,or 3 */ Pt=Pt->Next[Input]; } }; void resetVectors(void){ /* not really a function, but this must be last */ asm(" org $FFFE"); asm(" FDB __start"); asm(" org $FC00"); /* puts rts in a harmless place */ /* string constants also placed here */ /* the value FC00 means you can have up to 1000 characters of strings */ }