Hi-tech C PIC16F877A need help

Thread Starter

ericyeoh

Joined Aug 2, 2009
58
Guys,

Any 1 hv ideas how to use Timer2 as counter to count the value of 1second. Cause i need the microcontroller PIC16F877A to interface with LCD to display current time in the form of
HH:MM:SS AM/PM.

Please kindly share your ideas.
 

ELECTRONERD

Joined May 26, 2009
1,147
I haven't used Timer2 yet, but here's code for Timer1. It will be very similar, so you should be able to figure it out from here. This is a frequency generating function, but if you use the prescaler for the Timer2, you can make it have longer delays. Then just change the name to "timer" function! You won't need any input data for the function, so just put in "void". Also, you don't necessarily need GPIO, so don't output the data from GPIO.

PIC12F629

Rich (BB code):
void freq(char pins, unsigned int frqcy, unsigned int timer)       // Frequency Function using Timer1 (16-Bit)
    {    
            unsigned int times;
            TMR1IF = 0;       // Clear OVF Flag
            GPIO = pins;       // Initialize GPIO
        
            for(times=timer;times>0;times--)       // Duration of playing
            {
                TMR1H = (frqcy >> 8) & 0xFF;       //Load TMR0H byte first
                TMR1L = frqcy & 0xFF;       // Load TMR0L byte next
                while(!TMR1IF);       // Wait for timer
                TMR1IF = 0;       // Clear OVF Flag
                GPIO = ~GPIO;       // Invert output   
            }
            TMR1IF = 0;    // Clear OVF Flag
    }
 

t06afre

Joined May 11, 2009
5,934
Guys,

Any 1 hv ideas how to use Timer2 as counter to count the value of 1second. Cause i need the microcontroller PIC16F877A to interface with LCD to display current time in the form of
HH:MM:SS AM/PM.

Please kindly share your ideas.
This will depend on your cpu clock speed. The most common is to use Timer1 for this purpose. And a clock crystal. Will you be using interrupts?
 
Top