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

12f683 interrupts

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



Joined: 16 Oct 2006
Posts: 7

View user's profile Send private message

12f683 interrupts
PostPosted: Mon Oct 16, 2006 3:52 pm     Reply with quote

I've got a couple interrupts up and (mostly) working but right now they both go to the same ISR. Is there anything built in to check which pin generated the interupt, like a flag set in a register, or am I on my own for that. One int is a pushbutton, so I can just debounce it and check the state of the pin, but the other is rs232 data coming in, so there is no telling what state it might be in. If I miss the debounce, I'll handle the int wrong.

Thanks

edit: compiler version 3.249
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 16, 2006 6:14 pm     Reply with quote

You could use the INT_EXT interrupt (pin GP2) as the Rx pin for the
software UART. Then another GPIO pin with the Interrupt-on-Change
interrupt, to handle the push-button.

Here is a rough outline of how to do it. I haven't tested this code in
hardware. I just compiled it, and it compiles OK. I don't guarantee
that this works. I don't have time to test it in hardware, right at the
moment. But it should give you a start. I compiled it with vs. 3.249.
Code:

#include <12F683.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, PUT, BROWNOUT
#use delay(clock = 4000000)
#use rs232(baud=1200, xmit=PIN_A4, rcv=PIN_A5)

#int_ra
void ioc_isr(void)
{
int8 c;

// Put code in here to handle the interrupt


// Read Port A to clear 'change' condition
// before exiting from the isr.
c = input_a(); 
}


#int_ext
void int_ext_isr(void)
{
char c;

c = getc();

}

//============================
void main()
{
int c;

// Clear any pre-existing 'change' condition on
// Port A, and clear the interrupt flags before
// enabling interrupts.
c = input_a(); 
clear_interrupt(INT_RA);
clear_interrupt(INT_EXT);

// Then enable the interrupts.
enable_interrupts(INT_RA0);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);

while(1);
}



Note:
There is a bug with the enable_interrupts() function with this PIC with
compiler vs. 3.249. It may also be in vs. 4.xxx -- I haven't checked.
See this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=26559
It could be fixed by writing your own enable_interrupts() function
or by writing directly to the PIC registers in main().
jweller



Joined: 16 Oct 2006
Posts: 7

View user's profile Send private message

PostPosted: Tue Oct 17, 2006 9:02 am     Reply with quote

My understanding of INT_EXT is that it triggers on any change to input pins. I made a few quick and dirty changes to my code and it does appear to be triggering INT_EXT on both the push button and the rs232 input. It seems as if I have the same problem in a different location. Is there a way to tie INT_EXT to a single pin? If not, I think I am going to try and use kbhit().
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 17, 2006 11:34 am     Reply with quote

Quote:
My understsanding of INT_EXT is that it triggers on any change to input pins

EXT_INT only works on the GP2 pin.

From the 12F683 data sheet:
Quote:

12.4.1 GP2/INT INTERRUPT
External interrupt on GP2/INT pin is edge-triggered;
either rising if the INTEDG bit (OPTION<6>) is set, or
falling if the INTEDG bit is clear. When a valid edge
appears on the GP2/INT pin, the INTF bit
(INTCON<1>) is set.


You are thinking of INT_RA and INT_RAx, as shown in my post above.
Quote:

12.4.3 GPIO INTERRUPT
An input change on GPIO change sets the GPIF
(INTCON<0>) bit. The interrupt can be enabled/
disabled by setting/clearing the GPIE (INTCON<3>)
bit. Plus, individual pins can be configured through the
IOC register
.
jweller



Joined: 16 Oct 2006
Posts: 7

View user's profile Send private message

PostPosted: Tue Oct 17, 2006 1:11 pm     Reply with quote

Thanks, I missed that in the datasheet. Problem solved.
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