I'm a student and I've written out this code (the task involves controlling an automatic door) I thought I had everything sorted but when I try to build it it gives me a few errors. If someone could point me in the right direction to fixing them that would be great!
#include <reg167.h>
#define SensorsActive P2 & 0x0010 == 0x0010 || P2 & 0x0020 == 0x0020
/* Main program - Automatic doors */
int main(void)
{
DP2 = 0x0003;
/* sets bits 0,1 as outputs and the rest as inputs */
ODP2 = 0x0000;
/* selects output push/pull driver */
enum {closed, opening, open, closing} state;
/* define FSM states */
state = 1;
/* set starting state as door closed */
for (;;) {
switch (state) {
case closed: /* Door closed */
if (SensorsActive) {
/* If motion sensors are activated switch to opening state */
state = opening;
}
break;
case opening: /* Door opening */
P2 = P2 & ~0x0001;
/* Sets direction bit to clockwise (opening) */
P2 |= 0x0002; /* Turns on motor control bit */
if(P2&0x0004==0x0004)//door open limit switches triggered switch to open
state = open;
break;
case open: /* Door open */
timer();
while (T3OTL != 1) ;
if(SensorsActive) {
/* If sensors are active break so that open case will be repeated and timer reset... */ /* ...Else switch state to closing */
break;
}
else state = closing;
break;
case closing: /* Door closing */
P2 |= 0x0001;// Sets direction bit to counterclockwise (closing)
P2 |= 0x0002;/* Turns on motor control bit */
if(SensorsActive)/* If sensors are active start opening doors */
state = opening;
if(P2 & 0x0008 == 0x0008) {
//If closed limit switches are reached switch state to closed
state = closed;
}
break;
}
}
}
The errors it is giving are:
Build target 'Target 1'
compiling main.c...
main.c(10): error C25: syntax error near 'enum'
main.c(11): error C53: redefinition of 'state'
main.c(13): error C25: syntax error near 'while'
main.c(13): error C25: syntax error near '1'
main.c(16): error C103: 'state': illegal function definition (missing ';' ?)
Target not created.