Depok Instruments

We Present Technologies As Arts

Source Code BASCOM-AVR for RTC DS1307

$regfile = “m8535.dat”
$crystal = 11059200
$lib “lcd4busy.lib”
$baud = 9600

Const _lcdport = Portb
Const _lcdddr = Ddrb
Const _lcdin = Pinb
Const _lcd_e = 2
Const _lcd_rw = 1
Const _lcd_rs = 0
Config Lcd = 16 * 2

Cursor Off
Cursor Noblink

Dim _sec As Byte
Dim _min As Byte
Dim _hour As Byte
Dim _day As Byte
Dim _month As Byte
Dim _year As Byte
Dim _weekday As Byte

Dim Sa(3) As String * 2
Dim Sb(3) As String * 2

Config Sda = Portd.5
Config Scl = Portd.4
Const Ds1307w = &HD0 ‘ Addresses of Ds1307 clock
Const Ds1307r = &HD1

Declare Sub Getdatetime
Declare Sub Settime
Declare Sub Getsec
Declare Sub Disptime
Declare Sub Dispdate
Declare Sub Format_00
Declare Sub Setdate
Declare Sub Subset

Dim I As Byte
Dim Flagset As Bit ‘0 = Waktu, 1 = Tanggal
Dim Flagreset As Bit
Dim Line1 As String * 1

‘=========================================RTC

_sec = 50
_hour = 17
_min = 04
Settime

_day = 12
_month = 3
_year = 12
Setdate

I = 13
Line1 = Chr(13)

Cls
Do
Getdatetime
Upperline
Dispdate
Lowerline
Disptime
Print Line1 ; Sb(1) ; “:” ; Sb(2) ; “:” ; Sb(3);
Waitms 200
Loop

Sub Getdatetime:

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)
End Sub

Sub Settime:
_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

End Sub

Sub Setdate

_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

End Sub

Sub Dispdate
Sa(1) = Str(_day)
Sa(2) = Str(_month)
Sa(3) = Str(_year)
Format_00
Lcd “Date: ” ;Sb(1) ; “-” ; Sb(2) ; “-” ; Sb(3)
End Sub

Sub Disptime
Sa(1) = Str(_hour)
Sa(2) = Str(_min)
Sa(3) = Str(_sec)
Format_00
Lcd “Time: ” ; Sb(1) ; “:” ; Sb(2) ; “:” ; Sb(3)
End Sub

Sub Format_00
For I = 1 To 3 Step 1
Sb(i) = Format(sa(i) , “00”)
Next I
End Sub

About these ads

Maret 15, 2012 - Posted by | 3.2 Program | , , ,

1 Komentar »

  1. saya membeli produk DI-Smart 51 system, DI-D7s (seven segment), dan DI-Smart RTC.1307, bagaimana memodifikasi program Bascom supaya bisa diterapkan pada produk yg saya punya ?

    Komentar oleh jakopsen | Januari 15, 2013 | Balas


Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Logout / Ubah )

Twitter picture

You are commenting using your Twitter account. Logout / Ubah )

Facebook photo

You are commenting using your Facebook account. Logout / Ubah )

Google+ photo

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

Ikuti

Get every new post delivered to your Inbox.

Bergabunglah dengan 61 pengikut lainnya.

%d bloggers like this: