Shop OBEX P1 Docs P2 Docs Learn Events
Alarm clock DS1302 + Serial LCD — Parallax Forums

Alarm clock DS1302 + Serial LCD

WhatWhat Posts: 23
edited 2008-06-26 22:38 in BASIC Stamp
Hello everyone, me again lol.gif

I bought the Serial LCD with backlit, its amazing.
I pickeup the example from stampworks where they build a clock with 4 push buttons and i adapted it to display hour and day in the LCD. Its uses one button for minutes, one for hours and one for the day.
I want to use the fourth button to acces into an alarm mode and using the same hour and minute button i can set an alarm adn after alarm is done, use the same fourth button to go back into the time mode. Here is where i'm stucked, i need to set this up and keep the time runing in the clock. I have no problem setting a LED or a buzz when the time and the alarm time are equal.

I hope you can understand what i want, my english isn't perfect.

I'm trying to make it show the temperature too, but i almost got it. I think i can do the temp code works.

Any code help its really welcome.

Thanks everyone.

Post Edited (What) : 6/24/2008 5:47:39 PM GMT

Comments

  • WhatWhat Posts: 23
    edited 2008-06-23 15:58
    someone?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-06-23 20:46
    What is your question?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • WhatWhat Posts: 23
    edited 2008-06-23 21:03
    Its posible to make the fourth button to get into an alarm mode and use the same hour and minute buttons to set it?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-06-23 21:12
    Well yes, the code would simply have to be adjusted to accomodate that. But it could certainly be done.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • WhatWhat Posts: 23
    edited 2008-06-24 06:01
    Well, here i'm again.
    I've been working really hard and i had some progress, and now have a little problems with serout and LCD.

    Problem 1:
    As you can see on the picture attached (sorry for bad quality) i have the time, day and temp in ºC on line 1. Then when i press a button the program must show just the words "d/m/y" but when i hit the button, the program also show the actual day after the "y" ( i mean its show d/n/yDO").

    I don't know why this its happening, any idea?

    Problem 2:
    I think that this lines get the time and day from DS1302, how can i get the date from it?

    Set_Time:                                                   ' write data with burst mode
    HIGH CS1302
    SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]WrBurst]
    SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]secs, mins, hrs, 0, 0, day, 0, 0]
    LOW CS1302
    RETURN
    
    Get_Time:                                                   ' read data with burst mode
    HIGH CS1302
    SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdBurst]
    SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]secs, mins, hrs, day, day, day]
    LOW CS1302
    rawTime = ((hrs10 & %11) * 600) + (hrs01 * 60)
    rawTime = rawTime + (mins10 * 10) + mins01
    RETURN
    





    Thanks all for your time and help.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-06-24 14:33
    There are quite a few problems with your code…First of all I don’t think you’re using the DS1302 Demo Code as suggested in another thread. Your Get_Time routine looks like the one from the Stamp Works kit which does not deal with the date at all. It should look like this:
    Get_Time:                               ' DS1302 Burst Read
      HIGH CS1302                           ' Select DS1302
      SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdBurst]
      SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]secs, mins, hrs, date, month, day, year]
      LOW CS1302                            ' Deselect DS1302
      RETURN
    

    In your case the day, month and year are all lost into one variable (only the last value is valid).

    Also, the reason your code shows d/m/y is because you have a line of code sending that to the display. Your code is doing exactly what it programmed to. I would recommend checking out the DS1302 Demo Code at the following link.

    http://forums.parallax.com/showthread.php?p=531080

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • WhatWhat Posts: 23
    edited 2008-06-24 18:53
    Thanks for your help Chris, i think i have some progress, now i'm trying to show and setup date in the LCD with the same 4 buttons.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-06-24 18:55
    Here I have attached code that takes the Date/Time from the DS1302 and displays it on the LCD.

    http://forums.parallax.com/showthread.php?p=733345

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • WhatWhat Posts: 23
    edited 2008-06-24 19:06
    Yes i've been studing that code, but the problem is that i have to set the date from push buttons no from debug console. using one to enter a "date mode" where using the same buttons for the set the time, but now they should work to set the date and the go back to normal mode
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-06-24 19:09
    The code wasn’t designed to do that. It is an example of how to get the data from the DS1302 and format it to the LCD display. There is most likely no code floating around that does exactly what you want. So you need to write a custom program or customize existing code. I tend to do a little of both by drawing from examples. That is what I am recommending.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • WhatWhat Posts: 23
    edited 2008-06-26 21:22
    Hello everyone once again.

    With a lot of help i have my code runing perfect. The program read the time, date, temp, and alarm time from the debug console, then it shows the information in the LCD. The alarm its working perfect too.
    Then i found a code name EX30. Its a clock code using 4 push buttons but they only works on setting up the time. I tried to adapt the button code from this to my own code, but i always get this error: "Out of Variable space".
    Obviously i think its because i have too many VAR defined, but if that is the case, it should be impossible to make it works keeping date, alarm and temperature? If i remove some variables it means to no show temp, date, etc?

    Thanks for your time.
  • MSDTechMSDTech Posts: 342
    edited 2008-06-26 21:55
    What you will need to do to overcome the limited number of variable is to re-use the same memory location for more than one of the variables. To do this, review your code and find variables that are only used in a specific sub-routine. If the code does not require the variable in any other sub-routine, it is a candidate for reuse. To keep from having to re-write the entire code, you define the variables to use the same ram location.
    E. G.
    Var1 var byte
    Var2 var Var1
    With this definition, both Var1 and Var2 are assigned to the same RAM location. As long as they are both used in different sections of the code and you set both of them in their respective sub-routines, then the RAM space can be re-used.
    One other option you might consider, is that the DS1302 has a small amount of RAM available. It can't be used for variables, but it can be used to build the data string you are sending to the LCD. You collect the data in RAM and then using a single byte variable, write it to the LCD on piece at a time.
    I haven't used the serial LCD, but have been able to send long strings of characters to other serial devices using this technique.
  • WhatWhat Posts: 23
    edited 2008-06-26 22:38
    Thanks MSDTech, i'll try to reuse variables.

    I have another question, i need to make something like this (isn't a code, just like a pseudocode of what i'm trying)


    IF (button1=1) GOTO Subrutine   ' I don't know if i have to use IF or When?
    ELSE
    GOTO Nothing ' I need to do nothing untill i press button1
    
    Subrutine:
    ' i need to stay in this subtutine untill i press the button1 again
    IF (button1=1) GOTO Subrutine2
    Else 
    var1 = var1 + button2
    var2 = var2 + button3
    var3 = var 3 + button4
    'its like a bedroom alarm clock where you have the same button to go to hour mode, alarm mode or date mode
    
    Subrutine2:
    ' here i need if i hit button1 go back to main but the others buttons works like to set something
    IF (button1=1) GOTO Main
    Else
    var4 = var4 + button2
    var5 = var5 + button3
    var6 = var6 + button4
    



    I hope someone can understand what i'm trying to do. smile.gif

    Thanks.
Sign In or Register to comment.