This will compile
[code:1:4ee1b77c58]$regfile = "m2560def.dat" ' specify the used micro
$crystal = 16000000 ' used crystal frequency
$baud = 115200 ' use baud rate
$hwstack = 200
$swstack = 250
$framesize = 1000
$programmer = 23 ' Define programmer as ARDUINO V2 (using stk500v2 protocol)
'$prog $fc,$c6,$df,$ff ' Lock Bits, Fuse Bits Low, Fuse Bits High, Fuse Bits Extended
$lib "i2c_twi.lbx" ' using hardware I2C/TWI
Config Submode = New
Config Clock = User ' define USER clock, it dims date / time vars
Config Date = Mdy , Separator = / ' configure the date format
Const False = 0
Const True = 1
'-----[Serial Port(s)]--------------------------------------------------------
Config Com1 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Open "com1:" For Binary As #1
'address of ds1307
Const Ds1307w = &HD0 ' Addresses of Ds1307 clock
Const Ds1307r = &HD1
$include "DS1307_newmode.inc"
'dim other needed variables
Dim Weekday As Byte
Dim Lngtick As Long ' one second tick timer counter
Dim Boortcupdate As Boolean ' Flag to allow event to occur
Dim Strtime As String * 8
'
' The USER must have the calls of settime, setdate, getdatetime
' to talk to the USER's hardware
'
Config Sda = Portd.1 ' define pin names, scl and sda pins
Config Scl = Portd.0
Config Twi = 400000 ' CONFIG TWI will ENABLE the TWI master interface, 100KHZ or 400KHZ
I2cinit ' initialize the I2C bus
'-----[ Output Timer ISR for Oscilloscope Check on Porta.0 ]-----------------
Config Porta.0 = Output '
Porta.0 = 1 ' LED off, active lo.
Tickbit Alias Porta.0
'-----[ Setup Timer1 for Tick ISR off system XTAL]----------------------------
' Timer1 is used for Tick counter at 1Hz
Config Timer1 = Timer , Prescale = 1024 , Compare A = Disconnect , Clear Timer = 1
' crytal / prescale / x Hz = Compare1a val needed
' 16000000 / 1024 / 1(Hz) = 15625
Compare1a = 15625
On Compare1a T1_tickcounter_isr ' Define ISR Entry Point
Enable Timer1
Enable Compare1a
Waitms 5
'
Enable Interrupts ' Using a timer to generate 1 second ISR interval
Print #1 , "DS1307"
'
' Clear Vars
'
Lngtick = 0
Boortcupdate = False
Date$ = "12/02/14"
Time$ = "20:03:00"
'
Do ' Main Loop
If Boortcupdate = True Then
Boortcupdate = False
Call Getdatetime() ' read from RTC
Strtime = Time(_sec) ' use system vars to create time string
'strDate = Date(_day) ' use system vars to create date string
Print #1 , "Date : " ; _month ; "/" ; _day ; "/20" ; _year ; " Time : " ; Strtime
End If
Loop
End
'------[ Timer ISR routine ]----------------------------------------------------
T1_tickcounter_isr:
Incr Lngtick ' inc event counter
Toggle Tickbit ' allow visual on scope
Boortcupdate = True ' every tick, allow DS1307 RTC to read date/time
Return
[/code:1:4ee1b77c58]
[code:1:4ee1b77c58]$nocompile
Setdate: ' need to create a label for BASCOM funtions to hook in to
_day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 4 ' starting address in 1307
I2cwbyte _day ' Send Data to SECONDS
I2cwbyte _month ' MINUTES
I2cwbyte _year ' Hours
I2cstop
Print #1 , "SetDate completed"
Return
Settime: ' need to create a label for BASCOM funtions to hook in to
_sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 0 ' starting address in 1307
I2cwbyte _sec ' Send Data to SECONDS
I2cwbyte _min ' MINUTES
I2cwbyte _hour ' Hours
I2cstop
Print #1 , "SetTime completed"
Return
Sub Getdatetime()
'set PORTA.0
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 0 ' start address in 1307
I2cstart ' Generate start code
I2cwbyte Ds1307r ' send address
I2crbyte _sec , Ack
I2crbyte _min , Ack ' MINUTES
I2crbyte _hour , Ack ' Hours
I2crbyte Weekday , Ack ' Day of Week
I2crbyte _day , Ack ' Day of Month
I2crbyte _month , Ack ' Month of Year
I2crbyte _year , Nack ' Year
I2cstop
_sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
_day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year)
'reset PORTA.0
End Sub
Some order must be saved. You , for example, cannot use Print #1 before You declare/describe Print #1 and first User Clock must be declared for create variables used in subs. ( I think ) :D But now everything should work.
[/code:1:4ee1b77c58]
↧