Shop OBEX P1 Docs P2 Docs Learn Events
Switches to change time and date on LCD — Parallax Forums

Switches to change time and date on LCD

ShaliniShalini Posts: 59
edited 2013-04-12 19:30 in Propeller 1
Hello everyone!!

It's great that I got the time and date to display on JHD162A 16x2 LCD. The clock now running in 12hr-mode. Now I want to use 6 pushbuttons to change the time and date on the LCD...Can anybody help?? I've included the codes for you to take a look...

Thanks in advance

Comments

  • mindrobotsmindrobots Posts: 6,506
    edited 2013-04-05 08:12
    Have you read the data sheet for the RTC chip you are using? There is usually a register bit or command to indicate the 12/24 hour mode it should use. Once you know that, you can look at the code and find where it sets up the clock chip.

    You should do some of the work on YOUR project after all!
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2013-04-05 09:50
    The code I gave you in this message thread let's you set the RTC to 12 or 24 hr mode using the driver in the attachment.

    It seems like you want someone to develop your entire project for you with little understanding and work from you.

    Study the code people have provided if you really want to learn...
  • ShaliniShalini Posts: 59
    edited 2013-04-05 10:11
    The code I gave you in this message thread let's you set the RTC to 12 or 24 hr mode

    It seems like you want someone to develop your entire project for you with little understanding and work from you.

    Study the code people have provided if you really want to learn...

    sorry about that, yes i forgot to cancel this post...yes it is working as both modes...thank you

    now I want to add 6 switches to change the time and date using the switches instead of changing them in the code and downloading them each time I want to update the rtc with new data. And yes I'm doing my best to learn the code, but I also have to get the project to work in the next 2 weeks, so please do bare with me.... I'm learning spin only last 3 weeks and I'm not upto the level to do my own code.
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2013-04-05 10:22
    Shalini wrote: »
    ...
    And yes I'm doing my best to learn the code, but I also have to get the project to work in the next 2 weeks, so please do bare with me.... I'm learning spin only last 3 weeks and I'm not upto the level to do my own code.

    I hate to say it, but if you are not able to do some of the coding yourself, what's the point??
  • ShaliniShalini Posts: 59
    edited 2013-04-05 10:30
    I hate to say it, but if you are not able to do some of the coding yourself, what's the point??

    I can do some basic coding like writing strings, declaring variables and stuff...that's it. This is the last help I need, please help me!!!
  • ChrisGaddChrisGadd Posts: 310
    edited 2013-04-05 18:30
    If your only intention is to get a clock on a LCD and not have to deal with any programming, then fine, here ya go. It's a slightly modified version of the first program I gave you to try. It only uses two buttons to set the time, the same as every wristwatch and digital alarm clock I ever had. What would six buttons be used for? Note: it uses my version of the LCD driver which hasn't been successfully tested on your setup. If it doesn't work, I trust by now you can figure out how to modify it to use the 8x2_4bit one.

    If you do want to learn how to program microcontrollers, then like others have said, a good place to start is by reading the fine manual. Spending only a matter of minutes going through spin lesson 1 of the spin programming tutorial available through the help menu (F1) for the Propeller tool would've made clear how objects are loaded into the Propeller: how top object files load included objects, which would've saved quite a bit of time earlier. The DS1307 datasheet has an entire paragraph describing how to set 12-hour mode. And there are countless examples of how to interface a pushbutton switch to a program.
  • ShaliniShalini Posts: 59
    edited 2013-04-06 09:49
    ChrisGadd wrote: »
    If your only intention is to get a clock on a LCD and not have to deal with any programming, then fine, here ya go. It's a slightly modified version of the first program I gave you to try. It only uses two buttons to set the time, the same as every wristwatch and digital alarm clock I ever had. What would six buttons be used for? Note: it uses my version of the LCD driver which hasn't been successfully tested on your setup. If it doesn't work, I trust by now you can figure out how to modify it to use the 8x2_4bit one.

    If you do want to learn how to program microcontrollers, then like others have said, a good place to start is by reading the fine manual. Spending only a matter of minutes going through spin lesson 1 of the spin programming tutorial available through the help menu (F1) for the Propeller tool would've made clear how objects are loaded into the Propeller: how top object files load included objects, which would've saved quite a bit of time earlier. The DS1307 datasheet has an entire paragraph describing how to set 12-hour mode. And there are countless examples of how to interface a pushbutton switch to a program.

    Ok I'll work on the code with 2 switches. I'm going to look all the examples and if I have any critical issues I'll contact.

    thanks
  • ShaliniShalini Posts: 59
    edited 2013-04-07 10:06
    ChrisGadd wrote: »
    If your only intention is to get a clock on a LCD and not have to deal with any programming, then fine, here ya go. It's a slightly modified version of the first program I gave you to try. It only uses two buttons to set the time, the same as every wristwatch and digital alarm clock I ever had. What would six buttons be used for? Note: it uses my version of the LCD driver which hasn't been successfully tested on your setup. If it doesn't work, I trust by now you can figure out how to modify it to use the 8x2_4bit one.

    If you do want to learn how to program microcontrollers, then like others have said, a good place to start is by reading the fine manual. Spending only a matter of minutes going through spin lesson 1 of the spin programming tutorial available through the help menu (F1) for the Propeller tool would've made clear how objects are loaded into the Propeller: how top object files load included objects, which would've saved quite a bit of time earlier. The DS1307 datasheet has an entire paragraph describing how to set 12-hour mode. And there are countless examples of how to interface a pushbutton switch to a program.

    I was looking at the LCD clock 2 program u had given...can you please explain what these lines below do...

    case field
    0:
    if ++buffer[date] & $0F == $0A
    buffer[date] := (buffer[date] & $F0) + $10
    if buffer[date] > $31
    buffer[date] := 1
  • ChrisGaddChrisGadd Posts: 310
    edited 2013-04-07 11:20
    For setting the time, I made each part of the date and time its own field. Date is field 0, month is field 1, year is 2, hours 3, minutes 4, and for this version am/pm is 5, so when switch 2 is pressed, this section of code runs when the value of 'field' is 0. The other lines deal with incrementing the date and restricting its value.
        if not ina[s2]                                       ' run this section of code when switch 2 is pressed                        
          I2C.read_page(I2C#RTC,Seconds,@buffer,7)           ' read the current date and time from the clock
          case field                                         ' determine which field to operate on
            0:                                               '  If field == 0, operate on date
              if ++buffer[date] & $0F == $0A                 '  Increment the date, and if the 1's column of date contains 10 ($A)
                buffer[date] := (buffer[date] & $F0) + $10   '    then clear the one's column and add to the tens column
              if buffer[date] > $31                          '  If the date exceeds 31...
                buffer[date] := 1                            '    then reset the date to 1
    
    It's necessary to increment like that since the DS1307 stores date and time as binary-coded decimal values, where bits 7 through 4 in a byte contain the value of the ten's column, and bits 3 through 0 contain the value of the 1's column. In hexadecimal, adding $01 to $09 gives you $0A, which is meaningless to the DS1307. Instead, that section of code makes $01 + $09 = $10.
    This program does not check for invalid dates; February 31st is perfectly valid as far as it's concerned, though according to the clock datasheet 'Illogical time and date entries result in undefined operation,' so that's on the user.
    The month, year, and minutes fields operate the same as the date field, hours is made more complicated as it has to toggle the am/pm bit when going from 11 to 12, and preserve it otherwise, as well as preserving the 12-hour bit.
  • ShaliniShalini Posts: 59
    edited 2013-04-07 11:48
    ChrisGadd wrote: »
    For setting the time, I made each part of the date and time its own field. Date is field 0, month is field 1, year is 2, hours 3, minutes 4, and for this version am/pm is 5, so when switch 2 is pressed, this section of code runs when the value of 'field' is 0. The other lines deal with incrementing the date and restricting its value.
        if not ina[s2]                                       ' run this section of code when switch 2 is pressed                        
          I2C.read_page(I2C#RTC,Seconds,@buffer,7)           ' read the current date and time from the clock
          case field                                         ' determine which field to operate on
            0:                                               '  If field == 0, operate on date
              if ++buffer[date] & $0F == $0A                 '  Increment the date, and if the 1's column of date contains 10 ($A)
                buffer[date] := (buffer[date] & $F0) + $10   '    then clear the one's column and add to the tens column
              if buffer[date] > $31                          '  If the date exceeds 31...
                buffer[date] := 1                            '    then reset the date to 1
    
    It's necessary to increment like that since the DS1307 stores date and time as binary-coded decimal values, where bits 7 through 4 in a byte contain the value of the ten's column, and bits 3 through 0 contain the value of the 1's column. In hexadecimal, adding $01 to $09 gives you $0A, which is meaningless to the DS1307. Instead, that section of code makes $01 + $09 = $10.
    This program does not check for invalid dates; February 31st is perfectly valid as far as it's concerned, though according to the clock datasheet 'Illogical time and date entries result in undefined operation,' so that's on the user.
    The month, year, and minutes fields operate the same as the date field, hours is made more complicated as it has to toggle the am/pm bit when going from 11 to 12, and preserve it otherwise, as well as preserving the 12-hour bit.

    ok, thank you I get it now.
  • ShaliniShalini Posts: 59
    edited 2013-04-07 12:04
    what does ^= assignment operator mean?
  • ShaliniShalini Posts: 59
    edited 2013-04-07 19:31
    I've included the below lines in the program you had previously attached, so that the LCD displays the time and date given in the program first and then be able to use S1 and S2, but it's not giving any display I don't know why....Could you help me out???
    repeat
    waitcnt(cnt + clkfreq)
    I2C.read_page(I2C#RTC,Seconds,@buffer,7)
    LCD.move(1,1)
    LCD.str(string("DATE: "))
    LCD.hex(buffer[date],2)
    LCD.str(string("/"))
    LCD.hex(buffer[month],2)
    LCD.str(string("/"))
    LCD.hex(buffer[year],2)
    LCD.move(1,2)

    LCD.str(string("TIME: "))
    LCD.hex(buffer[hours],2)
    LCD.str(string(":"))
    LCD.hex(buffer[minutes],2)
    LCD.str(string(":"))
    LCD.hex(buffer[seconds],2)
    LCD.str(string(" "))
  • ShaliniShalini Posts: 59
    edited 2013-04-08 17:09
    Shalini wrote: »
    I've included the below lines in the program you had previously attached, so that the LCD displays the time and date given in the program first and then be able to use S1 and S2, but it's not giving any display I don't know why....Could you help me out???
    repeat
    waitcnt(cnt + clkfreq)
    I2C.read_page(I2C#RTC,Seconds,@buffer,7)
    LCD.move(1,1)
    LCD.str(string("DATE: "))
    LCD.hex(buffer[date],2)
    LCD.str(string("/"))
    LCD.hex(buffer[month],2)
    LCD.str(string("/"))
    LCD.hex(buffer[year],2)
    LCD.move(1,2)

    LCD.str(string("TIME: "))
    LCD.hex(buffer[hours],2)
    LCD.str(string(":"))
    LCD.hex(buffer[minutes],2)
    LCD.str(string(":"))
    LCD.hex(buffer[seconds],2)
    LCD.str(string(" "))

    help please!!!
  • AndroidAndroid Posts: 82
    edited 2013-04-08 17:23
    If you want to learn about spin coding you should try out the Programming and Customizing your propeller book it is very helpful! I am also new to spin and havent worked to much with LCD's but the program looks fine you should look at your wiring and hookup.Good Luck!!
    -Android
  • ChrisGaddChrisGadd Posts: 310
    edited 2013-04-08 17:43
    It isn't giving any display? I ran your attached program on my hardware without any problem. Be sure that you're completely powering the LCD down between reloads; the driver that you're using doesn't perform any initialization, and it can get stuck if commanded into 4-bit mode when it's already in 4-bit mode. Powering the LCD off causes the LCD to restart in 8-bit mode. Other than that, check the wiring. Also try running a previous copy of the program that you know was working. Every time you make a significant change to a working program, save the new version under a different name. That way if you break something, you can just restore from a previous copy. By the end of a project I'll usually have a dozen nearly identical copies of a program with only small incremental changes between them.
  • ShaliniShalini Posts: 59
    edited 2013-04-08 19:48
    really!!! so why isn't it running on mine??
  • ShaliniShalini Posts: 59
    edited 2013-04-09 05:47
    I tried running the one Ron Czapala provided (without the switches) and it works prefectly fine, but when I run this one the display is cleared and nothing shows up....If I keep reloading the program 2 or 3 times, then it sends some random characters to the display, but later gets fixed once I power off the LCD and start over. Here's the schematic of the circuit.
    Clock schematic.jpg
    1024 x 886 - 46K
  • ShaliniShalini Posts: 59
    edited 2013-04-09 16:56
    anybody help....I've attached my circuit schematic in my previous post
  • ChrisGaddChrisGadd Posts: 310
    edited 2013-04-09 19:51
    I don't see anything that'd be causing problems... the 4.7K current limiters on the LCD data lines are probably unnecessary, though I doubt they're hurting anything. For switches, typically you want a pull-up resistor to 3.3V and a switch to ground, rather than pulling down to ground and switching 3.3V - reduces the risk of something bad© happening if you accidentally output a low while pressing the switch. I don't see it as an issue for why the program won't display, however. I thought your display was connected to pins 20 through 26, so that could be an issue if you aren't making all of the re-assignments... though since the display is working with other routines, I dunno.

    Alright, you say that LCD clock - basic from the first post works? If that's the case, then this one should work. The same as LCD clock - basic, with the display format you want
    And if that one works, this one should also work. The same as LCD clock - basic 2, with the display routine moved to a separate method
    And if that one works, this one should work, too. The same as LCD clock - basic 3, with some switches connected to IO pins 20 through 25, as per your schematic, that display simple messages.
    And finally, if all of those work, this one had better work. The same as LCD clock - basic 4, except now each switch increments one field of the clock.

    Be sure to use the same LCD_8x2_4bit driver that you've been having success with for these.
  • ShaliniShalini Posts: 59
    edited 2013-04-10 17:04
    Sorry i uploaded the old schematic so it was showing the LCD data lines connected to p13 to p16....that shouldn't make any difference i just changed the pin assignments in the programs. But I changed the switch connections as you suggested earlier. Now I know LCD clock - basic 2, 3, and 4 are all working. When I download LCD clock - basic 5, the six fields were changing on their own...yes they are incrementing, but not using the switches. Their not following their respective ranges. For example, the month should increment upto 12 then start over, but here it keeps going upto 20, 30... Switches are not working in this program...I don't know why?? I tried LCD clock - basic 4 and it displayed the respective strings when each switch was pressed. Thanks for the help though, I going to try work these out and I'll get back to you if I need any help....and I've also attached the new schematic with all the corrections made, you can take a look at it.
    1024 x 886 - 46K
  • ShaliniShalini Posts: 59
    edited 2013-04-12 15:30
    just want to make sure what conversion are you using for hours because you're giving decimal value of 50 for hours in PUB main and the lcd displays 10....
  • garyggaryg Posts: 420
    edited 2013-04-12 16:06
    It sounds like you are chasing your tail.
    This happens to me very frequently.
    What I do is:
    1 -Check my physical circuit yet again.
    2 -Check my battery or power supply again.
    3 - Load an early version of the program that worked as I had expected.
    4 - If my early program worked, then I will progressivly load later versions until I find the one that does not work.
    5 - I compare the last program that worked against the one that does not work.

    Usually that leads me to a solution.

    You may already do this type of thing, but sometimes it's difficult to go through the steps because
    You've already been there.

    That's just my two cents worth.
    I hope it helps you on your quest.
  • ShaliniShalini Posts: 59
    edited 2013-04-12 17:36
    garyg wrote: »
    It sounds like you are chasing your tail.
    This happens to me very frequently.
    What I do is:
    1 -Check my physical circuit yet again.
    2 -Check my battery or power supply again.
    3 - Load an early version of the program that worked as I had expected.
    4 - If my early program worked, then I will progressivly load later versions until I find the one that does not work.
    5 - I compare the last program that worked against the one that does not work.

    Usually that leads me to a solution.

    You may already do this type of thing, but sometimes it's difficult to go through the steps because
    You've already been there.

    That's just my two cents worth.
    I hope it helps you on your quest.
    garyg wrote: »

    lol...I agree with you garyg!! These are the exact steps I've been taking since the beginning....I have my multi-meter connected to my circuit all the time and the voltages are prefectly falling into the ranges mentioned in datasheets. I've downloaded so many programs so far that I've completely used up an eeprom.... in the earlier program which was working if I declared hours in binary then it would convert to hex and then display it on the LCD, but here I'm able to understand how the LCD is displaying 10 for a binary value of 01010000 = 80....any help???
  • ChrisGaddChrisGadd Posts: 310
    edited 2013-04-12 18:21
    I presume you mean this section:
      waitcnt(clkfreq + cnt)                                                        '   ┌1 = 12-hour mode / 0 = 24-hour mode
                                                                                    '   │┌1 = pm / 0 = am
      buffer[seconds] := $00                                                        '   ││┌10's hours
      buffer[minutes] := $51                                                        '   │││ ┌┬┬┬1's hours
    ' buffer[hours] := %0010_0011        ' 23                                       '    
      buffer[hours] := %0101_0000        ' 10am                                     ' %0101_0000
    
    I gave you the answer in the comments. And I pointed you toward the datasheet, wherein it says:
    The DS1307 can be run in either 12-hour or 24-hour mode. Bit 6 of the hours register is defined as the 12-hour or 24-hour mode-select bit. When high, the 12-hour mode is selected. In the 12-hour mode, bit 5 is the AM/PM bit with logic high being PM. In the 24-hour mode, bit 5 is the second 10-hour bit (20 to 23 hours). The hours value must be re-entered whenever the 12/24-hour mode bit is changed.
  • ShaliniShalini Posts: 59
    edited 2013-04-12 19:30
    ok, now I understand. thanks.
Sign In or Register to comment.