/* Mealy FSM filename MEALY11.C Simulator program of a Mealy 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 bit 7 is input, bit 3 is output */ #include "HC11.h" const struct State{ unsigned int Time; /* Time to wait in each state */ unsigned char Out[2]; /* Output if input=0,1 */ const struct State *Next[2]; /* Next state if input=0,1 */ }; typedef const struct State StateType; typedef StateType * StatePtr; #define SA &fsm[0] #define SB &fsm[1] #define SC &fsm[2] #define SD &fsm[3] StateType fsm[4]={ {200,{0,0},{SB,SD}}, {200,{0,8},{SC,SA}}, {100,{0,0},{SB,SD}}, {100,{8,8},{SC,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=0x08; /* PortC bit3 is output */ while(1){ Wait(Pt->Time); /* Time to wait in this state */ Input=PORTC>>7; /* Input=0 or 1 */ PORTC=Pt->Out[Input]; 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 */ }