View previous topic :: View next topic |
Author |
Message |
Momboz
Joined: 03 Jun 2009 Posts: 29
|
PIC18F47K42 IOC on port A |
Posted: Sat Oct 02, 2021 1:15 pm |
|
|
Hi
I am trying to get IOC on port A working and I couldn't find out how to do.
Code: | //Interrupt routine
#INT_IOC
void IOC_isr(void) { output_toggle(PIN_B0); }
//main
void main() {
enable_interrupts(INT_IOC | H_TO_L);
enable_interrupts(GLOBAL);
while(TRUE) {}
}
|
and this should toggle PIN_B0 each time I press a port A pin. Port A pins are pulled up and pressing will put those to ground.
Many thanks in advance |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19730
|
|
Posted: Sun Oct 03, 2021 2:21 am |
|
|
Also as both a general, and 'specific' comment to what is being done,
#defines must _only_ be used for the commands for which they are
listed.
So the define 'H_TO_L', says
"// Constants used in EXT_INT_EDGE() are:".
This define cannot be used in the ENABLE/DISABLE interrupts command.
If you look for the defines for these commands, you see:
Code: |
#define INT_IOC_A0_L2H 0x10010080
#define INT_IOC_A0_H2L 0x20010080
|
and similar ones for all the other pins. So to enable for all the pins
on Port A, you would OR together all the pin enables you want.
INT_IOC_A0_H2L| INT_IOC_A1 | INT_IOC_A2 | INT_IOC_A3|
INT_IOC_A4| INT_IOC_A5| INT_IOC_A6 |
INT_IOC_A7
There are separate bit enables for each pin. All pins though share the
direction control bit, so this only has to be enabled on one pin. |
|
 |
Momboz
Joined: 03 Jun 2009 Posts: 29
|
|
Posted: Sun Oct 03, 2021 7:58 am |
|
|
I had a look to the given example and I find it's easier to do it another way and at microcontroller level.
Code: | #byte IOCAF=getenv("SFR:IOCAF")
#byte IOCAP=getenv("SFR:IOCAP")
#byte IOCAN=getenv("SFR:IOCAN")
#byte PIE0=getenv("SFR:PIE0")
void main() {
IOCAF = 0; // Clear any pending interrupt flag
IOCAP = IOCAP | 0x00; // do not react to positive edge
IOCAN = IOCAN | 0xFF; // React to negative edge
PIE0 = PIE0 | 0b10000000; // Activate PIE interrupts
enable_interrupts(GLOBAL);
while(1) {} |
Many thanks. |
|
 |
|