Sign in to follow this  
jdub

Why won't this C code compile?

Recommended Posts

jdub    459

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;			
		}
	}

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this