The wrote the following code for avr MCU and I compiled and uploaded the code with Arduino IDE, I did not get any error and the code works but I remembered C program does not support bool data type. Will this code still be compiled with avr-gcc on Linux.
//The following code is written for ATmega328P microcontroller
// Turns ON the led on a click of a switch and Turns OFF it again another click
#include <avr/io.h>
#include <avr/interrupt.h>
#define LED_PIN PB5
#define SW_PIN PD2
volatile bool ledOn = false;
// Function to initialize pinmode and interrupt
void init() {
// Set LED pin as output
DDRB = DDRB |(1 << DDB5);
// Set switch pin as pull-up resistor
PORTD = PORTD |(1 << SW_PIN);
// Enable interrupt on the switch pin
EIMSK = EIMSK |(1 << INT0);
// Trigger interrupt on failing edge of the switch signal
EICRA = (1 << ISC01);
// Enable global interrupts
sei();
}
// Interrupt service routine for the switch
ISR(INT0_vect) {
// If the switch is pressed, toggle the LED state
if ((~PIND & (1 << SW_PIN)) && !ledOn) {
PORTB = PORTB | (1 << LED_PIN);
ledOn = true;
}
else{
PORTB = PORTB & ~(1 << LED_PIN);
ledOn = false;
}
}
int main(void) {
// Initialization
init();
// Loop forever
while (1) {
// NOP
}
return 0;
}```