Shop OBEX P1 Docs P2 Docs Learn Events
DS1302 and BS2SX — Parallax Forums

DS1302 and BS2SX

lrohnlrohn Posts: 33
edited 2004-11-05 06:51 in BASIC Stamp
I am experimenting with the DS1302 and I have been trying to use the code included in the AppKit. on the Parallax website and I just can't seem to get anywhere. I am attaching the code and as you can see there is already a problem with the syntax here:

Initialize:
'Set Time and Date to 05/18/98 - 3:00 PM
'NOTE: Date must be set only once for every power-up of DS1302 chip.
Day = $02 'Monday
Month = $05 'May
Date = $18 '18th
Year = $98 '1998
Hours = $15 '3:00 PM (in 24-hour mode)
Minutes = $00
Seconds = $00
GOSUB SetTimeAndDate

LOOP: ***** HERE IS THE ERROR - 'LOOP' must be proceeded by 'DO' ****
'Read out all date and time values and display them in two formats on
'the debug screen.
GOSUB ReadRTCBurst
DEBUG HOME,"LONG FORMAT DATE AND TIME:",CR
GOSUB PrintLongDate
GOSUB Print12HourTime
DEBUG CR,CR,"SHORT FORMAT DATE AND TIME:",CR
GOSUB PrintShortDate
GOSUB Print24HourTime
GOTO LOOP


So I changed it to:


Initialize:
'Set Time and Date to 05/18/98 - 3:00 PM
'NOTE: Date must be set only once for every power-up of DS1302 chip.
Day = $02 'Monday
Month = $05 'May
Date = $18 '18th
Year = $98 '1998
Hours = $15 '3:00 PM (in 24-hour mode)
Minutes = $00
Seconds = $00
GOSUB SetTimeAndDate

DO 'LOOP: ***** HERE IS THE ERROR - 'LOOP' must be proceeded by 'DO' ****
'Read out all date and time values and display them in two formats on
'the debug screen.
GOSUB ReadRTCBurst
DEBUG HOME,"LONG FORMAT DATE AND TIME:",CR
GOSUB PrintLongDate
GOSUB Print12HourTime
DEBUG CR,CR,"SHORT FORMAT DATE AND TIME:",CR
GOSUB PrintShortDate
GOSUB Print24HourTime
LOOP 'GOTO LOOP

and now the program runs but no time appears on the Debug Terminal. All I get is:

LONG FORMAT DATE AND TIME:
day, 00, 2000
12:00:00 AM

SHORT FORMAT DATE AND TIME:
00/00/00
00:00:00

and nothing else happens or changes.

Can anyone give me any pointers. Attached is the program file.

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-05 06:19
    LOOP is a keyword in PBASIC 2.5. If you want to use older code, you can set the language level to 2.0 like this:

    ' {$PBASIC 2.0}

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • lrohnlrohn Posts: 33
    edited 2004-11-05 06:26
    Hello Jon,

    I prefer to USE PBASIC 2.5 and started the program off with

    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}

    Could it be that the AppKit was written 5/18/98 and has old code in it?

    Well why I was writing this I changed it to {$PBASIC 2.0} and it tokenized successfully. Thanks for your help. Let me play arround with it some more and see what I can come up with.

    Once I get the the hang of it maybe I can write the program to run in PBASIC 2.5.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-05 06:29
    Yes. PBASIC 2.5 wasn't introduced until 2003 -- that is definely older (but still working) code. It should be very easy to update to PBASIC 2.5.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • lrohnlrohn Posts: 33
    edited 2004-11-05 06:33
    Well at least the program tokenizes now. I still get the following on the debug terminal and nothing changes at all:

    LONG FORMAT DATE AND TIME:
    day, 00, 2000
    12:00:00 AM

    SHORT FORMAT DATE AND TIME:
    00/00/00
    00:00:00


    Let me change my pins from 7, 8 and 9 back to how it was originally in the program at 0, 1 and 2. Also I am using a 2k resistor from the stamp pin to the I/O pin (6) of the DS1302. Does this appear to be a good value. I have seen some make reference to a 1k resistor and others to a 10k resistor.

    P.S. it does not make mention to using a resistor in the AppKit for the DS1302.

    Luke
  • lrohnlrohn Posts: 33
    edited 2004-11-05 06:51
    Hello Jon,

    Simply amazing, everything seems to be working fine since I change back to pins 0, 1 and 2. I am using the original code and change the following back to:

    'Set I/O pin states and directions
    OUTS = %0000000000000000 'All logic low
    DIRS = %0000000000000111 'I/O 0,1 and 2 are OUTPUT, rest are INPUT

    prior to this, all the code was the same except I changed the following to:

    'Set I/O pin states and directions
    OUTS = %0000000000000000 'All logic low
    DIRS = %0000001110000000 'I/O 7,8 and 8 are OUTPUT, rest are INPUT

    I also change the wiring on the stamp as necessary to pins 7, 8 and 9.


    Is there anything else in the code that I did not see that would have kept pins 7, 8 and 9 from allowing this to work?

    Thanks for your help.

    Luke
Sign In or Register to comment.