20X2 4digitLED stopwatch

marks

Senior Member
20X2 4 digit 7 segment LED stopwatch

Timer,s seem to be a popular
99 minutes 59seconds
surprised that it is very acurate!

push the button
will start .01
push again
will stop 20.10 (fif you can wait that long)
and again
to reset .00
(Hold continuously will reset)
push again to start from .00

Code:
	'             -- --   -- --   -- --   -- --
	' b0-A       |     | |     | |     | |     |
	' b1-B	
	' B2-C       |     | |     | |     | |     |
	' b3-D        -- --   -- --   -- --   -- --
	' B4-E       |     | |     | |     | |     |
	' B5-F
	' B6-G       |     | |     | |     | |     |
	' B7-dp       -- --   -- -- o -- --   -- --   
	'
	'Display        1       2       3       4
	'Common anode  C.3     C.2     C.1     c.0

eeprom 0,(192,249,164,176,153,146,130,248,128,144,255)    'Display (0,1,2,3,4,5,6,7,8,9,blank)

main:
let dirsb = %11111111
let dirsc = %10111111

m: b10=0
SETTIMER T1S_8
TIMER = 0

start:
 w1=Timer/60                                               'time minutes
 
 w2=Timer//60
                                                           'time seconds  
stop1:

b0=10  : if w1 < 10 then dig1                           'Zero blanking
let b0 = w1 dig 1
Dig1: read b0,b11
	high c.0 : if pinc.6 = 1 then sw 	          
 	           let pinsb = b11 : low c.3 : pause 1        'Display1 


if w1 < 1 then dig2                                      'Zero blanking 
let b0 = w1 dig 0	                                          
Dig2: read b0,b12 : let b12=b12-128                       'with d.p
	high c.3 : let pinsb = b12 : low c.2 : pause 1        'Display2 
	
	
let b0 = w2 dig 1			
Dig3: read b0,b13
	high c.2 : let pinsb = b13 : low c.1 : pause 1        'Display3
	
	
let b0 = w2 dig 0	                                                              
Dig4:read b0,b14
	high c.1 : let pinsb = b14 : low c.0 : pause 1        'Display4 

	                                                                                     
if w1>99 then m                                        'once 99.59 is reached  stops and resets to 00 
                                        
on b10 goto m,start,stop1 
                              
sw:
 let b10=b10+1 :pause 1000
 if pinc.6 =1  then sw                                       
 on b10 goto m,start,stop1
 if b10 > 2 then m
 

Attachments

Last edited:

hippy

Ex-Staff (retired)
All the LOOKUP's will take a fair time to execute which could be part of the flicker issue. You can speed things up by using EEPROM to hold the lookup table and access that using READ commands.

You can also use SETFREQ to speed up the PICAXE execution speed.

You've got the right approach though; get it working, then improve it.
 

westaust55

Moderator
Even small tweaks to the code may make improvements.

For example:
Code:
start:
 w0=Timer/60                                               'time minutes
 w3=w0*60
 w1=Timer-w3                                              'time seconds
can be written as:
Code:
start:
 w0=Timer/60                                               'time minutes
 w1=Timer// 60                                              'time seconds
try it in a loop for say 10,000 times and see what the difference is.

If it is at least not slower than the original code, then it will save a word variable and six bytes of program code.


you also have the line:
if w0>100 then main

should this line read
if w0 = 100 then main

or what happen for the time duration between 99:59 and 100:59 until eventually minute roll over again as 101:00 when w0 > 100
 
Last edited:

marks

Senior Member
Thanks again for more great ideas !!!

thats anifty command // to give the remainder after you divide somthing
and does help.

yes should have been w0 > 99
next step after 99.59 resets to 00 and stops ready for next press to start

i guess i should of checked this ( its a long time to wait lol)
 

westaust55

Moderator
Hi marks,

Have you tried the use of the EEPROM with read and write commands as suggested by hippy?

You only need 11 values in total as
192,249,164,176,153,146,130,248,128,144, 255

Then if you are:
1. blanking the first digit just set the index/pointervariable to 10 to acces the last value
That should allow you to remove the jumps to labels bl10 and bl11 and goto statements to get back to the main aprt of the program with more time saving and less flicker.

2. for the hours units digit just read the "usual" value from EEPROM and then AND the result with $7F to turn on the decimal point


Finally, do your values have an error? :confused:
Where in the three sets of LOOKUP data you have 146, this sets the lower nybble (4 bits) to %0010
but in the hours units data your corresponding value is 118 which sets the lower nybble (4 bits) to %0110 or should 118 in fact be 114 ?
 

marks

Senior Member
Hi westaus55,
i,m sure your actually Neo from out of the Matrix
the code seems to flow through your veins. lol

havn't had a chance yet need to read up i will try and implement them tho

ive checked all values are correct just need to subtract 128 to get the decimal point.

now reading from eeprom display nice and steady! Thanks HippY!

THANKS FOR ALL YOUR EFFORTS UR'VE IMPUTTED !!!
 
Last edited:

marks

Senior Member
latest code its getting there lol

allways seem to be looking for an
IF Statement that doesn't use an address

if someone knows a similar statement please post
 

hippy

Ex-Staff (retired)
Not sure how you mean, but the PICAXE supports block sructured commands ...

IF <expr> THEN
<if true statement>
END IF

IF <expr> THEN
<if true statement>
ELSE
<if false statement>
END IF

Plus there's ELSEIF and SELECT CASE
 
Can you please add some more comments explaining the code in more detail as i would like to use the 7segment code to drive my own.
 

marks

Senior Member
Hi Terra,
try this program.
Code:
let dirsb = %11111111                                        '  make portb all outputs)
let dirsc = %00111111



temp:

Dig1:   let pinsb = 249 : low c.3 : pause 1 : high c.3       'Display1       1
                                          
Dig2:   let pinsb = 144 : low c.2 : pause 1 : high c.2       'Display2       9
			
Dig3:   let pinsb = 156 : low c.1 : pause 1 : high c.1       'Display3       o

Dig4:   let pinsb = 198 : low c.0 : pause 1 : high c.0       'Display4       C


goto temp

'      program must loop and always be continuous with out pausing

'     pinsb =(value determines whats displayed   255  Clear display    (   )
'                                                  0  full display     ( 8.)
'                                                249  will display     ( 1 )
'        low c.3   ( turn on  transistor 1)
'        pause 1   ( on period)
'        high c.3  ( turn off transistor 1)

      '                    a
	'                  -- --  
	' B0-A  ( 1 )     |     | 
	' B1-B  ( 2 )    f       b
	' B2-C  ( 4 )     |  g  | 
	' B3-D  ( 8 )      -- --   
	' B4-E  ( 16)     |     | 
	' B5-F  ( 32)    e       c
	' B6-G  ( 64)     |  d  | 
	' B7-dp (128)      -- --  o 
	
	' adding all the numbers up turns of all segments
	' if we want to display a  (C)   we turn off segments (  b   c   g    dp )   add values
      '                                            example  (  2 + 4 + 64 + 128)  = 198
 
Top