Shop OBEX P1 Docs P2 Docs Learn Events
DS1302 to activate an output — Parallax Forums

DS1302 to activate an output

jcook23jcook23 Posts: 2
edited 2012-04-12 17:29 in BASIC Stamp
Hello, I am doing a project and part of my program is to simply make an output high at a certain time and then low at a certain time. Could it be as easy:

IF (hrs = 10) THEN GOSUB output

output:
DO
HIGH 7
LOOP UNTIL (hrs = 12)
RETURN


Or would the time have to be in hexadecimal?
or am i missing something?

Also. I only need the DS1302 to turn a pin HIGH for a while and then make the same pin go LOW i don't need to display the time at all so it would be nice to get rid of all the extra variables and commands and stuff i have that I'm not actually using from the demo code to free up space. Im planning on using the DEBUGIN demo code to program the time in separately and then running my own program. Its just really hard to tell what I do and do not need in my program. I really only need the current hour, (i dont need minutes, seconds, day, month or year) i would like military mode if it meant i could get rid of am/pm.

Thank you for reading i appreciate your time.

Comments

  • Martin_HMartin_H Posts: 4,051
    edited 2012-04-12 06:22
    I've never used the DS1302, but I've been interested in it and the DS1307. That snippet of code below has some problems which I've noted in the comments.
      ' I don't see any call to get time or a main loop here.
      IF (hrs = 10) THEN
        GOSUB output
      ENDIF
    
      ' If the IF fails then it just runs into the output subroutine!
    output:
      DO
        HIGH 7
        ' You need to call a subroutine to get the DS1302 to load the time into hrs!
      LOOP UNTIL (hrs = 12)
      ' A return call without a GOSUB won't work because there's no return address!
      RETURN
    
  • jcook23jcook23 Posts: 2
    edited 2012-04-12 11:56
    yeah i was just trying to make a quick example to iterate my question. My code looks a lot different then that one. I was mainly just wondering if it will work with simpIe IF THEN statements and if the value of hrs had to be in hexadecimal. Thank you
  • Martin_HMartin_H Posts: 4,051
    edited 2012-04-12 12:10
    If you look in this thread there's a sample for using the time keeping chip:

    http://forums.parallax.com/showthread.php?77867-DS1302-Demo-Code-(Updated)

    Hexadecimal is a display format for numbers which humans use. Internally numbers are always in binary, so if you read an integer from something it is held in binary within the stamp. When your source is translated to byte code constants like 12 are translated to binary for processing by the stamp. So use which ever radix you are comfortable with.
  • bee_manbee_man Posts: 109
    edited 2012-04-12 17:29
    jcook23 wrote: »
    I only need the DS1302 to turn a pin HIGH for a while and then make the same pin go LOW i don't need to display the time at all so it would be nice to get rid of all the extra variables and commands and stuff i have that I'm not actually using from the demo code to free up space.


    Did you or can you use a different device that has a built in alarm. Then just set it and let it change the pin.
Sign In or Register to comment.