CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC18F47K42 IOC on port A

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Momboz



Joined: 03 Jun 2009
Posts: 29

View user's profile Send private message

PIC18F47K42 IOC on port A
PostPosted: Sat Oct 02, 2021 1:15 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Oct 02, 2021 10:33 pm     Reply with quote

See this sample code by Ttelmah for IOC interrupts on the K42 series PICs.
http://www.ccsinfo.com/forum/viewtopic.php?t=59364&start=22
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sun Oct 03, 2021 2:21 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Oct 03, 2021 7:58 am     Reply with quote

PCM programmer wrote:
See this sample code by Ttelmah for IOC interrupts on the K42 series PICs.
http://www.ccsinfo.com/forum/viewtopic.php?t=59364&start=22


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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group