20x2 led clock 6 digit 7 segment ds3231 rtc ds18b20

marks

Senior Member
Using bigger 4 one inch 7 segment displays , they are really impressive compared to the smaller 2 half inch used to display seconds.

For those wanting good time accuracy the ds3231 (ebay) is a good choice,both I2c slow 100kbps or fast 400kbps can be chosen.
The code is the same should you choose to use the ds1307 however suggest the pullup resistors be changed 2.2K.

With the power off it is backed up with a supercap expect it to last several days
I did try it without power for two days but too impatient after that lol.

The ds18b20 using the same pin as display1 ,will display the full temperature range from
(-55'C) to (125'C)and to one decimal place between (-9.9'C) to (99.9'C).
If the button is pressed while the temperature is displayed it will toggle to display fahrenheit
instead(-67'F)(-9.9'F)(99.9'F)(257'F).

If the button is pressed while the time is displayed, date and time(0-23hr format) can be programmed one digit at a time(days,months,years,hours mins).
Push to select,hold too remember,when the final selection is released the ds3231 will be programmed.Displays time in 12hr format.

Displays current temperature(26.5'C) at the 16th second and returns to time(10.23)(22)
AT the 31st second displays (29.9'C)(Hi) and then (26.2'C)(Lo) temperatures.
and lastly the date (31 )( 01)(2011) updating and returning to display time (10.23)(50).
the hi and lo temps reset at 0000 hrs.

Code:
	'              -- --   -- --   -- -- o -- --
	'C.0-A        |     | |     | |     | |     |        
	'C.1-B	                                      Picaxe  20x2  ver C.0
	'C.2-C        |     | |     | |     | |     |       
	'C.3-D         -- --   -- --   -- --   -- --   --   --
	'C.4-E        |     | |     | |     | |     | |  | |  |
	'C.5-F                                         --   --    marks    
	'C.7-G        |     | |     | |     | |     | |  | |  |
	'              -- --   -- -- o -- --   -- --   --   --
	'B.5-SDA
	'B.7-SCL                                   	 
	'A.0-D.P
	                                        
	'Display         1       2       3       4      5    6      
	'Common anode  
	
	
	SYMBOL pushbutton    = PINC.6
	SYMBOL ds18b20       = B.6
	SYMBOL display1      = B.6     
	SYMBOL display2      = B.5
	SYMBOL display3      = B.4
	SYMBOL display4      = B.3
	SYMBOL display5      = B.2
	SYMBOL display6      = B.1
	SYMBOL decimalpoint  = A.0	
	
	SYMBOL hours         = B10 'note selection uses (b0.b1,b2,b3,b4,b5)
	SYMBOL mins          = B11
	SYMBOL secs          = B12
	SYMBOL day           = B13
	SYMBOL date          = B14
	SYMBOL month         = B15
	SYMBOL year          = B16
	SYMBOL character     = B17
	SYMBOL recall        = B18
	SYMBOL degrees       = B19
	SYMBOL push          = B20
	SYMBOL Hilo          = b21
	 
	SYMBOL updatetime    = W11 '(b22,b23)
	SYMBOL totalminutes  = W12 '(b24,b25)
	SYMBOL displayedtime = W13 '(b26,b27)
	SYMBOL temperature   = W14 '(b28,b29)
	SYMBOL rawtemperature= W15 ' note if changing  ( b30,b31 ) change in Temperatureread.
	SYMBOL hold          = W16 '(b32.b33)
   	SYMBOL Maximum       = W17 '(b34,b35)
	SYMBOL Minimum       = W18 '(b36,b37)
	
	EEPROM   0, ( 63, 6 ,155,143,166,173,189, 7 ,191,175,  0  ,161,128,177,182, 16, 56,156)  
	 'Character ( 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ,blank, C , - , F , H , i , L , o )
      SETFREQ M16
      LET dirsb = %01011111                          
	LET dirsc = %10111111
	OWOUT ds18b20,%1001,($CC,$44)                              'reset(send skip rom ,send convert t)
      SETTIMER T1S_16  
      LOW decimalpoint 
     	Maximum = 0 : Minimum = 2880   	
Program1:
      PAUSE 10                                                   
	HI2CSETUP I2CMASTER, %11010000, I2Cslow_16, I2CBYTE        ' set to 100kbps default /change to I2Cfast_16 for 400kbps
      PAUSE 20                                                   
	HI2CIN 0,(secs,mins,hours,day,date,month,year)             ' read time ds3231
      HI2CSETUP OFF                                              
            
Main: IF hours = $0 and mins =$0 then :Maximum = 0 : Minimum = 2880 :  endif
      LET date  = BCDTOBIN date                                  'Date from ds3231 needs converting
      LET month = BCDTOBIN month
      LET year  = BCDTOBIN year
      
	LET secs = BCDTOBIN secs                                   'Time from ds3231 needs converting  
	LET totalminutes = BCDTOBIN mins * 60                                 
	LET hours = BCDTOBIN hours                                      
 
	IF hours > 12 THEN 
	LET updatetime = hours - 12 * 3600 + totalminutes + secs   'pm  
	ELSE                    
	LET updatetime = hours * 3600 + totalminutes + secs        'am 
	ENDIF	         
 
	LET TIMER = updatetime                                     'up date time from ds3231 every minute 

ClockDisplay:	                       
          LOW display6
  hours = TIMER /3600
   	                  
	character=10  : IF hours < 10 THEN dig1                                                'Display1 Zero blanking
	LET character = hours DIG 1
                     READ character,pinsc                         : HIGH display1 : PAUSEus 70  
    Dig1:
  	IF pushbutton = 1 THEN Menu                                                            'program 
 	       	
	LET character = hours DIG 0	                                          
    Dig2: low display1 : READ character,pinsc   :HIGH decimalpoint: HIGH display2 : PAUSEus 70 
  	     	 	 	     	  
  mins  = TIMER //3600/60 
    	
	LET character = mins DIG 1 : LOW decimalpoint			
    Dig3: LOW display2 : READ character,pinsc                     : HIGH display3 : PAUSEus 70 
                         		
	LET character = mins DIG 0     
    Dig4: LOW display3 : READ character,pinsc                     : HIGH display4 : PAUSEus 70 
                         		
  secs  = TIMER //3600//60  
      IF secs = 16 THEN gosub TemperatureDisplay                                 
      IF secs = 31 THEN  dateDisplay                                                         
      
    	LET character = secs DIG 1			
    Dig5: LOW display4 : READ character,pinsc                     : HIGH display5 : PAUSEus 130 
                         		
	LET character = secs DIG 0     
    Dig6: LOW display5 : READ character,pinsc                     : HIGH display6 : PAUSEus 130    
       
    GOTO clockdisplay
 

Attachments

Last edited:

marks

Senior Member
Part 2 of code.
Code:
Menu:b3=0 
    
Selection:on b3 goto days,months,years,hour,minute,program
    Days:    b0=3            :b2=32  : b4= display1 : b5 =display2 :goto Selection1
    Months:  b0=1 :date =b1  :b2=13  : b4= display3 : b5 =display4 :goto Selection1
    Years:   b0=9 :month=b1  :b2=100 : b4= display3 : b5 =display4 :goto Selection1     
    hour:    b0=2 :year =b1  :b2=24  : b4= display1 : b5 =display2 :goto Selection1
    minute:  b0=6 :hours=b1  :b2=60  : b4= display3 : b5 =display4 :goto Selection1
                               
 Selection1: let recall = 0 : LOW display1 :IF pushbutton = 1 THEN Selection1            
           SelectionDisplay1:hold = 0                                  
                      LET character = recall DIG 1	            
                     READ character,pinsc : HIGH b4 : PAUSE 1 : LOW b4  
          IF pushbutton=0 THEN SelectionDisplay1
                       Select1: HIGH b4 : IF hold > 600 then Selection2          
                        INC hold : LOW b4 : IF pushbutton = 1 THEN Select1          
                  recall = recall + 10 : IF character = b0 THEN Selection1 : GOTO SelectionDisplay1
                                                                                      	
 Selection2: let b1 = recall : LOW b4 : IF pushbutton = 1 THEN Selection2            
     SelectionDisplay2: hold = 0
                  LET character = b1 DIG 1	                                          
              READ character,pinsc : HIGH b4 : PAUSE 1 : LOW b4  
                  LET character = b1 DIG 0
              READ character,pinsc : HIGH b5 : PAUSE 1 : LOW b5        
          IF pushbutton=0 THEN SelectionDisplay2 	                     
       Select2:HIGH b5 : IF hold > 600 then : inc b3 :LOW b5:  goto Selection :endif                     
        INC hold : LOW b5 : IF pushbutton = 1 THEN Select2     
     INC b1 : IF character = 9 OR b1 = b2 THEN Selection2 : GOTO SelectionDisplay2  
      
 Program: IF pushbutton = 1 THEN program                        'release to program  
    mins=b1	                   
      LET  date  = BINTOBCD date                                'convert data going to ds3231              
 	LET  month = BINTOBCD month 
 	LET  year  = BINTOBCD year
 	LET  hours = BINTOBCD hours
      LET  mins  = BINTOBCD mins
      
      PAUSE 10
 	HI2CSETUP I2CMASTER, %11010000, I2Cslow_16, I2CBYTE       'set to 100kbps default /change to I2Cfast_16 for 400kbps 
 	PAUSE 20 
	HI2COUT 0, ($00, mins, hours, $00, date, month, year)     'prog time ds3231 (seconds,mins,hour,day,date,month,year)
	GOTO program1
	
DateDisplay:LOW display4:hilo=45:rawtemperature=maximum:gosub convert  'Hi
                         hilo=67:rawtemperature=minimum:gosub convert  'Lo
           
                FOR displayedtime = 1 TO 500
      LET character = date DIG 1			
        READ character,pinsc            : HIGH display1 : PAUSE 1 : LOW display1
    
      LET character = date DIG 0			
        READ character,pinsc            : HIGH display2 : PAUSE 1 : LOW display2
                NEXT displayedtime         
                     
                     FOR displayedtime = 1 TO 450
           LET character = month DIG 1			
             READ character,pinsc         : HIGH display3 : PAUSE 1 : LOW display3 
     
           LET character = month DIG 0	
             READ character,pinsc         : HIGH display4 : PAUSE 1 : LOW display4 
                     NEXT displayedtime
                                  
                  FOR displayedtime = 1 TO 320
      LET character = 2			
       READ character,pinsc       : HIGH display1 : PAUSE 2  :LOW display1 
     
      LET character = 0			
       READ character,pinsc       : HIGH display2 : PAUSE 2  :LOW display2 
    
      LET character = year DIG 1			
       READ character,pinsc       : HIGH display3 : PAUSE 2  :LOW display3 
     
      LET character = year DIG 0     	
       READ character,pinsc       : HIGH display4 : PAUSE 2  :LOW display4 
                 NEXT displayedtime
      GOTO program1           
    	                             
TemperatureDisplay:LOW display4:hilo=0
    	pinsc=0 :HIGH  ds18b20                                               'Initialise 
	OWOUT ds18b20,%0001,($CC,$BE)                                        'reset(send skip rom ,send read lsb msb)
	OWIN  ds18b20,%0000,(b30,b31)                                        'read in result
      RawTemperature = RawTemperature + 880
         IF RawTemperature > Maximum THEN LET Maximum = RawTemperature: ENDIF  'Hi:  
         IF RawTemperature < Minimum THEN LET Minimum = RawTemperature: ENDIF  'Lo:   
      OWOUT ds18b20,%1001,($CC,$44)                                        'reset(send skip rom ,send convert t)      
	low b.5
  	
Convert:     FOR displayedtime = 1 TO 400                                  
             Temperature = RawTemperature : LOW display6: recall=0 
   If push = 1 THEN                                                   'change to push=0 if Celsius default wanted
    degrees = 11 ' Celsius 
   Temperature=Temperature * 5 / 8 -550
               ELSE
    degrees = 13 ' Fahrenheit
   Temperature=Temperature * 9 / 8 -670
               ENDIF
       
        IF Temperature > 64865 THEN                                                      'if negative                 
     Temperature = -Temperature 
            IF temperature > 99  THEN : temperature = temperature/10 :recall=1 : ENDIF                    
     character=12  : GOTO dig111
        ELSE                                                                             'if positive
     character=10  : IF temperature < 100 THEN dig111                                    'Display1 zero blanking 
            IF temperature > 999 THEN : temperature = temperature/10 :recall=1 : ENDIF                               
        ENDIF                                       
	                                                      
	LET character = temperature DIG 2 
   Dig111: READ character,pinsc                                  : HIGH display1 : PAUSE   1               	
                        
      LET character = temperature DIG 1	                                                                           
          LOW display1 : READ character,pinsc : if recall=0 then : HIGH decimalpoint :endif
                                                                   HIGH display2 : PAUSE   1 : LOW decimalpoint                                 
	LET character = temperature DIG 0          
          LOW display2 : READ character,pinsc                    : HIGH display3 : PAUSE   2                 
         	
      LET character = degrees  
          LOW display3 : READ character,pinsc       : HIGH decimalpoint,display4 : PAUSE   1 : LOW decimalpoint  
           
      LET character = hilo DIG 1 + 10			
          LOW display4 : IF pushbutton = 1 THEN cfSelection
                         READ character,pinsc                    : HIGH display5 : PAUSE   1 
                         		
	LET character = hilo DIG 0 + 10     
          LOW display5 : READ character,pinsc                    : HIGH display6 : PAUSE   1 
           
	       NEXT displayedtime
	       pinsc=0 :LOW display6   	                                                
     Return
     
cfSelection:
   IF pushbutton = 1 THEN cfselection
   push = push + 1//2	
goto convert
 
Last edited:

william47316

New Member
looks good, how much did those large blue LED displays set you back, they look quite expensive.
i have made a clock myself using a picaxe 08M using a 1 pulse per second clock ticker using pushbuttons to set and sends the time hours first using 4800 baud serial, accurate to the second and i think loses less than 1 second per day or so, plus i have got it to send to multiple slave display units via some coax 10base2 cable and T connectors without terminators.
the displays show a seconds display widget between the hours and minutes showing one of the 7 segments as it goes around ten steps shows in 24 hours and does double beeps on the hour counting the hour in 12 hour format eg at 1300 it does one double beep and midnight/day it will do 12 double beeps
 

marks

Senior Member
Updated program now includes minimum and maximum temperatures.
yes blue displays can be expensive they were $ 2.90 from futurelec
wher all the components can be sourced from snailmail.

and the ds2321 and smaller 0.5" displays from ebay.

green 1" is proberly the way to go only 75c even the 2.3'' only $1.95

must get myself some red 10led bargraph displays only 30c lol.
 
Top