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 support@ccsinfo.com

interrupt help- pin B0

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



Joined: 14 Jun 2005
Posts: 64

View user's profile Send private message

interrupt help- pin B0
PostPosted: Fri Jun 17, 2005 1:58 pm     Reply with quote

Hi-
I'm trying to use Pin B0 on a PIC16C74A for a pushbutton switch.
Code is as follows:
/* Interrupt Routine- come here when push button switch */
#INT_EXT // interrupt on push button
rb_isr() { // set up int service routine
output_low (PIN_C5); // go high on pin C5 for testing

while(!input(PIN_B0)) // see if push button is pressed (grounded)
{
delay_ms (1); // delay for debounce
}
output_high (PIN_C5); // go low on pin C5 for testing
} //end isr_rb

And further down:
enable_interrupts(GLOBAL);
enable_interrupts(INT_EXT);
My code doesn't work- it gets stuck at enable_interrupts(GLOBAL). Any suggestions or advice?
Thanks-
Sophi
valemike
Guest







PostPosted: Fri Jun 17, 2005 2:07 pm     Reply with quote

I notice you didn't put the following instruction in the beginning of your main() when you set up your ports:

Code:

ext_int_edge(H_TO_L);
Sophi



Joined: 14 Jun 2005
Posts: 64

View user's profile Send private message

PostPosted: Fri Jun 17, 2005 2:39 pm     Reply with quote

Thanks Valemike!
I did have that line but then commented it out, uncommented, my code still gets stuck-
Sophi
valemike
Guest







PostPosted: Fri Jun 17, 2005 3:26 pm     Reply with quote

your program seems small enough. Can you post the program?

One thing i noticed is that you have the following loop in your ISR:

Code:
while(!input(PIN_B0)) // see if push button is pressed (grounded)
{
delay_ms (1); // delay for debounce
}


If i read it right, you want the loop to continue running until you release the pushbutton, right?

This is awkward to do in an interrupt service routine. You are starving the rest of the program from running.
Humberto



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

View user's profile Send private message

PostPosted: Fri Jun 17, 2005 4:03 pm     Reply with quote

Code:

#INT_EXT        // interrupt on push button
rb_isr()
{               // set up int service routine
   output_low (PIN_C5);    //  pin C5 Low for testing
}              //end isr_rb


main()
{
  ext_int_edge(H_TO_L);
  enable_interrupts(INT_EXT);
  enable_interrupts(GLOBAL);

  while(1)
     {
      do
        {
         delay_ms(1);
        }while( !input(PIN_B0) ); // see if push button is pressed (grounded)
     
      output_high(PIN_C5);     //    pin C5 High for testing
     } 
}

bfemmel



Joined: 18 Jul 2004
Posts: 40
Location: San Carlos, CA.

View user's profile Send private message Visit poster's website

PostPosted: Fri Jun 17, 2005 4:18 pm     Reply with quote

Sophi,

Since it is happening when you enable interrupts I can think of a few things. First, do you have another interrupt that the program is getting stuck in? Is there a interrupt enabled for which there is no ISR defined. Could it be that the line you are looking at in the ISR, (PIN_B0) is already low and the ISR never leaves because the while loop test is never false?

Just thoughts, good luck.
Wink
Bruce
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Jun 17, 2005 9:55 pm     Reply with quote

A 1ms debouce period is way too small for debouncing a mechanical switch. If you have an oscilloscope you may want to have a look at what is happening. 20ms is a lot more realistic value.

Rgds, Andrew
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Sophi



Joined: 14 Jun 2005
Posts: 64

View user's profile Send private message

interrupt fixed
PostPosted: Sun Jun 19, 2005 6:49 am     Reply with quote

Thanks to all who responded- and with helpful info for me!
Valemike- the line
ext_int_edge(H_TO_L); stayed

Andrew- good thought, I didn't check that yet but will

Bruce- Smile
What actually fixed this code was
1) starting over on a new file (copying all the code over except the interrupt section)
2) changing the order of the functions and the interrupt. Previously I had the code ordered Functions, Interrpts, then main. Now it is interrupt, then functions...

Sophi
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