Making 24 hour clock

Discussion in 'Programmer's Corner' started by FroceMaster, Feb 19, 2012.

  1. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    400
    4
    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.
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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.
     
  3. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    400
    4
    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.
     
  4. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    400
    4
    Here is my code, so far.

    Code ( (Unknown Language)):
    1.  
    2. ;Chip Settings
    3. #chip 16F690,4
    4. #config OSC=LP
    5. ;Defines (Constants)
    6. #define LCD_IO 4
    7. #define LCD_RW PORTC.5
    8. #define LCD_RS PORTC.6
    9. #define LCD_Enable PORTC.7
    10. #define LCD_DB4 PORTC.0
    11. #define LCD_DB5 PORTC.1
    12. #define LCD_DB6 PORTC.2
    13. #define LCD_DB7 PORTC.3
    14. ;Variables
    15. Dim DagTekst As string
    16. Dim Regn As integer
    17. Dim RegnTotal As integer
    18. Dim Regn_0 As integer
    19. Dim Sel_Dag As integer
    20. Dim Tekstdag As string
    21. Dim Ugedag As integer
    22. Dim dow As integer
    23. Dim en_minut As integer
    24. Dim ti_minut As integer
    25. Dim time As integer
    26. lcd 'Start Main, run once
    27. EPRead 1, RegnTotal
    28. EPRead 2, Regn
    29. dow = 0
    30. ti_minut = 0
    31. en_minut = 0
    32. time = 0
    33. Ugedag = 0
    34. Regn_0 = 0
    35. Wait 1 s
    36. Vis_Daglig
    37. Tjek: 'Main run in loop
    38. If PORTB.4 = 1 Then
    39. MM
    40. End If
    41. If PORTB.6 = 1 Then
    42. ResetTotal
    43. End If
    44. If PORTB.5 = 1 Then
    45. Sel_Dag = 0
    46. Select
    47. End If
    48. Goto Tjek ' until here
    49. Sub MM ' sub for adding rain
    50. Regn = Regn +1
    51. RegnTotal = RegnTotal+1
    52. EPWrite 1,RegnTotal
    53. EPWrite 2,Regn
    54. Wait 1 s
    55. Vis_Daglig
    56. Exit Sub
    57. End Sub
    58. Sub ResetTotal 'sub reset total
    59. CLS
    60. Locate 0, 3
    61. Print "Slet Total ?"
    62. Locate 1, 5
    63. Print "JA / NEJ ?"
    64. Wait 2 s
    65. If PORTB.6 = 1 Then
    66. RegnTotal = 0
    67. EPWrite 1, RegnTotal
    68. CLS
    69. Locate 1, 5
    70. Print "Slettet !!"
    71. Wait 1 s
    72. End If
    73. Vis_Daglig
    74. Exit Sub
    75. End Sub
    76. Sub lcd ' sub for clearing the lcd
    77. CLS
    78. Exit Sub
    79. End Sub
    80. Sub Select 'sub for selecting the last 7 days
    81. Sel_Start:
    82. Repeat 100
    83. If PORTB.5 = 1 Then
    84. Vis_Dag1
    85. Sel_Dag = Sel_Dag +1
    86. If Sel_Dag = 8 Then
    87. Sel_Dag = 0
    88. End If
    89. Wait 500 ms
    90. Goto Sel_Start
    91. End If
    92. Wait 100 ms
    93. End Repeat
    94. Vis_Daglig
    95. Exit Sub
    96. End Sub
    97. Sub Vis_Daglig ' normal readout on display
    98. CLS
    99. Locate 0, 1
    100. Print "Regn Total"
    101. Locate 0, 15
    102. If RegnTotal > 9 Then
    103. Locate 0, 14
    104. End If
    105. If RegnTotal > 99 Then
    106. Locate 0, 13
    107. End If
    108. Print RegnTotal
    109. Locate 0, 17
    110. Print "MM"
    111. Locate 1, 1
    112. Print "Regn Idag "
    113. Locate 1, 14
    114. If Regn < 10 Then
    115. Print " "
    116. End If
    117. Print Regn
    118. Locate 1, 17
    119. Print "MM"
    120. Exit Sub
    121. End Sub
    122. Sub Vis_Dag1 ' button line show "day" and amount of rain"
    123. If Sel_Dag = 0 Then
    124. Tekstdag = "Sondag"
    125. Goto Vis
    126. End If
    127. If Sel_Dag = 1 Then
    128. Tekstdag = "Lordag"
    129. Goto Vis
    130. End If
    131. If Sel_Dag = 2 Then
    132. Tekstdag = "Fredag"
    133. Goto Vis
    134. End If
    135. If Sel_Dag = 3 Then
    136. Tekstdag = "Torsdag"
    137. Goto Vis
    138. End If
    139. If Sel_Dag = 4 Then
    140. Tekstdag = "Onsdag"
    141. Goto Vis
    142. End If
    143. If Sel_Dag = 5 Then
    144. Tekstdag = "Tirsdag"
    145. Goto Vis
    146. End If
    147. If Sel_Dag = 6 Then
    148. Tekstdag = "Mandag"
    149. Goto Vis
    150. End If
    151. If Sel_Dag = 7 Then
    152. Vis_ur
    153. End If
    154. Exit Sub
    155. Vis:
    156. sletlinje1
    157. Locate 1, 1
    158. Print Tekstdag
    159. Locate 1, 14
    160. EPRead 10+Sel_Dag, Regn_0 ' and read out the value from eeprom
    161. If Regn_0 < 10 Then
    162. Locate 1, 15
    163. End If
    164. Print Regn_0
    165. Locate 1, 17
    166. Print "MM"
    167. Exit Sub
    168. End Sub
    169. Sub sletlinje1 ' clear the button line on LCD
    170. Locate 1, 0
    171. Print " "
    172. Exit Sub
    173. End Sub
    174. Sub Vis_ur ' show clock and day of week
    175. CLS
    176. Locate 0, 8
    177. If time < 10 Then
    178. Print "0"
    179. End If
    180. Print time
    181. Print ":"
    182. Print ti_minut
    183. Print en_minut
    184. Locate 1, 7
    185. If dow = 0 Then
    186. Print "Sondag"
    187. End If
    188. If dow = 1 Then
    189. Print "Lordag"
    190. End If
    191. If dow = 2 Then
    192. Print "Fredag"
    193. End If
    194. If dow = 3 Then
    195. Print "Torsdag"
    196. End If
    197. If dow = 4 Then
    198. Print "Onsdag"
    199. End If
    200. If dow = 5 Then
    201. Print "Tirsdag"
    202. End If
    203. If dow = 6 Then
    204. Print "Mandag"
    205. End If
    206. Wait 500 ms
    207. Repeat 100 ' if 10 second return to normal. or wait for input to adjust time
    208. If PORTB.5 = 1 Then
    209. Vis_Daglig
    210. Exit Sub
    211. End If
    212. If PORTB.6 = 1 Then
    213. Stil_ur ' adjust time
    214. End If
    215. Wait 100 ms
    216. End Repeat
    217. Exit Sub
    218. End Sub
    219. Sub Stil_ur ' adjust time
    220. Do Until PORTB.5 = 1
    221. If PORTB.6 = 1 Then
    222. time = time+1
    223. If time = 24 Then
    224. time = 0
    225. End If
    226. Wait 250 ms
    227. End If
    228. Locate 0, 9
    229. LCDWriteChar 255
    230. Wait 250 ms
    231. Locate 0, 8
    232. If time < 10 Then
    233. Print " "
    234. End If
    235. Print time
    236. Wait 250 ms
    237. Loop
    238. Wait 500 ms
    239. Do Until PORTB.5 = 1
    240. If PORTB.6 = 1 Then
    241. ti_minut = ti_minut+1
    242. If ti_minut = 6 Then
    243. ti_minut = 0
    244. End If
    245. Wait 250 ms
    246. End If
    247. Locate 0, 11
    248. LCDWriteChar 255
    249. Wait 250 ms
    250. Locate 0, 11
    251. Print ti_minut
    252. Wait 250 ms
    253. Loop
    254. Wait 500 ms
    255. Do Until PORTB.5 = 1
    256. If PORTB.6 = 1 Then
    257. en_minut = en_minut+1
    258. If en_minut = 10 Then
    259. en_minut = 0
    260. End If
    261. Wait 250 ms
    262. End If
    263. Locate 0, 12
    264. LCDWriteChar 255
    265. Wait 250 ms
    266. Locate 0, 12
    267. Print en_minut
    268. Wait 250 ms
    269. Loop
    270. Wait 500 ms
    271. DagTekst = "Dag "
    272. Do Until PORTB.5 = 1
    273. Wait 250 ms
    274. If PORTB.6 = 1 Then
    275. if dow = 0 then
    276. dow = 6
    277. DagTekst = "Mandag "
    278. Goto Vis_Dag
    279. end if
    280. If dow = 1 Then
    281. dow = 0
    282. DagTekst = "Sondag "
    283. End If
    284. If dow = 2 Then
    285. dow = 1
    286. DagTekst = "Lordag "
    287. End If
    288. If dow = 3 Then
    289. dow = 2
    290. DagTekst = "Fredag "
    291. End If
    292. If dow = 4 Then
    293. dow = 3
    294. DagTekst = "Torsdag"
    295. End If
    296. If dow = 5 Then
    297. dow = 4
    298. DagTekst = "Onsdag "
    299. End If
    300. If dow = 6 Then
    301. dow = 5
    302. DagTekst = "Tirsdag"
    303. End If
    304. End If
    305. Vis_Dag:
    306. Locate 1, 7
    307. LCDWriteChar 255
    308. Wait 250 ms
    309. Locate 1, 7
    310. Print DagTekst
    311. Wait 250 ms
    312. Loop
    313. EPWrite 0, dow ' here it should write the "dow" to eeprom, but always write "8D"
    314. Wait 2 s
    315. Exit Sub
    316. End Sub
    317.  
    318.  
     
  5. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    400
    4
    a couple of codeline more, and it's to big.
    Do i need a bigger PIC, or rewriting of code. ?
     
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    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.
     
  7. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    You defined dow here;
    Dim dow As integer
    is that a 2 byte variable or a 1 byte variable?
     
  8. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    400
    4
    And how ?
    EPWrite is writing to EEProm., it works.
     
  9. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    400
    4
    It's a number 0-1-2-3-4-5-6
     
  10. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    400
    4
    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
     
  11. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Hvad laver du!![​IMG]
    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[​IMG]
    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.
     
  12. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    400
    4
    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/
     
  13. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    400
    4
    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?.
     
  14. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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 ;)
     
  15. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    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
     
    Last edited: Feb 24, 2012
  16. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    400
    4
    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 ?
     
  17. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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?
     
    Last edited: Feb 23, 2012
  18. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    400
    4
    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 ;)
     
  19. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
     
  20. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
     
    Last edited: Feb 23, 2012
Loading...