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

Interrupt - How to do it... Help.

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








Interrupt - How to do it... Help.
PostPosted: Tue May 20, 2008 1:11 am     Reply with quote

Hi
I am trying to do a simple interrupt (for a pic16f690) and its not working.
I have a blinking led and i want that if i get in portA0 = high - it stops blinking.

Can someone give me the code for interrupt? Including what i must write at the start of my code for that.
thnx
Guest








PostPosted: Tue May 20, 2008 3:57 am     Reply with quote

this is my code- but the leds doesnt stop blink when interrupt..why ???

Code:
#include <16F690.h>       
#fuses XT,NOWDT,NOPROTECT,put
#use delay(clock=4000000)

#int_ext
void button_isr() {
delay_ms (20);
if(input(PIN_A0)==1)
          output_low(PIN_C0);
          output_low(PIN_C1);
}

void main() {
enable_interrupts(global);
enable_interrupts(int_ext);
ext_int_edge( H_TO_L );

   while(1)
   {
         output_high(PIN_C2);
         delay_ms(100);
         output_low(PIN_C2);
         delay_ms(800);
         output_high(PIN_C0);
         output_high(PIN_C1);
      }
     
     
   }
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Tue May 20, 2008 5:20 am     Reply with quote

Anonymous wrote:
this is my code- but the leds doesnt stop blink when interrupt..why ???

I don't know why you would think that your interrupt code is supposed to stop the LED from blinking. If there is an interrupt, the interrupt code does stuff and then returns. What it returns to is just what was happening when the interrupt occurred. So your main code is still in its loop, blinking the LED. You never did tell us which pin the LED is connected to. So even if your interrupt code did work, it would not stop what the main program is doing.

But your interrupt will not happen because the EXT INT is hardwired to pin RA2, not RA0. Connect your pushbutton to RA2. Then, if you really do want to stop the LED from blinking, then don't do it in your interrupt code. Make the interrupt code just set a flag in a RAM variable. Make the main program check that same flag and stop blinking the LED when it sees the flag is set.

Robert Scott
Real-Time Specialties
Guest








PostPosted: Tue May 20, 2008 11:53 am     Reply with quote

My goal was not to stop the blink- but to set low pin c0 and c1 , and the
button is part of a pickit 2 board that cant be removed, and as i
understood its should work on that pin.

Does some one has a specific answer-that indicate my problem on code?

Or- the right code for doing that ?
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Tue May 20, 2008 12:12 pm     Reply with quote

Anonymous wrote:
..the
button is part of a pickit 2 board that cant be removed, and as i
understood its should work on that pin...

Well, your understanding is incorrect. The external interrupt only works on RA2. However there is another kind of interrupt that will work on RA0. It is called "interrupt on change". Look up #INT_RA instead of #INT_EXT. Also read the datasheet for the PIC16F690 to see how interrupt-on-change works.

Robert Scott
Real-Time Specialties
Guest








PostPosted: Wed May 21, 2008 2:01 am     Reply with quote

I SAW THE DATASHEETS AND RA0 IS IOC ..

SO I CANT UNDERSTAND IF YOUR GOAL IS TO PROVE ME THAT I AM WRONG , OR TO HELP ME MORE SPESIFICLY.

IF THERE IS IOC ON RA0 -YOU COULD WRITE THE CODE FOR THAT BECAUSE THAT WAS MY ONLY REQUEST-2 LINES OF CODE.

THANX A LOT ANYWAY.
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Wed May 21, 2008 3:55 am     Reply with quote

The guest here believes that he/she has a right to a solution to the guest's problem on the guest's terms. Asking for help does not grant someone the right to define help. The issue the guest has has been resolved easily by most beginners. This board is like a museum. The visitors wish to see interesting issues. They are less interested in everyday beginners issues. Coders should search the forum first for an answer. New coders should use unmodified examples from CCS first and not expect that enthusiasm in their own coding modifications will guarantee success. After the CCS example is working then make small modifications and test . A coder with the humility to accept that almost all errors will be of the coders own making has the advantage of discovering errors on their own. If you are drowning in the sea you shouldn't dictate that you are only to be saved by helicopter.
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Wed May 21, 2008 5:35 am     Reply with quote

Anonymous wrote:
...IF THERE IS IOC ON RA0 -YOU COULD WRITE THE CODE FOR THAT BECAUSE THAT WAS MY ONLY REQUEST-2 LINES OF CODE.....

No, it is more complicated than that. You need to understand how IOC is different from the external interrupt. For one thing, IOC can only be cleared by first reading the port. Then the IOC interrupt flag needs to be cleared. Then the port needs to be read again in case it changed just as you were clearing the IOC interrupt flag. And that little tidbit is not in the datasheet.

Robert Scott
Real-Time Specialties
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed May 21, 2008 10:21 am     Reply with quote

I choose to ignore a thread from a shouting anonymous guest user.
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