- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How can i initalise the states and cause this state machine of 3 states to work effectively.
My code if found below: # include <stdio.h># include <io.h># include <system.h># include <alt_types.h># include "altera_avalon_pio_regs.h" int main() { alt_u32 key_in, signal_raknarvarde, state; # define Scan_keys_state 0x01 # define write_to_leds_state 0x02 # define no_keys_state 0x03 // Initiering av variabler och utsignaler till hårdvaran //int state = Scan_keys_state; //int state = write_to_leds_state; //int state = no_keys_state; // loop for ever while(1) { switch (state) { case Scan_keys_state: // if key_in, state = write_to_leds; state = write_to_leds_state; break; case write_to_leds_state: state = no_keys_state; break; case no_keys_state: // Kolla att ingen knapp är nertryckt, //denna function kan göra att //wait(time); inte behövs state = Scan_keys_state; break; } } return 0; } --------------------------- Thanks for the help in advanceLink Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You'll have to define a bit better "work effectively". A problem I see in your code though is that you don't give an initial value to the state variable. You should uncomment one of the three lines that do that.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page