#include<stdint.h>
#define PIND_BASE_ADDR 0x29
int last_button_state = 1;
int led_state = 0;
typedef struct
{
volatile uint8_t PIN;
volatile uint8_t DDR;
volatile uint8_t PORT;
}PORTD_Regs;
PORTD_Regs * pin_info = (PORTD_Regs *)PIND_BASE_ADDR;
void setup()
{
pin_info->DDR |= (1 << 5);
pin_info->DDR &= ~(1 << 6);
}
void loop()
{
int current_button_state = (pin_info->PIN & (1 << 6)) >> 6;
int led_state = (pin_info->PIN & (1 << 5)) >> 5;
if(current_button_state != last_button_state)
{
last_button_state = current_button_state;
if(current_button_state == 1)
{
if(led_state == 1)
{
pin_info->PORT &= ~(1<<5);
}
else
{
pin_info->PORT |= (1<<5);
}
}
}
}