![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
pic_micro
Joined: 07 Feb 2011 Posts: 26
|
ccp2 --> 1 btn to do 2 functions |
Posted: Thu Mar 24, 2011 10:56 am |
|
|
I want to use 1 button to do 2 functions at separate occassion.
button -->RC1 (ccp2) with ccp2 interrupt
counter = 0;
button press --> check counter=0, it is 1st pressed --> turn LED on PIN_B2, counter++
if button press --> check counter=1, it is 2nd pressed --> turn LED on PIN_B3, reset counter = 0;
see my code below
Code: |
#include <18F4620.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP,NOMCLR
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
unsigned char counter = 0;
long rise,fall,pulse_width;
#int_ccp1
void isr()
{
output_high(pin_b1);
clear_interrupt(INT_CCP1);
}
#int_ccp2
void iss2()
{
if(counter == 0)
{
output_high(pin_b2);
counter++;
}
if(counter == 1)
{
output_high(pin_b3);
counter = 0;
}
clear_interrupt(INT_CCP2);
}
void main()
{
printf("\n\rHigh time (sampled every second):\n\r");
setup_ccp1(CCP_CAPTURE_FE); // Configure CCP1 to capture rise
setup_ccp2(CCP_CAPTURE_FE); // Configure CCP2 to capture fall
setup_timer_1(T1_INTERNAL); // Start timer 1
enable_interrupts(INT_CCP1); // Setup interrupt on falling edge
enable_interrupts(INT_CCP2); // Setup interrupt on falling edge
enable_interrupts(GLOBAL);
while(TRUE) {
}
}
|
I couldn't get it to do 2 functions separately, it does both functions the same time.
What can I do to get it to work? is there any flag or else to do this?
Please help. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9173 Location: Greensville,Ontario
|
|
Posted: Thu Mar 24, 2011 11:28 am |
|
|
Among other things...
Buttons, switches, etc. are electrically noisey...
You MUST add a 'debounce' HW circuit or SW routine to get 'clean' transitions from your switch.
How you do it, is up to you as only you know the switch,it's characteristics,wiring, required speed, etc. |
|
![](templates/subSilver/images/spacer.gif) |
pic_micro
Joined: 07 Feb 2011 Posts: 26
|
|
Posted: Thu Mar 24, 2011 11:54 am |
|
|
Is there any instruction how to add the debounce to it? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 24, 2011 4:47 pm |
|
|
What is the purpose of your program ? Do you need the CCP ? |
|
![](templates/subSilver/images/spacer.gif) |
pic_micro
Joined: 07 Feb 2011 Posts: 26
|
|
Posted: Thu Mar 24, 2011 8:02 pm |
|
|
I am working on a project(custom camera) that interface to user by using 3 buttons. This is an existing custom board that all other I/O pins are being used.
btn1 ---connect to RB0 (INT0) //ONOFF switch
btn2 ---connect to RC2 (ccp1) //Video Zoom
btn3 ---connect to RC1 (ccp2) //Video Capture
all 3 buttons require interrupt because there are other tasks such as ADC,
RS232, SPI, etc running simultaneously.
btn1 control 2 functions (power on/off, 1st pressed = on, 2nd pressed = off)
btn2 will control zoom, this will only require to have outputs high at the same time for 500ms.
btn3 control 2 functions (start capture, stop capture , 2 different output)
The original design in mind was to use ccp1 and ccp2 to capture the external inputs how long the button pressed, but the timer1 and timer3 are already used for something else so I can not use it to measure a button press how long it being pressed, so I plan to use the interrupt but as soon as the ccp1 and ccp2 see the buttons pressed, jump to an interrupt routine, and determine btn3 --1st pressed is start capture, 2nd pressed is stop capture.
same for btn1
btn2 is to output 2 low output at same time for 500ms.
I guess you get the idea. This is just a test program to test the switch function.
I couldn't get btn1 and btn3 to do 2 functions each. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|