View previous topic :: View next topic |
Author |
Message |
elmurry
Joined: 15 May 2012 Posts: 1
|
Push Button Help |
Posted: Tue May 15, 2012 5:32 am |
|
|
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
|
|
Posted: Tue May 15, 2012 7:29 am |
|
|
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
|
|
Posted: Tue May 15, 2012 8:13 am |
|
|
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
|
|
Posted: Tue May 15, 2012 11:37 am |
|
|
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
|
|
|
|