Menu

Code for DS1307 ( I2C ) SQW/OUT RS1 RS0

Help
2011-04-23
2013-05-30
  • Dan Ambroise

    Dan Ambroise - 2011-04-23

    To turn on the SQW/OUT from the DS1307 at 1 Hz, I have to write h'01 to register h'07 of the DS1307,( I think ).
    Would anyone know how I would do that using GCBASIC?
    For that matter, how I would do it in .asm
    SDA connected to RA5, SCL connected to RA6, SQW/OUT connected to RA7

     
  • Nobody/Anonymous

    First you have to convert to BCD before writing to the DS1307 registers.  In GCBasic hex is like 0x07 for the control register, and 0x10 to set the SQWE bit.  So send out the control register over I2C and follow up by sending sending the SQWE bit.  Here is a BCD conversion sub, no assembly used:

    Sub BINtoBCD(Decimal)
    'Huns = 0
    Tens = 0 
    Ones = 0 
    DecimalTemp = 0
    'If Decimal >= 100 then
    'DecimalTemp = Decimal / 100
    ' Huns = Decimaltemp * 32 
    IF Decimal >= 10  then  'Decimal is between 10 and 99 
     DecimalTemp = Decimal / 10 
     Tens = DecimalTemp * 16  'Move to high nibble 
     Decimal = Decimal - DecimalTemp * 10 
    End if
    If Decimal >= 0  Then  'Decimal is between 0 and 10 
     Ones = Decimal
    End if
     BCD = Tens + Ones
    End sub
    

    Kent

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.