Making 24 hour clock

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
Hi,
Need to have a clock in my curciut 16f690 but do not have the space for it.
All i need i just the shift from 23:59 to 00:00
how can i fix it, as simpel as possible,
the time does not have to 100% precise, should it gain or lose a couple of second pr day the nevermind it.
 

t06afre

Joined May 11, 2009
5,934
I am kind of puzzled that you have filled up the 7K rom allready. Are you sure about this. Perhaps it is your compiler that is in some sort of demo mode not allowing code size larger than 2K.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
hex file now 13720 bytes.
Still ok, have found an error that make the file to big.

struggeling with eeprom, do not know why, but one value will allways be "8D" value that is writtin is between 0 and 6.
Works ok, when i write other places in program.
Still miss the clock.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
Here is my code, so far.

Rich (BB code):
;Chip Settings
#chip 16F690,4
#config OSC=LP
;Defines (Constants)
#define LCD_IO 4
#define LCD_RW PORTC.5
#define LCD_RS PORTC.6
#define LCD_Enable PORTC.7
#define LCD_DB4 PORTC.0
#define LCD_DB5 PORTC.1
#define LCD_DB6 PORTC.2
#define LCD_DB7 PORTC.3
;Variables
Dim DagTekst As string
Dim Regn As integer
Dim RegnTotal As integer
Dim Regn_0 As integer
Dim Sel_Dag As integer
Dim Tekstdag As string
Dim Ugedag As integer
Dim dow As integer
Dim en_minut As integer
Dim ti_minut As integer
Dim time As integer
lcd 'Start Main, run once
EPRead 1, RegnTotal
EPRead 2, Regn
dow = 0
ti_minut = 0
en_minut = 0
time = 0
Ugedag = 0
Regn_0 = 0
Wait 1 s
Vis_Daglig
Tjek: 'Main run in loop
If PORTB.4 = 1 Then
MM
End If
If PORTB.6 = 1 Then
ResetTotal
End If
If PORTB.5 = 1 Then
Sel_Dag = 0
Select
End If
Goto Tjek ' until here
Sub MM ' sub for adding rain
Regn = Regn +1
RegnTotal = RegnTotal+1
EPWrite 1,RegnTotal
EPWrite 2,Regn
Wait 1 s
Vis_Daglig
Exit Sub
End Sub
Sub ResetTotal 'sub reset total
CLS
Locate 0, 3
Print "Slet Total ?"
Locate 1, 5
Print "JA / NEJ ?"
Wait 2 s
If PORTB.6 = 1 Then
RegnTotal = 0
EPWrite 1, RegnTotal
CLS
Locate 1, 5
Print "Slettet !!"
Wait 1 s
End If
Vis_Daglig
Exit Sub
End Sub
Sub lcd ' sub for clearing the lcd
CLS
Exit Sub
End Sub
Sub Select 'sub for selecting the last 7 days
Sel_Start:
Repeat 100
If PORTB.5 = 1 Then
Vis_Dag1
Sel_Dag = Sel_Dag +1
If Sel_Dag = 8 Then
Sel_Dag = 0
End If
Wait 500 ms
Goto Sel_Start
End If
Wait 100 ms
End Repeat
Vis_Daglig
Exit Sub
End Sub
Sub Vis_Daglig ' normal readout on display
CLS
Locate 0, 1
Print "Regn Total"
Locate 0, 15
If RegnTotal > 9 Then
Locate 0, 14
End If
If RegnTotal > 99 Then
Locate 0, 13
End If
Print RegnTotal
Locate 0, 17
Print "MM"
Locate 1, 1
Print "Regn Idag "
Locate 1, 14
If Regn < 10 Then
Print " "
End If
Print Regn
Locate 1, 17
Print "MM"
Exit Sub
End Sub
Sub Vis_Dag1 ' button line show "day" and amount of rain"
If Sel_Dag = 0 Then
Tekstdag = "Sondag"
Goto Vis
End If
If Sel_Dag = 1 Then
Tekstdag = "Lordag"
Goto Vis
End If
If Sel_Dag = 2 Then
Tekstdag = "Fredag"
Goto Vis
End If
If Sel_Dag = 3 Then
Tekstdag = "Torsdag"
Goto Vis
End If
If Sel_Dag = 4 Then
Tekstdag = "Onsdag"
Goto Vis
End If
If Sel_Dag = 5 Then
Tekstdag = "Tirsdag"
Goto Vis
End If
If Sel_Dag = 6 Then
Tekstdag = "Mandag"
Goto Vis
End If
If Sel_Dag = 7 Then
Vis_ur
End If
Exit Sub
Vis:
sletlinje1
Locate 1, 1
Print Tekstdag
Locate 1, 14
EPRead 10+Sel_Dag, Regn_0 ' and read out the value from eeprom
If Regn_0 < 10 Then
Locate 1, 15
End If
Print Regn_0
Locate 1, 17
Print "MM"
Exit Sub
End Sub
Sub sletlinje1 ' clear the button line on LCD
Locate 1, 0
Print " "
Exit Sub
End Sub
Sub Vis_ur ' show clock and day of week
CLS
Locate 0, 8
If time < 10 Then
Print "0"
End If
Print time
Print ":"
Print ti_minut
Print en_minut
Locate 1, 7
If dow = 0 Then
Print "Sondag"
End If
If dow = 1 Then
Print "Lordag"
End If
If dow = 2 Then
Print "Fredag"
End If
If dow = 3 Then
Print "Torsdag"
End If
If dow = 4 Then
Print "Onsdag"
End If
If dow = 5 Then
Print "Tirsdag"
End If
If dow = 6 Then
Print "Mandag"
End If
Wait 500 ms
Repeat 100 ' if 10 second return to normal. or wait for input to adjust time
If PORTB.5 = 1 Then
Vis_Daglig
Exit Sub
End If
If PORTB.6 = 1 Then
Stil_ur ' adjust time
End If
Wait 100 ms
End Repeat
Exit Sub
End Sub
Sub Stil_ur ' adjust time
Do Until PORTB.5 = 1
If PORTB.6 = 1 Then
time = time+1
If time = 24 Then
time = 0
End If
Wait 250 ms
End If
Locate 0, 9
LCDWriteChar 255
Wait 250 ms
Locate 0, 8
If time < 10 Then
Print " "
End If
Print time
Wait 250 ms
Loop
Wait 500 ms
Do Until PORTB.5 = 1
If PORTB.6 = 1 Then
ti_minut = ti_minut+1
If ti_minut = 6 Then
ti_minut = 0
End If
Wait 250 ms
End If
Locate 0, 11
LCDWriteChar 255
Wait 250 ms
Locate 0, 11
Print ti_minut
Wait 250 ms
Loop
Wait 500 ms
Do Until PORTB.5 = 1
If PORTB.6 = 1 Then
en_minut = en_minut+1
If en_minut = 10 Then
en_minut = 0
End If
Wait 250 ms
End If
Locate 0, 12
LCDWriteChar 255
Wait 250 ms
Locate 0, 12
Print en_minut
Wait 250 ms
Loop
Wait 500 ms
DagTekst = "Dag "
Do Until PORTB.5 = 1
Wait 250 ms
If PORTB.6 = 1 Then
if dow = 0 then
dow = 6
DagTekst = "Mandag "
Goto Vis_Dag
end if
If dow = 1 Then
dow = 0
DagTekst = "Sondag "
End If
If dow = 2 Then
dow = 1
DagTekst = "Lordag "
End If
If dow = 3 Then
dow = 2
DagTekst = "Fredag "
End If
If dow = 4 Then
dow = 3
DagTekst = "Torsdag"
End If
If dow = 5 Then
dow = 4
DagTekst = "Onsdag "
End If
If dow = 6 Then
dow = 5
DagTekst = "Tirsdag"
End If
End If
Vis_Dag:
Locate 1, 7
LCDWriteChar 255
Wait 250 ms
Locate 1, 7
Print DagTekst
Wait 250 ms
Loop
EPWrite 0, dow ' here it should write the "dow" to eeprom, but always write "8D"
Wait 2 s
Exit Sub
End Sub
 
 

ErnieM

Joined Apr 24, 2011
8,377
You define strings for the names of the days of the week 3 different times. Doing this just once would be a significant savings.

I have no idea what the "EPWrite" function is.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
Maybe i will just add another chip for keeping track of the time.
16F84 is at my draw, so i could use that as the 24 hour clock, and just set a output high at midnight. that i could use i 16f690
same me a lot of space in the 16f690
 

t06afre

Joined May 11, 2009
5,934
Hvad laver du!!

You have very little functionalty in your program. So perhaps drop the compiler instead. What is your compiler by the way. It could also help if you wrote a few lines what your current program is meant to do. Perhaps keep it more simple. Then things are working as it should. You can add more advanced functions. Just remember KISS (keep it simple stupid) A saying I picked up during my time in the army. In basic forms it a saying to remind you about the fact. That a simple plan is more likely to sucseed than a more fancy and complicated plan

Do you know what the record of rain in denmark during a 24 hour period. In Norway it is 229,6 mm So I would have used timer0 in counter mode to keep track of rain.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
Hmm, i mean i keep it simpel.
only to count to 99 is enough in one day, and total 256, for a month.
Well can you make it more simpel, and still the same cabilities.
i have more than 300 lines of C Code, and still not all i want in the chip.
I use Great Cow Basic http://gcbasic.sourceforge.net/
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
Can i get som help, or do i need to use 2 chip.
I want it all in chip at one time.
Simpel version, is a counter from input ( RB4).
Count both as rain today, and rain total since last reset.
A Button as reset total ( RB6 ), with confirmation before reset.
Button ( RB5 ) as select between rain from last 7 days , stored in EEPROM
And ofcause the famous 24 hour clock, so that it can roll over at midningt.
All C output is for LCD,
C5 = R/W could remove it and just ground the wire.
C6 = RS.
C7 = Enable.
C0-C3 is DB4-DB7
Free I/O is All A, and RB7 and RC4-RC5?.
 

t06afre

Joined May 11, 2009
5,934
Just to see how much space it would take. I made a 24 hours clock in C using a free C compiler, PIC16f690 and a LCD display. Like yours. The full setup. Used 905 words of program memory. And used a total of 46 bytes RAM. It was about 215 lines of C code. Much of that "stolen" from examples ;). So as I see it. Your compiler is not suited for the kind of work you want to do. But it may work OK for just simple work like toggling some LEDs. So my advice is still. Just drop it ;)
 

MMcLaren

Joined Feb 14, 2010
861
I just checked my old 16F88 single chip Charlieplexed Clock/Calendar/Timer project which was written in BoostC and it only uses 711 words of program memory. If I had used an LCD display instead of the six digit 7-segment display the program would probably be slightly larger.

I agree with t06afre. Your BASIC compiler may not be very efficient.

Regards, Mike
 

Attachments

Last edited:

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
Just to see how much space it would take. I made a 24 hours clock in C using a free C compiler, PIC16f690 and a LCD display. Like yours. The full setup. Used 905 words of program memory. And used a total of 46 bytes RAM. It was about 215 lines of C code. Much of that "stolen" from examples ;). So as I see it. Your compiler is not suited for the kind of work you want to do. But it may work OK for just simple work like toggling some LEDs. So my advice is still. Just drop it ;)
You say drop it, do you mean the project ?
I will try to finde another C program to make it in, have you some good one to recomend ?
 

t06afre

Joined May 11, 2009
5,934
You say drop it, do you mean the project ?
I will try to finde another C program to make it in, have you some good one to recomend ?
No do not drop your project. But use another C compiler. I use this one http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en542849 Most of the commercial compilers do have some free versions. And most of them will do nice for the hobbyist. I have inclued the schematics and the hex file for you to play with. By the way is this some kind of school work?
 

Attachments

Last edited:

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
No do not drop your project. But use another C compiler. I use this one http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en542849 Most of the commercial compilers do have some free versions. And most of them will do nice for the hobbyist. I have inclued the schematics and the hex file for you to play with. By the way is this some kind of school work?
No it's for my own use only. only hobby.
Will try to use the compiler.
Fine with scematic, but how do i see the sample you have made, just a hex files, and i dont think i can understand much of that ;)
 

t06afre

Joined May 11, 2009
5,934
I am somwehat sceptical to just hand you the code. The reason for this. Is because I am afraid that will hamper your learning process. The code itself has no kind of value to me. But let me see later to day if I can throw you a "bone" with still some meat on it. For you to chew on. If you show a learning curve. I may send you more
 

t06afre

Joined May 11, 2009
5,934
here is your bone ;). Note that in the schematic I have changed some minor details. Regarding the LED and LCD control lines. The switches are not needed for demo. So you can wait with mounting then. Questions are welcome
 

Attachments

Last edited:
Top