Shop OBEX P1 Docs P2 Docs Learn Events
detecting if DS1302 is programmed or not — Parallax Forums

detecting if DS1302 is programmed or not

hmlittle59hmlittle59 Posts: 404
edited 2007-09-17 15:32 in BASIC Stamp
Hello everyone,

I've ask this before can not still figure it out. I still can not get the Temp.bit8 concept down. But why would this routine not work? Detection of the Clock not being programmed. With the clock reset, it seems to work, but is it correct? thanks for any help


reg = CWPr ' Initialize DS1302
ioByte = WPr0 ' Clear Write Protect
GOSUB RTC_Out ' Send Command

GOSUB Get_Time
IF (secs <> $80) THEN start 'Clock is programmed and working'

DEBUG "STOP": ' Clock needs programming
PAUSE 3000
stop

Start:
hrs = $00
mins = $00
secs = $00

Howard

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-09-17 00:15
    Is " <> " a proper expression?· You're trying to use that for "not equal to."· Suggest you conditionally branch another way.

    e.g. --
    Check:
     IF (secs = $80) THEN Unprogrammed
      hrs = $00
      mins = $00
      secs = $00
      GOTO Check
     
    Unprogrammed:
     DEBUG "Unprogrammed": ' Clock needs programming
     PAUSE 3000
     STOP
    
    


    ·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-09-17 15:32
    By not checking the specific bit it’s possible for the register to not contain $80 and have that bit still set meaning your program could fail. I would be checking secs.bit7 for a 1.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.