int main(void)
{
unsigned char *portD;
portD = (unsigned char *) 0x2B;
// Enable the pull-up resistor on PD2 using the Port D
// Data Register (PORTD)
*portD |= 0x04;
// Configure external interrupt 0 to generate an interrupt request on any
// logical change using External Interrupt Control Register A (EICRA)
unsigned char *AT328_EICRA;
AT328_EICRA = (unsigned char *) 0x69;
*AT328_EICRA |= 0x01;
*AT328_EICRA &= ~(0x02);
// Enable external interrupt 0 using the External Interrupt Mask Register (EIMSK)
unsigned char *AT328_EIMSK;
AT328_EIMSK = (unsigned char *) 0x3D;
*AT328_EIMSK |= 0x01;
// Configure PC0-5 as an output using the Port C Data Direction Register (DDRC)
unsigned char *portDDRC;
portDDRC = (unsigned char *) 0x27;
*portDDRC |= 0x08;
// Enable interrupts
unsigned char *ptrSREG;
portDDRC = (unsigned char *) 0x5F;
*portDDRC |= 0x80;
// Loop forever
while (1)
{
// Nothing to do here. All work is done in the ISR
}
}
ISR(INT0_vect)
{
unsigned char *portPinD;
portPinD = (unsigned char *) 0x29;
unsigned char *portC;
portC = (unsigned char *) 0x28;
// Read PD2 using the Port D Pin Input Register (PIND)
if (*portPinD & 0x04)
{
// PD2 is high, so button is released
// Set PC0 low using the Port C Data Register (PORTC)
*portC &= ~0x08;
}
else
{
// PD2 is low, so button is pressed
*portC |= 0x08;
}
}