Shop OBEX P1 Docs P2 Docs Learn Events
555 timers and counters - Page 2 — Parallax Forums

555 timers and counters

2»

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-02-06 15:22
    Matthew,

    ·· The % symbol indicates that the data following it is binary, hence 1's and 0's.· The backslash tells the SHIFTOUT command how many bits to SHIFTOUT.· This information can be found in the online help file under SHIFTOUT.· This also explains·LSBFIRST and LSBPRE.

    As a side-note...You won't be using this exact command if you want to read an individual register.

    And no, you probably won't just be able to replace BrstReg with SecReg...That code you posted has binary values that were being used to construct a command byte (8 bits).· You already have this value in the code from the StampWorks manual.· I would use that code as a template...Not the code you posted...Good luck!



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --==<{Chris}>==--
  • MatthewMatthew Posts: 200
    edited 2005-02-11 04:51
    Okay, so I finally got something and edited it to only display seconds. Now why does it skip some numbers when I display the seconds?

    'RTC Test1.bs2
    '2/10/2005
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    'Define I/O pins and RTC variables
    Clk CON 0
    Dta CON 1
    RTCCS CON 2
    RTCCmd VAR Byte
    Value VAR Byte
    Seconds VAR Byte
    Idx VAR Byte

    'Define RTC Command Constants
    SecReg CON %00000
    CtrlReg CON %00111

    '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

    Initialize:
    'Set Time to 0 seconds
    'NOTE: Date must be set only once for every power-up of DS1302 chip.
    Seconds = $00
    GOSUB SetTimeAndDate

    LOOPer:
    'Read out all date and time values and display them in two formats on
    'the debug screen.
    GOSUB ReadRTCBurst
    DEBUG HOME,"seconds: ", DEC2 seconds
    GOTO LOOPer


    '==================== DS1302 Real-Time Clock Subroutines ===================

    WriteRTCRAM:
    'Write to DS1302 RAM Register
    HIGH RTCCS
    SHIFTOUT Dta, Clk, LSBFIRST, [noparse][[/noparse]%0\1,RTCCmd\5,%11\2,Value]
    LOW RTCCS
    RETURN

    WriteRTC:
    'Write to DS1302
    HIGH RTCCS
    SHIFTOUT Dta, Clk, LSBFIRST, [noparse][[/noparse]%0\1,RTCCmd\5,%10\2,Value]
    LOW RTCCS
    RETURN

    ReadRTCBurst:
    'Read all time-keeping registers in one burst
    HIGH RTCCS
    SHIFTOUT DTA, Clk, LSBFIRST, [noparse][[/noparse]%1\1,SecReg\5,%10\2]
    SHIFTIN DTA, Clk, LSBPRE, [noparse][[/noparse]Seconds]
    LOW RTCCS
    RETURN

    ReadRTCRAM:
    'Read DS1302 RAM Register
    HIGH RTCCS
    SHIFTOUT DTA, Clk, LSBFIRST, [noparse][[/noparse]%1\1,RTCCmd\5,%11\2]
    SHIFTIN DTA, Clk, LSBPRE, [noparse][[/noparse]Value]
    LOW RTCCS
    RETURN

    SetTimeAndDate:
    'Write time values into all time-keeping registers, being sure to clear
    'the write-protect bit in CtrlReg before the write, and set the
    'write-protect bit after the write
    FOR Idx = 0 TO 8
    LOOKUP Idx,[noparse][[/noparse]0,Seconds,128],Value
    LOOKUP Idx,[noparse][[/noparse]CtrlReg, SecReg, CtrlReg],RTCCmd
    GOSUB WriteRTC
    NEXT
    RETURN


    Thanks,
    Matthew
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-02-11 13:51
    Matthew,

    ·· I'm not where I can try your code out for a few days...What exactly is happening?· What are you seeing on the display and which numbers appear to be skipped?



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --==<{Chris}>==--
  • MatthewMatthew Posts: 200
    edited 2005-02-12 01:04
    Two major problems with the debug screen:

    1) the numbers go from 00-89, instead of 00-60
    2) it skips the numbers 10-15, 26-31, 42-47, 58-63, 74-79, 90-99

    Thanks,
    Matthew
  • MatthewMatthew Posts: 200
    edited 2005-02-12 06:06
    AH HA! Found the problem. In the debug comand, I used "DEC2 Seconds", it it supposed to be "HEX2 Seconds"

    Yipee!!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-02-12 17:19
    Matthew said...
    AH HA! Found the problem. In the debug comand, I used "DEC2 Seconds", it it supposed to be "HEX2 Seconds"
    Yipee!!
    I was going to say...Those are the ranges that would affected by that.· I'm glad you got it working.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --==<{Chris}>==--
  • MatthewMatthew Posts: 200
    edited 2005-02-12 17:37
    Thanks Chris for all of your help!
Sign In or Register to comment.