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

count using interrupt routine

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



Joined: 16 Mar 2005
Posts: 13

View user's profile Send private message

count using interrupt routine
PostPosted: Sat Mar 19, 2005 2:48 am     Reply with quote

Hi all

I have a simple but very important problem in my project. I need to count the push button number in external1(B1) interrupt routine in 18f452 I think i am doing something wrong but i couldn't find where i am wrong.
Any help would be appreciatted

Code:
#int_EXT1  NOCLEAR
void EXT1_isr()
{
  x=x+1;diable_interrupts(INT_EXT1);       
  pc=x;
  enable_interrupts(INT_EXT1);
  output_high(PIN_B5);
}
[/quote]
Andreas



Joined: 25 Oct 2004
Posts: 136

View user's profile Send private message

PostPosted: Sat Mar 19, 2005 2:56 am     Reply with quote

Hi,

If this is a code snippnet form your original programm than You have a spelling misstake = diable instead of disable.

May this causes Your problem as the int will never be disabled so if you have bouncing on the switch the int will come very often

best regards

Andreas
ariza



Joined: 16 Mar 2005
Posts: 13

View user's profile Send private message

PostPosted: Sat Mar 19, 2005 3:10 am     Reply with quote

Embarassed
Hi,

Sorry a small mistake, the true code is here. When i test this code it only counts one time and i obserce 00000001 in PORTC
[code]#int_EXT1 NOCLEAR
EXT1_isr()
{
x=x+1;disable_interrupts(INT_EXT1);
pc=x;
enable_interrupts(INT_EXT1);output_high(PIN_B5);
}
Ttelmah
Guest







PostPosted: Sat Mar 19, 2005 3:25 am     Reply with quote

Don't disable the interrupt inside the interrupt handler. This is unnecessary. On the PIC, when an interrupt is executing, the global interrupt enable is disabled, and only re-enabled, when the routine exits. However this would not cause any problem, just waste time.
Remember also, that a switch making, may well trigger five or six counts, if the contact is not clean.
The big problem in what you post, is that you are specifying 'NOCLEAR', which tells the compiler not to clear the interrupt, and you are not then clearing it yourself. Enabling, and disabling the interrupt, _do not_ clear the interrupt flag.
So, this should work:
Code:

#int_EXT1
void EXT1_isr()
{
  x=x+1;
  pc=x;
  output_high(PIN_B5);
}


Best Wishes
ariza



Joined: 16 Mar 2005
Posts: 13

View user's profile Send private message

PostPosted: Sat Mar 19, 2005 4:29 am     Reply with quote

Thanks your help but i still could't solve my problem. When i did what Ttelmah recommended , after 5 seconds later from first push ,it accepts the new push and increase the value of x. : confused:
[/code]
Humberto



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

View user's profile Send private message

PostPosted: Sat Mar 19, 2005 8:05 am     Reply with quote

Quote:

Sorry a small mistake, the true code is here. When i test this code it only counts one time and i obserce 00000001 in PORTC



The PIC18F452 has the EXT interupts pins in RB0 RB1 and RB2 only.
I guess you are using PORTC...

Best wishes,

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