Jump to content

View more

Image of the Day

Adding some finishing touches...
Follow us for more
#screenshotsaturday #indiedev... by #MakeGoodGames https://t.co/Otbwywbm3a
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Why won't this C code compile?

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
1 reply to this topic

#1 jdub   Members   

459
Like
0Likes
Like

Posted 15 February 2013 - 05:16 PM

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

 

 


J.W.

#2 Martins Mozeiko   Members   

1436
Like
6Likes
Like

Posted 15 February 2013 - 05:22 PM

*
POPULAR

Variable definitions inside case must be in some scope.

Like this:

 

case RUNNING:
{ // <---- note the new scope
    unsigned char data;
    ...
}
 
case SAMPLING:
...

Edited by Martins Mozeiko, 15 February 2013 - 05:23 PM.





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.