Kali ini saya akan menjelaskan mengenai bagaimana cara membuat timbangan digital yang dapat menghitung berat dan jumlah benda yang ada di timbangan, kelebihan timbangan ini selain bisa menghitung jumlah benda, hasil dari perhitungan baik itu jumlah dan berat bisa disimpan ke MMC card dengan maksimal kapasitas MMC card 1 Gb. Timbangan ini juga dilengkapi dengan modul RTC sehingga saat penyimpanan data ke MMC card, terdapat jam dan tanggal saat itu juga, dengan demikian pihak penjual maupun pembeli bisa tahu kapan dan pada jam berapa transaksi tersebut berlangsung. selain itu bukti simpanan juga bisa digunakan sebagai alat bukti transaksi. untuk lebih jelasnya beriku penjelasan program dan skemanya.
a. Minimum System
b. Modul HX711 dan Load Cell
c. Modul SD Card
*NOTE =
MODUL - MCU
MOSI - > MOSI
MISO - > MISO
SCK - > SCK
CS - > SS
d. Rangkaian RTC
e. Program Bascom AVR
'created by yanuar mukhammad
'email = yanuarm@hotmail.com
$regfile = "m32def.dat"
$crystal = 12000000
Config Lcdpin = Pin , Rs = Portc.6 , E = Portc.7 , Db4 = Portc.2
Config Lcdpin = Pin , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5
Config Lcd = 16 * 2
Cls
Cursor Off
$lib "ds1307clock.lib"
Config Sda = Portc.1
Config Scl = Portc.0
Const Ds1307w = &HD0
Const Ds1307r = &HD1
Config Clock = User
Dim Weekday As Byte
Dim Char As String * 10 , Tanda As String * 1
Dim Jam As String * 10 , Menit As String * 10 , Detik As String * 10
Dim Hari As String * 10 , Bulan As String * 10 , Tahun As String * 10
Dim A As Byte , B As Byte , C As Byte
Dim X As Byte , Y As Byte , Z As Byte
Dim Waktu As String * 10
Dim Tanggal As String * 10
Dim Oke As String * 5
Dim Count As Long
Dim I As Byte
Dim Hx711_read As Long
Dim Hx711 As String * 10
Dim Datafix As Integer
Dim Dataok As Single
Dim Strdatok As String * 10
Dim Strjml As String * 10
Dim Ax As Byte
Dim L As String * 10
Dim Ff As Byte
Dim S As Long
Dim Diskf As Long
Dim Disks As Long
Dim Nama As String * 20
Dim Satuan As Eram Single
Dim Datasatuan As Single
Dim Jumlah As Single
Dim Tera As Eram Single
Dim Datatera As Single
Dim Pilih As Integer
Adsk Alias Portd.4 ' use pin D.4 as output sck
Addo Alias Pind.5 ' use pin D.5 as input Dataout
Config Adsk = Output
Config Addo = Input
$include "Config_AVR-DOS32.BAS"
$include "Config_MMC32.bas"
Ff = Drivereset()
Ff = Driveinit()
$external Waitms
'Date$ = "08/13/15" 'mm/dd/yy
'Time$ = "15:36:00" 'hh:mm:ss
Ddrd.4 = 1
Ddrd.5 = 0
Ddrb.0 = 0
Ddrb.1 = 0
Ddrb.2 = 0
Ddrb.3 = 0
Ddrd.0 = 0
Ddrd.1 = 0
Ddrd.2 = 0
Ddrd.3 = 0
Tmbok Alias Pinb.4
Tmbmulai Alias Pinb.1
Tmbunit Alias Pinb.3
Tmbhitung Alias Pinb.0
Tmbback Alias Pind.3
Tmbtera Alias Pind.2
Tmbsimpan Alias Pind.1
Tmbparam Alias Pind.0
Set Portb.0
Set Portb.1
Set Portb.2
Set Portb.3
Set Portd.0
Set Portd.1
Set Portd.2
Set Portd.3
Pilih = 1
Main:
Datatera = Tera
Do
Addo = 1
Adsk = 0
Count = 0
While Addo = 1
Wend
For I = 1 To 24
Adsk = 1
Shift Count , Left , 1
Adsk = 0
If Addo = 1 Then Incr Count
Next
Adsk = 1
Count = Count Xor &H800000
Adsk = 0
Hx711_read = Count
Hx711 = Str(hx711_read)
Hx711 = Left(hx711 , 3)
Datafix = Val(hx711)
If Pilih = 1 Then
Dataok = Datafix - Datatera
Dataok = Dataok / 0.047
Strdatok = Fusing(dataok , "#.##")
Upperline
Lcd "Berat = " ; Strdatok ; "gr"
Locate 2 , 1
Lcd "Tera"
Locate 2 , 11
Lcd "Hitung"
Waitms 500
Cls
Elseif Pilih = 2 Then
Dataok = Datafix - Datatera
Dataok = Dataok / 0.047
Dataok = Dataok / 1000
Strdatok = Fusing(dataok , "#.####")
Lcd "Berat = " ; Strdatok ; "kg"
Locate 2 , 1
Lcd "Tera"
Locate 2 , 11
Lcd "Hitung"
Waitms 500
Cls
End If
If Tmbtera = 0 Then
Goto Terazone
End If
If Tmbhitung = 0 Then
Goto Hitung
End If
If Tmbparam = 0 Then
Goto Param
End If
If Tmbunit = 0 Then
Incr Pilih
If Pilih > 2 Then
Pilih = 1
End If
End If
Loop
Terazone:
Addo = 1
Adsk = 0
Count = 0
While Addo = 1
Wend
For I = 1 To 24
Adsk = 1
Shift Count , Left , 1
Adsk = 0
If Addo = 1 Then Incr Count
Next
Adsk = 1
Count = Count Xor &H800000
Adsk = 0
Hx711_read = Count
Hx711 = Str(hx711_read)
Hx711 = Left(hx711 , 3)
Datafix = Val(hx711)
Cls
Upperline
Lcd "Nilai = " ; Datafix
Wait 3
Datatera = Datafix
Tera = Datatera
Datatera = Tera
Goto Main
Return
'========================================
Hitung:
Cls
Datatera = Tera
Do
Addo = 1
Adsk = 0
Count = 0
While Addo = 1
Wend
For I = 1 To 24
Adsk = 1
Shift Count , Left , 1
Adsk = 0
If Addo = 1 Then Incr Count
Next
Adsk = 1
Count = Count Xor &H800000
Adsk = 0
Hx711_read = Count
Hx711 = Str(hx711_read)
Hx711 = Left(hx711 , 3)
Datafix = Val(hx711)
Dataok = Datafix - Datatera
Dataok = Dataok / 0.047
Strdatok = Fusing(dataok , "#.##")
Upperline
Lcd "Letakkan 1 item"
Lowerline
Lcd "Berat = " ; Strdatok ; "gr"
Waitms 500
Cls
If Tmbmulai = 0 Then
Datasatuan = Dataok
Satuan = Datasatuan
Datasatuan = Satuan
Goto Hitungpcs
End If
Loop
Return
'=========================================
Hitungpcs:
Cls
Datatera = Tera
Datasatuan = Satuan
Do
Addo = 1
Adsk = 0
Count = 0
While Addo = 1
Wend
For I = 1 To 24
Adsk = 1
Shift Count , Left , 1
Adsk = 0
If Addo = 1 Then Incr Count
Next
Adsk = 1
Count = Count Xor &H800000
Adsk = 0
Hx711_read = Count
Hx711 = Str(hx711_read)
Hx711 = Left(hx711 , 3)
Datafix = Val(hx711)
If Pilih = 1 Then
Dataok = Datafix - Datatera
Dataok = Dataok / 0.047
Jumlah = Dataok / Datasatuan
Strdatok = Fusing(dataok , "#.##")
Strjml = Fusing(jumlah , "#.##")
Upperline
Lcd "Berat = " ; Strdatok ; "gr"
Lowerline
Lcd "Jumlah = " ; Strjml
Waitms 500
Cls
Elseif Pilih = 2 Then
Dataok = Datafix - Datatera
Dataok = Dataok / 0.047
Jumlah = Dataok / Datasatuan
Dataok = Dataok / 1000
Strdatok = Fusing(dataok , "#.####")
Strjml = Fusing(jumlah , "#.##")
Upperline
Lcd "Berat = " ; Strdatok ; "kg"
Lowerline
Lcd "Jumlah = " ; Strjml
Waitms 500
Cls
End If
If Tmbback = 0 Then
Goto Main
End If
If Tmbparam = 0 Then
Goto Param
End If
If Tmbsimpan = 0 Then
Goto Simpan
End If
If Tmbunit = 0 Then
Incr Pilih
If Pilih > 2 Then
Pilih = 1
End If
End If
Loop
Return
'==========================================
Param:
Cls
Upperline
Lcd "Satuan = " ; Datasatuan
Lowerline
Lcd "Tera = " ; Datatera
Wait 10
Goto Main
Return
'=========================================
Simpan:
Cls
Waitms 200
Upperline
Lcd " PLEASE WAIT !!"
Wait 1
Cls
Do
If Gbdriveerror <> 0 Then 'CEK MEMORY CARD ERROR
Cls
Locate 1 , 1
Lcd "Error Config"
Locate 2 , 1
Lcd "CEK MEMORY"
Wait 2
End If
Ax = Initfilesystem(1) 'init file system
If Ax <> 0 Then
Cls
Locate 1 , 1
Lcd "Error MEMORY"
Locate 2 , 1
Lcd "CEK MEMORY CARD"
Wait 2
Cls
Goto Hitungpcs
End If
Cls
If Ax = 0 Then
Cls
Locate 1 , 1
Lcd "MEMORY OK"
Wait 1
End If
Diskf = Diskfree()
Select Case Diskf 'CEK FREESPACE
S = Diskf
S = Str(s)
Case Is > 3000 : Locate 2 , 1
Lcd " Free > 3MB"
Lcd S
Case Is > 1000 : Locate 2 , 1
Lcd " Free > 1MB"
Lcd S
Case Else : Locate 2 , 1
Lcd "!! FREE < 1MB !!"
Wait 1
Locate 2 , 1
Lcd "GANTI memoryCARD"
End Select
Wait 3
Gosub Getdatetime
Cls
Upperline
Lcd Date$
Lowerline
Lcd Time$
Wait 3
Cls
Ff = Freefile()
L = "RECORD"
Nama = L + ".txt"
Open Nama For Append As #ff 'buat file baru (bisa append, bisa output)
If Pilih = 1 Then
Oke = " gr"
Else
Oke = " kg"
End If
Print #ff , " RESULT"
Print #ff , "#################################"
Print #ff , "#" ; Date$ ; ", " ; Time$
Print #ff , "#################################"
Print #ff , "Berat : " ; Strdatok ; Oke
Print #ff , "Jumlah: " ; Strjml ; " pcs"
Print #ff ,
Close #ff 'tutup file
Cls
Locate 1 , 1
Lcd "FILE CREATED"
Wait 2
Goto Hitungpcs
Cls
Loop
Return
'///////////////////////////////////////////////////////////////////////////////
'dari ds1307clock.lib
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 'detik
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)
Return
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 day
I2cwbyte _month ' Month
I2cwbyte _year ' years
I2cstop
Return
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
Return
$crystal = 12000000
Config Lcdpin = Pin , Rs = Portc.6 , E = Portc.7 , Db4 = Portc.2
Config Lcdpin = Pin , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5
Config Lcd = 16 * 2
Cls
Cursor Off
$lib "ds1307clock.lib"
Config Sda = Portc.1
Config Scl = Portc.0
Const Ds1307w = &HD0
Const Ds1307r = &HD1
Config Clock = User
Dim Weekday As Byte
Dim Char As String * 10 , Tanda As String * 1
Dim Jam As String * 10 , Menit As String * 10 , Detik As String * 10
Dim Hari As String * 10 , Bulan As String * 10 , Tahun As String * 10
Dim A As Byte , B As Byte , C As Byte
Dim X As Byte , Y As Byte , Z As Byte
Dim Waktu As String * 10
Dim Tanggal As String * 10
Dim Oke As String * 5
Dim Count As Long
Dim I As Byte
Dim Hx711_read As Long
Dim Hx711 As String * 10
Dim Datafix As Integer
Dim Dataok As Single
Dim Strdatok As String * 10
Dim Strjml As String * 10
Dim Ax As Byte
Dim L As String * 10
Dim Ff As Byte
Dim S As Long
Dim Diskf As Long
Dim Disks As Long
Dim Nama As String * 20
Dim Satuan As Eram Single
Dim Datasatuan As Single
Dim Jumlah As Single
Dim Tera As Eram Single
Dim Datatera As Single
Dim Pilih As Integer
Adsk Alias Portd.4 ' use pin D.4 as output sck
Addo Alias Pind.5 ' use pin D.5 as input Dataout
Config Adsk = Output
Config Addo = Input
$include "Config_AVR-DOS32.BAS"
$include "Config_MMC32.bas"
Ff = Drivereset()
Ff = Driveinit()
$external Waitms
'Date$ = "08/13/15" 'mm/dd/yy
'Time$ = "15:36:00" 'hh:mm:ss
Ddrd.4 = 1
Ddrd.5 = 0
Ddrb.0 = 0
Ddrb.1 = 0
Ddrb.2 = 0
Ddrb.3 = 0
Ddrd.0 = 0
Ddrd.1 = 0
Ddrd.2 = 0
Ddrd.3 = 0
Tmbok Alias Pinb.4
Tmbmulai Alias Pinb.1
Tmbunit Alias Pinb.3
Tmbhitung Alias Pinb.0
Tmbback Alias Pind.3
Tmbtera Alias Pind.2
Tmbsimpan Alias Pind.1
Tmbparam Alias Pind.0
Set Portb.0
Set Portb.1
Set Portb.2
Set Portb.3
Set Portd.0
Set Portd.1
Set Portd.2
Set Portd.3
Pilih = 1
Main:
Datatera = Tera
Do
Addo = 1
Adsk = 0
Count = 0
While Addo = 1
Wend
For I = 1 To 24
Adsk = 1
Shift Count , Left , 1
Adsk = 0
If Addo = 1 Then Incr Count
Next
Adsk = 1
Count = Count Xor &H800000
Adsk = 0
Hx711_read = Count
Hx711 = Str(hx711_read)
Hx711 = Left(hx711 , 3)
Datafix = Val(hx711)
If Pilih = 1 Then
Dataok = Datafix - Datatera
Dataok = Dataok / 0.047
Strdatok = Fusing(dataok , "#.##")
Upperline
Lcd "Berat = " ; Strdatok ; "gr"
Locate 2 , 1
Lcd "Tera"
Locate 2 , 11
Lcd "Hitung"
Waitms 500
Cls
Elseif Pilih = 2 Then
Dataok = Datafix - Datatera
Dataok = Dataok / 0.047
Dataok = Dataok / 1000
Strdatok = Fusing(dataok , "#.####")
Lcd "Berat = " ; Strdatok ; "kg"
Locate 2 , 1
Lcd "Tera"
Locate 2 , 11
Lcd "Hitung"
Waitms 500
Cls
End If
If Tmbtera = 0 Then
Goto Terazone
End If
If Tmbhitung = 0 Then
Goto Hitung
End If
If Tmbparam = 0 Then
Goto Param
End If
If Tmbunit = 0 Then
Incr Pilih
If Pilih > 2 Then
Pilih = 1
End If
End If
Loop
Terazone:
Addo = 1
Adsk = 0
Count = 0
While Addo = 1
Wend
For I = 1 To 24
Adsk = 1
Shift Count , Left , 1
Adsk = 0
If Addo = 1 Then Incr Count
Next
Adsk = 1
Count = Count Xor &H800000
Adsk = 0
Hx711_read = Count
Hx711 = Str(hx711_read)
Hx711 = Left(hx711 , 3)
Datafix = Val(hx711)
Cls
Upperline
Lcd "Nilai = " ; Datafix
Wait 3
Datatera = Datafix
Tera = Datatera
Datatera = Tera
Goto Main
Return
'========================================
Hitung:
Cls
Datatera = Tera
Do
Addo = 1
Adsk = 0
Count = 0
While Addo = 1
Wend
For I = 1 To 24
Adsk = 1
Shift Count , Left , 1
Adsk = 0
If Addo = 1 Then Incr Count
Next
Adsk = 1
Count = Count Xor &H800000
Adsk = 0
Hx711_read = Count
Hx711 = Str(hx711_read)
Hx711 = Left(hx711 , 3)
Datafix = Val(hx711)
Dataok = Datafix - Datatera
Dataok = Dataok / 0.047
Strdatok = Fusing(dataok , "#.##")
Upperline
Lcd "Letakkan 1 item"
Lowerline
Lcd "Berat = " ; Strdatok ; "gr"
Waitms 500
Cls
If Tmbmulai = 0 Then
Datasatuan = Dataok
Satuan = Datasatuan
Datasatuan = Satuan
Goto Hitungpcs
End If
Loop
Return
'=========================================
Hitungpcs:
Cls
Datatera = Tera
Datasatuan = Satuan
Do
Addo = 1
Adsk = 0
Count = 0
While Addo = 1
Wend
For I = 1 To 24
Adsk = 1
Shift Count , Left , 1
Adsk = 0
If Addo = 1 Then Incr Count
Next
Adsk = 1
Count = Count Xor &H800000
Adsk = 0
Hx711_read = Count
Hx711 = Str(hx711_read)
Hx711 = Left(hx711 , 3)
Datafix = Val(hx711)
If Pilih = 1 Then
Dataok = Datafix - Datatera
Dataok = Dataok / 0.047
Jumlah = Dataok / Datasatuan
Strdatok = Fusing(dataok , "#.##")
Strjml = Fusing(jumlah , "#.##")
Upperline
Lcd "Berat = " ; Strdatok ; "gr"
Lowerline
Lcd "Jumlah = " ; Strjml
Waitms 500
Cls
Elseif Pilih = 2 Then
Dataok = Datafix - Datatera
Dataok = Dataok / 0.047
Jumlah = Dataok / Datasatuan
Dataok = Dataok / 1000
Strdatok = Fusing(dataok , "#.####")
Strjml = Fusing(jumlah , "#.##")
Upperline
Lcd "Berat = " ; Strdatok ; "kg"
Lowerline
Lcd "Jumlah = " ; Strjml
Waitms 500
Cls
End If
If Tmbback = 0 Then
Goto Main
End If
If Tmbparam = 0 Then
Goto Param
End If
If Tmbsimpan = 0 Then
Goto Simpan
End If
If Tmbunit = 0 Then
Incr Pilih
If Pilih > 2 Then
Pilih = 1
End If
End If
Loop
Return
'==========================================
Param:
Cls
Upperline
Lcd "Satuan = " ; Datasatuan
Lowerline
Lcd "Tera = " ; Datatera
Wait 10
Goto Main
Return
'=========================================
Simpan:
Cls
Waitms 200
Upperline
Lcd " PLEASE WAIT !!"
Wait 1
Cls
Do
If Gbdriveerror <> 0 Then 'CEK MEMORY CARD ERROR
Cls
Locate 1 , 1
Lcd "Error Config"
Locate 2 , 1
Lcd "CEK MEMORY"
Wait 2
End If
Ax = Initfilesystem(1) 'init file system
If Ax <> 0 Then
Cls
Locate 1 , 1
Lcd "Error MEMORY"
Locate 2 , 1
Lcd "CEK MEMORY CARD"
Wait 2
Cls
Goto Hitungpcs
End If
Cls
If Ax = 0 Then
Cls
Locate 1 , 1
Lcd "MEMORY OK"
Wait 1
End If
Diskf = Diskfree()
Select Case Diskf 'CEK FREESPACE
S = Diskf
S = Str(s)
Case Is > 3000 : Locate 2 , 1
Lcd " Free > 3MB"
Lcd S
Case Is > 1000 : Locate 2 , 1
Lcd " Free > 1MB"
Lcd S
Case Else : Locate 2 , 1
Lcd "!! FREE < 1MB !!"
Wait 1
Locate 2 , 1
Lcd "GANTI memoryCARD"
End Select
Wait 3
Gosub Getdatetime
Cls
Upperline
Lcd Date$
Lowerline
Lcd Time$
Wait 3
Cls
Ff = Freefile()
L = "RECORD"
Nama = L + ".txt"
Open Nama For Append As #ff 'buat file baru (bisa append, bisa output)
If Pilih = 1 Then
Oke = " gr"
Else
Oke = " kg"
End If
Print #ff , " RESULT"
Print #ff , "#################################"
Print #ff , "#" ; Date$ ; ", " ; Time$
Print #ff , "#################################"
Print #ff , "Berat : " ; Strdatok ; Oke
Print #ff , "Jumlah: " ; Strjml ; " pcs"
Print #ff ,
Close #ff 'tutup file
Cls
Locate 1 , 1
Lcd "FILE CREATED"
Wait 2
Goto Hitungpcs
Cls
Loop
Return
'///////////////////////////////////////////////////////////////////////////////
'dari ds1307clock.lib
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 'detik
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)
Return
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 day
I2cwbyte _month ' Month
I2cwbyte _year ' years
I2cstop
Return
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
Return
'=======================================================
f. Program Bascom AVR Update
$regfile = "m32def.dat"
$crystal = 12000000
Config Lcdpin = Pin , Rs = Portc.6 , E = Portc.7 , Db4 = Portc.2
Config Lcdpin = Pin , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5
Config Lcd = 16 * 2
Cls
Cursor Off
$lib "ds1307clock.lib"
Config Sda = Portc.1
Config Scl = Portc.0
Const Ds1307w = &HD0
Const Ds1307r = &HD1
Config Clock = User
Dim Weekday As Byte
Dim Char As String * 10 , Tanda As String * 1
Dim Jam As String * 10 , Menit As String * 10 , Detik As String * 10
Dim Hari As String * 10 , Bulan As String * 10 , Tahun As String * 10
Dim A As Byte , B As Byte , C As Byte
Dim X As Byte , Y As Byte , Z As Byte
Dim Waktu As String * 10
Dim Tanggal As String * 10
Dim Oke As String * 5
Dim Pcs As Integer
Dim Count As Long
Dim I As Byte
Dim Hx711_read As Long
Dim Hx711 As String * 10
Dim Datafix As Integer
Dim Dataok As Single
Dim Strdatok As String * 10
Dim Strjml As String * 10
Dim Ax As Byte
Dim L As String * 10
Dim Ff As Byte
Dim S As Long
Dim Diskf As Long
Dim Disks As Long
Dim Nama As String * 20
Dim Satuan As Eram Single
Dim Datasatuan As Single
Dim Jumlah As Integer
Dim Tera As Eram Single
Dim Datatera As Single
Dim Pilih As Integer
Adsk Alias Portd.4 ' use pin D.4 as output sck
Addo Alias Pind.5 ' use pin D.5 as input Dataout
Config Adsk = Output
Config Addo = Input
$include "Config_AVR-DOS32.BAS"
$include "Config_MMC32.bas"
Ff = Drivereset()
Ff = Driveinit()
$external Waitms
'Date$ = "08/13/15" 'mm/dd/yy
'Time$ = "15:36:00" 'hh:mm:ss
Ddrd.4 = 1
Ddrd.5 = 0
Ddrb.0 = 0
Ddrb.1 = 0
Ddrb.2 = 0
Ddrb.3 = 0
Ddrd.0 = 0
Ddrd.1 = 0
Ddrd.2 = 0
Ddrd.3 = 0
Tmbok Alias Pinb.4
Tmbmulai Alias Pinb.1
Tmbunit Alias Pinb.3
Tmbhitung Alias Pinb.0
Tmbback Alias Pind.3
Tmbtera Alias Pind.2
Tmbsimpan Alias Pind.1
Tmbparam Alias Pind.0
Set Portb.0
Set Portb.1
Set Portb.2
Set Portb.3
Set Portd.0
Set Portd.1
Set Portd.2
Set Portd.3
Pilih = 1
Main:
Datatera = Tera
Do
Addo = 1
Adsk = 0
Count = 0
While Addo = 1
Wend
For I = 1 To 24
Adsk = 1
Shift Count , Left , 1
Adsk = 0
If Addo = 1 Then Incr Count
Next
Adsk = 1
Count = Count Xor &H800000
Adsk = 0
Hx711_read = Count
Hx711 = Str(hx711_read)
Hx711 = Left(hx711 , 4)
Datafix = Val(hx711)
If Pilih = 1 Then
Dataok = Datafix - Datatera
Dataok = Dataok / 0.423
Strdatok = Fusing(dataok , "#.##")
Upperline
Lcd "Berat = " ; Strdatok ; "gr"
Locate 2 , 1
Lcd "Tera"
Locate 2 , 11
Lcd "Hitung"
Waitms 500
Cls
Elseif Pilih = 2 Then
Dataok = Datafix - Datatera
Dataok = Dataok / 0.423
Dataok = Dataok * 1000
Strdatok = Fusing(dataok , "#.####")
Lcd "Berat = " ; Strdatok ; "mg"
Locate 2 , 1
Lcd "Tera"
Locate 2 , 11
Lcd "Hitung"
Waitms 500
Cls
End If
If Tmbtera = 0 Then
Goto Terazone
End If
If Tmbhitung = 0 Then
Goto Hitung
End If
If Tmbparam = 0 Then
Goto Param
End If
If Tmbunit = 0 Then
Incr Pilih
If Pilih > 2 Then
Pilih = 1
End If
End If
Loop
Terazone:
Addo = 1
Adsk = 0
Count = 0
While Addo = 1
Wend
For I = 1 To 24
Adsk = 1
Shift Count , Left , 1
Adsk = 0
If Addo = 1 Then Incr Count
Next
Adsk = 1
Count = Count Xor &H800000
Adsk = 0
Hx711_read = Count
Hx711 = Str(hx711_read)
Hx711 = Left(hx711 , 4)
Datafix = Val(hx711)
Cls
Upperline
Lcd "Nilai = " ; Datafix
Wait 3
Datatera = Datafix
Tera = Datatera
Datatera = Tera
Goto Main
Return
'========================================
Hitung:
Cls
Datatera = Tera
Do
Addo = 1
Adsk = 0
Count = 0
While Addo = 1
Wend
For I = 1 To 24
Adsk = 1
Shift Count , Left , 1
Adsk = 0
If Addo = 1 Then Incr Count
Next
Adsk = 1
Count = Count Xor &H800000
Adsk = 0
Hx711_read = Count
Hx711 = Str(hx711_read)
Hx711 = Left(hx711 , 4)
Datafix = Val(hx711)
Dataok = Datafix - Datatera
Dataok = Dataok / 0.423
Strdatok = Fusing(dataok , "#.##")
If Tmbunit = 0 Then
Incr Pcs
If Pcs > 2 Then
Pcs = 1
End If
End If
If Pcs = 1 Then
Upperline
Lcd "Letakkan 100 pcs"
Lowerline
Lcd "Berat = " ; Strdatok ; "gr"
Else
Upperline
Lcd "Letakkan 500 pcs"
Lowerline
Lcd "Berat = " ; Strdatok ; "gr"
End If
Waitms 500
Cls
If Tmbmulai = 0 Then
If Pcs = 1 Then
Datasatuan = Dataok / 100
Satuan = Datasatuan
Datasatuan = Satuan
Else
Datasatuan = Dataok / 500
Satuan = Datasatuan
Datasatuan = Satuan
End If
Goto Hitungpcs
End If
Loop
Return
'=========================================
Hitungpcs:
Cls
Datatera = Tera
Datasatuan = Satuan
Upperline
Lcd "Berat Satuan"
Lowerline
Lcd "Berat = " ; Datasatuan
Wait 5
Cls
Do
Addo = 1
Adsk = 0
Count = 0
While Addo = 1
Wend
For I = 1 To 24
Adsk = 1
Shift Count , Left , 1
Adsk = 0
If Addo = 1 Then Incr Count
Next
Adsk = 1
Count = Count Xor &H800000
Adsk = 0
Hx711_read = Count
Hx711 = Str(hx711_read)
Hx711 = Left(hx711 , 4)
Datafix = Val(hx711)
If Pilih = 1 Then
Dataok = Datafix - Datatera
Dataok = Dataok / 0.423
Jumlah = Dataok / Datasatuan
Strdatok = Fusing(dataok , "#.##")
Upperline
Lcd "Berat = " ; Strdatok ; "gr"
Lowerline
Lcd "Jumlah = " ; Jumlah
Waitms 500
Cls
Elseif Pilih = 2 Then
Dataok = Datafix - Datatera
Dataok = Dataok / 0.423
Jumlah = Dataok / Datasatuan
Dataok = Dataok * 1000
Strdatok = Fusing(dataok , "#.####")
Upperline
Lcd "Berat = " ; Strdatok ; "mg"
Lowerline
Lcd "Jumlah = " ; Jumlah
Waitms 500
Cls
End If
If Tmbback = 0 Then
Goto Main
End If
If Tmbparam = 0 Then
Goto Param
End If
If Tmbsimpan = 0 Then
Goto Simpan
End If
If Tmbunit = 0 Then
Incr Pilih
If Pilih > 2 Then
Pilih = 1
End If
End If
Loop
Return
'==========================================
Param:
Cls
Upperline
Lcd "Satuan = " ; Datasatuan
Lowerline
Lcd "Tera = " ; Datatera
Wait 10
Goto Main
Return
'=========================================
Simpan:
Cls
Waitms 200
Upperline
Lcd " PLEASE WAIT !!"
Wait 1
Cls
Do
If Gbdriveerror <> 0 Then 'CEK MEMORY CARD ERROR
Cls
Locate 1 , 1
Lcd "Error Config"
Locate 2 , 1
Lcd "CEK MEMORY"
Wait 2
End If
Ax = Initfilesystem(1) 'init file system
If Ax <> 0 Then
Cls
Locate 1 , 1
Lcd "Error MEMORY"
Locate 2 , 1
Lcd "CEK MEMORY CARD"
Wait 2
Cls
Goto Hitungpcs
End If
Cls
If Ax = 0 Then
Cls
Locate 1 , 1
Lcd "MEMORY OK"
Wait 1
End If
Diskf = Diskfree()
Select Case Diskf 'CEK FREESPACE
S = Diskf
S = Str(s)
Case Is > 3000 : Locate 2 , 1
Lcd " Free > 3MB"
Lcd S
Case Is > 1000 : Locate 2 , 1
Lcd " Free > 1MB"
Lcd S
Case Else : Locate 2 , 1
Lcd "!! FREE < 1MB !!"
Wait 1
Locate 2 , 1
Lcd "GANTI memoryCARD"
End Select
Wait 3
Gosub Getdatetime
Cls
Upperline
Lcd Date$
Lowerline
Lcd Time$
Wait 3
Cls
Ff = Freefile()
L = "RECORD"
Nama = L + ".txt"
Open Nama For Append As #ff 'buat file baru (bisa append bisa output)
If Pilih = 1 Then
Oke = " gr"
Else
Oke = " mg"
End If
Print #ff , " RESULT"
Print #ff , "#################################"
Print #ff , "#" ; Date$ ; ", " ; Time$
Print #ff , "#################################"
Print #ff , "Berat All : " ; Strdatok ; Oke
Print #ff , "Berat @ : " ; Datasatuan ; " gr"
Print #ff , "Jumlah : " ; Jumlah ; " pcs"
Print #ff ,
Close #ff 'tutup file
Cls
Locate 1 , 1
Lcd "FILE CREATED"
Wait 2
Goto Hitungpcs
Cls
Loop
Return
'///////////////////////////////////////////////////////////////////////////////
'dari ds1307clock.lib
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 'detik
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)
Return
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 day
I2cwbyte _month ' Month
I2cwbyte _year ' years
I2cstop
Return
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
Return
f. Program Bascom AVR Update
$regfile = "m32def.dat"
$crystal = 12000000
Config Lcdpin = Pin , Rs = Portc.6 , E = Portc.7 , Db4 = Portc.2
Config Lcdpin = Pin , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5
Config Lcd = 16 * 2
Cls
Cursor Off
$lib "ds1307clock.lib"
Config Sda = Portc.1
Config Scl = Portc.0
Const Ds1307w = &HD0
Const Ds1307r = &HD1
Config Clock = User
Dim Weekday As Byte
Dim Char As String * 10 , Tanda As String * 1
Dim Jam As String * 10 , Menit As String * 10 , Detik As String * 10
Dim Hari As String * 10 , Bulan As String * 10 , Tahun As String * 10
Dim A As Byte , B As Byte , C As Byte
Dim X As Byte , Y As Byte , Z As Byte
Dim Waktu As String * 10
Dim Tanggal As String * 10
Dim Oke As String * 5
Dim Pcs As Integer
Dim Count As Long
Dim I As Byte
Dim Hx711_read As Long
Dim Hx711 As String * 10
Dim Datafix As Integer
Dim Dataok As Single
Dim Strdatok As String * 10
Dim Strjml As String * 10
Dim Ax As Byte
Dim L As String * 10
Dim Ff As Byte
Dim S As Long
Dim Diskf As Long
Dim Disks As Long
Dim Nama As String * 20
Dim Satuan As Eram Single
Dim Datasatuan As Single
Dim Jumlah As Integer
Dim Tera As Eram Single
Dim Datatera As Single
Dim Pilih As Integer
Adsk Alias Portd.4 ' use pin D.4 as output sck
Addo Alias Pind.5 ' use pin D.5 as input Dataout
Config Adsk = Output
Config Addo = Input
$include "Config_AVR-DOS32.BAS"
$include "Config_MMC32.bas"
Ff = Drivereset()
Ff = Driveinit()
$external Waitms
'Date$ = "08/13/15" 'mm/dd/yy
'Time$ = "15:36:00" 'hh:mm:ss
Ddrd.4 = 1
Ddrd.5 = 0
Ddrb.0 = 0
Ddrb.1 = 0
Ddrb.2 = 0
Ddrb.3 = 0
Ddrd.0 = 0
Ddrd.1 = 0
Ddrd.2 = 0
Ddrd.3 = 0
Tmbok Alias Pinb.4
Tmbmulai Alias Pinb.1
Tmbunit Alias Pinb.3
Tmbhitung Alias Pinb.0
Tmbback Alias Pind.3
Tmbtera Alias Pind.2
Tmbsimpan Alias Pind.1
Tmbparam Alias Pind.0
Set Portb.0
Set Portb.1
Set Portb.2
Set Portb.3
Set Portd.0
Set Portd.1
Set Portd.2
Set Portd.3
Pilih = 1
Main:
Datatera = Tera
Do
Addo = 1
Adsk = 0
Count = 0
While Addo = 1
Wend
For I = 1 To 24
Adsk = 1
Shift Count , Left , 1
Adsk = 0
If Addo = 1 Then Incr Count
Next
Adsk = 1
Count = Count Xor &H800000
Adsk = 0
Hx711_read = Count
Hx711 = Str(hx711_read)
Hx711 = Left(hx711 , 4)
Datafix = Val(hx711)
If Pilih = 1 Then
Dataok = Datafix - Datatera
Dataok = Dataok / 0.423
Strdatok = Fusing(dataok , "#.##")
Upperline
Lcd "Berat = " ; Strdatok ; "gr"
Locate 2 , 1
Lcd "Tera"
Locate 2 , 11
Lcd "Hitung"
Waitms 500
Cls
Elseif Pilih = 2 Then
Dataok = Datafix - Datatera
Dataok = Dataok / 0.423
Dataok = Dataok * 1000
Strdatok = Fusing(dataok , "#.####")
Lcd "Berat = " ; Strdatok ; "mg"
Locate 2 , 1
Lcd "Tera"
Locate 2 , 11
Lcd "Hitung"
Waitms 500
Cls
End If
If Tmbtera = 0 Then
Goto Terazone
End If
If Tmbhitung = 0 Then
Goto Hitung
End If
If Tmbparam = 0 Then
Goto Param
End If
If Tmbunit = 0 Then
Incr Pilih
If Pilih > 2 Then
Pilih = 1
End If
End If
Loop
Terazone:
Addo = 1
Adsk = 0
Count = 0
While Addo = 1
Wend
For I = 1 To 24
Adsk = 1
Shift Count , Left , 1
Adsk = 0
If Addo = 1 Then Incr Count
Next
Adsk = 1
Count = Count Xor &H800000
Adsk = 0
Hx711_read = Count
Hx711 = Str(hx711_read)
Hx711 = Left(hx711 , 4)
Datafix = Val(hx711)
Cls
Upperline
Lcd "Nilai = " ; Datafix
Wait 3
Datatera = Datafix
Tera = Datatera
Datatera = Tera
Goto Main
Return
'========================================
Hitung:
Cls
Datatera = Tera
Do
Addo = 1
Adsk = 0
Count = 0
While Addo = 1
Wend
For I = 1 To 24
Adsk = 1
Shift Count , Left , 1
Adsk = 0
If Addo = 1 Then Incr Count
Next
Adsk = 1
Count = Count Xor &H800000
Adsk = 0
Hx711_read = Count
Hx711 = Str(hx711_read)
Hx711 = Left(hx711 , 4)
Datafix = Val(hx711)
Dataok = Datafix - Datatera
Dataok = Dataok / 0.423
Strdatok = Fusing(dataok , "#.##")
If Tmbunit = 0 Then
Incr Pcs
If Pcs > 2 Then
Pcs = 1
End If
End If
If Pcs = 1 Then
Upperline
Lcd "Letakkan 100 pcs"
Lowerline
Lcd "Berat = " ; Strdatok ; "gr"
Else
Upperline
Lcd "Letakkan 500 pcs"
Lowerline
Lcd "Berat = " ; Strdatok ; "gr"
End If
Waitms 500
Cls
If Tmbmulai = 0 Then
If Pcs = 1 Then
Datasatuan = Dataok / 100
Satuan = Datasatuan
Datasatuan = Satuan
Else
Datasatuan = Dataok / 500
Satuan = Datasatuan
Datasatuan = Satuan
End If
Goto Hitungpcs
End If
Loop
Return
'=========================================
Hitungpcs:
Cls
Datatera = Tera
Datasatuan = Satuan
Upperline
Lcd "Berat Satuan"
Lowerline
Lcd "Berat = " ; Datasatuan
Wait 5
Cls
Do
Addo = 1
Adsk = 0
Count = 0
While Addo = 1
Wend
For I = 1 To 24
Adsk = 1
Shift Count , Left , 1
Adsk = 0
If Addo = 1 Then Incr Count
Next
Adsk = 1
Count = Count Xor &H800000
Adsk = 0
Hx711_read = Count
Hx711 = Str(hx711_read)
Hx711 = Left(hx711 , 4)
Datafix = Val(hx711)
If Pilih = 1 Then
Dataok = Datafix - Datatera
Dataok = Dataok / 0.423
Jumlah = Dataok / Datasatuan
Strdatok = Fusing(dataok , "#.##")
Upperline
Lcd "Berat = " ; Strdatok ; "gr"
Lowerline
Lcd "Jumlah = " ; Jumlah
Waitms 500
Cls
Elseif Pilih = 2 Then
Dataok = Datafix - Datatera
Dataok = Dataok / 0.423
Jumlah = Dataok / Datasatuan
Dataok = Dataok * 1000
Strdatok = Fusing(dataok , "#.####")
Upperline
Lcd "Berat = " ; Strdatok ; "mg"
Lowerline
Lcd "Jumlah = " ; Jumlah
Waitms 500
Cls
End If
If Tmbback = 0 Then
Goto Main
End If
If Tmbparam = 0 Then
Goto Param
End If
If Tmbsimpan = 0 Then
Goto Simpan
End If
If Tmbunit = 0 Then
Incr Pilih
If Pilih > 2 Then
Pilih = 1
End If
End If
Loop
Return
'==========================================
Param:
Cls
Upperline
Lcd "Satuan = " ; Datasatuan
Lowerline
Lcd "Tera = " ; Datatera
Wait 10
Goto Main
Return
'=========================================
Simpan:
Cls
Waitms 200
Upperline
Lcd " PLEASE WAIT !!"
Wait 1
Cls
Do
If Gbdriveerror <> 0 Then 'CEK MEMORY CARD ERROR
Cls
Locate 1 , 1
Lcd "Error Config"
Locate 2 , 1
Lcd "CEK MEMORY"
Wait 2
End If
Ax = Initfilesystem(1) 'init file system
If Ax <> 0 Then
Cls
Locate 1 , 1
Lcd "Error MEMORY"
Locate 2 , 1
Lcd "CEK MEMORY CARD"
Wait 2
Cls
Goto Hitungpcs
End If
Cls
If Ax = 0 Then
Cls
Locate 1 , 1
Lcd "MEMORY OK"
Wait 1
End If
Diskf = Diskfree()
Select Case Diskf 'CEK FREESPACE
S = Diskf
S = Str(s)
Case Is > 3000 : Locate 2 , 1
Lcd " Free > 3MB"
Lcd S
Case Is > 1000 : Locate 2 , 1
Lcd " Free > 1MB"
Lcd S
Case Else : Locate 2 , 1
Lcd "!! FREE < 1MB !!"
Wait 1
Locate 2 , 1
Lcd "GANTI memoryCARD"
End Select
Wait 3
Gosub Getdatetime
Cls
Upperline
Lcd Date$
Lowerline
Lcd Time$
Wait 3
Cls
Ff = Freefile()
L = "RECORD"
Nama = L + ".txt"
Open Nama For Append As #ff 'buat file baru (bisa append bisa output)
If Pilih = 1 Then
Oke = " gr"
Else
Oke = " mg"
End If
Print #ff , " RESULT"
Print #ff , "#################################"
Print #ff , "#" ; Date$ ; ", " ; Time$
Print #ff , "#################################"
Print #ff , "Berat All : " ; Strdatok ; Oke
Print #ff , "Berat @ : " ; Datasatuan ; " gr"
Print #ff , "Jumlah : " ; Jumlah ; " pcs"
Print #ff ,
Close #ff 'tutup file
Cls
Locate 1 , 1
Lcd "FILE CREATED"
Wait 2
Goto Hitungpcs
Cls
Loop
Return
'///////////////////////////////////////////////////////////////////////////////
'dari ds1307clock.lib
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 'detik
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)
Return
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 day
I2cwbyte _month ' Month
I2cwbyte _year ' years
I2cstop
Return
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
Return
g. VIDEO HASILNYA
No comments:
Post a Comment