State machine

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <reg66x.h>
#include <DISPPORT.h>
//#define Zy P1; //add separate function(sceleton )
void delay(unsigned int c, t);
typedef enum {As,Bs,Cs,Ds,Es,Fs,Gs,Hs} states;
states code narray[8][4] = {{As,Es,Bs,Bs},{Bs,Bs,Ds,Ds},{Cs,Gs,As,As},{Ds,Ds,Cs,Cs},{Fs,Fs,Fs,Fs},{Bs,Bs,Bs,Bs},{Hs,Hs,Hs,Hs},{Ds,Ds,Ds,Ds}};
unsigned int code zarray[8] = {2,2,2,0,3,2,3,3};
void main()
{states Q; int XY,Zy,a,b;
init_display();
while(1)
{
delay(2,40000);
XY=P2&0x03;
Q = narray[Q][XY];
P1=zarray[Q];
Zy=zarray[Q];
a=Q; b=Zy;
cursor(1,1);
printf("%d %d ",a,b);
delay(2,40000);
}
}
void delay(unsigned int c, t)
{
unsigned int j,i;
for (j=0;j<c;j++){
for (i=0;i<t;i++){}}
}