kali ini saya akan menjelskan mengenai bagaimana cara membuat alat untuk perhitungan kalori, jadi alat ini bisa menghitung kalori seseorang dengan menggunakan beberapa input data dan sebuah timbangan badan. alat ini menggunakan keypad matrik yang berfungsi sebagai input nilai dan kontrol penyimpanan data, selain itu alat ini dilengkapi dengan display LCD 16x2 sebagai penampilnya agar user bisa mengetahui nilai yang didapat dan juga nilai hasil perhitungan. Terdapat 4 buah push button yang digunakan untuk input level aktifitas, yang mana tiap tombol mewakili suatu nilai terkait level aktifitas orang yang akan dihitung kalorinya.
a.Minimum System ATMega
b. Keypad Matrix
c. Push Button
d. Load Cell 100kg + Amplifier
e. Program Bascom AVR
$regfile = "m16def.dat"
$crystal = 11059200
Config Lcdpin = Pin , Rs = Portc.2 , E = Portc.3 , Db4 = Portc.4
Config Lcdpin = Pin , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7
Config Lcd = 16 * 2
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Dim Dataadc As Word
Declare Sub Keypad
Declare Sub Entri_data
Declare Sub Keypad2
Declare Sub Entri_data2
Declare Sub Keypad3
Declare Sub Keypad5
Dim Urut As Byte
Dim Kode As Byte
Dim Flag As Bit
Dim I As Word
Dim Nilai As Long
Dim Angka As Integer
Dim Valtinggi As Integer
Dim Urut2 As Byte
Dim Kode2 As Byte
Dim Flag2 As Bit
Dim I2 As Word
Dim Valusia As Integer
Dim Urut3 As Byte
Dim Kode3 As Byte
Dim Flag3 As Bit
Dim I3 As Word
Dim Valgender As Integer
Dim Aktifitas As Single
Dim Urut5 As Byte
Dim Kode5 As Byte
Dim Flag5 As Bit
Dim I5 As Word
Dim Male1 As Single
Dim Male2 As Single
Dim Male3 As Single
Dim Female1 As Single
Dim Female2 As Single
Dim Female3 As Single
Dim Bmrmale As Single
Dim Bmrfemale As Single
Dim Hasil As Single
Dim W As String * 6
Cls
Cursor Off
Config Pinb.0 = Input
Config Pinb.1 = Input
Config Pinb.2 = Input
Config Pinb.3 = Input
Tombol1 Alias Pinb.0
Tombol2 Alias Pinb.1
Tombol3 Alias Pinb.2
Tombol4 Alias Pinb.3
Set Portb.0
Set Portb.1
Set Portb.2
Set Portb.3
Ddrd = &B11110000
Portd = &HFF
Inputdata1:
Cls
Locate 1 , 1
Lcd "Kalori Counter"
Locate 2 , 1
Lcd "Mulai Tekan * "
Gosub Keypad
'Baca Keypad
Sub Keypad()
Kode = 0
Urut = 0
Flag = 0
I = 0
Do
For I = 0 To 20000
'KOLOM 1
Portd = &B11101111
'tombol A
If Pind.0 = 0 Then
Waitms 200
Elseif Pind.1 = 0 Then
Angka = 4
Gosub Entri_data
Waitms 200
Elseif Pind.2 = 0 Then
Angka = 7
Gosub Entri_data
Waitms 200
'tombol *
Elseif Pind.3 = 0 Then
Waitms 200
Goto Datain
End If
'KOLOM 2
Portd = &B11011111
If Pind.0 = 0 Then
Angka = 1
Gosub Entri_data
Waitms 200
Elseif Pind.1 = 0 Then
Angka = 5
Gosub Entri_data
Waitms 200
Elseif Pind.2 = 0 Then
Angka = 8
Gosub Entri_data
Waitms 200
Elseif Pind.3 = 0 Then
Angka = 0
Gosub Entri_data
Waitms 200
End If
'KOLOM 3
Portd = &B10111111
If Pind.0 = 0 Then
Angka = 2
Gosub Entri_data
Waitms 200
Elseif Pind.1 = 0 Then
Angka = 6
Gosub Entri_data
Waitms 200
Elseif Pind.2 = 0 Then
Angka = 9
Gosub Entri_data
Waitms 200
'tombol #
Elseif Pind.3 = 0 Then
Waitms 200
Valtinggi = Nilai
Cls
Upperline
Lcd "Simpan...."
Wait 1
Cls
Goto Inputdata2
End If
'KOLOM 4
Portd = &B01111111
If Pind.0 = 0 Then
Angka = 3
Gosub Entri_data
Waitms 200
' tombol B
Elseif Pind.1 = 0 Then
Waitms 200
'tombol C
Elseif Pind.2 = 0 Then
Waitms 200
'tombol D
Elseif Pind.3 = 0 Then
Waitms 200
End If
Next
Loop
End Sub
'Entri Data
Sub Entri_data()
Incr Urut
Select Case Urut
Case 1 : Nilai = Angka
Lcd Angka
Case 2 : Nilai = Nilai * 10
Nilai = Nilai + Angka
Lcd Angka
Valtinggi = Nilai
Case 3 : Nilai = Nilai * 10
Nilai = Nilai + Angka
Lcd Angka
Valtinggi = Nilai
Case 4 : Nilai = Nilai * 10
Nilai = Nilai + Angka
Lcd Angka
Valtinggi = Nilai
Case 5 : Nilai = Nilai * 10
Nilai = Nilai + Angka
Lcd Angka
Urut = 0
Locate 2 , 1
Valtinggi = Nilai
End Select
End Sub
Datain:
Cls
Cursor Blink
Cursor On
Locate 1 , 1
Lcd "Tnput Tinggi:"
Locate 2 , 1
Cursor Blink
Cursor On
Waitms 200
Return
'================================================
Inputdata2:
Nilai = 0
Cls
Locate 1 , 1
Lcd "Data Usia"
Locate 2 , 1
Lcd "Mulai Tekan * "
Gosub Keypad2
'Baca Keypad
Sub Keypad2()
Kode2 = 0
Urut2 = 0
Flag2 = 0
I2 = 0
Do
For I2 = 0 To 20000
'KOLOM 1
Portd = &B11101111
'tombol A
If Pind.0 = 0 Then
Waitms 200
Elseif Pind.1 = 0 Then
Angka = 4
Gosub Entri_data2
Waitms 200
Elseif Pind.2 = 0 Then
Angka = 7
Gosub Entri_data2
Waitms 200
'tombol *
Elseif Pind.3 = 0 Then
Waitms 200
Goto Datain2
End If
'KOLOM 2
Portd = &B11011111
If Pind.0 = 0 Then
Angka = 1
Gosub Entri_data2
Waitms 200
Elseif Pind.1 = 0 Then
Angka = 5
Gosub Entri_data2
Waitms 200
Elseif Pind.2 = 0 Then
Angka = 8
Gosub Entri_data2
Waitms 200
Elseif Pind.3 = 0 Then
Angka = 0
Gosub Entri_data2
Waitms 200
End If
'KOLOM 3
Portd = &B10111111
If Pind.0 = 0 Then
Angka = 2
Gosub Entri_data2
Waitms 200
Elseif Pind.1 = 0 Then
Angka = 6
Gosub Entri_data2
Waitms 200
Elseif Pind.2 = 0 Then
Angka = 9
Gosub Entri_data2
Waitms 200
'tombol #
Elseif Pind.3 = 0 Then
Waitms 200
Valusia = Nilai
Cls
Upperline
Lcd "Simpan...."
Wait 1
Goto Inputdata3
End If
'KOLOM 4
Portd = &B01111111
If Pind.0 = 0 Then
Angka = 3
Gosub Entri_data2
Waitms 200
' tombol B
Elseif Pind.1 = 0 Then
Waitms 200
'tombol C
Elseif Pind.2 = 0 Then
Waitms 200
'tombol D
Elseif Pind.3 = 0 Then
Waitms 200
End If
Next
Loop
End Sub
'Entri Data
Sub Entri_data2()
Incr Urut2
Select Case Urut
Case 1 : Nilai = Angka
Lcd Angka
Case 2 : Nilai = Nilai * 10
Nilai = Nilai + Angka
Lcd Angka
Valusia = Nilai
Case 3 : Nilai = Nilai * 10
Nilai = Nilai + Angka
Lcd Angka
Valusia = Nilai
Case 4 : Nilai = Nilai * 10
Nilai = Nilai + Angka
Lcd Angka
Valusia = Nilai
Case 5 : Nilai = Nilai * 10
Nilai = Nilai + Angka
Lcd Angka
Urut2 = 0
Locate 2 , 1
Valusia = Nilai
End Select
End Sub
Datain2:
Cls
Cursor Blink
Cursor On
Locate 1 , 1
Lcd "Tnput Usia:"
Locate 2 , 1
Cursor Blink
Cursor On
Waitms 200
Return
'================================================
Inputdata3:
Cls
Locate 1 , 1
Lcd "Tekan A atau B"
Locate 2 , 1
Lcd "A:Male" ; " " ; "B:Female"
Gosub Keypad3
'Baca Keypad
Sub Keypad3()
Kode3 = 0
Urut3 = 0
Flag3 = 0
I3 = 0
Do
For I3 = 0 To 20000
'KOLOM 1
Portd = &B11101111
'tombol A
If Pind.0 = 0 Then
Waitms 200
Valgender = 1
Cls
Goto Inputdata4
Elseif Pind.1 = 0 Then
Waitms 200
Elseif Pind.2 = 0 Then
Waitms 200
'tombol *
Elseif Pind.3 = 0 Then
Waitms 200
End If
'KOLOM 2
Portd = &B11011111
If Pind.0 = 0 Then
Waitms 200
Elseif Pind.1 = 0 Then
Waitms 200
Elseif Pind.2 = 0 Then
Waitms 200
Elseif Pind.3 = 0 Then
Waitms 200
End If
'KOLOM 3
Portd = &B10111111
If Pind.0 = 0 Then
Waitms 200
Elseif Pind.1 = 0 Then
Waitms 200
Elseif Pind.2 = 0 Then
Waitms 200
'tombol #
Elseif Pind.3 = 0 Then
Waitms 200
End If
'KOLOM 4
Portd = &B01111111
If Pind.0 = 0 Then
Waitms 200
' tombol B
Elseif Pind.1 = 0 Then
Waitms 200
Valgender = 2
Cls
Goto Inputdata4
'tombol C
Elseif Pind.2 = 0 Then
Waitms 200
'tombol D
Elseif Pind.3 = 0 Then
Waitms 200
End If
Next
Loop
End Sub
'================================================
Inputdata4:
Do
Upperline
Lcd "Level Aktivitas"
If Tombol1 = 0 Then
Waitms 200
Aktifitas = 1.200
Cls
Upperline
Lcd "Tidak Aktif"
Wait 3
Cls
Goto Inputdata5
Elseif Tombol2 = 0 Then
Waitms 200
Aktifitas = 1.375
Cls
Upperline
Lcd "Aktifitas Ringan"
Wait 3
Cls
Goto Inputdata5
Elseif Tombol3 = 0 Then
Waitms 200
Aktifitas = 1.550
Cls
Upperline
Lcd "Aktifitas Sedang"
Wait 3
Cls
Goto Inputdata5
Elseif Tombol4 = 0 Then
Waitms 200
Aktifitas = 1.725
Cls
Upperline
Lcd "Aktifitas Berat"
Wait 3
Cls
Goto Inputdata5
End If
Loop
'===========================================
Inputdata5:
Wait 1
Cls
Start Adc
Gosub Keypad5
'Baca Keypad
Sub Keypad5()
Kode5 = 0
Urut5 = 0
Flag5 = 0
I5 = 0
Do
'kalibrasi loadcell
Dataadc = Getadc(0)
Upperline
Lcd "Berat = " ; Dataadc
For I5 = 0 To 20000
'KOLOM 1
Portd = &B11101111
'tombol A
If Pind.0 = 0 Then
Waitms 200
Elseif Pind.1 = 0 Then
Waitms 200
Elseif Pind.2 = 0 Then
Waitms 200
'tombol *
Elseif Pind.3 = 0 Then
Waitms 200
End If
'KOLOM 2
Portd = &B11011111
If Pind.0 = 0 Then
Waitms 200
Elseif Pind.1 = 0 Then
Waitms 200
Elseif Pind.2 = 0 Then
Waitms 200
Elseif Pind.3 = 0 Then
Waitms 200
End If
'KOLOM 3
Portd = &B10111111
If Pind.0 = 0 Then
Waitms 200
Elseif Pind.1 = 0 Then
Waitms 200
Elseif Pind.2 = 0 Then
Waitms 200
'tombol #
Elseif Pind.3 = 0 Then
Waitms 200
Goto Proses
End If
'KOLOM 4
Portd = &B01111111
If Pind.0 = 0 Then
Waitms 200
' tombol B
Elseif Pind.1 = 0 Then
Waitms 200
'tombol C
Elseif Pind.2 = 0 Then
Waitms 200
'tombol D
Elseif Pind.3 = 0 Then
Waitms 200
End If
Next
Loop
End Sub
'================================================
Proses:
Cls
If Valgender = 1 Then
Male1 = 13.7516 * Dataadc
Male2 = 5.003 * Valtinggi
Male3 = 6.7550 * Valusia
Bmrmale = 66.4730 + Male1
Bmrmale = Bmrmale + Male2
Bmrmale = Bmrmale - Male3
Hasil = Bmrmale * Aktifitas
W = "Pria"
Elseif Valgender = 2 Then
Female1 = 9.5634 * Dataadc
Female2 = 1.8496 * Valtinggi
Female3 = 4.6756 * Valusia
Bmrfemale = 655.0955 + Female1
Bmrfemale = Bmrfemale + Female2
Bmrfemale = Bmrfemale - Female3
Hasil = Bmrfemale * Aktifitas
W = "Wanita"
End If
Do
Upperline
Lcd "Hasil Kalori"
Lowerline
Lcd W ; " " ; Fusing(hasil , "#.###")
Loop
f. VIDEO HASILNYA
No comments:
Post a Comment