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

Push Button Help

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



Joined: 15 May 2012
Posts: 1

View user's profile Send private message

Push Button Help
PostPosted: Tue May 15, 2012 5:32 am     Reply with quote

Hi everyone,
I'm newby in uC and need some help.
I use pic16f877a to generate PWM and I have written the code to generate it with 50 kHz freq. and 50% duty, but now I want to use two push buttons conneted to RE0 and RE1 pins to change the duty cycle, one for up and the other for down the duty. how to configure the ports and what code lines should I add to achieve this task ?

Thanks
Mike Walne



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

View user's profile Send private message

PostPosted: Tue May 15, 2012 7:29 am     Reply with quote

You will need something similar to keypad reading.

CCS provides a sample.

Look up button debounce on the forum.

You will also need to deal with over-flow and under-flow.

Do you want auto-repeat?

This is not a write it for you forum.

Cut some code yourself. When (if) you get stuck ask for help and guidance.

Mike
hoangkhuong



Joined: 16 Mar 2012
Posts: 31

View user's profile Send private message

PostPosted: Tue May 15, 2012 8:13 am     Reply with quote

As far as I know, you can do that by configuring pin E0 and E1 as input pin. Then use function like input(PIN_E0) to check whether it is pushed or not.
Mike Walne



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

View user's profile Send private message

PostPosted: Tue May 15, 2012 11:37 am     Reply with quote

I'm assuming that you know how to connect the ports to switches.

When you close a switch, yes indeed input(pin_x) returns the port state. Don't forget to set port as digital.

You will also have to deal with switch bounce and how quickly you want the duty rate to increase / decrease.

CCS provides loads of sample code. Have a play with some, get to know the ropes.

Mike
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 15, 2012 12:18 pm     Reply with quote

Here's an example of servo motor control with push-buttons that might
help you with the basic structure of the program and with the push-button
code:
http://www.ccsinfo.com/forum/viewtopic.php?t=47510
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