![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Hello,
I am trying to make a stopwatch that reads up to 99.99 (1 min 39 secs.99hundredths). When the button is pressed it starts and upon the second button push it displays the time elapsed on the 8 leds in a line in BCD. It first displays up to 99 then blank then whats after the decimal. I know I need to utilize either timer0 or timer1 possibly even use the OSCCON register to slow down the internal clock. I am having trouble getting started. This is for a school project so I am not asking for the code but does anyone have any ideas that can help me? I am having trouble getting started. thanks |
|
|
|
|
|
|
(permalink) |
|
The internal osc is too inaccurate for a stopwatch, use a crystal instead. Since you're trying for a 10ms timebase find a crystal that divides perfectly into 10ms (after prescaling etc) Timer 2 is a good choice as it can do some pretty handy clock division.
|
|
|
|
|
|
|
(permalink) |
|
thanks, I will look into timer2
|
|
|
|
|
|
|
(permalink) |
|
Is there a way I can post the below routine(display,rotation,Displaytime)into my main? The way it is set up calls display from main and I need to integrate it into the main.
thanks Display: btfss Rotate,0 goto DisplayTime goto Rotation Rotation: call Delay rlf LED,f ; rotates bit to left. btfsc STATUS,C ; did it rotate out of the display bsf LED,0 ; yes, put it into bit 0 movf LED,w movwf PORTD retlw 0 DisplayTime: movlw 0x00 movwf PORTD call Delay swapf TenSeconds,w addwf Seconds,w movwf PORTD call Delay swapf Hundreds,w addwf Tens,w movwf PORTD call Delay movlw 0x00 movwf PORTD retlw 0 ;Program Start--------------------------------------------------------- Start call Init Main call Display goto Main end |
|
|
|
|
|
|
(permalink) |
|
The below code is for utilizing TMR2, I declared the variables hundreds,tens,seconds, and tenseconds. When each variable is declared does that mark that register address as with the result of TMR2? I am not sure if I explained it right but I am trying to make a stopwatch on the 16f887 board.
thanks Stopwatch: bcf PIR1,TMR2IF ;Clears interrupt flag incf Hundreds,f ;Increment hundreds by one, subtract 10 from hundr movlw .10 ;when zero flag is set clear hundreds and skip to Tens. subwf Hundreds,w ;if zero flag in STATUS Z not reached skiptoEXITISR. btfss STATUS,Z goto ExitISR clrf Hundreds incf Tens,f ;after hundreds have been incremented and zero flagset in movlw .10 ;STATUS z, skip to Tens which are incremented in similar subwf Tens,w btfss STATUS,Z goto ExitISR clrf Tens incf Seconds,f movlw .10 subwf Seconds,w btfss STATUS,Z goto ExitISR clrf Seconds incf TenSeconds,f movlw .10 subwf TenSeconds,w btfss STATUS,Z goto ExitISR movlw 0xFF movwf PORTD goto $-1 |
|
|
|
|
|
|
(permalink) |
|
Here's a nice tip.
It should look like this: Code:
Stopwatch: bcf PIR1,TMR2IF ;Clears interrupt flag incf Hundreds,f ;Increment hundreds by one, subtract 10 from hundr movlw .10 ;when zero flag is set clear hundreds and skip to Tens. subwf Hundreds,w ;if zero flag in STATUS Z not reached skiptoEXITISR. btfss STATUS,Z goto ExitISR clrf Hundreds incf Tens,f ;after hundreds have been incremented and zero flagset in movlw .10 ;STATUS z, skip to Tens which are incremented in similar subwf Tens,w btfss STATUS,Z goto ExitISR clrf Tens incf Seconds,f movlw .10 subwf Seconds,w btfss STATUS,Z goto ExitISR clrf Seconds incf TenSeconds,f movlw .10 subwf TenSeconds,w btfss STATUS,Z goto ExitISR movlw 0xFF movwf PORTD goto $-1
__________________
========================= Futz's Microcontrollers & Robotics ========================= |
|
|
|
|
|
|
(permalink) |
|
Thanks for the info.
|
|
|
|
|
|
|
(permalink) | |
|
hi futz,
Quote:
__________________
Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ |
||
|
|
|
|
|
(permalink) |
|
I've seen it mentioned. Been meaning to try it.
__________________
========================= Futz's Microcontrollers & Robotics ========================= |
|
|
|
|
|
|
(permalink) |
|
hi,
Just before the infamous finger, Mike was fixing a small bug. The latest version has a convert from upper case to lower case option. The original version works OK, no case change.
__________________
Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ |
|
|
|
|
|
|
(permalink) | |
|
Quote:
I just wish I could edit the first post and add the fixed version. Oh well. The infamous finger has now started to contribute the odd keypress to late night postings. Mike. |
||
|
|
|
|
|
(permalink) | |
|
Quote:
Thanks, I have re-downloaded,, will give it a go. Are you going to release the VB source.? Reason for asking is, I reduce the tabs sizes, so that the tidied listing is confined to left side of the screen when running simulations. Regards
__________________
Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ |
||
|
|
|
|
|
(permalink) |
|
I'll post the source tomorrow. I thought about making the tab sizes settable and will probably add that in the morning as well. If you find any problems with the new version then let me know and I'll fix them as well.
Mike. |
|
|
|
|
|
|
(permalink) |
|
I also find myself writing in SF for small code snippets, its formatting works great for code tags (tabs don't jumble up with space's etc)
Just on the project, have you heard of a DS1307? It uses a 32.768Khz external crystal, and depending on your circuit layout, its by far more accurate from my experience. Its got some great built in features that make things like this easy, like leap year compensation until the year 2100, and battery powered backup mode so it utilizes minuscule current while doing so Spency's digital-diy 18F PIC micro Tutorial - DS1307 ![]()
__________________
Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| Can someone explain the adc? 16f887 | matlark | Micro Controllers | 1 | 25th April 2008 01:29 PM |
| Building a stopwatch with PIC16F877a | ag501 | Electronic Projects Design/Ideas/Reviews | 23 | 8th January 2008 03:18 PM |
| I can't find the PGD and PGC pins on the 16F887... | Krumlink | Datasheet/Parts Requests | 9 | 30th September 2007 06:43 PM |
| Stopwatch Schematic | 7404 quad2 input | Electronic Projects Design/Ideas/Reviews | 7 | 16th November 2004 12:37 PM |
| Automatic timing with a stopwatch | Ybody | Electronic Projects Design/Ideas/Reviews | 0 | 3rd June 2003 12:02 AM |