Making a switch case for isr with multiple interrupts

Thread Starter

SaveMeGalactic

Joined May 20, 2021
3
I'm having a hard time including interrupts into my cases for a traffic light code. The interrupts are supposed to start a sequence of events but my brain is just fried on how to go about it.
 

Thread Starter

SaveMeGalactic

Joined May 20, 2021
3
Welcome to the forum. Show us what you got so far.
ISR(INT0_vect) {
uint8_t data = SPI_Read_Command(1, 0x13);
if ((data & 0b00000001) == 0b00000001) { // BW Southbound Main Green S0
SPI_Send_Command(1,0x12, 0b00100000);
}
if ((data & 0b00000010) == 0b00000010) { // BW Southbound Turn Green S1
SPI_Send_Command(1,0x12, 0b00000100);
}
if ((data & 0b00000100) == 0b00000100) { // BW Southbound Tram White . S2
SPI_Send_Command(1,0x12, 0b00000001);
}
if ((data & 0b00001000) == 0b00001000) { // BW Northbound Bus Lane S3
SPI_Send_Command(2,0x12, 0x0b00010000);
}
if ((data & 0b00010000) == 0b00010000) { // BW Northbound Main Green . S4
SPI_Send_Command(2,0x12, 0b00100000);
}
if ((data & 0b00100000) == 0b00100000) { // BW Northbound TRAM White S5
SPI_Send_Command(2,0x12, 0b00000100);
}
if ((data & 0b01000000) == 0b01000000) { // BW Northbound Main Green S6
SPI_Send_Command(2,0x13, 0b00100000);
}
if ((data & 0b10000000) == 0b10000000) { // BW Northbound Main Green S7
SPI_Send_Command(2,0x13, 0b00000001);

}
SPI_Send_Command(2,0x12, 0b00000001);
}
// if ((data & 0xff) == 0xff) { // BW Southbound Main
// SPI_Send_Command(1,0x12, 0xff);
// } else {
// SPI_Send_Command(1,0x12,0x00);
// }
// }





ISR(INT1_vect) {
uint8_t data = SPI_Read_Command(2, 0x13);


// if ((data & 0x0f) == 0x0f) {
// //LCD_PosnWrite(addr, 0x49, "All ON ", 7);
// SPI_Send_Command(2, 0x12, 0xff);
// SPI_Send_Command(2, 0x13, 0xf0);
// } else { // turn off LEDs when button is pressed
// //LCD_PosnWrite(addr, 0x49, "EXP B ", 7);
// SPI_Send_Command(2, 0x12, 0x00);
// SPI_Send_Command(2, 0x13, 0x00);
// }
}

ISR(PCINT2_vect) {
if ((PIND & 0xf0) == 0xf0) {
//LCD_PosnWrite(addr, 0x49, "All ON ", 7);
PORTC |= 0b00001110;
} else {
//LCD_PosnWrite(addr, 0x49, "PORT D ", 7);
PORTC &= 0b11110001;
}
}



/*
* Main routine. Run the tests in sequence.
*/
int main(void) {
uint32_t end_time;
uint32_t now_ms;
//uint8_t input;

// run setups
setup_Ports();
setup_Timer0();
setup_AtoD();
setup_I2C();
setup_SPI();
setup_interrupts();
if (I2C_CheckAddress(0x27)) {
addr = 0x27;
} else if (I2C_CheckAddress(0x3F)) {
addr = 0x3F;
} else if (I2C_CheckAddress(0x20)) {
addr = 0x20;
}
do_LCD(addr);
sei();

// turn on all LEDs
SPI_Send_Command(1, 0x12, 0x00);
SPI_Send_Command(2, 0x12, 0x00);
SPI_Send_Command(2, 0x13, 0x00);
PORTC |= 0b00001110;



while (1) {


//

// run the buzzer for half a second
LCD_PosnWrite(addr, 0x49, "Buzzer ", 7);

PORTB |= 0b00000010;
now_ms = cur_ms;
end_time = cur_ms + 500;
//LCD_quad(addr, 0x00, cur_ms);
//LCD_quad(addr, 0x40, end_time);
while (end_time != cur_ms) {
if (now_ms != cur_ms) {
// another ms has passed, toggle the buzzer
now_ms = cur_ms;
PORTB ^= 0x02;
}
}
PORTB &= 0b11111101;

// show Pot changes on LCD for 4 seconds
LCD_PosnWrite(addr, 0x49, "Pot ", 7);
end_time = cur_ms + 4000;
while (cur_ms < end_time) {
LCD_hex(addr, 0x09, cur_AtoD);
}
}


}
 

Thread Starter

SaveMeGalactic

Joined May 20, 2021
3
ISR(INT0_vect) {
uint8_t data = SPI_Read_Command(1, 0x13);
if ((data & 0b00000001) == 0b00000001) { // BW Southbound Main Green S0
SPI_Send_Command(1,0x12, 0b00100000);
}
if ((data & 0b00000010) == 0b00000010) { // BW Southbound Turn Green S1
SPI_Send_Command(1,0x12, 0b00000100);
}
if ((data & 0b00000100) == 0b00000100) { // BW Southbound Tram White . S2
SPI_Send_Command(1,0x12, 0b00000001);
}
if ((data & 0b00001000) == 0b00001000) { // BW Northbound Bus Lane S3
SPI_Send_Command(2,0x12, 0x0b00010000);
}
if ((data & 0b00010000) == 0b00010000) { // BW Northbound Main Green . S4
SPI_Send_Command(2,0x12, 0b00100000);
}
if ((data & 0b00100000) == 0b00100000) { // BW Northbound TRAM White S5
SPI_Send_Command(2,0x12, 0b00000100);
}
if ((data & 0b01000000) == 0b01000000) { // BW Northbound Main Green S6
SPI_Send_Command(2,0x13, 0b00100000);
}
if ((data & 0b10000000) == 0b10000000) { // BW Northbound Main Green S7
SPI_Send_Command(2,0x13, 0b00000001);

}
SPI_Send_Command(2,0x12, 0b00000001);
}
// if ((data & 0xff) == 0xff) { // BW Southbound Main
// SPI_Send_Command(1,0x12, 0xff);
// } else {
// SPI_Send_Command(1,0x12,0x00);
// }
// }





ISR(INT1_vect) {
uint8_t data = SPI_Read_Command(2, 0x13);


// if ((data & 0x0f) == 0x0f) {
// //LCD_PosnWrite(addr, 0x49, "All ON ", 7);
// SPI_Send_Command(2, 0x12, 0xff);
// SPI_Send_Command(2, 0x13, 0xf0);
// } else { // turn off LEDs when button is pressed
// //LCD_PosnWrite(addr, 0x49, "EXP B ", 7);
// SPI_Send_Command(2, 0x12, 0x00);
// SPI_Send_Command(2, 0x13, 0x00);
// }
}

ISR(PCINT2_vect) {
if ((PIND & 0xf0) == 0xf0) {
//LCD_PosnWrite(addr, 0x49, "All ON ", 7);
PORTC |= 0b00001110;
} else {
//LCD_PosnWrite(addr, 0x49, "PORT D ", 7);
PORTC &= 0b11110001;
}
}



/*
* Main routine. Run the tests in sequence.
*/
int main(void) {
uint32_t end_time;
uint32_t now_ms;
//uint8_t input;

// run setups
setup_Ports();
setup_Timer0();
setup_AtoD();
setup_I2C();
setup_SPI();
setup_interrupts();
if (I2C_CheckAddress(0x27)) {
addr = 0x27;
} else if (I2C_CheckAddress(0x3F)) {
addr = 0x3F;
} else if (I2C_CheckAddress(0x20)) {
addr = 0x20;
}
do_LCD(addr);
sei();

// turn on all LEDs
SPI_Send_Command(1, 0x12, 0x00);
SPI_Send_Command(2, 0x12, 0x00);
SPI_Send_Command(2, 0x13, 0x00);
PORTC |= 0b00001110;



while (1) {


//

// run the buzzer for half a second
LCD_PosnWrite(addr, 0x49, "Buzzer ", 7);

PORTB |= 0b00000010;
now_ms = cur_ms;
end_time = cur_ms + 500;
//LCD_quad(addr, 0x00, cur_ms);
//LCD_quad(addr, 0x40, end_time);
while (end_time != cur_ms) {
if (now_ms != cur_ms) {
// another ms has passed, toggle the buzzer
now_ms = cur_ms;
PORTB ^= 0x02;
}
}
PORTB &= 0b11111101;

// show Pot changes on LCD for 4 seconds
LCD_PosnWrite(addr, 0x49, "Pot ", 7);
end_time = cur_ms + 4000;
while (cur_ms < end_time) {
LCD_hex(addr, 0x09, cur_AtoD);
}
}


}
It's more so with isr(int0)
 
Top