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

need help on external interrupt for PIC16C63A

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



Joined: 03 May 2004
Posts: 48
Location: Sg

View user's profile Send private message

need help on external interrupt for PIC16C63A
PostPosted: Fri Sep 22, 2006 11:19 pm     Reply with quote

Hi, all,
I could not have external interrupt triggered on my ICE2000 emulating 16C63A. I have a 10K resistor pull high on RB0. And a on/off switch to ground.

Code:

#include    <16C63A.h>
#fuses       HS,NOWDT,NOPROTECT,PUT,NOBROWNOUT

#use delay(clock=8000000)

#INT_EXT
void ext_ISR()
{
   output_low(PIN_A1);      //Breakpoint set here, but not triggered when switch is tied to ground
}


void main()
{

   port_b_pullups(TRUE);                     //Port B weak pullup


   ext_int_edge(H_to_L);                     //External interrupt edge from high to low
   enable_interrupts(INT_EXT);   
   clear_interrupt(INT_EXT);               
   enable_interrupts(GLOBAL);                  


   while(1)
   {

      if(input(PIN_B0)==0)
      {
         output_high(PIN_A1);         
      }

   }

}


I am using PCM 4.010

thanks.

Sigma
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sat Sep 23, 2006 3:27 pm     Reply with quote

After RESET - by default - ALL pins that share an Analog function are configured as Analog INPUTS.

During the initialisation part of your code, disable the Analog function:

Code:

   port_b_pullups(TRUE);    //Port B weak pullup
   ext_int_edge(H_to_L);    //External interrupt edge from high to low
   enable_interrupts(INT_EXT);   
   clear_interrupt(INT_EXT);               
   enable_interrupts(GLOBAL);
   SETUP_ADC_PORTS(NO_ANALOG);  // ********Add this ********



Humberto
hate



Joined: 29 Apr 2006
Posts: 6

View user's profile Send private message

PostPosted: Sat Sep 23, 2006 4:41 pm     Reply with quote

How did you get the idea that the interrupt isn't triggered? By checking the Pin A1? In the ext_ISR you make the A1 pin go low but in the main function you make it high when the B0 pin goes low. Your code triggers the interrupt when the B0 pin goes low so both the interrupt and the if() code gets active by the same event. And they both act on the pin B0 going low. So the ISR makes the pin A1 go low then immediately after exiting the interrupt the if statement makes the A1 pin go high. If you don't have a very slow clock speed it is not much possible to see the change. And my guess is that you get the idea that the intterupt isn't triggered.

Regards...
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Sep 24, 2006 8:31 am     Reply with quote

Quote:

How did you get the idea that the interrupt isn't triggered? By checking the Pin A1?

I�m agree with you that this may be not the best example to see the INT_EXT
action
but it should work anyway.
The signal received by PIN_B0 causes a temporary halt in the execution of the main
program (wich is to keep the PIN_A1 HIGH while PIN_B0 is HIGH) so the task is
re-directed to the interrupt handler that will keep PIN_A1 LOW as long as PIN_B0
is LOW. When the interrupt had been serviced, the program return to main in
the last instruction + 1 to follow it�s main task, that is to keep PIN_A1 HIGH ONLY
while PIN_B0 is HIGH, but as PIN_B0 is still LOW, the interrupt is triggered again and
by no way the PIN_A1 will go HIGH while PIN_B0 stay LOW.

Quote:

Your code triggers the interrupt when the B0 pin goes low so both the interrupt and the if() code gets active by the same event.

The posted code do not do that. The if() condition does nothing when PIN_B0 is LOW.


Humberto
hate



Joined: 29 Apr 2006
Posts: 6

View user's profile Send private message

PostPosted: Mon Sep 25, 2006 2:59 pm     Reply with quote

Hi Humberto;

I think you have to check the code again to see the if() statement in the main loop will repeatedly check for "B0 pin" to get low(0) and then make the "A1 pin" high(1) when "B0 pin" gets low(0). So that's the same event that triggers the interrupt. Are we clear on that? The interrupt will get triggered only ONCE when the B0 pin gets LOW(0) as it isn't LEVEL triggered like the Externel Interrupts of 8051 structure. And it WON'T get triggered again if the "B0 pin" is low and until it goes high(1) and low(0) again as it is EDGE triggered. When after the ISR finishes its work the program will continue executing the while loop in the main function and the if() statement. He said he uses a switch on the "B0 pin" so the pin will probably be at logic low(0) state which is TRUE for the if() statement and the "A1 pin" will go high(1) immediately after existing the ISR. Correct me if I'm wrong. Best wishes.

Regards...
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon Sep 25, 2006 4:09 pm     Reply with quote

My mistake, I never use such notation:
Code:

   if(input(PIN_B0)==0)
    {
    }


Instead I use
Code:
   
  if(!input(PIN_B0))
    {
    }

so I assume he was testing for HIGH.

Sorry Embarassed

Humberto
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