View previous topic :: View next topic |
Author |
Message |
glavic
Joined: 13 Jul 2005 Posts: 7
|
Scanning many keys with one input |
Posted: Tue Aug 02, 2005 1:20 pm |
|
|
Hi,
i am new to the CCS and i am interested in how to make "trick" with CCS showed on the picture > http://www.shrani.si/pics/tip58433.jpg |
|
|
MikeValencia
Joined: 04 Aug 2004 Posts: 238 Location: Chicago
|
|
Posted: Tue Aug 02, 2005 3:47 pm |
|
|
1. Configure GP2 to output a low voltage to
discharge capacitor through I/O resistor.
2. Configure GP2 as one comparator input and
CVREF as the other.
3. Use a timer to measure when the comparator
trips. If the time measured is greater than the
maximum allowed time, then repeat; otherwise
determine which button is pressed.
When a key is pressed, the voltage divider network
changes the RC ramp rate.
That's pretty much how to do it. Perhaps you should post your code so that someone may know where the problem is. |
|
|
glavic
Joined: 13 Jul 2005 Posts: 7
|
|
Posted: Tue Aug 02, 2005 4:33 pm |
|
|
Like i said, i am new to the CCS.
1. Configure GP2 to output a low voltage to
discharge capacitor through I/O resistor.
output_low(PIN_A2);
2. Configure GP2 as one comparator input and
CVREF as the other.
In datasheet of 12F675 on chapter 6.2. Comparator Configuration i can find where i can set GP2 as comparator input + i want to use GP0 and GP1 for other purposes.
3. Use a timer to measure when the comparator
trips. If the time measured is greater than the
maximum allowed time, then repeat; otherwise
determine which button is pressed.
Never used timer in CCS yet. |
|
|
sseidman
Joined: 14 Mar 2005 Posts: 159
|
|
Posted: Wed Aug 03, 2005 11:05 am |
|
|
Frankly, you have some reading to do. I'd recommend trying one of the 30 or so books on programming PIC processors. Pic Micro MCU C by Gardner is a pretty good intro to CCS C, and an OK intro the the PIC in general.
There are also probably 30 good internet sites on basic PIC programming. Search for "PIC Tutorial" and see what happens.
Scott |
|
|
glavic
Joined: 13 Jul 2005 Posts: 7
|
|
Posted: Thu Aug 04, 2005 11:25 am |
|
|
I found another way, without the use of timer.
http://www.shrani.si/pics/tipke60169.gif
Code: | #include <12F675.h>
#device ADC=8
#fuses NOWDT, PUT, NOPROTECT, NOCPD, NOMCLR, XT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_A0, rcv=PIN_A1) // for testing
main ()
{
int value=0;
set_tris_a(0b00000100);
setup_adc( ADC_CLOCK_INTERNAL );
setup_comparator( NC_NC );
setup_adc_ports( sAN2 );
set_adc_channel(2);
while(1)
{
value = read_adc();
delay_ms(1);
if (value > 0)
{
printf("A/D value = %U\n\r", value); // print the ADC result value
delay_ms(500);
}
}
}
|
|
|
|
|