Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20577

BASCOM-AVR : (Need Help) : How to configure DS3231 RTC with AVR8535? : NEWTOPIC

$
0
0
Dear all... I'm trying to configure DS3231 RTC by simply connect the pins as i have done with DS1307. But the uC haven't work correctly yet. Is there any solution for this problem? I prefer DS3231 because i want to use alarm function next time. The uC will sleep when not active and alarm will wake up the uC on the right date, so i can prolonged lifetime of battery for PSU Thanks for your help [code:1:fe552161fa] ' '====================RTC CLOCK NO ALARM===================== 'By : CahDeso 'avrprojects2014 '=========================================================== $regfile = "m8535.dat" $crystal = 11059200 'LCD Kontrol------------------------------------------------- Config Lcdpin = Pin , Db4 = Portc.5 , Db5 = Portc.4 , Db6 = Portc.3 , Db7 = Portc.2 , E = Portc.6 , Rs = Portc.7 Config Lcd = 16 * 2 'Port C as output for LCD Initlcd Cursor Off Cursor Noblink 'Dimensi variabel-------------------------------------------- Dim _sec As Byte Dim _min As Byte Dim _hour As Byte Dim _weekday As Byte Dim _day As Byte Dim _month As Byte Dim _year As Byte Dim A As Byte Dim B As Long Dim Sa(3) As String * 2 Dim Sb(3) As String * 2 Dim Sc(3) As String * 2 Dim Sd(3) As String * 2 Dim I As Byte 'I2C Control------------------------------------------------- Config Sda = Portc.1 'Pin C.1 sebagai Sda Config Scl = Portc.0 'Pin C.0 sebagai Scl Const Ds1307w = &HD0 'Address of Ds1307 clock (write) Const Ds1307r = &HD1 'Address of Ds1307 clock (read) 'Deklarasi Sub Rutin----------------------------------------- Declare Sub Getdatetime() Declare Sub Settime() Declare Sub Getsec() Declare Sub Disptime() Declare Sub Dispdate() Declare Sub Format_00() Declare Sub Format_01() Declare Sub Setdate() Declare Sub Subset() Declare Sub Ukur() 'RTC Setting-------------------------------------------- _sec = 0 _hour = 17 _min = 14 Call Settime() _day = 2 _month = 2 _year = 14 Call Setdate() '======================= MAIN PROGRAM ======================= '============================================================ Do 'Lakukan perulangan Cls Call Getdatetime() 'ambil data waktu dan tanggal Upperline Call Dispdate() 'Tampilkan tanggal di baris 1 Lowerline Call Disptime() 'Tampilkan jam di baris 2 Waitms 100 Loop '======================= MAIN PROGRAM ======================= '============================================================ 'Sub Rutin ambil data waktu dan tanggal---------------------- Sub Getdatetime() I2cstart ' Generate start code I2cwbyte Ds1307w ' send address I2cwbyte 0 ' starting address in 1307 I2cstart ' Generate start code I2cwbyte Ds1307r ' send address I2crbyte _sec , Ack ' Seconds I2crbyte _min , Ack ' Minutes I2crbyte _hour , Ack ' Hours I2crbyte _weekday , Ack ' Day names 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 Rutin setting waktu-------------------------------------- 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 Rutin setting tanggal------------------------------------ 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 DAYS I2cwbyte _month ' MONTHS I2cwbyte _year ' YEARS I2cstop End Sub 'Sub Rutin tampilkan tanggal--------------------------------- Sub Dispdate() Sa(1) = Str(_day) Sa(2) = Str(_month) Sa(3) = Str(_year) Call Format_01() 'Panggil Sub Rutin Format 2 digit Lcd "Date: " ; Sb(1) ; "-" ; Sb(2) ; "-" ; Sb(3) End Sub 'Sub Rutin tampilkan waktu----------------------------------- Sub Disptime() Sc(1) = Str(_hour) Sc(2) = Str(_min) Sc(3) = Str(_sec) Call Format_00() 'Panggil Sub Rutin Format 2 digit Lcd "Time: " ; Sd(1) ; ":" ; Sd(2) ; ":" ; Sd(3) End Sub 'Sub Rutin format 2 digit------------------------------------ Sub Format_00() For I = 1 To 3 'Step 1 Sd(i) = Format(sc(i) , "00") Next I End Sub Sub Format_01() For I = 1 To 3 Step 1 Sb(i) = Format(sa(i) , "00") Next I End Sub[/code:1:fe552161fa] [b:fe552161fa][color=red:fe552161fa](BASCOM-AVR version : 1.11.9.0 , Latest : 2.0.7.7 )[/b:fe552161fa][/color:fe552161fa]

Viewing all articles
Browse latest Browse all 20577

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>