Hi.
This is my code (example from Nick Gammon site) but it does't work in my Proteus simulation. What is wrong with it? I don't have my Arduino so I can't really test the code in a real Arduino. Can someone help?
/*
Example copied from Nick Gammon site
http://www.gammon.com.au/interrupts
Changes where made to original POST
*/
volatile byte IntCalled=0;
const byte LEDOnOff=A0;
unsigned long time=0;
ISR (PCINT0_vect)
{
if (bitRead(PORTD,2)) IntCalled=2;
if (bitRead(PORTD,3)) IntCalled=3;
if (bitRead(PORTD,4)) IntCalled=4;
if (bitRead(PORTD,5)) IntCalled=5;
if (bitRead(PORTD,6)) IntCalled=6;
if (bitRead(PORTD,7)) IntCalled=7;
}
ISR (PCINT2_vect)
{
if (bitRead(PORTB,0)) IntCalled=8;
if (bitRead(PORTB,1)) IntCalled=9;
if (bitRead(PORTB,2)) IntCalled=10;
if (bitRead(PORTB,3)) IntCalled=11;
if (bitRead(PORTB,4)) IntCalled=12;
if (bitRead(PORTB,5)) IntCalled=13;
}
void setup ()
{
pinMode (LEDOnOff, OUTPUT);
digitalWrite (LEDOnOff, LOW); // Led Blink Off
PCMSK2 |= bit (PCINT16); // Pin D0
PCMSK2 |= bit (PCINT17); // Pin D1
PCMSK2 |= bit (PCINT18); // Pin D2
PCMSK2 |= bit (PCINT19); // Pin D3
PCMSK2 |= bit (PCINT20); // Pin D4
PCMSK2 |= bit (PCINT21); // Pin D5
PCMSK2 |= bit (PCINT22); // Pin D6
PCMSK2 |= bit (PCINT23); // Pin D7
PCIFR |= bit (PCIF2); // clear any outstanding interrupts
PCICR |= bit (PCIE2); // enable pin change interrupts for D0 to D7
PCMSK0 |= bit (PCINT0); // Pin D8
PCMSK0 |= bit (PCINT1); // Pin D9
PCMSK0 |= bit (PCINT2); // Pin D10
PCMSK0 |= bit (PCINT3); // Pin D11
PCMSK0 |= bit (PCINT4); // Pin D12
PCMSK0 |= bit (PCINT5); // Pin D13
PCIFR |= bit (PCIF0); // clear any outstanding interrupts
PCICR |= bit (PCIE0); // enable pin change interrupts for D8 to D13
}
void loop ()
{
if (IntCalled!=0)
{
time=millis()+1000;
Serial.print("Interrupt called ");
Serial.println(IntCalled);
digitalWrite (LEDOnOff, HIGH);
}
if (time==millis()) digitalWrite(LEDOnOff, LOW);
}