20x2 LED Clock 4 digit 7 segment

marks

Senior Member
Hmmm I hate clocks 88.88
on power on starts at 1.00

push the button to program
push to select hours

ie if your want 10.
push to select 9.
push and hold to get 10. then will jump to minutes 00

push to select 29
push and hold on 30 will display a dot
when you release clock starts at 10.30

dont know how acurate it is yet only being going 10 mins lol
using internal timer resets every 12 hours i hope.

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

cl: 
SETTIMER T1S_8
TIMER =3600

start:

clock:
 w1=Timer/3600                                             'time hours                                             
 
 w2=Timer//3600/60                                         'time minutes
                       

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 hours 	          
 	           let pinsb = b11 : low c.3 : pause 1       'Display1 


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>12 then cl                                            'once 12.59 is reached  stops and resets to 1.00 
                                        
goto clock
                              



Hours:w1=0
hrs:w20=0
Ho:  
b0=10  : if w1 < 10 then dig11                           'Zero blanking
let b0 = w1 dig 1
dig11: read b0,b11
high c.2 : let pinsb = b11 : low c.3 : pause 1           'Display1 
high c.1  :  high c.0
let b0 = w1 dig 0	                                         
 read b0,b12 : let b12=b12-128                           'with d.p

high c.3 : let pinsb = b12 : low c.2 : pause 1           'Display2
		 
if pinc.6=0 then hrs                                     'reset ready for next count
 
let w20=w20+1 
if w20 > 200 then Minutes                                'hold to goto Minutes                                              
if w20 > 1 then ho                                       'ignores button bounce

let w1=w1+1                                              'Add count by 1 
if w1=13 then hours                                      'Reset after 12 reached
goto ho


Minutes:w2=65535                                          ' start at 0 
mins:w21=0                                                ' reset sw
Mi:  
	
let b0 = w2 dig 1			
 read b0,b13
	high c.0 : let pinsb = b13 : low c.1 : pause 1      'Display3
high c.3  :  high c.2	
let b0 = w2 dig 0	                                                              
 read b0,b14
	high c.1 : let pinsb = b14 : low c.0 : pause 1      'Display4 

if pinc.6=0 then mins                                     'reset ready for next count

let w21=w21+1
if w21 > 200 then prog                                    'hold to goto prog
if w21 > 1 then Mi                                        'ignores button bounce
                                         
let w2=w2+1                                               'Add count by 1 
if w2=60 then minutes                                     'Reset after 59 reached
goto Mi




 
prog:
 let pinsb = 127                                           'd.p display4
 if pinc.6 = 1 then prog                                   'relase to program  
 let w2=w2*60
 let timer = w1*3600+w2
 
 goto clock
 

Attachments

Last edited:

marks

Senior Member
hmm i hate maths
shud of paid better attention at skool lol

well time went fast
over the 12 hour period time was 90 seconds ahead.
i thought it would be slower so much for being factory set.

Code:
cl: 
SETTIMER 34221           'T1S_8 =34286                      ahead  90s over 12h(43200s) fast 
                         '                                  90/43200 =0.00208333   or 2083us per second
                         'at 8mhz 32us per step             therefor 2083/32  = 65 (ammount we need to reduce settimer)
TIMER =3600
i like the idea of slowing time down
so after we adjust preload timer things improve i think that will now
gain just 2 seconds per week in theory .not to shabby

does anyone know if the calibrate freqency
might work as i read somewhere it doesnt affect the internal timer
just plays havoc with serial comms lol.


yes looks like supply effects it too
by reducing from 5v to 3.8v it gained 12 secs over a 12 hour period
so you could also slow it down by increasing supply voltage
and i guess the other unknown variable how much change in temp
may effect it .so getting it accurate may be harder then first thought.


i guess 2083 us per second is 0.2% accuracy lol
 
Last edited:

SAborn

Senior Member
You have gone this far you may as well add a DS 1307 real time clock chip and a little lithium battery for back up and once set it will keep time for the next ten years regardless if its turned off or not.

If you dont wish to build the RTC board you can pick them up on ebay compleet with backup battery for less than some sell the chip for.

That way when you turn the clock on the correct time will pop up instantly every time regardless how long the clock was switched off for.

Set it once and forget setting it again for life.
 

hippy

Ex-Staff (retired)
Using CALIBFREQ will affect almost everything time related on the PICAXE. Its primary purpose is to adjust operational speed when the on-chip oscillator is not quite spot-on when manufactured. For most PICAXE it should be within 1%-2% of what it is meant to be.

Calibrating the on-chip oscillator once will only set it as close as right as possible at one voltage and one temperature. It may still alter as voltage and temperature changes. For most accurate operational timing you need to use a crystal or resonator and a PICAXE capable of using one.
 
Top