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

Interrupts

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



Joined: 28 Jun 2012
Posts: 1

View user's profile Send private message

Interrupts
PostPosted: Thu Jun 28, 2012 6:58 am     Reply with quote

I want to increment a counter, when an external push button connected to my pic ic 16f877a is pressed. I am quite new to interrupts and have no idea on how they work. Can you give me a very basic coding with line by line explanation of how this is done.
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jun 28, 2012 1:40 pm     Reply with quote

There are several example programs that CCS kindly supplies in the examples folder.Some of those do use interrupts and have the information you need to complete your project.
I'm quite busy at my other job, organic farming, and cannot afford to spend the time to cut the code you want, unless you can wait for 3 weeks.You'ld also have to supply the crystal you're using as well as which pin the interrrupt will occour on.PB7...4 or PB0 would be the obvious choices.
Now if you want to come here and tear apart a 60 year old tractor and fix it, I'll cut the code while you fix my problem .
Seems fair to me.
hth jay
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Thu Jun 28, 2012 2:02 pm     Reply with quote

Nice one Jay.

No, seriously he's right, this a help forum, NOT a do it for you.

Show us that you have tried and we will gladly assist.

It's useful for you to read the CCS forum guide.

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19505

View user's profile Send private message

PostPosted: Thu Jun 28, 2012 2:32 pm     Reply with quote

Also, there may be severe "doubt's" about whether an interrupt on the button is the right solution. Buttons tend to _bounce_. When pushed, you can often get several connection pulses one after the other. Using an interrupt, you will count every one. Hence better in general, for something as slow as a button, to use a 'tick' timer, and verify that once the button is made, it is still made a few uSec latter, and only then 'accept' it. There is keyboard code, in the code library, which demonstrates 'debouncing'.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 28, 2012 2:45 pm     Reply with quote

Here is an older demo program for External Interrupts and it does have
an explanation of each line of code. It's at the end of the thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=17301

This post gives an outline description of how to increment a variable
when a button is pushed, without actually giving the main code to do it:
http://www.ccsinfo.com/forum/viewtopic.php?t=44229&start=1
This code doesn't use interrupts.
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