Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 2nd June 2008, 12:58 PM   (permalink)
Default Designing stopwatch with 16f887

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
matlark is offline   Reply With Quote
Old 2nd June 2008, 03:45 PM   (permalink)
Default

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.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is online now   Reply With Quote
Old 3rd June 2008, 01:40 AM   (permalink)
Default

thanks, I will look into timer2
matlark is offline   Reply With Quote
Old 4th June 2008, 02:28 AM   (permalink)
Default

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
matlark is offline   Reply With Quote
Old 4th June 2008, 02:40 AM   (permalink)
Default

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
matlark is offline   Reply With Quote
Old 4th June 2008, 03:11 AM   (permalink)
Default

Here's a nice tip. When you post code here, be sure to put it inside Code tags. Easiest way is to click the # in the menu just before pasting your code. Alternately, you can type in [code] before your code and [/code] after your code. This forces the web-site to keep your formatting so people can actually read your code. When you don't do this, it loses all indentation and turns into the unreadable lump in your original post.

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
=========================
futz is offline   Reply With Quote
Old 4th June 2008, 01:26 PM   (permalink)
Default

Thanks for the info.
matlark is offline   Reply With Quote
Old 4th June 2008, 02:16 PM   (permalink)
Default

hi futz,
Quote:
When you don't do this, it loses all indentation and turns into the unreadable lump in your original post.
Have you seen Pommies codetidy, nice little program reformats lumps into readable and pasteable code..
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/
ericgibbs is offline   Reply With Quote
Old 4th June 2008, 02:24 PM   (permalink)
Default

Quote:
Originally Posted by ericgibbs View Post
Have you seen Pommies codetidy, nice little program reformats lumps into readable and pasteable code..
I've seen it mentioned. Been meaning to try it.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline   Reply With Quote
Old 4th June 2008, 02:40 PM   (permalink)
Default

Quote:
Originally Posted by futz View Post
I've seen it mentioned. Been meaning to try it.
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/
ericgibbs is offline   Reply With Quote
Old 4th June 2008, 02:55 PM   (permalink)
Default

Quote:
Originally Posted by ericgibbs View Post
hi,
Just before the infamous finger, Mike was fixing a small bug.
Mike managed to fix the small bug within the 15 minute edit window.

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.
Pommie is online now   Reply With Quote
Old 4th June 2008, 03:21 PM   (permalink)
Default

Quote:
Originally Posted by Pommie View Post
Mike managed to fix the small bug within the 15 minute edit window.

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.
hi Mike,
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/
ericgibbs is offline   Reply With Quote
Old 4th June 2008, 03:27 PM   (permalink)
Default

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.
Pommie is online now   Reply With Quote
Old 6th June 2008, 11:19 PM   (permalink)
Default

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
gramo is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
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



All times are GMT. The time now is 04:47 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.