change_notification_interrupts
Here is a sample sketch that sets up change notification on some of the pins. This sketch should run in any version of MPIDE that lists the Quick240 in the boards menu.
Note: We are working on a library that does not need the user to see direct register writes.
- Quick240 ChangeNoticeExample.pde
//DO NOT use digital read on pins that are in port b volatile unsigned char holdint = 0; void setup() { Serial.begin(115200); pinMode(57, INPUT); //Kard 1 IO 0 CN 5 pinMode(56, INPUT); //Kard 1 IO 1 CN 4 pinMode(54, INPUT); //Kard 1 IO 3 CN 2 pinMode(55, INPUT); //Kard 0 IO 3 CN 3 //need direct register addressing CN pins not set up in MPIDE yet unsigned int value; AD1PCFGSET = 0x0000803c; //turn analog 2-5,15 off AD1CON2CLR = 0x0000d000; //turn off external voltage compare pins? CNCON = 0x00008000; //turn "interrupt on change" on CNEN = 0x0000003c; //enable cn2-5 CNPUE= 0x00000000; //weak pull up off value = PORTB; //Read the Port IPC6SET = 0x001b0000; //set priority to 6 sub 4 IFS1CLR = 0x0001; //clear the interupt flag bit IEC1SET= 0x0001; // Enable Change Notice interrupts } void loop() { if(holdint & 0x01) { holdint &= ~0x01; Serial.println("CN2 Interrupt"); } if(holdint & 0x02) { holdint &= ~0x02; Serial.println("CN3 Interrupt"); } if(holdint & 0x04) { holdint &= ~0x04; Serial.println("CN4 Interrupt"); } if(holdint & 0x08) { holdint &= ~0x08; Serial.println("CN5 Interrupt"); } } extern "C" { void __ISR(_CHANGE_NOTICE_VECTOR, ipl6) CN_Interrupt_ISR(void) { unsigned int thisb = PORTB; // Read PORTB to clear mismatch condition unsigned int static lastb; if ((thisb & 0x01) != (lastb & 0x01) && (thisb & 0x01)) //cn2 fire going high { holdint |= 0x01; } if ((thisb & 0x02) != (lastb & 0x02) && !(thisb & 0x02)) //cn3 fire going low { holdint |= 0x02; } if ((thisb & 0x04) != (lastb & 0x04)) //cn4 fire on every change { holdint |= 0x04; } if ((thisb & 0x08) != (lastb & 0x08) && (thisb & 0x08)) //cn5 fire going high { holdint |= 0x08; } lastb = thisb; IFS1CLR = 0x0001; // Be sure to clear the CN interrupt status // flag before exiting the service routine. } } // end extern "C"
change_notification_interrupts.txt · Last modified: 2019/08/17 15:04 by 127.0.0.1