Question: #include enum States {Start, Init, LED_Lit1} state; unsigned char button; #define button PINA & 0x01 void tick_LED() { switch(state) { // Transitions case Start: //

#include

enum States {Start, Init, LED_Lit1} state; unsigned char button; #define button PINA & 0x01

void tick_LED() { switch(state) { // Transitions case Start: // Start transition state = Init; break;

case Init: // Initial transition if(button == 1){ // If PINA0 is 1 state goes to led_lit in LED_Lit1 state = LED_Lit1; } else { // If PINA0 is 0 state remains in initial state = Init; } break;

case LED_Lit1: // LED_Lit1 Transition if(button == 0){ // If PA0 is 1 state remains in LED_Lit1 state = LED_Lit1; } else { state = Init; // if PA1 is 1 state goes to initial } break;

default: state = Start; break; }

switch(state) { // Actions case Start: PORTB = 0x01; // PB0 set to 1 break; case Init: PORTB = 0x01; // PB0 set to 1 break; case LED_Lit1: PORTB = 0x02; // PB1 set to 1 break; } }

int main(void) { DDRA = 0x00; PORTA = 0xFF; // Configure port A's 8 pins as inputs DDRB = 0xFF; PORTB = 0x00; // Configure port B's 8 pins as outputs, while (1) { state = Start; tick_LED(); } }

Hi, could someone please help me debug this code....I've created a simple state machine but it wont transition into different states....I would like it so when I press the button PINA0 is 1 and it transitions into the LED_LIT1 state and the output of PORTB becomes 0x02 instead of the default 0x01. this is done in Atmel studio 7.0 using Atmega32 using C programming

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!