$regfile = "m32def.dat"
$crystal = 12000000
$baud = 19200
$lib "mcsbyte.lbx"
$lib "ds1307clock.lib"
$framesize = 16
$hwstack = 24
$swstack = 16
Config Porta.0 = Output
Config Porta.1 = Output
Config Porta.2 = Output
Rst Alias Porta.1
Ck Alias Porta.0
Dat Alias Porta.2
Dim A As Byte , B As Byte , C As Byte , D As Byte ,
Menit As Integer ,Jam As Integer
Menit = 0
Config Portd.2 = Output
Config Portd.3 = Output
Config Portd.4 = Output
Config Porta.7 = Output
Set Portd.2
Set Portd.3
Set Portd.4
Set Porta.7
Config Pind.5 = Output
Config Pind.6 = Output
Config Pind.7 = Output
Set Portd.5
Set Portd.6
Set Portd.7
Setting Alias Pind.5
Up Alias Pind.6
Down Alias Pind.7
Config Portc.2 = Output
Config Portc.3 = Output
Config Portc.4 = Output
Config Portc.5 = Output
Config Portc.6 = Output
Config Portc.7 = Output
Reset Portc.2
Reset Portc.3
Reset Portc.4
Reset Portc.5
Reset Portc.6
Reset Portc.7
Declare Sub Cocok
Config Sda = Portc.1
Config Scl = Portc.0
Config Portb = Output
Const Ds1307w = &HD0
Const Ds1307r = &HD1
Config Clock = User
Dim Weekday As Byte
Dim Jam_puluhan As Byte
Dim Jam_satuan As Byte , Buff2 As Byte
Dim Menit_puluhan As Byte
Dim Menit_satuan As Byte , Buff As Byte
Dim I As Byte
Dim Stat As Bit
Print "DS1307" '
Time$ = "03:46:00"
Date$ = "05/11/10"
'Kedua baris distas digunakan untuk menyetting nilai awal
dari Jam dan Tanggal pada IC DS1307
Reset Stat
Utama:
Do
Print Time$
Set Dat
A = _sec
Menit = _min
Jam = _hour
Menit_puluhan = _min / 10
Buff = Menit_puluhan * 10
Menit_satuan = _min - Buff
Jam_puluhan = _hour / 10
Buff2 = Jam_puluhan * 10
Jam_satuan = _hour - Buff2
If _sec = 0 Then
Reset Rst
Set Rst
Reset Ck
Set Ck
End If
If Setting = 0 Then
Bitwait Setting , Set
Gosub Cocok
End If
Portb = Lookup(Menit_puluhan , Data7a)
Set Portd.3
Reset Porta.7
Waitus 3000
Portb = Lookup(Menit_satuan , Data7)
Set Porta.7
Reset Portd.4
Waitus 3000
Portb = Lookup(Jam_satuan , Data7)
Set Portd.4
Reset Portd.2
Waitus 3000
Portb = Lookup(Jam_puluhan , Data7a)
Set Portd.2
Reset Portd.3
Waitus 3000
Portb = Lookup(Menit_puluhan , Data7)
Reset Portd.0
Set Portd.3
If Stat = 0 Then
Set Dat
Reset Rst
Set Rst
For B = 0 To A
Reset Ck
Set Ck
Next
End If
If A <> D And Stat = 1 Then
Reset Ck
Set Ck
End If
Set Stat
D = A
Loop
End
Data7:
Data &B11000000 , &B11111001 , &B10100100 ,
&B10110000 , &B10011001 , &B10010010 , &B10000010 ,
&B11111000 , &B10000000 , &B10010000
Data7a:
Data &B11000000 , &B11111001 , &B10100100 ,
&B10110000 , &B10011001 , &B10010010 , &B10000010 ,
&B11111000 , &B10000000 , &B10010000
Data1:
Data &B11111110 , &B11111101 , &B11111011 , &B11110111 , &B11101111
Getdatetime:
I2cstart
I2cwbyte Ds1307w
I2cwbyte 0
I2cstart
I2cwbyte Ds1307r
I2crbyte _sec , Ack
I2crbyte _min , Ack
I2crbyte _hour , Ack
I2crbyte Weekday , Ack
I2crbyte _day , Ack
I2crbyte _month , Ack
I2crbyte _year , Nack
I2cstop
_sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
_month = Makedec(_month) : _day = Makedec(_day) : _year = Makedec(_year)
Return
Setdate:
_day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year)
I2cstart
I2cwbyte Ds1307w
I2cwbyte 4
I2cwbyte _day
I2cwbyte _month
I2cwbyte _year
I2cstop
Return
Settime:
_sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
I2cstart
I2cwbyte Ds1307w
I2cwbyte 0
I2cwbyte _sec
I2cwbyte _min
I2cwbyte _hour
I2cstop
Return
Sub Cocok:
Do
If Up = 0 Then
Incr Menit
Waitms 80
If Menit > 59 Then
Menit = 0
Incr Jam
If Jam > 23 Then Jam = 0
End If
End If
If Down = 0 Then
Decr Menit
Waitms 80
If Menit < 0 Then
Menit = 59
Decr Jam
If Jam < 0 Then Jam = 23
End If
End If
Menit_puluhan = Menit / 10
Buff = Menit_puluhan * 10
Menit_satuan = Menit - Buff
Jam_puluhan = Jam / 10
Buff2 = Jam_puluhan * 10
Jam_satuan = Jam - Buff2
Portb = Lookup(Menit_puluhan , Data7b)
Set Portd.3
Reset Porta.7
Waitus 5000
Portb = Lookup(Menit_satuan , Data7b)
Set Porta.7
Reset Portd.4
Waitus 5000
Portb = Lookup(Jam_satuan , Data7b)
Set Portd.4
Reset Portd.2
Waitus 5000
Portb = Lookup(Jam_puluhan , Data7b)
Set Portd.2
Reset Portd.3
Waitus 5000
Portb = Lookup(Menit_puluhan , Data7b)
Reset Portd.0
Set Portd.3
If Setting = 0 Then
Bitwait Setting , Set
_sec = 0
_min = Menit
_hour = Jam
Goto Settime
End If
Loop
End Sub
Data7b:
Data &B01000000 , &B01111001 , &B00100100 ,
&B00110000 , &B00011001 , &B00010010 , &B00000010 ,
&B01111000 , &B00000000 , &B00010000
Tidak ada komentar:
Posting Komentar