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

Tactile Button PIC18F46K22

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



Joined: 13 Sep 2011
Posts: 13

View user's profile Send private message

Tactile Button PIC18F46K22
PostPosted: Mon Oct 10, 2011 4:18 pm     Reply with quote

Hi there,
I have a PIC18F46K22 and i want to activate the interrupts by pressing a tactile button. The problem that is the interrupt doesn't work and i don't know how to solve it.
Code:

#FUSES NOPLLEN,NOWDT, NOLVP, HS
int current=0;
#INT_RB
void rb_isr() {
   
   //current=input_b();

   current=input(PIN_B4);
   fputs("Bottom", hostPC);
   
   if(!current){
      output_high(PIN_A0);
      fputs("Button", hostPC);
      output_high(PIN_A1);
   }
   delay_ms(1000);
}

void main(){
 
   enable_interrupts(INT_RB);
   enable_interrupts(GLOBAL);
}


Thank you!
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Oct 10, 2011 4:28 pm     Reply with quote

Just for starters
DO NOT DO any serial transmission within the int handler.

Set a variable or use the state of the pin YOU changed
to signal the MAIN() as to what you want to send to the host.

If your pic interrupts on both state changes hi/lo -- lo/hi.

THEN TEST which STATE YOU ARE IN AND SAY ONLY FLAG
the release and act accordingly.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 10, 2011 4:36 pm     Reply with quote

Read this thread. It's possible that your compiler version has bugs with
the 18F46K22. This thread has code to make #int_rb work with that PIC:
http://www.ccsinfo.com/forum/viewtopic.php?t=45032
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Oct 10, 2011 5:16 pm     Reply with quote

ALSO

that 1 second delay in the ISR is the KISS of DEATH
to anything else you might put in MAIN()

the rule of ALL good INT handlers is:

GET in and out FAST
no delays

no serial comm
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Tue Oct 11, 2011 1:51 am     Reply with quote

Also, the other glaring thing, is that the chip will have gone to sleep. Potentially should wake up, but no guarantees.
You need to have something at the end of main, to stop the code dropping off the end.

Best Wishes
scuba



Joined: 13 Sep 2011
Posts: 13

View user's profile Send private message

PostPosted: Tue Oct 11, 2011 7:46 pm     Reply with quote

following your suggestions i programmed this code but the button doesn't work too. Is that the problem may be hardware or still bug?
Thank you all.
Code:
#FUSES NOPLLEN,NOWDT, NOLVP, HS

#INT_RB

void rb_isr() {
   
   
   fputs("Hi", hostPC);
   
      output_high(PIN_A0);
      output_high(PIN_A1);
   }

void main(){
 
   enable_interrupts(INT_RB);
   enable_interrupts(GLOBAL);

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 11, 2011 9:00 pm     Reply with quote

Why not try the code in the link that I gave you ?

The program is at the end of this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=45032
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Oct 11, 2011 9:04 pm     Reply with quote

Hi,

Actually, you haven't implemented a single suggestion from the respondents to your query!

As asmboy said, no serial ops inside the ISR. This means get rid of the puts statement.

As pcm programmer said, your version of the compiler might have a bug, and you might need to manually configure the chip. Where is that code?

As Ttelmah said, you need to insert some code at the bottom of main to keep the code from reaching the default 'sleep' instruction put in by the compiler. A 'while(1){}' works nicely!

Other than that, you got everything ;-)!

I'd take a step back a bit and try a much simpler task like blinking an LED. Can you do that? Once that is done, you can use the LED for diagnostics in place of the serial ops in your ISR.

John
scuba



Joined: 13 Sep 2011
Posts: 13

View user's profile Send private message

PostPosted: Wed Oct 12, 2011 1:01 pm     Reply with quote

Problem Solved!
Thank you PCM Programmer, you're right.
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