I am trying to compile some code to run a state machine on an embedded device for CS class. However, this code won't compile and its got me stumped. Got the error "error: a label can only be part of a statement and a declaration is not a statement".
Any help would be appreciated.
while(1){
switch(state)
{
case IDLE:
if(USART_receive() == 's')
{
state = RUNNING;
}
break;
case INITIALLIZING:
initialize_TIMER0();
set_TIMER0(0b00000101, 255);
state = IDLE;
break;
case RUNNING:
//Error occurs here <--------
unsigned char data;
if(try_receive(&data))
{
if(data == 's')
{
state = IDLE;
USART_transmit('h');
break;
}
}
if(check_TIMER0())
{
state = SAMPLING;
}
break;
case SAMPLING:
x = read_ADC(ADC_X);
y = read_ADC(ADC_Y);
z = read_ADC(ADC_Z);
state = TRANSMITTING;
break;
case TRANSMITTING:
//transmit x,y,z. Wait between each transmission
//so that the data can be effectively read
USART_transmit((char)x);
_delay_ms(50);
USART_transmit((char)y);
_delay_ms(50);
USART_transmit((char)z);
state = RUNNING;
break;
default:
break;
}
}