You are on page 1of 30

'==================Pendefinisian Mikrokontroler=================================

$regfile =
$crystal =
$hwstack =
$swstack =
$framesize

"m32def.dat"
16000000
50
100
= 100

'==================Konfigurasi Fungsi Port======================================


' ADC CONFIGURATION
Config Porta.1 = Input
Config Porta.2 = Input
Config Porta.3 = Input
Config Porta.4 = Input
Config Porta.5 = Input
Config Porta.6 = Input
Config Porta.7 = Input
' LCD CONFIGURATION
Config Portc.1 = Output
Config Portc.2 = Output
Config Portc.4 = Output
Config Portc.5 = Output
Config Portc.6 = Output
Config Portc.7 = Output
' INPUT CONFIGURATION
Config Pinb.2 = Input
Config Pinb.3 = Input
Config Pind.2 = Input
Config Pinc.0 = Input
' LCD LED CONFIG
Config Pinc.3 = Output
' MOTOR LOGIC
Config Portd.0 = Output
Config Portd.6 = Output
' EAGLE EYE
Config Pind.7 = Input
Config Pind.3 = Input
' SDA SCL EEPROM
Config Scl = Portb.1
Config Sda = Portb.0
'==================================ALIAS========================================
Sw1
Sw2
Sw3
Sw4

Alias
Alias
Alias
Alias

Pinb.3
Pinb.2
Pind.2
Pinc.0

Led_lcd Alias Portc.3


S_kiri Alias Pind.7
S_kanan Alias Pind.3

Mokir Alias Portd.6


Mokan Alias Portd.0
'===============================Konfigurasi ADC=================================
Config Adc = Single , Prescaler = Auto
'===============================Konfigurasi LCD=================================
Config Lcdpin = Pin , Db4 = Portc.7 , Db5 = Portc.6 , Db6 = Portc.5 , Db7 = Port
c.4 , Rs = Portc.1 , E = Portc.2
Config Lcd = 16 * 2 : Cursor Off
'===============================konfigurasi PWM=================================
Config Timer1 = Pwm , Pwm = 8 , Prescale = 256 , Compare A Pwm = Clear Down , Co
mpare B Pwm = Clear Down
'==================================Tipe data====================================
Dim P As Integer , D As Integer , I As Integer
Dim Z As Byte , G As Byte , Dot As Byte
Dim Y As Byte , X As Byte , Q As Byte
Dim S(7) As Byte , Sensor(7) As Integer , Kepekaan As Integer
Dim Kp As Integer , Kd As Integer , Ki As Integer , Speed As Integer
Dim Nilai_sensor As Integer , Error As Integer , Last_error As Integer
Dim Pd As Integer , Pid As Integer
Dim M_left As Integer , M_right As Integer
Dim S_p As Byte , Pv As Integer , Pvv As Integer
Dim Command(255) As Word , Cabang As Word , Map As Byte , Simpang As Byte
Dim L As Byte , H As Byte , Data_eeprom As Word , Perempatan As Byte
Dim Empat As Bit
'=========================Konstanta eeprom======================================
Const Addressw = &B10100000
'slave write address
Const Addressr = &B10100001
'slave read address
'==================================Deklarasi SUB================================
Declare
Declare
Declare
Declare
Declare
Declare
Declare
Declare
Declare
Declare
Declare
Declare
Declare
Declare
Declare
Declare
Declare
Declare
Declare
Declare
Declare

Sub
Sub
Sub
Sub
Sub
Sub
Sub
Sub
Sub
Sub
Sub
Sub
Sub
Sub
Sub
Sub
Sub
Sub
Sub
Sub
Sub

Incr_decr
Kemungkinan
Titik
Loading
Perhitungan
Map_sensor
Panah
Get_adc
Tampil_eeprom
Incr_cabang
Maju
Kiri
Kiri1
Kanan1
Kanan
Kanan2
Kiri2
Kanan3
Kiri4
Kiri5
Kanan5

Declare
Declare
Declare
Declare
Declare
Declare

Sub
Sub
Sub
Sub
Sub
Sub

Henti
Baca_adc
Set_start_map
Set_start_map2
Write_eeprom(byval Cabang As Word , Byval Command(cabang) As Word)
Read_eeprom(byval Cabang As Word)

'===================================Baca EEPROM=================================
Readeeprom
Readeeprom
Readeeprom
Readeeprom
Readeeprom

Speed , 60
Kp , 70
Kd , 75
Ki , 65
Kepekaan , 80

'============================Baca EEPROM Percabangan============================


For Cabang = 1 To 255
Call Read_eeprom(cabang)
Command(cabang) = Data_eeprom
Next
'======================================Start====================================
Cls
Set Led_lcd
Goto Menu
'===============================SUB Loading=====================================
Loading:
Cls
Locate 1 , 1 : Lcd "Loading "
Waitms 60
Gosub Titik
Cls
Return
'===============================SUB Titik=======================================
Sub Titik
X = 9
For X = 9 To 16
Y = 1
Locate Y , X : Lcd "."
Waitms 40
Next
End Sub
'================================Pembacaan EEPROM===============================
Sub Tampil_eeprom
Cls
Locate 1 , 1 : Lcd "Speed= " ; Speed
Locate 2 , 1 : Lcd "Kepekaan= " ; Kepekaan
Wait 1
Cls
Locate 1 , 1 : Lcd "KP= " ; Kp
Locate 1 , 11 : Lcd "KD= " ; Kd
Locate 2 , 1 : Lcd "KI= " ; Ki
Wait 1

Cls
Goto Menu
End Sub
'=================================SUB Menu======================================
Menu:
Cls
Locate 1 , 1 : Lcd "Tes Bro"
Locate 2 , 2 : Lcd "Adc Set Map Go "
Do
If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Go_adc
End If
If Sw2 = 0 Then
Bitwait Sw2 , Set
Goto Setting
End If
If Sw3 = 0 Then
Bitwait Sw3 , Set
Goto Map_kondisi
End If
If Sw4 = 0 Then
Waitms 100
Bitwait Sw4 , Set
Goto Road_race
End If
Loop
'====================================SUB Road Race==============================
Road_race:
Cls
Locate 1 , 4 : Lcd "Race Mode"
Locate 2 , 1 : Lcd "pid / 1=3 / 2=4"
Do
If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Menu
End If
If Sw2 = 0 Then
Bitwait Sw2 , Set
Goto Rutin_pid
End If
If Sw3 = 0 Then
Bitwait Sw3 , Set
Goto Start_1dan3
End If
If Sw4 = 0 Then
Waitms 100

Bitwait Sw4 , Set


'Goto Start_2dan4
End If
Loop
'===================================SUB Rutin_Utama_1===========================
Rutin_pid:
Gosub Loading
Reset Led_lcd
Mokir
Mokan
Do
Gosub
Gosub
Gosub
Gosub

= 0
= 0
Baca_adc
Map_sensor
Kemungkinan
Perhitungan

If Sw4 = 0 Then
Bitwait Sw4 , Set
Set Led_lcd
Pwm1a = 0
Pwm1b = 0
Gosub Loading
Goto Menu
End If
Loop
'===================================Start 1 dan 3===============================
'===============================================================================
Start_1dan3:
Cabang = 1
Gosub Set_start_map
Gosub Loading
Reset Led_lcd
1dan3:
Mokir = 0
Mokan = 0
Pwm1a = Speed
Pwm1b = Speed
Waitms 400
Do
Gosub Baca_adc
Gosub Map_sensor
Gosub Kemungkinan
'=========================logika siku 90========================================

'==============================untuk belok kanan================================


If Nilai_sensor = 28 Then
While S_kanan = 1
Mokir = 0

Mokan = 0
Pwm1a = Speed
Pwm1b = Speed
Wend
If Pv = 7 Then
Set Led_lcd
Select Case Command(cabang)
Case 1 : Call Maju
Case 2 : Call Kiri
Case 3 : Call Kanan
Case 4 : Call Henti
End Select
End If
End If
'===========================siku kiri===========================================
If Nilai_sensor = 112 Then
While S_kiri = 1
Mokir = 0
Mokan = 0
Pwm1a = Speed
Pwm1b = Speed
Wend
If Pv = -7 Then
Set Led_lcd
Select Case Command(cabang)
Case 1 : Call Maju
Case 2 : Call Kiri
Case 3 : Call Kanan
Case 4 : Call Henti
End Select
End If
End If
If S_kanan = 0 Then
If Nilai_sensor = 1 Then
Set Led_lcd
Select Case Command(cabang)
Case 1 : Call Maju
Case 2 : Call Kiri
Case 3 : Call Kanan
Case 4 : Call Henti
End Select
End If
End If
'=================================untuk belok kiri==============================
If S_kiri = 0 Then
If Nilai_sensor = 256 Then
Set Led_lcd
Select Case Command(cabang)
Case 1 : Call Maju
Case 2 : Call Kiri
Case 3 : Call Kanan
Case 4 : Call Henti
End Select
End If
End If

'=====================pertigaan ==========================
If S_kiri = 0 And S_kanan = 0 Then
If Pv > -1 And Pv < 1 Then
Set Led_lcd
Select Case Command(cabang)
Case 1 : Call Maju
Case 2 : Call Kiri
Case 3 : Call Kanan
Case 4 : Call Henti
End Select
End If
End If

'==============================logika perempatan================================
'=======================logika perempatan finis=================================
'If Perempatan = 2 And S_kiri = 0 And S_kanan = 0 Then
' If Pv > -2 And Pv < 2 Then
'
Set Led_lcd
'
Select Case Command(cabang)
'
Case 1 : Call Maju
'
Case 2 : Call Kiri
'
Case 3 : Call Kanan
'
Case 4 : Call Henti
'
End Select
' End If
'End If
'===============================putus-putus=====================================
'If Nilai_sensor = 1 Then
'If Cabang > 22 Then
' Call Kiri5
'End If
'End If
'If Nilai_sensor = 64 Then
'If Cabang > 22 Then
'Call Kanan5
'End If
'End If
'=========================logika pertigaan 270 kanan============================
'If Nilai_sensor = 51 Then
'
Set Led_lcd
'
Select Case Command(cabang)
'
Case 1 : Call Maju
'
Case 2 : Call Kiri2
'
Case 3 : Call Kanan2
'
Case 4 : Call Henti
'
End Select
'End If
'
'If Nilai_sensor = 50 Then

'
Set Led_lcd
'
Select Case Command(cabang)
'
Case 1 : Call Maju
'
Case 2 : Call Kiri2
'
Case 3 : Call Kanan2
'
Case 4 : Call Henti
'
End Select
'End If
'
'=========================logika pertigaan 270 kiri=============================
'If Nilai_sensor = 99 Then
'
Set Led_lcd
'
Select Case Command(cabang)
'
Case 1 : Call Maju
'
Case 2 : Call Kiri2
'
Case 3 : Call Kanan2
'
Case 4 : Call Henti
'
End Select
'End If
'
'If Nilai_sensor = 98 Then
'
Set Led_lcd
'
Select Case Command(cabang)
'
Case 1 : Call Maju
'
Case 2 : Call Kiri2
'
Case 3 : Call Kanan2
'
Case 4 : Call Henti
'
End Select
'End If
Gosub Perhitungan
If Sw4 = 0 Then
Bitwait Sw4 , Set
Set Led_lcd
Pwm1a = 0
Pwm1b = 0
Gosub Loading
Goto Menu
End If
Loop
'===============================================================================
'================================SUB Setting====================================
Setting:
Cls
Locate 1 , 5 : Lcd "Setting"
Locate 2 , 2 : Lcd "Speed Kp Kd Ki"
Do
If Sw1 = 0 Then
Waitms 300
If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Menu
Else
Goto Kecepatan

End If
End If
If Sw2 = 0 Then
Bitwait Sw2 , Set
Goto Proportional
End If
If Sw3 = 0 Then
Bitwait Sw3 , Set
Goto Defrential
End If
If Sw4 = 0 Then
Bitwait Sw4 , Set
Goto Integral
End If
Loop
'=====================================SUB Panah=================================
Panah:
Locate 2 ,
Locate 2 ,
Deflcdchar
Deflcdchar
Return

6
7
0
1

:
:
,
,

Lcd Chr(0)
Lcd Chr(1)
32 , 32 , 31 , 32 , 32 , 31 , 32 , 32
24 , 4 , 2 , 1 , 2 , 4 , 24 , 32

'===================================SUB Speed===================================
Kecepatan:
Cls
Gosub Panah
Locate 1 , 6 : Lcd "Speed"
Do
Locate 2 , 9 : Lcd Speed ; " "
If Sw2 = 0 Then
Waitms 10
Speed = Speed - 3
End If
If Sw3 = 0 Then
Waitms 10
Speed = Speed + 3
End If
If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Setting
End If
If Sw4 = 0 Then
Bitwait Sw4 , Set
Cls
Locate 2 , 6 : Lcd "Speed"
Locate 1 , 1 : Lcd "Saving"

Waitms 200
Gosub Titik
Writeeeprom Speed , 60
Goto Setting
Cls
End If
If Speed >= 255 Then
Speed = 255
End If
If Speed <= 0 Then
Speed = 0
End If
Loop
'=================================SUB Proportional==============================
Proportional:
Cls
Locate 1 , 3 : Lcd "Proportional"
Gosub Panah
Do
Gosub Incr_decr
G = Kp
Gosub Incr_decr
Kp = G
If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Setting
End If
If Sw4 = 0 Then
Bitwait Sw4 , Set
Cls
Locate 2 , 3 : Lcd "Proportional"
Locate 1 , 1 : Lcd "Saving"
Waitms 200
Gosub Titik
Writeeeprom Kp , 70
Goto Setting
Cls
End If
Loop
'================================SUB Defrential=================================
Defrential:
Cls
Locate 1 , 4 : Lcd "Defrential"
Gosub Panah
Do
Gosub Incr_decr
G = Kd
Gosub Incr_decr

Kd = G
If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Setting
End If
If Sw4 = 0 Then
Bitwait Sw4 , Set
Cls
Locate 2 , 4 : Lcd "Defrential"
Locate 1 , 1 : Lcd "Saving"
Waitms 200
Gosub Titik
Writeeeprom Kd , 75
Goto Setting
Cls
End If
Loop
'===============================SUB Integral====================================
Integral:
Cls
Locate 1 , 5 : Lcd "Integral"
Gosub Panah
Do
Gosub Incr_decr
G = Ki
Gosub Incr_decr
Ki = G
If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Setting
End If
If Sw4 = 0 Then
Bitwait Sw4 , Set
Cls
Locate 2 , 5 : Lcd "Integral"
Locate 1 , 1 : Lcd "Saving"
Waitms 200
Gosub Titik
Writeeeprom Ki , 65
Goto Setting
Cls
End If
Loop
'============================SUB Incr_Decr======================================
Sub Incr_decr
Locate 2 , 9 : Lcd G ; " "
If Sw2 = 0 Then
Waitms 50

G = G - 1
End If
If Sw3 = 0 Then
Waitms 50
G = G + 1
End If
If G >= 100 Then
G = 100
End If
If G <= 0 Then
G = 0
End If
End Sub
'==================================SUB Menu_ADC=================================
Go_adc:
Cls
Locate 1 , 7 : Lcd "ADC"
Locate 2 , 1 : Lcd "bck Sen Peka spc"
Do
If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Menu
End If
If Sw2 = 0 Then
Bitwait Sw2 , Set
Goto Sens_adc
End If
If Sw3 = 0 Then
Bitwait Sw3 , Set
Goto Peka
End If
If Sw4 = 0 Then
Bitwait Sw4 , Set
'Goto Kondisi_spesial
End If
Loop
'===================================Sens_Adc====================================
Sens_adc:
Cls
Do
Gosub Baca_adc
Locate 1 , 1 : Lcd Sensor(7) ; " "
Locate 1 , 5 : Lcd Sensor(6) ; " "
Locate 1 , 9 : Lcd Sensor(5) ; " "
Locate 1 , 13 : Lcd Sensor(4) ; " "
Locate 2 , 1 : Lcd Sensor(3) ; " "
Locate 2 , 5 : Lcd Sensor(2) ; " "
Locate 2 , 9 : Lcd Sensor(1) ; " "

Waitms 400
If Sw2 = 0 Then
Bitwait Sw2 , Set
Goto Sens_bit
End If
If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Go_adc
End If
Cls
Loop
'===================================Sens_Bit====================================
Sens_bit:
Cls
Locate 2 , 4 : Lcd "<"
Locate 2 , 12 : Lcd ">"
Do
Z = 1
For Z = 1 To 7
Start Adc
Sensor(z) = Getadc(z)
If Sensor(z) >= Kepekaan Then
S(z) = 1
Else
S(z) = 0
End If
Next
Locate
Locate
Locate
Locate
Locate
Locate
Locate
Waitms

2 ,
2 ,
2 ,
1 ,
2 ,
2 ,
2 ,
400

5 : Lcd S(7)
6 : Lcd S(6)
7 : Lcd S(5)
8 : Lcd S(4)
9 : Lcd S(3)
10 : Lcd S(2)
11 : Lcd S(1)

If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Sens_adc
End If
Loop
'===============================Baca_ADC========================================
Sub Baca_adc
Start Adc
Sensor(1)
Sensor(2)
Sensor(3)
Sensor(4)
Sensor(5)
Sensor(6)

=
=
=
=
=
=

Getadc(1)
Getadc(2)
Getadc(3)
Getadc(4)
Getadc(5)
Getadc(6)

Sensor(7) = Getadc(7)
Stop Adc
End Sub
'==================================Peka=========================================
Peka:
Cls
Gosub Panah
Locate 1 , 5 : Lcd "Kepekaan"
Do
Locate 2 , 9 : Lcd Kepekaan ; " "
If Sw2 = 0 Then
Waitms 10
Kepekaan = Kepekaan - 10
End If
If Sw3 = 0 Then
Waitms 10
Kepekaan = Kepekaan + 10
End If
If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Go_adc
End If
If Sw4 = 0 Then
Bitwait Sw4 , Set
Cls
Locate 2 , 5 : Lcd "Kepekaan"
Locate 1 , 1 : Lcd "Saving"
Waitms 200
Gosub Titik
Writeeeprom Kepekaan , 80
Goto Go_adc
Cls
End If
If Kepekaan >= 1023 Then
Kepekaan = 1023
End If
If Kepekaan <= 0 Then
Kepekaan = 0
End If
Loop
'===============================SUB Map_Sensor==================================
Sub Map_sensor
Nilai_sensor = 0
If S_kanan = 0 Then

Nilai_sensor = Nilai_sensor + 1
End If
If Sensor(1) >= Kepekaan Then
Nilai_sensor = Nilai_sensor + 2
End If
If Sensor(2) >= Kepekaan Then
Nilai_sensor = Nilai_sensor + 4
End If
If Sensor(3) >= Kepekaan Then
Nilai_sensor = Nilai_sensor + 8
End If
If Sensor(4) >= Kepekaan Then
Nilai_sensor = Nilai_sensor + 16
End If
If Sensor(5) >= Kepekaan Then
Nilai_sensor = Nilai_sensor + 32
End If
If Sensor(6) >= Kepekaan Then
Nilai_sensor = Nilai_sensor + 64
End If
If Sensor(7) >= Kepekaan Then
Nilai_sensor = Nilai_sensor + 128
End If
If S_kiri = 0 Then
Nilai_sensor = Nilai_sensor + 256
End If
'' Garis Putih diatas Hitam ''''
'If S_kanan = 1 Then
'Nilai_sensor = Nilai_sensor + 512
'End If
'If S_kiri = 1 Then
'Nilai_sensor = Nilai_sensor + 131072
'End If
End Sub
'===============================Kemungkinan=====================================
'256 , 128 , 64 , 32 , 16 , 8 , 4 , 2 ,
1
Sub Kemungkinan
Select Case Nilai_sensor
Case 128 : Pv = -7

Case
Case
Case
Case
Case
Case

192 : Pv = -6
64 : Pv = -5
225 : Pv = -4
96 : Pv = -3
32 : Pv = -2
48 : Pv = -1

Case 16 : Pv = 0
Case
Case
Case
Case
Case
Case
Case

24 : Pv = 1
8 : Pv = 2
12 : Pv = 3
14 : Pv = 4
4 : Pv = 5
6 : Pv = 6
2 : Pv = 7

End Select
End Sub
'================================Perhitungan====================================
Sub Perhitungan
If Nilai_sensor = 0 Then
If Pv < -6 Then : Pv = -7
End If
If Pv > 6 Then : Pv = 7
End If
End If
Error = S_p - Pv
P = Kp * Error
I = Error + Last_error
I = I * Ki
I = I / 5
D = Error - Last_error
D = D * Kd
Last_error = Error
Pd = P + D
Pid = Pd + I
M_right = Speed + Pid
M_left = Speed - Pid
If
If
If
If

M_left < 0 Then M_left = 0


M_left > 255 Then M_left = 255
M_right < 0 Then M_right = 0
M_right > 255 Then M_right = 255

Pwm1a = M_right
Pwm1b = M_left
End Sub

'================================SUB Map Kondisi================================


Map_kondisi:
Cls
Locate 1 , 4 : Lcd "Map Option"
Locate 2 , 3 : Lcd "Bck 1/3 2/4"
Do
If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Menu
End If
If Sw2 = 0 Then
Bitwait Sw2 , Set
Goto Mapping_1dan3
End If
If Sw3 = 0 Then
Bitwait Sw3 , Set
Goto Mapping_2dan4
End If
Loop
'==================================Mapping 1 dan 3==============================
Mapping_1dan3:
Cls
Locate 1 , 3 : Lcd "Start 1 / 3"
Locate 2 , 1 : Lcd "Bck Set Look Hps"
Do
If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Map_kondisi
End If
If Sw2 = 0 Then
Bitwait Sw2 , Set
Goto Set_mapping1
End If
If Sw3 = 0 Then
Bitwait Sw3 , Set
Goto Lihat_map1
End If
If Sw4 = 0 Then
Bitwait Sw4 , Set
Goto Hapus_eeprom1
End If
Loop
'==================================set mapping1=================================
Set_mapping1:

Cabang = 1
Set1:
Cls
Locate 1 , 3 : Lcd "Path Setting"
Locate 2 , 1 : Lcd "=> "
Map = 1
Do
Locate 2 , 5 : Lcd Cabang ; " "
If Sw1 = 0 Then
Waitms 300
If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Mapping_1dan3
Else
Cls
Locate 2 , 5 : Lcd "Command"
Locate 1 , 1 : Lcd "Saving"
Waitms 200
Gosub Titik
Command(cabang) = Map
Call Write_eeprom(cabang , Command(cabang))
Goto Set1
Cls
End If
End If
If Sw2 = 0 Then
Waitms 100
Cabang = Cabang - 1
End If
If Cabang > 75 Then
Cabang = 75
End If
If Cabang < 1 Then
Cabang = 1
End If
If Sw3 = 0 Then
Waitms 100
Cabang = Cabang + 1
End If
If Sw4 = 0 Then
Waitms 200
Map = Map + 1
End If
If Map
Locate
End If
If Map
Locate
End If
If Map
Locate
End If
If Map

= 1 Then
2 , 10 : Lcd "Maju "
= 2 Then
2 , 10 : Lcd "Kiri "
= 3 Then
2 , 10 : Lcd "Kanan "
= 4 Then

Locate 2 , 10 : Lcd "Stop "


End If
If Map > 4 Then
Map = 1
End If
Loop
'==================================Mapping 2 dan 4==============================
Mapping_2dan4:
Cls
Locate 1 , 3 : Lcd "Start 2 / 4"
Locate 2 , 1 : Lcd "Bck Set Look Hps"
Do
If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Map_kondisi
End If
If Sw2 = 0 Then
Bitwait Sw2 , Set
Goto Set_mapping2
End If
If Sw3 = 0 Then
Bitwait Sw3 , Set
Goto Lihat_map2
End If
If Sw4 = 0 Then
Bitwait Sw4 , Set
Goto Hapus_eeprom2
End If
Loop
'==================================set mapping2=================================
Set_mapping2:
Cabang = 76
Set2:
Cls
Locate 1 , 3 : Lcd "Path Setting"
Locate 2 , 1 : Lcd "=> "
Map = 1
Do
Simpang = Cabang - 75
Locate 2 , 5 : Lcd Simpang ; "
If Sw1 = 0 Then
Waitms 300
If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Mapping_2dan4
Else
Cls

"

Locate 2 , 5 : Lcd "Command"


Locate 1 , 1 : Lcd "Saving"
Waitms 200
Gosub Titik
Command(cabang) = Map
Call Write_eeprom(cabang , Command(cabang))
Goto Set2
Cls
End If
End If
If Sw2 = 0 Then
Waitms 100
Cabang = Cabang - 1
End If
If Cabang > 255 Then
Cabang = 255
End If
If Cabang < 76 Then
Cabang = 76
End If
If Sw3 = 0 Then
Waitms 100
Cabang = Cabang + 1
End If
If Sw4 = 0 Then
Waitms 200
Map = Map + 1
End If
If Map
Locate
End If
If Map
Locate
End If
If Map
Locate
End If
If Map
Locate
End If

= 1 Then
2 , 10 : Lcd "Maju "
= 2 Then
2 , 10 : Lcd "Kiri "
= 3 Then
2 , 10 : Lcd "Kanan "
= 4 Then
2 , 10 : Lcd "Stop "

If Map > 4 Then


Map = 1
End If
Loop
'======================================Lihat map 1==============================
Lihat_map1:
Cls
Locate 1 , 2 : Lcd "Map Sementara"
Cabang = 1

Do
If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Mapping_1dan3
End If
If Sw2 = 0 Then
Waitms 200
Cabang = Cabang - 1
End If
If Cabang > 74 Then
Cabang = 74
End If
If Cabang < 1 Then
Cabang = 1
End If
If Sw3 = 0 Then
Waitms 200
Cabang = Cabang + 1
End If
Locate 2 , 3 : Lcd Cabang ; "

"

If Command(cabang) = 1 Then
Locate 2 , 10 : Lcd "Maju "
End If
If Command(cabang) = 2 Then
Locate 2 , 10 : Lcd "Kiri "
End If
If Command(cabang) = 3 Then
Locate 2 , 10 : Lcd "Kanan "
End If
If Command(cabang) = 4 Then
Locate 2 , 10 : Lcd "Stop "
End If
If Command(cabang) = 0 Then
Locate 2 , 10 : Lcd "Kosong"
End If
Loop
'=================================lihat map 2===================================
Lihat_map2:
Cls
Locate 1 , 2 : Lcd "Map Sementara"
Cabang = 76
Do
Simpang = Cabang - 75
If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Mapping_2dan4
End If
If Sw2 = 0 Then

Waitms 200
Cabang = Cabang - 1
End If
If Cabang > 255 Then
Cabang = 255
End If
If Cabang < 76 Then
Cabang = 76
End If
If Sw3 = 0 Then
Waitms 200
Cabang = Cabang + 1
End If
Locate 2 , 3 : Lcd Simpang ; "

"

If Command(cabang) = 1 Then
Locate 2 , 10 : Lcd "Maju "
End If
If Command(cabang) = 2 Then
Locate 2 , 10 : Lcd "Kiri "
End If
If Command(cabang) = 3 Then
Locate 2 , 10 : Lcd "Kanan "
End If
If Command(cabang) = 4 Then
Locate 2 , 10 : Lcd "Stop "
End If
If Command(cabang) = 0 Then
Locate 2 , 10 : Lcd "Kosong"
End If
Loop
'=============================Hapus eeprom1=====================================
=
Hapus_eeprom1:
Cls
Locate 1 , 2 : Lcd "Hapus Eeprom ?"
Locate 2 , 6 : Lcd "No/Yes"
Do
If Sw2 = 0 Then
Bitwait Sw2 , Set
Cls
Locate 1 , 1 : Lcd "No Erasing......"
Waitms 250
Goto Mapping_1dan3
End If
If Sw3 = 0 Then
Bitwait Sw3 , Set
Cls
Locate 1 , 1 : Lcd "Please"
Locate 2 , 3 : Lcd "Wait"
For Dot = 7 To 11

Locate 2 , Dot : Lcd "."


For Cabang = 1 To 75
Map = 0
Command(cabang) = Map
Call Write_eeprom(cabang , Command(cabang))
Next
Cabang = Cabang + 75
Next
Cabang = 1
Cls
Locate 1 , 1 : Lcd "Erasing complete"
Locate 2 , 1 : Lcd "................"
Waitms 250
Goto Mapping_1dan3
End If
Loop
'=============================Hapus eeprom2=====================================
Hapus_eeprom2:
Cls
Locate 1 , 2 : Lcd "Hapus Eeprom ?"
Locate 2 , 6 : Lcd "No/Yes"
Do
If Sw2 = 0 Then
Bitwait Sw2 , Set
Cls
Locate 1 , 1 : Lcd "No Erasing......"
Waitms 250
Goto Mapping_2dan4
End If
If Sw3 = 0 Then
Bitwait Sw3 , Set
Cls
Locate 1 , 1 : Lcd "Please"
Locate 2 , 3 : Lcd "Wait"
For Dot = 7 To 11
Locate 2 , Dot : Lcd ".."
For Cabang = 76 To 90
Map = 0
Command(cabang) = Map
Call Write_eeprom(cabang , Command(cabang))
Next
Cabang = Cabang + 15
Next
Cabang = 76
Simpang = Cabang - 75
Cls
Locate 1 , 1 : Lcd "Erasing complete"
Locate 2 , 1 : Lcd "................"
Waitms 250
Goto Mapping_2dan4
End If
Loop
'=====================================Maju======================================
Sub Maju

Reset Led_lcd
Incr Cabang
Mokir = 0
Mokan = 0
Pwm1a = Speed
Pwm1b = Speed
Waitms 40
Waitms 10
End Sub
'=====================================Kiri======================================
Sub Kiri
Pwm1a = 0
Pwm1b = 0
Waitms 250
While Sensor(6) < Kepekaan
Mokir = 1
Mokan = 0
Pwm1a = Speed
Pwm1b = Speed
Gosub Baca_adc
Wend
Mokir = 0
Mokan = 0
Pwm1a = Speed
Pwm1b = Speed
Waitms 10
Cls
Set Led_lcd
Incr Cabang
End Sub
'====================================Kanan======================================
Sub Kanan
Pwm1a = 0
Pwm1b = 0
Waitms 250
While Sensor(2) < Kepekaan
Mokir = 0
Mokan = 1
Pwm1a = Speed
Pwm1b = Speed
Gosub Baca_adc
Wend
Mokir = 0
Mokan = 0
Pwm1a = Speed
Pwm1b = Speed
Waitms 10
Cls
Set Led_lcd
Incr Cabang
End Sub
'==================================kiri1========================================
Sub Kiri1

Mokir = 1
Mokan = 1
Pwm1a = Speed + 80
Pwm1b = Speed + 80
Waitms 50
Waitms 10
Pwm1a = 0
Pwm1b = 0
Waitms 100
While Sensor(7) < Kepekaan
Mokir = 1
Mokan = 0
Pwm1a = 130
Pwm1b = 130
Gosub Baca_adc
Wend
Mokir = 0
Mokan = 1
Pwm1a = 100
Pwm1b = 100
Waitms 60
Cls
Reset Led_lcd
Incr Cabang
End Sub
'==================================kiri2========================================
Sub Kiri2
While
Mokir
Mokan
Pwm1a
Pwm1b
Wend

S_kiri = 0
= 0
= 0
= 100
= 100

Mokir = 1
Mokan = 1
Pwm1a = Speed + 80
Pwm1b = Speed + 80
Waitms 50
Waitms 10
Pwm1a = 0
Pwm1b = 0
Waitms 100
While Sensor(6) < Kepekaan
Mokir = 1
Mokan = 0
Pwm1a = 130
Pwm1b = 130
Gosub Baca_adc
Wend
Mokir = 0
Mokan = 1
Pwm1a = 100
Pwm1b = 100
Waitms 60
Cls

Reset Led_lcd
Incr Cabang
End Sub

'=================================kanan1========================================
Sub Kanan1
Mokir = 1
Mokan = 1
Pwm1a = Speed + 80
Pwm1b = Speed + 80
Waitms 50
Waitms 10
Pwm1a = 0
Pwm1b = 0
Waitms 100
While Sensor(1) < Kepekaan
Mokir = 0
Mokan = 1
Pwm1a = 130
Pwm1b = 130
Gosub Baca_adc
Wend
Mokir = 1
Mokan = 0
Pwm1a = 100
Pwm1b = 100
Waitms 60
Cls
Reset Led_lcd
Incr Cabang
End Sub
'=================================kanan2========================================
Sub Kanan2
While
Mokir
Mokan
Pwm1a
Pwm1b
Wend

S_kanan = 0
= 0
= 0
= 100
= 100

Mokir = 1
Mokan = 1
Pwm1a = Speed + 80
Pwm1b = Speed + 80
Waitms 50
Waitms 10
Pwm1a = 0
Pwm1b = 0
Waitms 100
While Sensor(2) < Kepekaan
Mokir = 0
Mokan = 1
Pwm1a = 130

Pwm1b = 130
Gosub Baca_adc
Wend
Mokir = 1
Mokan = 0
Pwm1a = 100
Pwm1b = 100
Waitms 60
Cls
Reset Led_lcd
Incr Cabang
End Sub
'==================================kanan3=======================================
=
Sub Kanan3
Pwm1a = 0
Pwm1b = 0
Waitms 50
While
Mokir
Mokan
Pwm1a
Pwm1b
Gosub
Wend

Sensor(2) < Kepekaan


= 1
= 0
= 130
= 130
Baca_adc

Incr Cabang
Reset Led_lcd
End Sub
'==================================kiri4========================================
Sub Kiri4
Pwm1a = 0
Pwm1b = 0
Waitms 50
While
Mokir
Mokan
Pwm1a
Pwm1b
Gosub
Gosub
Gosub
Wend

Nilai_sensor > 0
= 0
= 0
= 30
= 30
Baca_adc
Map_sensor
Kemungkinan

Pwm1a = 0
Pwm1b = 0
Waitms 50
While Sensor(7) < Kepekaan
Mokir = 1

Mokan
Pwm1a
Pwm1b
Gosub
Wend

= 0
= 80
= 80
Baca_adc

Incr Cabang
Reset Led_lcd
End Sub
'====================================Stop=======================================
Sub Henti
Waitms 10
Mokir = 1
Mokan = 1
Pwm1a = 200
Pwm1b = 200
Waitms 80
Pwm1a = 0
Pwm1b = 0
Cls
Locate 1 , 4 : Lcd "Perjalanan"
Locate 2 , 6 : Lcd "Selesai"
Do
If Sw4 = 0 Then
Bitwait Sw4 , Set
Gosub Loading
Gosub Titik
Goto Menu
End If
Loop
End Sub
Sub Set_start_map
Cls
Locate 1 , 3 : Lcd "Start Cabang"
Do
Locate 2 , 8 : Lcd Cabang ; "
If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Road_race
End If
If Sw3 = 0 Then
Waitms 100
Cabang = Cabang + 1
End If
If Sw2 = 0 Then
Waitms 100
Cabang = Cabang - 1
End If
If Cabang > 75 Then
Cabang = 1
Elseif Cabang < 1 Then
Cabang = 75

"

End If
If Cabang = 19 Then
Perempatan = 2
End If
If Cabang <= 18 Then
Perempatan = 1
End If
If Sw4 = 0 Then
Bitwait Sw4 , Set
Return
End If
Loop
End Sub
Sub Set_start_map2
Cls
Locate 1 , 3 : Lcd "Start Cabang"
Do
Locate 2 , 8 : Lcd Cabang ; "
If Sw1 = 0 Then
Bitwait Sw1 , Set
Goto Road_race
End If
If Sw3 = 0 Then
Waitms 100
Cabang = Cabang + 1
End If
If Sw2 = 0 Then
Waitms 100
Cabang = Cabang - 1
End If
If Cabang > 255 Then
Cabang = 76
Elseif Cabang < 76 Then
Cabang = 255
End If
If Sw4 = 0 Then
Bitwait Sw4 , Set
Return
End If
Loop
End Sub
Sub Kiri5
Mokir = 1
Mokan = 0
Pwm1a = 50
Pwm1b = 50
Waitms 100
Reset Led_lcd
End Sub

"

Sub Kanan5
Mokir = 0
Mokan = 1
Pwm1a = 50
Pwm1b = 50
Waitms 100
Reset Led_lcd
End Sub
Sub Write_eeprom(byval Cabang As Word , Byval Command(cabang) As Word)
H = High(cabang)
L = Low(cabang)
I2cstart
'start condition
I2cwbyte Addressw
'slave address
I2cwbyte H
'high address
I2cwbyte L
'low address
I2cwbyte Command(cabang)
'value to write
I2cstop
'stop condition
Waitms 10
End Sub
Sub Read_eeprom(byval Cabang As Word)
H = High(cabang)
L = Low(cabang)
I2cstart
I2cwbyte Addressw
I2cwbyte H
I2cwbyte L
I2cstart
I2cwbyte Addressr
)
I2crbyte Data_eeprom , Nack
I2cstop
End Sub

'generate start
'slave adsress
'high address
'low address
'repeated start
'slave address (read
'read byte
'generate stop

You might also like