Pada kesempatan kali ini akan dibahs mengenai bagaimana cara membuat jam digital sendiri dengan interface 7 segment, sebenarnya membuat alat ini tidaklah sulit namun memerlukan ketelitian dalam menyolder karena banyaknya jumper pada pcb, alat ini menggunakan RTC Ds1307 yang berfungsi agar saat mikrokontroller tidak diberi supply, jam digital masih menyala, sehingga saat dihidupkan kembali dengan memberikan vcc pada mikrokontroller jam yang tertera telah up to date atau waktu sekarang, berikut adalah skematik dan programnya.
1. Minimum System ATMega8
2. Skematik 7Segment Interface
3. Program Bascom AVR
$regfile = "m8def.dat"
$crystal = 12000000
Config Sda = Portc.4
Config Scl = Portc.5
Const Ds1307w = &HD0
Const Ds1307r = &HD1
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
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
Dim Weekday As Byte
Dim Jam_puluhan As Integer
Dim Jam_satuan As Integer
Dim Min_puluhan As Integer
Dim Min_satuan As Integer
Dim Sec_puluhan As Integer
Dim Sec_satuan As Integer
Dataout Alias Portd.6
Clocke Alias Portd.7
Dim Datas As Byte
Dim Jeda As Integer
Dim Clearseg As Integer
Clearseg = 20000
Jeda = 100
Ddrd.2 = 1
Ddrd.3 = 1
Ddrd.4 = 1
Ddrd.5 = 1
Ddrc.0 = 1
Ddrc.1 = 1
Ddrc.2 = 1
Ddrc.3 = 1
Portc.2 = 1
Portc.3 = 1
Ddrb.0 = 0
Ddrb.1 = 0
Ddrb.2 = 0
Tombolup Alias Pinb.2
Tomboldown Alias Pinb.1
Tombolselect Alias Pinb.0
'_sec = 00
'_hour = 14
'_min = 36
'Settime
'_day = 12
'_month = 3
'_year = 12
'Setdate
I = 13
Line1 = Chr(13)
Do
Getdatetime
'Upperline
'Dispdate
'Lowerline
'Disptime
'Print Line1 ; Sb(1) ; ":" ; Sb(2) ; ":" ; Sb(3);
'Waitms 200
'Mencari angka Puluhan
_hour = _hour Mod 100
Jam_puluhan = _hour / 10
'Mencari angka Satuan
Jam_satuan = _hour Mod 10
'Mencari angka Puluhan
_min = _min Mod 100
Min_puluhan = _min / 10
'Mencari angka Satuan
Min_satuan = _min Mod 10
'Mencari angka Puluhan
_sec = _sec Mod 100
Sec_puluhan = _sec / 10
'Mencari angka Satuan
Sec_satuan = _sec Mod 10
Portc.0 = 1
Portc.1 = 0
Portd.2 = 0
Portd.3 = 0
Portd.4 = 0
Portd.5 = 0
Clocke = 0
Clocke = 1
Datas = Lookup(jam_puluhan , Data7seg)
Shiftout Dataout , Clocke , Datas , 0 , 8 , 0
Clocke = 0
Waitus Jeda
Portc.0 = 0
Portc.1 = 1
Portd.2 = 0
Portd.3 = 0
Portd.4 = 0
Portd.5 = 0
Clocke = 0
Clocke = 1
Datas = Lookup(jam_satuan , Data7seg)
Shiftout Dataout , Clocke , Datas , 0 , 8 , 0
Clocke = 0
Waitus Jeda
Portc.0 = 0
Portc.1 = 0
Portd.2 = 1
Portd.3 = 0
Portd.4 = 0
Portd.5 = 0
Clocke = 0
Clocke = 1
Datas = Lookup(min_puluhan , Data7seg)
Shiftout Dataout , Clocke , Datas , 0 , 8 , 0
Clocke = 0
Waitus Jeda
Portc.0 = 0
Portc.1 = 0
Portd.2 = 0
Portd.3 = 1
Portd.4 = 0
Portd.5 = 0
Clocke = 0
Clocke = 1
Datas = Lookup(min_satuan , Data7seg)
Shiftout Dataout , Clocke , Datas , 0 , 8 , 0
Clocke = 0
Waitus Jeda
Portc.0 = 0
Portc.1 = 0
Portd.2 = 0
Portd.3 = 0
Portd.4 = 1
Portd.5 = 0
Clocke = 0
Clocke = 1
Datas = Lookup(sec_puluhan , Data7seg)
Shiftout Dataout , Clocke , Datas , 0 , 8 , 0
Clocke = 0
Waitus Jeda
Portc.0 = 0
Portc.1 = 0
Portd.2 = 0
Portd.3 = 0
Portd.4 = 0
Portd.5 = 1
Clocke = 0
Clocke = 1
Datas = Lookup(sec_satuan , Data7seg)
Shiftout Dataout , Clocke , Datas , 0 , 8 , 0
Clocke = 0
Waitus Jeda
Portc.0 = 0
Portc.1 = 0
Portd.2 = 0
Portd.3 = 0
Portd.4 = 0
Portd.5 = 0
Waitus Clearseg
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
Data7seg:
Data &B11000000 '0
Data &B11111001 '1
Data &B10100100 '2
Data &B10110000 '3
Data &B10011001 '4
Data &B10010010 '5
Data &B10000010 '6
Data &B11111000 '7
Data &B10000000 '8
Data &B10010000 '9
4. Cara Penggunaan Alat
Saat pertama download program sertakan baris berikut dan isikan waktu dan tanggal pertama yang akan ditampilkan oleh jam digital:
_sec = 00
_hour = 14
_min = 36
Settime
_day = 12
_month = 3
_year = 12
Setdate
Kemudian download-kan lagi ke mikrokontroller tanpa kode tersebut atau berikan tanda ' seperti berikut ini
'_sec = 00
'_hour = 14
'_min = 36
'Settime
'_day = 12
'_month = 3
'_year = 12
'Setdate
Hal itu berfungsi agar saat dilakukan reset atau tidak ada supply tegangan, jam digital tidak kembali ke nilai awal atau ke nilai saat dimasukkan nilai.
Mau Pesan PCB 7Segment interfacenya atau Sistem Minimumnya ? Please Contact Me..............
berapa gan harga sepaket sytem minimum dan 7 segmen dan rtcnya, kalo bisa berikut tutorialnya, saya pengen belajar mikrokontroller khususnya menggunakan bascom avr. kirim via email ya bos. sidiato@gmail.com
ReplyDelete