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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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:
Kent