Tanpa basa basi lagi dari judulnya mungkin sudah pada tau, yaitu bagaimana cara membuat menu program dengan beberapa tombol, yang gunanya untuk menseting beberapa nilai variable atau pilihan lainnya juga dapat dibuat. disini akan saya buat contoh program pengaturan suhu dan dapat di aplikasikan untuk mesin tetas telur.
karna saya jarang membuat skematik dalam me-Layout rangkaian jadi saya deskripsikan pin2 yang digunakan pada rankaian nantinya.
4 buah tombol aktiv low yang dihubungkan ke PortB.0 - PortB.3
LCD 2 x 16 ke Portc dengan susunan (RS= PC.0 / RW=PC.1 / EN=PC.2 / DB1=PC4 / DB2=PC5 / DB3=PC6 / DB4=PC7 )
Sensor LM 35 ke PORTA.0
Led di Portd / dapat di ganti untuk relay karna sebagai outputnya.
listing program nya:
$regfile = "m16def.dat"
$crystal = 11059200
$crystal = 11059200
membuat inisialisasi header program yaitu menggunakan mikrokontroler ATmega16, dan menggunakan cristal 11.059200. kenapa pake cristal segitu..?? ya karna di sismin saya selalu pake segitu dan bisa juga mau pake yang lebih kecil juga bisa.. hehehe..
$lib "lcd4busy.lbx"
Config Lcd = 16 * 2
Const _lcdport = Portc
Const _lcdddr = Ddrc
Const _lcdin = Pinc
Const _lcd_e = 2
Const _lcd_rw = 1
Const _lcd_rs = 0
Cursor Off
Config Lcd = 16 * 2
Const _lcdport = Portc
Const _lcdddr = Ddrc
Const _lcdin = Pinc
Const _lcd_e = 2
Const _lcd_rw = 1
Const _lcd_rs = 0
Cursor Off
nah kalo ini hanya untuk inisialisasi atau konfigurasi LCD, saya menggunakan library nya baskom jadi sedikit berbeda dari biasanya.. dan kenapa saya pake seperti ini karna alasan kadang saya menggunakan library codevision jadi biar tidak memindahkan pin RW nya ke GND jadi saya lebih suka buat seperti di atas jika menggunakan Baskom AVR.
Deflcdchar 1 , 32 , 32 , 32 , 31 , 31 , 32 , 32 , 32
Deflcdchar 0 , 32 , 4 , 10 , 21 , 27 , 14 , 4 , 32
Config Adc = Single , Prescaler = Auto , Reference = Avcc
'#===========================================
Deflcdchar 0 , 32 , 4 , 10 , 21 , 27 , 14 , 4 , 32
Config Adc = Single , Prescaler = Auto , Reference = Avcc
'#===========================================
Dim X As Byte
Dim Ws As Word
Dim Wt As Word
Dim Ss As Word
Dim Aa_suhu0 As Eram Byte
Dim Aa_suhu1 As Eram Byte
Dim Aa_suhu2 As Eram Byte
Dim Oper_heat As Eram Byte
Dim Kalibrasi As Eram Byte
Dim Bb_lembab As Eram Byte
Dim Sensor As Eram Byte
Dim Kp0 As Byte
Dim Kp1 As Byte
Dim Kp2 As Byte
Dim Kp3 As Byte
Dim Kd As Byte
Dim Kb As Byte
Ddrb = &B11110000
Portb = &B11111111
Ddrd = &B11111111
Portd = &B11111111
Kp0 = Aa_suhu0
Kp1 = Aa_suhu1
Kp2 = Aa_suhu2
Kp3 = Oper_heat
Kd = Bb_lembab
Kb = Kalibrasi
Dim Ws As Word
Dim Wt As Word
Dim Ss As Word
Dim Aa_suhu0 As Eram Byte
Dim Aa_suhu1 As Eram Byte
Dim Aa_suhu2 As Eram Byte
Dim Oper_heat As Eram Byte
Dim Kalibrasi As Eram Byte
Dim Bb_lembab As Eram Byte
Dim Sensor As Eram Byte
Dim Kp0 As Byte
Dim Kp1 As Byte
Dim Kp2 As Byte
Dim Kp3 As Byte
Dim Kd As Byte
Dim Kb As Byte
Ddrb = &B11110000
Portb = &B11111111
Ddrd = &B11111111
Portd = &B11111111
Kp0 = Aa_suhu0
Kp1 = Aa_suhu1
Kp2 = Aa_suhu2
Kp3 = Oper_heat
Kd = Bb_lembab
Kb = Kalibrasi
Program di atas inisialisasi juga.. mari kita lanjuta ke berikutnya nanti bagian atas itu akan ngerti dengan sendirinya. menu program yang akan di buat ada bebrapa pengturan yang dirancang yaitu:
pengaturan suhu0 yaitu untuk level 1
pengaturan suhu0 yaitu untuk level 1
pengaturan suhu1 yaitu untuk level 2
pengaturan suhu2 yaitu untuk level 3
pengaturan oper_heat atau batas suhu maksimal nya pada sistem
serta menu program untuk mengkalibrasi sensor *misal alat ukur nya tidak sesui nilainya dengan alat ukur yang sudah ada maka dibuat menu untuk mencocokan kalibrasinya
pengaturan suhu2 yaitu untuk level 3
pengaturan oper_heat atau batas suhu maksimal nya pada sistem
serta menu program untuk mengkalibrasi sensor *misal alat ukur nya tidak sesui nilainya dengan alat ukur yang sudah ada maka dibuat menu untuk mencocokan kalibrasinya
Sw_a Alias Pinb.0 ' Tombol Program
Sw_b Alias Pinb.1 ' Tombol OK
Sw_c Alias Pinb.2 ' Tombol UP
Sw_d Alias Pinb.3 ' Tombol Donw
membuat inisial tombol pada pin mikronya, tombol aktiv low atau akan aktiv jika dihubungkan dengan ground nya.
Cls
Ok:
Start Adc
Gosub Suhu
Gosub Kelembapan
Do
If Sw_a = 0 Then Goto Program 'masuk menu setingan
If Sw_b = 0 Then Goto Ok
Loop
'*******************************************************************************
Program:
If Sw_c = 0 Then Goto Atur_suhu0
If Sw_d = 0 Then Goto Atur_lembab
Cls
Lcd "Input Setingan"
Lcd " "
Waitms 300
Do
If Sw_c = 0 Then Goto Kalibrasi
If Sw_a = 0 Then Goto Credit
If Sw_b = 0 Then
Waitms 300
Goto Set_simpan
End If
If Sw_c = 0 Then
Waitms 300
Goto Atur_suhu0
End If
If Sw_d = 0 Then
Waitms 300
Goto Atur_lembab
End If
Loop
'*******************************************************************************
Atur_suhu0:
Cls
Locate 1 , 1
Lcd "Atur Suhu"
Locate 2 , 1
Lcd "Level_1 " ; Chr(0)
Do
Locate 2 , 12
Lcd Kp0 ; " "
If Sw_b = 0 Then
Aa_suhu0 = Kp0
Aa_suhu1 = Kp1
Aa_suhu2 = Kp2
Kalibrasi = Kb
Bb_lembab = Kd
Goto Set_simpan
End If
If Sw_a = 0 Then
Waitms 300
Goto Atur_suhu1
End If
If Sw_c = 0 Then
Waitms 150
Incr Kp0
End If
If Sw_d = 0 Then
Waitms 150
Decr Kp0
End If
Loop
Atur_suhu1:
Cls
Locate 1 , 1
Lcd "Atur Suhu"
Locate 2 , 1
Lcd "Level_2 " ; Chr(0)
Do
Locate 2 , 12
Lcd Kp1 ; " "
If Sw_b = 0 Then
Aa_suhu0 = Kp0
Aa_suhu1 = Kp1
Aa_suhu2 = Kp2
Kalibrasi = Kb
Bb_lembab = Kd
Goto Set_simpan
End If
If Sw_a = 0 Then
Waitms 300
Goto Atur_suhu2
End If
If Sw_c = 0 Then
Waitms 150
Incr Kp1
End If
If Sw_d = 0 Then
Waitms 150
Decr Kp1
End If
Loop
Atur_suhu2:
Cls
Locate 1 , 1
Lcd "Atur Suhu"
Locate 2 , 1
Lcd "Level_3 " ; Chr(0)
Do
Locate 2 , 12
Lcd Kp2 ; " "
If Sw_b = 0 Then
Aa_suhu0 = Kp0
Aa_suhu1 = Kp1
Aa_suhu2 = Kp2
Kalibrasi = Kb
Bb_lembab = Kd
Goto Set_simpan
End If
If Sw_a = 0 Then
Waitms 300
Goto Oper_heat
End If
If Sw_c = 0 Then
Waitms 150
Incr Kp2
End If
If Sw_d = 0 Then
Waitms 150
Decr Kp2
End If
Loop
Oper_heat:
Cls
Locate 1 , 1
Lcd "Atur Suhu"
Locate 2 , 1
Lcd "OperHeat " ; Chr(0)
Do
Locate 2 , 13
Lcd Kp3 ; " "
If Sw_b = 0 Then
Aa_suhu0 = Kp0
Aa_suhu1 = Kp1
Aa_suhu2 = Kp2
Kalibrasi = Kb
Bb_lembab = Kd
Goto Set_simpan
End If
If Sw_a = 0 Then
Waitms 200
Goto Kalibrasi
End If
If Sw_c = 0 Then
Waitms 200
Incr Kp3
End If
If Sw_d = 0 Then
Waitms 200
Decr Kp3
End If
Loop
Kalibrasi:
Cls
Locate 1 , 1
Lcd "Kalibrasi Suhu"
Locate 2 , 1
Lcd "kalibarsi= "
Do
Locate 2 , 13
Lcd Kb ; " "
If Sw_b = 0 Then
Aa_suhu0 = Kp0
Aa_suhu1 = Kp1
Aa_suhu2 = Kp2
Kalibrasi = Kb
Bb_lembab = Kd
Goto Set_simpan
End If
If Sw_a = 0 Then
Waitms 200
Goto Atur_suhu0
End If
If Sw_c = 0 Then
Waitms 200
Incr Kb
End If
If Sw_d = 0 Then
Waitms 200
Decr Kb
End If
Loop
'*******************************************************************************
Atur_lembab:
Cls
Locate 1 , 1
Lcd "Atur Kelembapan"
Locate 2 , 1
Lcd "Lembab " ; Chr(0)
Do
Locate 2 , 10
Lcd Kd ; " "
If Sw_b = 0 Then
Aa_suhu0 = Kp0
Aa_suhu1 = Kp1
Aa_suhu2 = Kp2
Kalibrasi = Kb
Bb_lembab = Kd
Goto Set_simpan
End If
If Sw_b = 0 Then
Waitms 300
Goto Atur_lembab
End If
If Sw_c = 0 Then
Waitms 150
Incr Kd
End If
If Sw_d = 0 Then
Waitms 150
Decr Kd
End If
Loop
'*******************************************************************************
Set_selesai:
Cls
Locate 1 , 1
Lcd "SETTING SELESAI..."
Waitms 500
Set_simpan:
Cls
Locate 1 , 1
Lcd Chr(0) ; "Simpan Program" ; Chr(0)
Locate 2 , 1
Lcd "Loading " ; Chr(1)
Waitms 400
Locate 2 , 1
Lcd "Loading " ; Chr(1) ; Chr(1)
Waitms 400
Locate 2 , 1
Lcd "Loading " ; Chr(1) ; Chr(1) ; Chr(1)
Waitms 400
Locate 2 , 1
Lcd "Loading " ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1)
Waitms 500
Locate 2 , 1
Lcd "Loading " ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1)
Waitms 500
Locate 2 , 1
Lcd "Loading " ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1)
Waitms 500
Locate 2 , 1
Lcd "Loading " ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1)
Waitms 600
'*******************************************************************************
Suhu:
Cls
Locate 1 , 1
Lcd "Suhu " ; Chr(0);
Locate 2 , 1
Lcd "Lembab " ; Chr(0);
Do
Ws = Getadc(0)
X = Ws / 2
Ss = X + Kb
Locate 1 , 10
Lcd Ss ; " "
Waitms 50
If Ss >= Kp0 Then
Portd.2 = 0
Elseif Ss <= Kp0 Then
'Kp0 = Kp0 - 2
Portd.2 = 1
End If
If Ss >= Kp1 Then
Portd.3 = 0
Elseif Ss <= Kp1 Then
'Kp0 = Kp0 - 2
Portd.3 = 1
End If
If Ss >= Kp2 Then
Portd.4 = 0
Elseif Ss <= Kp2 Then
'Kp0 = Kp0 - 2
Portd.4 = 1
End If
If Sw_a = 0 Then
Goto Program
End If
'*******************************************************************************
Kelembapan:
Wt = Getadc(1)
Locate 2 , 10
Lcd Wt ; " "
Waitms 500
If Wt >= Kd Then
Portd.5 = 0
Elseif Wt <= Kd Then
Portd.5 = 1
End If
If Sw_a = 0 Then
Goto Program
End If
Loop
'*******************************************************************************
Credit:
Cls
Locate 1 , 1
Lcd Chr(0) ; "Sistem Kontrol Temp By. Micro Logic"
Locate 2 , 1
Lcd Chr(0) ; " Keren Sekali Pokoknya ................."
Waitms 800
For X = 1 To 44
Shiftlcd Left
Waitms 250
Next
Wait 1
Goto Ok
Program diatas memiliki 3 level suhu, masing2 level dengan output terpisah
Sekian Program jadinya... panjang banget kalo saya jelaskan bisa sampe pagi.. hehehe..
silahkan di coba aja dulu .. jika ada yang kurang jelas monggo di tanyaken..
Donwload program......
Selamat Berkarya...
Cls
Ok:
Start Adc
Gosub Suhu
Gosub Kelembapan
Do
If Sw_a = 0 Then Goto Program 'masuk menu setingan
If Sw_b = 0 Then Goto Ok
Loop
'*******************************************************************************
Program:
If Sw_c = 0 Then Goto Atur_suhu0
If Sw_d = 0 Then Goto Atur_lembab
Cls
Lcd "Input Setingan"
Lcd " "
Waitms 300
Do
If Sw_c = 0 Then Goto Kalibrasi
If Sw_a = 0 Then Goto Credit
If Sw_b = 0 Then
Waitms 300
Goto Set_simpan
End If
If Sw_c = 0 Then
Waitms 300
Goto Atur_suhu0
End If
If Sw_d = 0 Then
Waitms 300
Goto Atur_lembab
End If
Loop
'*******************************************************************************
Atur_suhu0:
Cls
Locate 1 , 1
Lcd "Atur Suhu"
Locate 2 , 1
Lcd "Level_1 " ; Chr(0)
Do
Locate 2 , 12
Lcd Kp0 ; " "
If Sw_b = 0 Then
Aa_suhu0 = Kp0
Aa_suhu1 = Kp1
Aa_suhu2 = Kp2
Kalibrasi = Kb
Bb_lembab = Kd
Goto Set_simpan
End If
If Sw_a = 0 Then
Waitms 300
Goto Atur_suhu1
End If
If Sw_c = 0 Then
Waitms 150
Incr Kp0
End If
If Sw_d = 0 Then
Waitms 150
Decr Kp0
End If
Loop
Atur_suhu1:
Cls
Locate 1 , 1
Lcd "Atur Suhu"
Locate 2 , 1
Lcd "Level_2 " ; Chr(0)
Do
Locate 2 , 12
Lcd Kp1 ; " "
If Sw_b = 0 Then
Aa_suhu0 = Kp0
Aa_suhu1 = Kp1
Aa_suhu2 = Kp2
Kalibrasi = Kb
Bb_lembab = Kd
Goto Set_simpan
End If
If Sw_a = 0 Then
Waitms 300
Goto Atur_suhu2
End If
If Sw_c = 0 Then
Waitms 150
Incr Kp1
End If
If Sw_d = 0 Then
Waitms 150
Decr Kp1
End If
Loop
Atur_suhu2:
Cls
Locate 1 , 1
Lcd "Atur Suhu"
Locate 2 , 1
Lcd "Level_3 " ; Chr(0)
Do
Locate 2 , 12
Lcd Kp2 ; " "
If Sw_b = 0 Then
Aa_suhu0 = Kp0
Aa_suhu1 = Kp1
Aa_suhu2 = Kp2
Kalibrasi = Kb
Bb_lembab = Kd
Goto Set_simpan
End If
If Sw_a = 0 Then
Waitms 300
Goto Oper_heat
End If
If Sw_c = 0 Then
Waitms 150
Incr Kp2
End If
If Sw_d = 0 Then
Waitms 150
Decr Kp2
End If
Loop
Oper_heat:
Cls
Locate 1 , 1
Lcd "Atur Suhu"
Locate 2 , 1
Lcd "OperHeat " ; Chr(0)
Do
Locate 2 , 13
Lcd Kp3 ; " "
If Sw_b = 0 Then
Aa_suhu0 = Kp0
Aa_suhu1 = Kp1
Aa_suhu2 = Kp2
Kalibrasi = Kb
Bb_lembab = Kd
Goto Set_simpan
End If
If Sw_a = 0 Then
Waitms 200
Goto Kalibrasi
End If
If Sw_c = 0 Then
Waitms 200
Incr Kp3
End If
If Sw_d = 0 Then
Waitms 200
Decr Kp3
End If
Loop
Kalibrasi:
Cls
Locate 1 , 1
Lcd "Kalibrasi Suhu"
Locate 2 , 1
Lcd "kalibarsi= "
Do
Locate 2 , 13
Lcd Kb ; " "
If Sw_b = 0 Then
Aa_suhu0 = Kp0
Aa_suhu1 = Kp1
Aa_suhu2 = Kp2
Kalibrasi = Kb
Bb_lembab = Kd
Goto Set_simpan
End If
If Sw_a = 0 Then
Waitms 200
Goto Atur_suhu0
End If
If Sw_c = 0 Then
Waitms 200
Incr Kb
End If
If Sw_d = 0 Then
Waitms 200
Decr Kb
End If
Loop
'*******************************************************************************
Atur_lembab:
Cls
Locate 1 , 1
Lcd "Atur Kelembapan"
Locate 2 , 1
Lcd "Lembab " ; Chr(0)
Do
Locate 2 , 10
Lcd Kd ; " "
If Sw_b = 0 Then
Aa_suhu0 = Kp0
Aa_suhu1 = Kp1
Aa_suhu2 = Kp2
Kalibrasi = Kb
Bb_lembab = Kd
Goto Set_simpan
End If
If Sw_b = 0 Then
Waitms 300
Goto Atur_lembab
End If
If Sw_c = 0 Then
Waitms 150
Incr Kd
End If
If Sw_d = 0 Then
Waitms 150
Decr Kd
End If
Loop
'*******************************************************************************
Set_selesai:
Cls
Locate 1 , 1
Lcd "SETTING SELESAI..."
Waitms 500
Set_simpan:
Cls
Locate 1 , 1
Lcd Chr(0) ; "Simpan Program" ; Chr(0)
Locate 2 , 1
Lcd "Loading " ; Chr(1)
Waitms 400
Locate 2 , 1
Lcd "Loading " ; Chr(1) ; Chr(1)
Waitms 400
Locate 2 , 1
Lcd "Loading " ; Chr(1) ; Chr(1) ; Chr(1)
Waitms 400
Locate 2 , 1
Lcd "Loading " ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1)
Waitms 500
Locate 2 , 1
Lcd "Loading " ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1)
Waitms 500
Locate 2 , 1
Lcd "Loading " ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1)
Waitms 500
Locate 2 , 1
Lcd "Loading " ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1) ; Chr(1)
Waitms 600
'*******************************************************************************
Suhu:
Cls
Locate 1 , 1
Lcd "Suhu " ; Chr(0);
Locate 2 , 1
Lcd "Lembab " ; Chr(0);
Do
Ws = Getadc(0)
X = Ws / 2
Ss = X + Kb
Locate 1 , 10
Lcd Ss ; " "
Waitms 50
If Ss >= Kp0 Then
Portd.2 = 0
Elseif Ss <= Kp0 Then
'Kp0 = Kp0 - 2
Portd.2 = 1
End If
If Ss >= Kp1 Then
Portd.3 = 0
Elseif Ss <= Kp1 Then
'Kp0 = Kp0 - 2
Portd.3 = 1
End If
If Ss >= Kp2 Then
Portd.4 = 0
Elseif Ss <= Kp2 Then
'Kp0 = Kp0 - 2
Portd.4 = 1
End If
If Sw_a = 0 Then
Goto Program
End If
'*******************************************************************************
Kelembapan:
Wt = Getadc(1)
Locate 2 , 10
Lcd Wt ; " "
Waitms 500
If Wt >= Kd Then
Portd.5 = 0
Elseif Wt <= Kd Then
Portd.5 = 1
End If
If Sw_a = 0 Then
Goto Program
End If
Loop
'*******************************************************************************
Credit:
Cls
Locate 1 , 1
Lcd Chr(0) ; "Sistem Kontrol Temp By. Micro Logic"
Locate 2 , 1
Lcd Chr(0) ; " Keren Sekali Pokoknya ................."
Waitms 800
For X = 1 To 44
Shiftlcd Left
Waitms 250
Next
Wait 1
Goto Ok
Program diatas memiliki 3 level suhu, masing2 level dengan output terpisah
Sekian Program jadinya... panjang banget kalo saya jelaskan bisa sampe pagi.. hehehe..
silahkan di coba aja dulu .. jika ada yang kurang jelas monggo di tanyaken..
Donwload program......
Selamat Berkarya...