Input for timer0 for the 16F877A

Thread Starter

kandasamy

Joined Aug 22, 2009
2
Hello all,

New to this forum and to pic programming.
I am working on a circuit using the 16F877A using the ccs-C compiler.
In this circuit I am required to send an input the timer0 of the PIC (by adjusting a variable resistor connected to 5V & Gnd) via pin #6 (RA4/T0CKI/C1OUT). The issue is that I do not know what function to use to read the input and act accordingly.
Can anyone suggest a (if not the) function I should use.

Thanks a lot in advance.
 

Dragonblight

Joined Aug 19, 2009
35
Well, the pin will register something if you throttle the variable resistor back and forth a whole lot, it could be used to count a whole lot of bunch of wiggling.

To really know what's going on, what's the purpose of this program?
 

Thread Starter

kandasamy

Joined Aug 22, 2009
2
This is what I intend to do with my circuit.
I want to use the variable resistor to control the frequency an LED blinks.
I'm copying a certain part of the code so that it will be easy to understand


#int_rtcc
void timer0_isr(void){
set_timer0(55);
clk_counter++;
rt_clock(); //User defined function
}

void rt_clock(void){ //Configures a 500ms flashing status LED
if(status_led==9)
{
status_led=0;
output_toggle(PIN_C0); //LED output toggled every 500ms
}
else{
status_led++;
}
}



This is what I want to do. Instead of "set_timer0(55)" I want it to be "set_timer(x)" where 'x' is a variable that will change when the variable resistor is adjusted.
The variable resistor is connected to pin #6 (which is RA4/T0CKI/C1OUT according to the data sheet) - and the 2 ends of the variable resistor are at 0 & 5 V respectively.
And then again the data sheet says that pin #6 (T0CKI) is the timer0 input so I presumed that the PIC would directly read it without having to use an ADC.

So now my Q is - How do I use an ADC to read off the resistor and transfer it to 'x'?
 

Dragonblight

Joined Aug 19, 2009
35
I just flipped through the 16f877A data sheet, and you picked the ONE pin in the dead center of eight A/D converters that isn't one. On the data sheet the "an(x)" pins are the A/D converters.

To run the ADC, you need to set a bit in the "ADC0N" register (I just closed the data sheet- i'm not looking up the register address) to initialize the ADC, then it takes a few clock cycles, after that a bit in ADC0N will go high as a 'converstion finished' flag. Then you can read the results right off the ADRES register.

Make sure you define some of the bits in the ADC0N register properly- they've given me issues in the past (the past two weeks- oh ho!)


On the electronics side, you'll need a pot or a voltage drop- just adjusting the resistance off of a power rail won't play with the voltage.


I know that i've omitted a lot of information in this answer- i'm still learning a bit myself. The way I see it, a little bit more than what you have is often just enough to point you in the right direction.

Best of luck!
 
Top