0% found this document useful (0 votes)
2K views

Sample Listing Program DS1307 Using BASCOM AVR

The document contains code for a microcontroller program that displays the date and time from a DS1307 real-time clock module on an LCD screen. It allows the user to set the date and time by pressing buttons. The program initializes the LCD pins and I2C pins for communication with the DS1307. It then enters a main loop that displays the current date and time, and checks for button presses to enter setting modes for date or time. Subroutines are used to read from and write to the DS1307 to get and set the date/time values.

Uploaded by

Muhammad FunDay
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Sample Listing Program DS1307 Using BASCOM AVR

The document contains code for a microcontroller program that displays the date and time from a DS1307 real-time clock module on an LCD screen. It allows the user to set the date and time by pressing buttons. The program initializes the LCD pins and I2C pins for communication with the DS1307. It then enters a main loop that displays the current date and time, and checks for button presses to enter setting modes for date or time. Subroutines are used to read from and write to the DS1307 to get and set the date/time values.

Uploaded by

Muhammad FunDay
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

$regfile = "m32def.

dat"
$crystal = 11059200
'$baud = 9600
$hwstack = 32
$swstack = 10
$framesize = 40
$lib "mcs.lib"
$lib "mcsbyte.lbx" , "ds1307clock.lib" , "i2c.lib"
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Port
b.7 , E = Portb.2 , Rs = Portb.0
Config Lcd = 20 * 4
Cursor Off
Cls
Config Sda = Portc.1
Config Scl = Portc.0
Const Ds1307w = &HD0
Const Ds1307r = &HD1
'============input tombol sbg pengatur jam======================
Config Pinc.2 = Input
Config Pinc.3 = Input
Config Pinc.4 = Input
Config Pinc.5 = Input
Config Debounce = 30
Dim Seco As Byte , Mine As Byte , Hour As Byte
Dim Day As Byte , Bulan As Byte , Tahun As Byte , Weekday As Byte
locate 1,1
lcd " Buat yang tercinta"
locate 2,1
lcd "Dyah Alivia"
wait 3
Main:
cls
Do
Gosub Ds1307
Select Case Weekday
Case 1 : Locate 3 , 1
Lcd "Sun"
Case 2 : Locate 3 , 1
Lcd "Mon"
Case 3 : Locate 3 , 1
Lcd "Tue"
Case 4 : Locate 3 , 1
Lcd "Wed"
Case 5 : Locate 3 , 1
Lcd " thur"
Case 6 : Locate 3 , 1
Lcd "Fri"
Case 7 : Locate 3 , 1
Lcd "Sat"
End Select
Locate 1 , 1
Lcd "Dr.Dyah Alivia Sp.OG"
Locate 2 , 1
Lcd "Jam = " ;
If Hour < 10 Then
Lcd "0" ; Hour ; ":"
Else
Lcd Hour ; ":"
End If
If Mine < 10 Then
Lcd "0" ; Mine ; ":" ;
Else
Lcd Mine ; ":" ;
End If
If Seco < 10 Then
Lcd "0" ; Seco
Else
Lcd Seco
End If
Locate 3 , 6
If Day < 10 Then
Lcd "0" ; Day ; ":";
Else
Lcd Day ; ":";
End If
If Bulan < 10 Then
Lcd "0" ; Bulan ; ":" ;
Else
Lcd Bulan ; ":" ;
End If
If Tahun < 10 Then
Lcd "0" ; Tahun
Else
Lcd Tahun
End If
Debounce Pinc.4 , 0 , Setting_jam , Sub
Debounce Pinc.3 , 0 , Setting_tanggal , Sub
Loop
Setting_jam:
Cls
Do
Gosub Ds1307
Locate 1 , 1
Lcd "Setting Jam"
Locate 2 , 1
Lcd "Jam = " ;
If Hour < 10 Then
Lcd "0" ; Hour ; ":"
Else
Lcd Hour ; ":"
End If
If Mine < 10 Then
Lcd "0" ; Mine ; ":" ;
Else
Lcd Mine ; ":" ;
End If
If Seco < 10 Then
Lcd "0" ; Seco
Else
Lcd Seco
End If
Debounce Pinc.4 , 0 , _seco , Sub
Debounce Pinc.3 , 0 , _mine , Sub
Debounce Pinc.2 , 0 , _hour , Sub
If Pinc.5 = 0 Then
Waitms 200
Gosub Main
End If
Loop
Setting_tanggal:
Cls
Do
Gosub Ds1307
Locate 1 , 1
Lcd "Setting Tanggal"
Locate 2 , 1
Lcd "Tgl = " ;
If Day < 10 Then
Lcd "0" ; Day ; ":";
Else
Lcd Day ; ":";
End If
If Bulan < 10 Then
Lcd "0" ; Bulan ; ":" ;
Else
Lcd Bulan ; ":" ;
End If
If Tahun < 10 Then
Lcd "0" ; Tahun
Else
Lcd Tahun
End If
Debounce Pinc.2 , 0 , _day , Sub
Debounce Pinc.3 , 0 , _bulan , Sub
Debounce Pinc.4 , 0 , _tahun , Sub
If Pinc.5 = 0 Then
Waitms 200
Gosub Main
End If
Loop
Ds1307:
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 0 ' start address in 1307
I2cstart ' Generate start code
I2cwbyte Ds1307r ' send address
I2crbyte Seco , Ack 'sec
I2crbyte Mine , Ack ' MINUTES
I2crbyte Hour , Ack ' Hours
I2crbyte Weekday , Ack
I2crbyte Day , Ack
I2crbyte Bulan , Ack
I2crbyte Tahun , Nack
I2cstop
Seco = Makedec(seco) : Mine = Makedec(mine) : Hour = Makedec(hour)
If Seco > 59 Then Seco = 0
If Mine > 59 Then Mine = 0
If Hour > 23 Then
Hour = 0
' Gosub Seco
End If
Day = Makedec(day) : Bulan = Makedec(bulan) : Tahun = Makedec(tahun)
If Day > 30 Then Day = 1
If Tahun > 100 Then Tahun = 1
If Bulan > 12 Then
Bulan = 1
End If
Return
_seco:
Incr Seco
If Seco > 59 Then Seco = 0
Seco = Makebcd(seco)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 0 ' starting address in 1307
I2cwbyte Seco
I2cstop
Return
'-------------------------------------
_mine:
Incr Mine
If Mine > 59 Then Mine = 0
Mine = Makebcd(mine)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 1 ' starting address in 1307
I2cwbyte Mine
I2cstop
Return
_hour:
Incr Hour
If Hour > 23 Then Hour = 0
Hour = Makebcd(hour)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 2 ' starting address in 1307
I2cwbyte Hour
I2cstop
Return
_day:
Incr Day
If Day > 30 Then Day = 1
Day = Makebcd(day)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 4 ' starting address in 1307
I2cwbyte Day
I2cstop
Return
_bulan:
Incr Bulan
If Bulan > 12 Then Bulan = 1
Bulan = Makebcd(bulan)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 5 ' starting address in 1307
I2cwbyte Bulan
I2cstop
Return
_tahun:
Incr Tahun
If Tahun > 99 Then Tahun = 0
Tahun = Makebcd(tahun)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 6 ' starting address in 1307
I2cwbyte Tahun
I2cstop
Return

You might also like