Help with pic16f877a programming stopwatch

Discussion in 'Embedded Systems and Microcontrollers' started by helloiamkat, Aug 2, 2010.

  1. helloiamkat

    Thread Starter New Member

    Jun 17, 2010

    I want to create a stopwatch using a PIC16F877A. To start and stop the stopwatch a simple switch can be used. Since, I'm more familiar with C++ language and I was told I can use it to program such, I plan to use that to program my microcontroller.

    I did some initial reading and found out that Timer1 can be used for this. I'm not asking for codes, however I was just wondering if I was going in the right direction and if you could give me your opinions, advices, tips and such with my programming.

    Looking forward to your replies.

    THANKS! ♥
  2. Markd77

    Senior Member

    Sep 7, 2009
    There may be some built in timer in C, I use assembler myself.
    Timer1 is a 16 bit timer so it counts up to 65535 then resets. There is a prescaler that can be set to slow the timer down up to 8 times, but that means it will still overflow about twice a second with a 4MHz clock speed.
    An interrupt can be set up that triggers when the timer resets and that can be used to increment your own counter variable. At that point you can also set the timer so it can interrupt at a more useful interval (exactly 1/10 second, etc).
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    Last edited: Aug 2, 2010
  4. helloiamkat

    Thread Starter New Member

    Jun 17, 2010
    @Markd77 I'm sorry but I didn't understand what you said. Haha. :) I'm quite new with programming - I'm trying my best though. Can you explain it again?? Thanks.
  5. wannaBinventor


    Apr 8, 2010
    Read about the timers and interrupts in that PIC's datasheet about 4 times over. Give it a day, and then read it again. At that point, what Mark said will begin to make sense.

    The 16 bit timer has a place for 16 zeros or ones can count to ~65000. To be very basic lets pretend that each "tick" of the internal oscillator = 1 increment of the timer which = 1 second. (Again, this is just to be simple). After 65000 seconds, or 65000 oscillator "ticks" the timer will "overflow" (reset to 0). In your programming, you can test for this condition and then make the program perform a function based on this (IE: increment the displayed time).