Vous êtes sur la page 1sur 44

/*****************************************************

This program was produced by the


CodeWizardAVR V1.24.6 Professional
Automatic Program Generator
Copyright 1998-2005 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
e-mail:office@hpinfotech.com
Project :
Version :
Date
: 2/16/2009
Author : F4CG
Company : F4CG
Comments:
Chip type
: ATmega32L
Program type
: Application
Clock frequency
: 8.000000 MHz
Memory model
: Small
External SRAM size : 0
Data Stack size
: 512
*****************************************************/
#include <mega32.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x18 ;PORTB
#endasm
#include <lcd.h>
#include <stdio.h>
#include <delay.h>
#include <math.h>
#define FIRST 0
#define LAST 7
#define VREF 0x20
#define kanan OCR1BL
#define kiri OCR1AL
#define arah_ka1 PORTC.1
#define arah_ka2 PORTC.0
#define arah_ki1 PORTD.7
#define arah_ki2 PORTD.6
#define pin_ir !PIND.1
#define
#define
#define
#define
#define
#define

back !PINC.5
up !PINC.4
down !PINC.3
enter !PINC.2
tidak_ditekan PINC.5&&PINC.4&&PINC.3&&PINC.2
ditekan !PINC.5||!PINC.4||!PINC.3||!PINC.2

#define
#define
#define
#define
#define
#define
#define

nyala 200
lampu_depan_on PORTC.7=0;
lampu_depan_off PORTC.7=1;
lampu_belakang_on PORTD.2=0;
lampu_belakang_off PORTD.2=1;
back_on PORTB.3=1;
back_off PORTB.3=0;

#define sensor_on PORTC.6=0;


#define sensor_off PORTC.6=1;
#define batas 50
#define power 0b0110100010
int nil_kan,nil_kir,error0,error1,sum,ovtim,sekon,speed,speed_1,derror;
int ki,kp_bts_bawah,kp_bts_atas,top_speed,cacah;
signed int adtf;
unsigned char adc[8],lcd[16],sens,sensor,sensor_lalu,maxi[8],mini[8],er;
unsigned char bts[8]={128,128,128,128,128,128,128,128};
unsigned int e[7];
char bat,error,led,tikungan,leb;
char kp,kp1,kd,cuplik,turbo;
char m,belokan_kan,belokan_kir;
bit pilih_autoset,sbg_def,kondisi_turbo,remote;
bit garis,adaptif,garis1,lebar1,lebar2,lebar3,lebar4,lebar5,belokan,siasat_y_ena
ble;
char count_cab,count_cab1,count_cab2,count_cab3, count_cab4,count_cab5,count_cab
6,count_cab7;
char count_warnab,count_warnab1,count_warnab2,count_warnab3,count_warnab4,count_
warnab5,count_warnab6,count_warnab7;
char count_warnaw,count_warnaw1,count_warnaw2,count_warnaw3,count_warnaw4,count_
warnaw5,count_warnaw6,count_warnaw7;
char berubahb,berubahb1,berubahb2,berubahb3,berubahb4,berubahb5,berubahb6,beruba
hb7;
char berubahw,berubahw1,berubahw2,berubahw3,berubahw4,berubahw5,berubahw6,beruba
hw7;
char count_kiri1, count_kiri2, count_kiri3, count_kiri4, count_kiri5, count_kiri
6, count_kiri7, count_kiri8;
char count_kanan1, count_kanan2, count_kanan3, count_kanan4, count_kanan5, count
_kanan6, count_kanan7, count_kanan8;
unsigned char waktu_nyala,jmlh_cab,;
char k,l,index,start_count;
char runing,siasat_enable;
unsigned long int milisekon;
char jum_siasat;
char siasat_arah[30],urut_cab;
char count_cab_y, count_cab_y1, count_cab_y2, count_cab_y3, count_cab_y4, count_
cab_y5, jmlh_cab_y;
eeprom
];
eeprom
eeprom
eeprom
eeprom
eeprom

int eeki[5],eekp_bts_bawah[5],eekp_bts_atas[5], eetop_speed[5],eedelay[5


unsigned char eebts[8][5], eee[8][5], eekekiri[5], eekekanan[5];
char eekp[5], eekd[5], eecabang[5], eegaris[5],eecuplik[5],eeadaptif[5];
char eeutama,eelebar,eeturbo[5];
char eejum_siasat[5];
char eesiasat_arah[30][5];

void bismillah()
{
lcd_clear(); lcd_putsf("Bismillah");
}
void id1()
{
lcd_clear(); lcd_putsf(" ==>Robot_OX<== ");

lcd_gotoxy(0,1); lcd_putsf("Go to Galelobot");


}
void id2()
{
lcd_clear(); lcd_putsf(" Uun Triyas Y K ");
lcd_gotoxy(0,1); lcd_putsf(" +6285292648484 ");
}
void tampil_waktu()
{
lcd_clear();
lcd_putsf("waktu :");
sprintf(lcd,"%d:%d%d:%d%d,%d%d%d",
sekon/3600,(sekon%3600)/600,(sekon%600)/60,(sekon%60)/10,sekon%10,
ovtim/100,(ovtim%100)/10,ovtim%10);
lcd_gotoxy(0,1);
lcd_puts(lcd);
}
void tunggu_tekan(int waktu)
{
int i;
delay_ms(25);
for (i=25;i<waktu;i++)
{
delay_ms(1);
if (back||up||down||enter) goto tunggu_tekan1;
}
tunggu_tekan1:
}
void tunggu_lepas(int waktu)
{
int i;
delay_ms(25);
for (i=25;i<waktu;i++)
{
delay_ms(1);
if (tidak_ditekan) goto tunggu_lepas1;
}
tunggu_lepas1:
}
void keluarkan()
{
if (nil_kan >255)
an;};
if (nil_kan >0)
an;};
if (nil_kan <-255)
an;};
if (nil_kan <0)
an;};
if (nil_kan ==0)
an;};
akhir_kan:
if (nil_kir >255)

//pengeluaran
{kanan =255;

arah_ka1=0; arah_ka2=1; goto akhir_k

{kanan =nil_kan;

arah_ka1=0; arah_ka2=1; goto akhir_k

{kanan =255;

arah_ka1=1; arah_ka2=0; goto akhir_k

{kanan =(-nil_kan); arah_ka1=1; arah_ka2=0; goto akhir_k


{kanan =0;

arah_ka1=0; arah_ka2=0; goto akhir_k

{kiri

arah_ki1=0; arah_ki2=1; goto akhir_k

=255;

ir;};
if (nil_kir
ir;};
if (nil_kir
ir;};
if (nil_kir
ir;};
if (nil_kir
ir;};
akhir_kir:
}

>0)

{kiri

=nil_kir;

arah_ki1=0; arah_ki2=1; goto akhir_k

<-255)

{kiri

=255;

arah_ki1=1; arah_ki2=0; goto akhir_k

<0)

{kiri

=(-nil_kir); arah_ki1=1; arah_ki2=0; goto akhir_k

==0)

{kiri

=0;

void bobot_error0()
{
switch (error)
{
case -5: error0 =
case -4: error0 =
case -3: error0 =
case -2: error0 =
case -1: error0 =
case 0: error0 =
case 1: error0 =
case 2: error0 =
case 3: error0 =
case 4: error0 =
case 5: error0 =
}
}

(int)
(int)
(int)
(int)
(int)
(int)
(int)
(int)
(int)
(int)
(int)

(0-e[5]);
(0-e[4]);
(0-e[3]);
(0-e[2]);
(0-e[1]);
e[0] ;
e[1] ;
e[2] ;
e[3] ;
e[4] ;
e[5] ;

arah_ki1=0; arah_ki2=0; goto akhir_k

break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;

void tampil_pid()
{
lcd_clear();
sprintf (lcd,"p%d",kp); lcd_gotoxy(0,0); lcd_puts(lcd);
sprintf (lcd,"i%d",ki); lcd_gotoxy(5,0); lcd_puts(lcd);
sprintf (lcd,"d%d",kd); lcd_gotoxy(11,0); lcd_puts(lcd);
}
void tampil_kp()
{
sprintf (lcd,"Kp%d",kp);
lcd_clear();lcd_puts(lcd);
}
void tampil_ki()
{
sprintf (lcd,"Ki%d",ki);
lcd_clear();lcd_puts(lcd);
}
void tampil_kd()
{
sprintf (lcd,"Kd%d",kd);
lcd_clear(); lcd_puts(lcd);
}
void tampil_ts()
{
lcd_clear(); lcd_putsf("speed");
sprintf(lcd,"%d",top_speed);

lcd_gotoxy(0,1); lcd_puts(lcd);
}
void tampil_bts_atas()
{
lcd_clear(); lcd_putsf("Batas atas Kp");
sprintf(lcd,"%d",kp_bts_atas);
lcd_gotoxy(0,1); lcd_puts(lcd);
}
void tampil_bts_bawah()
{
lcd_clear(); lcd_putsf("Batas bawah Kp");
sprintf(lcd,"%d",kp_bts_bawah);
lcd_gotoxy(0,1); lcd_puts(lcd);
}
/*tampil_turbo()
{
lcd_clear(); lcd_putsf("Set Turbo");
sprintf(lcd,"%d",turbo);
lcd_gotoxy(0,1); lcd_puts(lcd);
}*/
void tampil_e()
{
lcd_clear();
sprintf(lcd,"%d",e[0]); lcd_gotoxy(0,0); lcd_puts(lcd);
sprintf(lcd,"%d",e[1]); lcd_gotoxy(4,0); lcd_puts(lcd);
sprintf(lcd,"%d",e[2]); lcd_gotoxy(8,0); lcd_puts(lcd);
sprintf(lcd,"%d",e[3]); lcd_gotoxy(12,0); lcd_puts(lcd);
sprintf(lcd,"%d",e[4]); lcd_gotoxy(0,1); lcd_puts(lcd);
sprintf(lcd,"%d",e[5]); lcd_gotoxy(4,1); lcd_puts(lcd);
sprintf(lcd,"%d",e[6]); lcd_gotoxy(8,1); lcd_puts(lcd);
sprintf(lcd,"e%d",er); lcd_gotoxy(13,1); lcd_puts(lcd);
lcd_gotoxy(((((er)%4)*4)+2),(er/4)); lcd_putchar(127);
}
void tampil_autoset()
{
lcd_clear(); lcd_putsf("autoset?");
lcd_gotoxy(0,1);
if (pilih_autoset) lcd_putsf("Y");
else lcd_putsf("T");
}
void tampil_bts()
{
char i;
lcd_clear();
for (i=0;i<8;i++)
{
if (i==bat) lcd_putchar(126);
if (adc[i]<bts[i]) lcd_putsf("0"); else lcd_putsf("1");
if (i==bat) lcd_putchar(127);
}
sprintf (lcd,"%d",adc[bat]);
lcd_gotoxy(12,0); lcd_puts(lcd);
sprintf(lcd,"H%d >%d< L%d",maxi[bat],bts[bat],mini[bat]);

lcd_gotoxy(0,1); lcd_puts(lcd); delay_ms(5);


}
tampil_jmlh_cabang()
{
sprintf(lcd,"jumlah cabang=%d",jum_siasat);
lcd_clear(); lcd_puts(lcd);
}
void tampil_cabang()
{
sprintf(lcd,"cabangan ke %d",urut_cab);
lcd_clear();
lcd_puts(lcd);
lcd_gotoxy(0,1);
if (siasat_arah[urut_cab]==0){lcd_putsf("lurus");};
if (siasat_arah[urut_cab]==1){lcd_putsf("kanan");};
if (siasat_arah[urut_cab]==2){lcd_putsf("kiri");};
}
/*void tampil_cabang1()
{
lcd_clear(); lcd_putsf("cabang?");
sprintf(lcd,"kan=%d",kekanan);
lcd_gotoxy(0,1);
lcd_puts(lcd);
}
void tampil_delay()
{
sprintf(lcd,"delay=%d",nil_delay);
lcd_clear();
lcd_puts(lcd);
}*/
void tampil_cuplik()
{
lcd_clear();
sprintf(lcd,"cuplik %d ms",cuplik);
lcd_puts(lcd);
}
void tampil_warna()
{
lcd_clear(); lcd_putsf("garis");
lcd_gotoxy(0,1);
if (garis) lcd_putsf("Hitam"); else lcd_putsf("Putih");
}
void tampil_strategi()
{
lcd_clear(); lcd_putsf("Strategi");
lcd_gotoxy(0,1);
if(adaptif) lcd_putsf("Adaptif"); else lcd_putsf("PID");
}
void tampil_lebar()
{
lcd_clear(); lcd_putsf("Lbr: 1 2 3 4 5");
lcd_gotoxy(5,1); if (lebar1==1) lcd_putchar('+'); else putchar('-');

lcd_gotoxy(7,1); if (lebar2==1) lcd_putchar('+'); else putchar('-');


lcd_gotoxy(9,1); if (lebar3==1) lcd_putchar('+'); else putchar('-');
lcd_gotoxy(11,1); if (lebar4==1) lcd_putchar('+'); else putchar('-');
lcd_gotoxy(13,1); if (lebar5==1) lcd_putchar('+'); else putchar('-');
lcd_gotoxy(2+(leb*2),0); lcd_putchar('<');
lcd_gotoxy(4+(leb*2),0); lcd_putchar('>');
lcd_gotoxy(2+(leb*2),1); lcd_putchar('<');
lcd_gotoxy(4+(leb*2),1); lcd_putchar('>');
}
void tampil_ask_save()
{
lcd_clear();
lcd_putsf("Salin ke EEPROM?");
lcd_gotoxy(0,1);
if (m>=0&&m<10)
{
sprintf(lcd,"pd memory%d",m);
lcd_puts(lcd);
}
else lcd_putsf("tdk");
}
void save()
{
char i,acc;
eekp[m]=kp; eeki[m]=ki; eekd[m]=kd; eetop_speed[m]=top_speed; eeturbo[m]=turbo;
for (i=0;i<8;i++)
{
eee[i][m]=e[i];
eebts[i][m]=bts[i];
}
eecuplik[m]=cuplik;
//eecabang[m]=cabang;
eegaris[m]=garis;
eeadaptif[m]=adaptif;
eekp_bts_atas[m]=kp_bts_atas;
eekp_bts_bawah[m]=kp_bts_bawah;
//eekekiri[m]=kekiri;
//eekekanan[m]=kekanan;
//eedelay[m]=nil_delay;
eejum_siasat[m]=jum_siasat;
for (i=0;i<30;i++)
{
eesiasat_arah[i][m]=siasat_arah[i];
}
if (lebar5==1) acc|=0b00010000; else acc&=0b11101111;
if (lebar4==1) acc|=0b00001000; else acc&=0b11110111;
if (lebar3==1) acc|=0b00000100; else acc&=0b11111011;
if (lebar2==1) acc|=0b00000010; else acc&=0b11111101;
if (lebar1==1) acc|=0b00000001; else acc&=0b11111110;
eelebar=acc;
}
void tampil_memory()
{
lcd_clear();
sprintf(lcd,"akses m%d",m);

lcd_puts(lcd);
}
void load()
{
char i;
kp=eekp[m]; ki=eeki[m]; kd=eekd[m]; top_speed=eetop_speed[m]; turbo=eeturbo[m];
for (i=0;i<8;i++)
{
e[i]=eee[i][m];
bts[i]=eebts[i][m];
}
cuplik=eecuplik[m];
//cabang=eecabang[m];
garis=eegaris[m];
adaptif=eeadaptif[m];
kp_bts_bawah=eekp_bts_bawah[m];
kp_bts_atas=eekp_bts_atas[m];
//kekiri=eekekiri[m];
//kekanan=eekekanan[m];
//nil_delay=eedelay[m];
jum_siasat=eejum_siasat[m];
for (i=0;i<30;i++)
{
siasat_arah[i]=eesiasat_arah[i][m];
}
if ((eelebar%32)>15)lebar5=1; else lebar5=0;
if ((eelebar%16)>7)lebar4=1; else lebar4=0;
if ((eelebar%8)>3)lebar3=1; else lebar3=0;
if ((eelebar%4)>1)lebar2=1; else lebar2=0;
if ((eelebar%2)>0)lebar1=1; else lebar1=0;
}
void tampil_default()
{
lcd_clear();
lcd_putsf("sbg mem. utama?");
lcd_gotoxy(0,1);
if (sbg_def) lcd_putsf("ya");
else lcd_putsf("tidak");
}
void tampil()
{
unsigned char i;
sprintf(lcd,"p%d d%d s%d ",kp,kd,top_speed);
lcd_clear();
lcd_puts(lcd);
if (garis) lcd_putchar('B');
else lcd_putchar('W');
for (i=0;i<8;i++)
{
lcd_gotoxy(i,1);
if (adc[(i)]<bts[i]) lcd_putsf("0"); else lcd_putsf("1");
};
sprintf(lcd," %d>%d",error0,jmlh_cab);
lcd_puts(lcd);
if (count_cab==1||count_cab1==1||count_cab2==1||count_cab3==1||count_cab4==1||co
unt_cab5==1||count_cab6==1||count_cab7==1)

{lcd_putchar('+');};
if (count_cab_y==1||count_cab_y1==1||count_cab_y2==1||count_cab_y3==1||count_cab
_y4==1||count_cab_y5==1)
{lcd_putchar('Y');};
}
/*timer2_start()
{
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: 31.250 kHz
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x06;
TCNT2=0x00;
OCR2=0x00;
} */
/*timer2_stop()
{
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
}*/
int minimum (int a, int b)
{
if (a<b) {return a;}
else {return b;}
}
baca_ir()
{
}/*
if (pin_ir==0)
{
buffer[i]=TCNT2;
//while (pin_ir==0);
timer2_start();i++;k=0;
if (i==1&&buffer[0]<batas)
if (i==2&&buffer[1]>batas)
if (i==3&&buffer[2]>batas)
if (i==4&&buffer[3]>batas)
if (i==5&&buffer[4]>batas)
}
}*/
/*void percabangan()
{
if (led==2) {back_on; PORTD.0=0;}
switch (cabang)
{
case 1: error= 6; break;
case 2: error= -6; break;
}
}*/

i=0;
i=0;
i=0;
i=0;
i=0;

void kond_sensor()
//kondisi sensor
{
char i;
sens=0;
for(i=0;i<8;i++)
{
if (adc[i]>bts[i]) sens=sens|1<<(7-i);
}
}
void rem()
{
nil_kan=-100; nil_kir=-100;
keluarkan();
delay_ms(cuplik);
}
void nil_error()
//kesetaraan nilai error
{
char sensor1,sensor2,sensor3,sensor4,sensor5,sensor6;
//bit kosong1,kosong2,kosong3,kosong4,kosong5,kosong6,kosong7,kosong8;
/*char sensor1,sensor2;
sensor1=sensor&0b11111000;
sensor2=sensor&0b00000101;
*/
kondisi_turbo=0;
back_off;
count_cab7=count_cab6;
count_cab6=count_cab5;
count_cab5=count_cab4;
count_cab4=count_cab3;
count_cab3=count_cab2;
count_cab2=count_cab1;
count_cab1=count_cab;
count_kiri8=count_kiri7;
count_kiri7=count_kiri6;
count_kiri6=count_kiri5;
count_kiri5=count_kiri4;
count_kiri4=count_kiri3;
count_kiri3=count_kiri2;
count_kiri2=count_kiri1;

count_kanan8=count_kanan7;
count_kanan7=count_kanan6;
count_kanan6=count_kanan5;
count_kanan5=count_kanan4;
count_kanan4=count_kanan3;
count_kanan3=count_kanan2;
count_kanan2=count_kanan1;

count_cab_y5=count_cab_y4;
count_cab_y4=count_cab_y3;
count_cab_y3=count_cab_y2;
count_cab_y2=count_cab_y1;
count_cab_y1=count_cab_y;
count_cab_y=0;
count_warnab7=count_warnab6;
count_warnab6=count_warnab5;
count_warnab5=count_warnab4;
count_warnab4=count_warnab3;
count_warnab3=count_warnab2;
count_warnab2=count_warnab1;
count_warnab1=count_warnab;

count_warnaw7=count_warnaw6;
count_warnaw6=count_warnaw5;
count_warnaw5=count_warnaw4;
count_warnaw4=count_warnaw3;
count_warnaw3=count_warnaw2;
count_warnaw2=count_warnaw1;
count_warnaw1=count_warnaw;

berubahw7=berubahw6;
berubahw6=berubahw5;
berubahw5=berubahw4;
berubahw4=berubahw3;
berubahw3=berubahw2;
berubahw2=berubahw1;
berubahw1=berubahw;

berubahb7=berubahb6;
berubahb6=berubahb5;
berubahb5=berubahb4;
berubahb4=berubahb3;
berubahb3=berubahb2;
berubahb2=berubahb1;
berubahb1=berubahb;

//kosong8=kosong7;kosong7=kosong6;kosong6=kosong5;kosong5=kosong4;kosong4=kos
ong3;kosong3=kosong2;kosong2=kosong1;
sensor1=sensor;
sensor1&=0b01111110;
//if(sensor1==0b00000000){speed_1=top_speed/5*2;speed=speed_1;}
//else {speed_1= minimum(top_speed,speed);};
speed_1= minimum(top_speed,speed);
sensor2=sensor;
sensor2&=0b00111100;
sensor3=sensor;
sensor3&=0b10000000;
sensor4=sensor;
sensor4&=0b00000001;
sensor5=sens;
sensor5&=0b00011000;
sensor6=sens;
sensor6&=0b10000001;
//nos=0;
//if ((sensor2!=0b00000000)&(sensor6!=0b00000000)){count_kiri1=1;} else {coun
t_kiri1=0;};
//berubah warna
if ((sensor5!=0b00011000)&(sensor6==0b10000001)){count_warnaw=1;} else {count
_warnaw=0;};
if ((sensor5!=0b00000000)&(sensor6==0b00000000)){count_warnab=1;} else {count
_warnab=0;};
if ((sensor2!=0b00000000)&(sensor3!=0b00000000)){count_kiri1=1;} else {count_
kiri1=0;};
if ((sensor2!=0b00000000)&(sensor4!=0b00000000)){count_kanan1=1;} else {count
_kanan1=0;};
//diteksi pertigaan
/*if ((sensor5!=0b00000000)&(sensor3!=0b00000000))
{
if ((count_kiri1)&&!(count_kanan1||count_kanan2||count_kanan3||count_kan
an4||count_kanan5))
{
tikungan=4; count_cab=0;
};
};
if ((sensor5!=0b00000000)&(sensor4!=0b00000000))
{
if ((count_kanan1)&&!(count_kiri1||count_kiri2||count_kiri3||count_kiri4

||count_kiri5))
{
tikungan=3; count_cab=0;
};
};*/
/*if (sensor2!=0b00000000)
{
if ((sensor&&0b10000000)!=0) {count_kiri1=1;} else{count_kiri1=0;};
if ((sensor&&0b00000001)!=0) {count_kanan1=1;} else{count_kanan1=0;};
}
else {count_kiri1=0;count_kanan1=0;};
*/
if (lebar1==1)
{
if (sensor1==0b00000010) {error= 5; tikungan=0;count_cab=0;};
if (sensor1==0b00000100) {error= 3; tikungan=0;count_cab=0;};
if (sensor1==0b00001000) {error= 1; tikungan=0;count_cab=0;};
if (sensor1==0b00010000) {error=-1; tikungan=0;count_cab=0;};
if (sensor1==0b00100000) {error=-3; tikungan=0;count_cab=0;};
if (sensor1==0b01000000) {error=-5; tikungan=0;count_cab=0;};
};
if (lebar2==1)
{
if (sensor1==0b00000010)
if (sensor1==0b00000110)
if (sensor1==0b00001100)
if (sensor1==0b00011000)
if (sensor1==0b00110000)
if (sensor1==0b01100000)
if (sensor1==0b01000000)
};

{error= 5;
{error= 4;
{error= 2;
{error= 0;
{error=-2;
{error=-4;
{error=-5;

tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};

if (lebar3==1)
{
if (sensor1==0b00000010)
if (sensor1==0b00000110)
if (sensor1==0b00001110)
if (sensor1==0b00011100)
if (sensor1==0b00111000)
if (sensor1==0b01110000)
if (sensor1==0b01100000)
if (sensor1==0b01000000)
};

{error= 5;
{error= 4;
{error= 3;
{error= 1;
{error=-1;
{error=-3;
{error=-4;
{error=-5;

tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};

if (lebar4==1)
{
if (sensor1==0b00000010)
if (sensor1==0b00000110)
if (sensor1==0b00001110)
if (sensor1==0b00011110)
if (sensor1==0b00111100)
if (sensor1==0b01111000)
if (sensor1==0b01110000)
if (sensor1==0b01100000)
if (sensor1==0b01000000)
};

{error= 5;
{error= 4;
{error= 3;
{error= 2;
{error= 0;
{error=-2;
{error=-3;
{error=-4;
{error=-5;

tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};

if (lebar5==1)

{
//lebar 1
if (sensor1==0b01111100)
if (sensor1==0b01111010)
if (sensor1==0b01110110)
if (sensor1==0b01101110)
if (sensor1==0b01011110)
if (sensor1==0b00111110)

{error= 5;
{error= 3;
{error= 1;
{error=-1;
{error=-3;
{error=-5;

tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};
tikungan=0;count_cab=0;};

//lebar 2
if (sensor1==0b01111100) {error= 5; tikungan=0;count_cab=0;};
//if (sensor1==0b01111000) {error= 4; tikungan=0;count_cab=0;};
if (sensor1==0b01110010) {error= 2; tikungan=0;count_cab=0;};
if (sensor1==0b01100110) {error= 0; tikungan=0;count_cab=0;};
if (sensor1==0b01001110) {error=-2; tikungan=0;count_cab=0;};
//if (sensor1==0b00011110) {error=-4; tikungan=0;count_cab=0;};
if (sensor1==0b00111110) {error=-5; tikungan=0;count_cab=0;};
//lebar 3
//if (sensor1==0b01111100) {error= 5; tikungan=0;count_cab=0;};
//if (sensor1==0b01111000) {error= 4; tikungan=0;count_cab=0;};
//if (sensor1==0b01110000) {error= 3; tikungan=0;count_cab=0;};
if (sensor1==0b01100010) {error= 1; tikungan=0;count_cab=0;};
if (sensor1==0b01000110) {error=-1; tikungan=0;count_cab=0;};
//if (sensor1==0b00001110) {error=-3; tikungan=0;count_cab=0;};
//if (sensor1==0b00011110) {error=-4; tikungan=0;count_cab=0;};
//if (sensor1==0b00111110) {error=-5; tikungan=0;count_cab=0;};
//lebar 4
//if (sensor1==0b01111100) {error= 5; tikungan=0;count_cab=0;};
//if (sensor1==0b01111000) {error= 4; tikungan=0;count_cab=0;};
//if (sensor1==0b01110000) {error= 3; tikungan=0;count_cab=0;};
//if (sensor1==0b01100000) {error= 2; tikungan=0;count_cab=0;};
if (sensor1==0b01000010) {error= 0; tikungan=0;count_cab=0;};
//if (sensor1==0b00000110) {error=-2; tikungan=0;count_cab=0;};
//if (sensor1==0b00001110) {error=-3; tikungan=0;count_cab=0;};
//if (sensor1==0b00011110) {error=-4; tikungan=0;count_cab=0;};
//if (sensor1==0b00111110) {error=-5; tikungan=0;count_cab=0;};
};
// belokan siku
//if ((sensor1==0b00000000)&(sensor7==0b00000001)) {tikungan=1; count_cab=0;}
;
//if ((sensor1==0b00000000)&(sensor7==0b10000000)) {tikungan=2; count_cab=0;}
;
//if ((sensor1==0b01111110)&(sensor7==0b10000000)) {tikungan=1; count_cab=0;}
;
//if ((sensor1==0b01111110)&(sensor7==0b00000001)) {tikungan=2; count_cab=0;}
;
if(belokan==1)
{
if (sensor==0b00000001)
if (sensor==0b10000000)
if (sensor==0b11111110)
if (sensor==0b01111111)

{tikungan=1;
{tikungan=2;
{tikungan=5;
{tikungan=6;

count_cab=0;};
count_cab=0;};
count_cab=0;};
count_cab=0;};

if (sensor==0b11110110) {tikungan=5; count_cab=0;};


if (sensor==0b11100110) {tikungan=5; count_cab=0;};

if
if
if
if
if

(sensor==0b11101110)
(sensor==0b11001110)
(sensor==0b11011110)
(sensor==0b10011110)
(sensor==0b10111110)

{tikungan=5;
{tikungan=5;
{tikungan=5;
{tikungan=5;
{tikungan=5;

count_cab=0;};
count_cab=0;};
count_cab=0;};
count_cab=0;};
count_cab=0;};

if
if
if
if
if
if
if
};

(sensor==0b01101111)
(sensor==0b01100111)
(sensor==0b01110111)
(sensor==0b01110011)
(sensor==0b01111011)
(sensor==0b01111001)
(sensor==0b01111101)

{tikungan=5;
{tikungan=5;
{tikungan=5;
{tikungan=5;
{tikungan=5;
{tikungan=5;
{tikungan=5;

count_cab=0;};
count_cab=0;};
count_cab=0;};
count_cab=0;};
count_cab=0;};
count_cab=0;};
count_cab=0;};

//berubah warna
/*if (count_warnaw==1&&count_warnaw1==1&&count_warnaw2==1&&count_warnaw3==1&&
count_warnaw4==1&&count_warnaw5==1&&count_warnaw6==1&&count_warnaw7==1)
{berubahw=1;};
if (berubahw==1&&berubahw1==0&&berubahw2==0&&berubahw3==0&&berubahw4==0&&beru
bahw5==0&&berubahw6==0&&berubahw7==0)
{garis=0;};
if (count_warnab==1&&count_warnab1==1&&count_warnab2==1&&count_warnab3==1&&co
unt_warnab4==1&&count_warnab5==1&&count_warnab6==1&&count_warnab7==1)
{berubahb=1;};
if (berubahb==1&&berubahb1==0&&berubahb2==0&&berubahb3==0&&berubahb4==0&&beru
bahb5==0&&berubahb6==0&&berubahb7==0)
{garis=1;};*/
if ((count_kiri1)&&(count_kanan1||count_kanan2||count_kanan3||count_kanan4||c
ount_kanan5))
{count_cab=1;belokan_kir=0;};
if ((count_kanan1)&&(count_kiri1||count_kiri2||count_kiri3||count_kiri4||coun
t_kiri5))
{count_cab=1;belokan_kan=0;};
if ((count_kiri1)&&!(count_kanan1||count_kanan2||count_kanan3||count_kanan4||
count_kanan5))
{belokan_kir=1;};
//{tikungan=4; count_cab=0;};
if ((count_kanan1)&&!(count_kiri1||count_kiri2||count_kiri3||count_kiri4||cou
nt_kiri5))
{belokan_kan=1;};
//{tikungan=3; count_cab=0;};
if ((belokan_kir==1)&&(sensor1==0b00000000)) {tikungan=4; count_cab=0;};
if ((belokan_kan==1)&&(sensor1==0b00000000)) {tikungan=3; count_cab=0;};
if(siasat_enable==1)
{
if (count_cab==1&&count_cab1==0&&count_cab2==0&&count_cab3==0&&count_cab4==0&
&count_cab5==0&&count_cab6==0&&count_cab7==0)
{if (++jmlh_cab>jum_siasat){jmlh_cab=1;};};
if (siasat_arah[jmlh_cab]==1&&count_cab==0&&count_cab1==0&&count_cab2==0&&cou
nt_cab3==1) tikungan=3;
if (siasat_arah[jmlh_cab]==2&&count_cab==0&&count_cab1==0&&count_cab2==0&&cou
nt_cab3==1) tikungan=4;
};
//if ((sensor==0b10000001)||(sensor==0b10000010)||(sensor==0b01000001)||(sens
or==0b01111110)||(sensor==0b01111101)||(sensor==0b10111110)||(sensor==0b10111101

)||(sensor==0b01000010))
//{
/*count_cab_y=1;
if(siasat_y_enable==1)
{
if (jmlh_cab_y%2) tikungan=1;
else tikungan=2;
}
else tikungan=2;*/
// tikungan=1;
//}
//if (jmlh_cab>=jum_siasat&&
//count_cab==0&&count_cab1==0&&count_cab2==0&&count_cab3==0&&count_cab4==0&&c
ount_cab5==0&&count_cab6==0&&count_cab7==0)
//{jmlh_cab=0;};
if (runing)
{
if (garis1!=garis){back_on;delay_ms(50);back_off;delay_ms(50);back_on;};
//if (count_warnab==1&&count_warnab1==1&&count_warnab2==1&&count_warnab3==1&&
count_warnab4==1&&count_warnab5==1&&count_warnab6==1&&count_warnab7==1)
//{back_on;delay_ms(50);back_off;delay_ms(50);back_on};
if (count_cab==1||count_cab1==1||count_cab2==1||count_cab3==1||count_cab4==1|
|count_cab5==1||count_cab6==1||count_cab7==1)
{back_on;};
if (count_cab_y==1||count_cab_y1==1||count_cab_y2==1||count_cab_y3==1||count_
cab_y4==1||count_cab_y5==1)
{back_on;};
};
bobot_error0();
}
/*mundur_bentar()
{
kanan=speed; arah_ka1=1; arah_ka2=0;
kiri=speed; arah_ki1=1; arah_ki2=0;
} */
void pid()
{
char sensor1;
belokan=1;

//pengolahan PID

if (tikungan==0)
{
sum+=error0;
if ((sum*0.01*ki)<((int)0-top_speed)) sum=(int)0-(top_speed*(1/ki)*100);
else {if ((sum*0.001*ki)>top_speed) sum=(int)(top_speed*(1/ki)*100);}
if (adaptif==1)
{
adtf=(derror)*abs(error0);
kp=(kp1+(adtf*0.05));
if (kp<=kp_bts_bawah) kp=kp_bts_bawah;
else if (kp>=kp_bts_atas) kp=kp_bts_atas;
kd=kp*3;
kp1=kp;

derror=(error0)-(error1);
};
nil_kan=(int)speed_1-(error0*kp)-((error0-error1)*kd)-(int)(sum*0.001*ki);
nil_kir=(int)speed_1+(error0*kp)+((error0-error1)*kd)+(int)(sum*0.001*ki);
error1=error0;
};
if (tikungan==1)
{
nil_kan=(int)(0);
nil_kir=(int)(0);
keluarkan();
delay_ms(cuplik*3);
error= 5;
//if (sensor&&0b00000101)mundur_bentar();
nil_kan=(int)(0-(top_speed*1.2));
nil_kir=(int)((top_speed*0.2*3));
keluarkan();
cacah=0;
//delay_ms(10);
//delay_ms(nil_delay);
while ((sensor1==0b00000000)&&(cacah<10000))
{
kond_sensor();
if (garis) sensor=sens; else sensor=~sens;
sensor1=sensor&0b00011110;
delay_us(100);
cacah++;
//nil_error();
};
belokan=0;
speed=0;
};
if (tikungan==2)
{
nil_kan=(int)(0);
nil_kir=(int)(0);
keluarkan();
delay_ms(cuplik*3);
error=-5;
//if (sensor&&0b00000101)mundur_bentar();
nil_kan=(int)((top_speed*0.2*3));
nil_kir=(int)(0-(top_speed*1.2));
keluarkan();
//delay_ms(cuplik*3);
cacah=0;
//delay_ms(10);
//delay_ms(nil_delay);
while ((sensor1==0b00000000)&&(cacah<10000))
{
kond_sensor();
if (garis) sensor=sens; else sensor=~sens;
sensor1=sensor&0b01111000;
delay_us(100);
cacah++;
//nil_error();
};
belokan=0;

speed=0;
};
if (tikungan==3)
{
error= 5;
//if (sensor&&0b00000101)mundur_bentar();
nil_kan=(int)(0);
nil_kir=(int)(0);
keluarkan();
//delay_ms(cuplik*3);
nil_kan=(int)(0-(top_speed/5*4));
nil_kir=(int)((top_speed/5*2));
keluarkan();
//delay_ms(cuplik*3);
cacah=0;
//delay_ms(10);
//delay_ms(nil_delay);
if (runing==1)
{
while ((sensor1!=0b00000000)&&(cacah<10000))
{
kond_sensor();
if (garis) sensor=sens; else sensor=~sens;
sensor1=sensor&0b01111100;
delay_us(100);
cacah++;
//nil_error();
};
while ((sensor1==0b00000000)&&(cacah<10000))
{
kond_sensor();
if (garis) sensor=sens; else sensor=~sens;
sensor1=sensor&0b00011110;
delay_us(100);
cacah++;
//nil_error();
};
belokan_kan=0;
//belokan=0;
speed=0;
};
};
if (tikungan==4)
{
error=-5;
//if (sensor&&0b00000101)mundur_bentar();
nil_kan=(int)(0);
nil_kir=(int)(0);
keluarkan();
//delay_ms(cuplik*3);
nil_kan=(int)((top_speed/5*2));
nil_kir=(int)(0-(top_speed/5*4));

keluarkan();
//delay_ms(cuplik*3);
cacah=0;
//delay_ms(10);
//delay_ms(nil_delay);
if (runing==1)
{
while ((sensor1!=0b00000000)&&(cacah<10000))
{
kond_sensor();
if (garis) sensor=sens; else sensor=~sens;
sensor1=sensor&0b00111110;
delay_us(100);
cacah++;
//nil_error();
};
while ((sensor1==0b00000000)&&(cacah<10000))
{
kond_sensor();
if (garis) sensor=sens; else sensor=~sens;
sensor1=sensor&0b01111000;
delay_us(100);
cacah++;
//nil_error();
};
belokan_kir=0;
//belokan=0;
speed=0;
};
};
//if ((nos1==1)&&(nos==0))rem();
//nos=nos1;
if (tikungan==5)
{
nil_kan=(int)(0);
nil_kir=(int)(0);
keluarkan();
delay_ms(cuplik*3);
error= 5;
//if (sensor&&0b00000101)mundur_bentar();
nil_kan=(int)(0-(top_speed*0.2*6));
nil_kir=(int)((top_speed*0.2*4));
sensor1=~sens;
sensor1&=0b01111000;
belokan=0;
speed=0;
};
if (tikungan==6)
{
nil_kan=(int)(0);
nil_kir=(int)(0);
keluarkan();
delay_ms(cuplik*3);
error=-5;
//if (sensor&&0b00000101)mundur_bentar();

nil_kan=(int)((top_speed*0.2*5));
nil_kir=(int)(0-(top_speed*0.2*6));
sensor1=~sens;
sensor1&=0b00011110;
belokan=0;
speed=0;
};
}
hitung_batas()
{
char i;
for (i=0;i<8;i++)
{
bts[i]=((maxi[i]/2)+(mini[i]/2));
}
}
/*char remote (void)
{
char baca_remote;
int i;
baca_remote=1;
for (i=0;1<200;i++)
{
if (ir) delay_us(10); else baca_remote=0;
}
return (char) baca_remote;
}*/
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
l++;
}
interrupt [TIM0_COMP] void timer0_comp_isr(void)
{
ovtim++;
milisekon++;
if (ovtim>999) {ovtim=0;sekon++;}
}
interrupt [TIM2_OVF] void timer2_comp_isr(void)
{
/*data_sementara=0;
for (j=0;j<10&&i>14;j++)
{
lcd_gotoxy((j),0);
if (buffer[j+5] < batas)
{
lcd_putchar('1');
data_sementara = data_sementara | 1<<(9-j);
}
else if (buffer[j+5] >= batas)

{
lcd_putchar('0');
data_sementara = data_sementara | 0<<(9-j);
}
}
if (i>14) {data_valid=data_sementara;}
if (++k>t_validasi) {data_valid=0; timer2_stop();}
if (data_valid==power||data_valid==1023-power)
{
remote=1;
}
i=0;*/
}
interrupt [ADC_INT] void adc_isr(void)
{
adc[index]=ADCH;
if (++index > (LAST-FIRST))
index=0;
ADMUX=(FIRST|VREF)+index;
ADCSRA|=0x40;
}
void timer1_on()
{
TCCR1A=0xA1; //0XA1= non invert (sesuai dengan hardware)
TCCR1B=0x02;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
}
void timer1_off()
{
TCCR1A=0x00; //0XA1= non invert (sesuai dengan hardware)
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
}
void timer0_on()
{
TCCR0=0x0B;
TCNT0=0x00;
OCR0=0x7f;
}

void timer0_off()
{
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
}
putar_kanan()
{
nil_kan=(int)(0-100); nil_kir=(int)(100);
keluarkan();
}
henti()
{
nil_kan=(int)0; nil_kir=(int)0;
keluarkan();
}
void main(void)
{
char i;
unsigned char hold_key;
PORTA=0xFF;DDRA=0x00;
PORTB=0x00;DDRB=0xFF;
PORTC=0b10111100;DDRC=0b11000011;
PORTD=0b00000011;DDRD=0b11111100;
ASSR=0x00;
TCCR2=0x0E;
TCNT2=0x00;
OCR2=0xFF;
ACSR=0x80;
SFIOR=0x00;
TIMSK=0x46;
ADMUX=FIRST|VREF;
ADCSRA=0xCE;
load();
lcd_init(16);
bismillah();back_on;
#asm ("sei")
while (1)
{
tunggu_tekan(500);
back_off;
lcd_clear(); tunggu_tekan(250);
back_on;
id1(); tunggu_tekan(1000);
back_off;

lcd_clear(); tunggu_tekan(500);
back_on;
id2(); tunggu_tekan(1000);
m=eeutama;
load();
led=2;
back_off;
//goto idle_mode;
ask_run:
back_off;
tampil();
tunggu_lepas(500);
led=2;
if (led==0) {back_on; led=1;}
else if (led==1) {back_on; waktu_nyala=nyala; led=2;}
else {back_off; led=0;};
_ask_run:
kond_sensor();
if (garis) sensor=sens; else sensor=~sens;
nil_error();
pid();
tampil();delay_ms(10);
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
hold_key=0;
while (back)
{
delay_ms(25);
if (++hold_key>100) hold_key=100;
if (hold_key==100)
{
if (led==0) {back_on; led=1;goto no_efect_1;}
if (led==1) {back_on; led=2;goto no_efect_1;}
if (led>1) {back_off; led=0;goto no_efect_1;}
}
}
delay_ms(10);
goto pilih_memory;
no_efect_1:
while (back) delay_ms(10);
}
if (up)
{
if (led==2){back_on; waktu_nyala=nyala;}
hold_key=0;
while (up)
{
delay_ms(30);
if (++hold_key>100) hold_key=100;
//if (hold_key==100) {goto idle_mode;}
}
delay_ms(10);
if (m>8) m=0; else m++;

load();
tampil_memory(); tunggu_lepas(1000); tunggu_tekan(1000);
while (up) {tampil_waktu(); delay_ms(10);}
}
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
if (m<1) m=9; else m--;
load();
tampil_memory(); tunggu_lepas(1000); tunggu_tekan(1000);
while (down) {tampil_waktu(); delay_ms(10);}
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
goto ready;
}
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _ask_run;

ready:
sensor_on;
lcd_gotoxy(0,1); lcd_putsf("Siap!"); delay_ms(250);
_ready:
kond_sensor();
if (garis) sensor=sens; else sensor=~sens;
nil_error();
pid();
tampil();delay_ms(10);
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
sensor_off
goto ask_run;
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
bismillah();
//while (enter||remote==1);
delay_ms(10);
goto run_n;
}
goto _ready;
run_n:

siasat_enable=1;
siasat_y_enable=1;
runing=1;
sensor_on;
milisekon=0;
ovtim=0; sekon=0; timer0_on();
timer1_on();
start_count=0;
count_cab=0;
count_kiri1=0;
count_kanan1=0;
speed=0;
tikungan=0;
jmlh_cab=0;
while (ditekan)
{
//delay_ms(1);
if (back){siasat_enable=0; back_on;};
if (up){siasat_y_enable=0; back_on;tunggu_lepas(250);back_off;tunggu_lepas
(250);back_on;}
};
back_off;
run:
k=2*cuplik;
if (l>=k)
{
baca_ir();
kond_sensor();
if (garis) sensor=sens; else sensor=~sens;
nil_error();
pid();
keluarkan();
tampil();
l=0;
garis1=garis;
}
if (start_count>=(10/cuplik))
{
start_count=0;
if (speed<255)speed++;
}
else start_count++;
if (back||up||down)
{
runing=0;
if (led==2){back_on; waktu_nyala=nyala;}
timer1_off();
kanan=0; kiri=0; sensor_off
lcd_clear(); lcd_putsf("Alhamdulillah"); delay_ms(500);
nil_kan=0; nil_kir=0; keluarkan();
id1();tunggu_tekan(500);
id2();tunggu_tekan(500);
while (ditekan); delay_ms(10);
timer0_off(); tampil_waktu(); tunggu_tekan(500);
while (tidak_ditekan); delay_ms(10); goto ask_run;
}
goto run;

pilih_memory:
sensor_off;
tampil_memory();
tunggu_lepas(500);
_pilih_memory:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
goto ask_run;
}
if (up)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
if (m>4) m=0; else m++;
load();
tampil_memory(); tunggu_lepas(500); tunggu_tekan(500);
}
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
if (m<1) m=4; else m--;
load();
tampil_memory(); tunggu_lepas(500); tunggu_tekan(500);
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
goto autoset;
}
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _pilih_memory;
autoset:
sensor_off;
pilih_autoset=0;
tampil_autoset();
tunggu_lepas(500);
_autoset:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
goto ask_run;
}
if (up)
{

if (led==2){back_on; waktu_nyala=nyala;}
pilih_autoset=1;tampil_autoset();
}
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;}
pilih_autoset=0;tampil_autoset();
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
if (pilih_autoset) goto autoseting;
else {bat=0; goto set_bts;}
}
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _autoset;
autoseting:
sensor_on;
lcd_clear();lcd_putsf("autoseting!!");
//lcd_gotoxy(0,1);lcd_putsf("geser2 d garis");
timer1_on();
nil_kan=(int)(0-50);
nil_kir=(int)(50);
keluarkan();
cacah=0;
while (enter)
{if (led==2){back_on; waktu_nyala=nyala;}};
delay_ms(500);
for (i=0;i<8;i++) {maxi[i]=adc[i]; mini[i]=adc[i];}
_autoseting:
baca_ir();
hitung_batas();
kond_sensor();
sensor_lalu=sensor;
if (garis){sensor=sens;} else {sensor=~sens;};
if ((sensor!=0b00000000)&&(sensor_lalu==0b00000000))cacah++;
for (i=0;i<8;i++)
{
if (adc[i]>maxi[i]) maxi[i]=adc[i];
if (adc[i]<mini[i]) mini[i]=adc[i];
}
if (ditekan||((cacah>=3)&&(sensor&&0b00011000)))
{
nil_kan=(int)(0);
nil_kir=(int)(0);
keluarkan();
timer1_off();
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bat=0; goto ready;

}
if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}
goto _autoseting;
set_bts:
sensor_on;
maxi[bat]=adc[bat]; mini[bat]=adc[bat];
tampil_bts();
tunggu_lepas(500);
_set_bts:
baca_ir();
tampil_bts();
if (adc[bat]>maxi[bat]) maxi[bat]=adc[bat];
if (adc[bat]<mini[bat]) mini[bat]=adc[bat];
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (bat<1) {delay_ms(10); goto autoset;}
bat--; delay_ms(10); goto set_bts;
}
if (up)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (bts[bat]<255) bts[bat]++; else bts[bat]=0;
tampil_bts(); tunggu_lepas(250);
while (up)
{
if (bts[bat]<255) bts[bat]++; else bts[bat]=0;
tampil_bts(); tunggu_lepas(25);
if (bts[bat]==255||bts[bat]==128||bts[bat]==0) tunggu_lepas(250);
if ((bts[bat]%10)==0) tunggu_lepas(100);
}
}
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (bts[bat]>0) bts[bat]--; else bts[bat]=255;
tampil_bts(); tunggu_lepas(250);
while (down)
{
if (bts[bat]>0) bts[bat]--; else bts[bat]=255;
tampil_bts(); tunggu_lepas(25);
if (bts[bat]==255||bts[bat]==128||bts[bat]==0) tunggu_lepas(250);
if ((bts[bat]%10)==0) tunggu_lepas(100);
}
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (bat>6) {delay_ms(10); goto set_speed;}
bat++; delay_ms(10); goto set_bts;
}
/*if (remote)

{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _set_bts;
set_speed:
sensor_off;
tampil_ts();
tunggu_lepas(500);
_set_speed:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
bat=7; delay_ms(10); goto set_bts;
}
if (up)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (top_speed<300) top_speed++; else top_speed=0;
tampil_ts(); tunggu_lepas(250);
while (up)
{
if (top_speed<300) top_speed++; else {top_speed=0; tampil_ts(); tunggu_
lepas(250);}
tampil_ts();
tunggu_lepas(25);
if (top_speed==0||top_speed==128||top_speed==255||top_speed==300) tungg
u_lepas(250);
if ((top_speed%50)==0) tunggu_lepas(250);
}
}
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (top_speed>0) top_speed--; else top_speed=300;
tampil_ts(); tunggu_lepas(250);
while (down)
{
if (top_speed>0) top_speed--; else {top_speed=300;tampil_ts(); tunggu_l
epas(250);}
tampil_ts();
tunggu_lepas(25);
if (top_speed==0||top_speed==128||top_speed==255||top_speed==300) tungg
u_lepas(250);
if ((top_speed%50)==0) tunggu_lepas(250);
}
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
goto set_e0;
}
/*if (remote)
{

remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _set_speed;
/*set_turbo:
sensor_off
tampil_turbo();
tunggu_lepas(500);
_set_turbo:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
goto set_speed;
}
if (up)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (turbo<255) turbo++; else turbo=0;
tampil_turbo(); tunggu_lepas(250);
while (up)
{
if (turbo<255) turbo++; else {turbo=0; tampil_turbo(); tunggu_lepas(250
);}
tampil_turbo();
tunggu_lepas(25);
if (turbo==0||turbo==128||turbo==255) tunggu_lepas(250);
if ((turbo%50)==0) tunggu_lepas(250);
}
}
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (turbo>0) turbo--; else turbo=255;
tampil_turbo(); tunggu_lepas(250);
while (down)
{
if (turbo>0) turbo--; else {turbo=255; tampil_turbo(); tunggu_lepas(250
);}
tampil_turbo();
tunggu_lepas(25);
if (turbo==0||turbo==128||turbo==255) tunggu_lepas(250);
if ((turbo%50)==0) tunggu_lepas(250);
}
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
er=0; delay_ms(10); goto set_e0;
}
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);

bismillah();
goto run_n;
}*/
//goto _set_turbo;
set_e0:
sensor_off
tampil_e();
tunggu_lepas(500);
_set_e0:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (er<1) {delay_ms(10); goto set_speed;}
er--; goto set_e0;
}
if (up)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (e[er]<99) e[er]++; else e[er]=0;
tampil_e(); tunggu_lepas(250);
while (up)
{
if (e[er]<99) e[er]++; else e[er]=0;
tampil_e(); tunggu_lepas(25);
if (e[er]==99||e[er]==0) tunggu_lepas(250);
if ((e[er]%10)==0) tunggu_lepas(100);
}
}
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (e[er]>0) e[er]--; else e[er]=99;
tampil_e();tunggu_lepas(500);
while (down)
{
if (e[er]>0) e[er]--; else e[er]=99;
tampil_e(); tunggu_lepas(25);
if (e[er]==99||e[er]==0) tunggu_lepas(250);
if ((e[er]%10)==0) tunggu_lepas(100);
}
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (er>5) {delay_ms(10); goto set_cuplik;}
er++; delay_ms(10);goto set_e0;
}
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _set_e0;
set_cuplik:

sensor_off
tampil_cuplik();
tunggu_lepas(500);
_set_cuplik:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
er=6; delay_ms(10); goto set_e0;
}
if (up)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (cuplik<25) cuplik++; else cuplik=0;
tampil_cuplik(); tunggu_lepas(250);
while (up)
{
if (cuplik<25) cuplik++; else cuplik=0;
tampil_cuplik(); tunggu_lepas(25);
if (cuplik==0||cuplik==25) tunggu_lepas(250);;
}
}
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (cuplik>0) cuplik--; else cuplik=0;
tampil_cuplik(); tunggu_lepas(250);
while (down)
{
if (cuplik>0) cuplik--; else cuplik=0;
tampil_cuplik(); tunggu_lepas(25);
if (cuplik==0||cuplik==25) tunggu_lepas(250);
}
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10); goto set_kp;
}
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _set_cuplik;
set_kp:
sensor_off
tampil_pid();
tampil_kp();
tunggu_lepas(500);
_set_kp:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10); goto set_cuplik;

}
if (up)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (kp<99) kp++; else kp=0;
tampil_pid();
tampil_kp(); tunggu_lepas(250);
while (up)
{
if (kp<99) kp++; else kp=0;
tampil_pid();
tampil_kp(); tunggu_lepas(25);
if (kp==99||kp==0) tunggu_lepas(250);
if ((kp%10)==0) tunggu_lepas(100);
}
}
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (kp>0) kp--; else kp=99;
tampil_pid();
tampil_kp(); tunggu_lepas(250);
while (down)
{
if (kp>0) kp--; else kp=99;
tampil_pid();
tampil_kp(); tunggu_lepas(25);
if (kp==99||kp==0) tunggu_lepas(250);
if ((kp%10)==0) tunggu_lepas(100);
}
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10); goto set_ki;
}
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _set_kp;
set_ki:
sensor_off
tampil_pid();
tampil_ki();
tunggu_lepas(500);
_set_ki:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10); goto set_kp;
}
if (up)
{

if (led==2){back_on; waktu_nyala=nyala;}
if (ki<10000) ki++; else ki=-10000;
tampil_pid();
tampil_ki(); tunggu_lepas(250);
while (up)
{
if (ki<10000) ki++; else ki=-10000;
tampil_pid();
tampil_ki(); tunggu_lepas(1);
if (ki==1000||ki==-1000) tunggu_lepas(100);
if ((ki%10)==0) tunggu_lepas(50);
}
}
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (ki>-10000) ki--; else ki=10000;
tampil_pid();
tampil_ki(); delay_ms(250);
while (down)
{
if (ki>-10000) ki--; else ki=10000;
tampil_pid();
tampil_ki(); tunggu_lepas(1);
if (ki==1000||ki==-1000) tunggu_lepas(100);
if ((ki%10)==0) tunggu_lepas(50);
}
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10); goto set_kd;
}
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _set_ki;
set_kd:
sensor_off
tampil_pid();
tampil_kd();
tunggu_lepas(500);
_set_kd:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10); goto set_ki;
}
if (up)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (kd<99) kd++; else kd=0;

tampil_pid();
tampil_kd(); tunggu_lepas(250);
while (up)
{
if (kd<99) kd++; else kd=0;
tampil_pid();
tampil_kd(); tunggu_lepas(25);
if (kd==99||kd==0) tunggu_lepas(250);
if ((kd%10)==0) tunggu_lepas(100);
}
}
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (kd>0) kd--; else kd=99;
tampil_pid();
tampil_kd(); tunggu_lepas(250);
while (down)
{
if (kd>0) kd--; else kd=99;
tampil_pid();
tampil_kd(); tunggu_lepas(25);
if (kd==99||kd==0) tunggu_lepas(250);
if ((kd%10)==0) tunggu_lepas(100);
}
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10); goto set_warna;
}
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _set_kd;
set_warna:
sensor_off;
tampil_warna();
tunggu_lepas(500);
_set_warna:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10); goto set_kd;
}
if (up)
{
if (led==2){back_on; waktu_nyala=nyala;}
garis=0;
tampil_warna();
}
if (down)
{

if (led==2){back_on; waktu_nyala=nyala;}
garis=1;
tampil_warna();
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10); goto set_strategi;
}
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _set_warna;
//************************************************************************
//strategi****************************************************************
set_strategi:
sensor_off;
tampil_strategi();
tunggu_lepas(500);
_set_strategi:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10); goto set_warna;
}
if (up)
{
if (led==2){back_on; waktu_nyala=nyala;}
adaptif=0;
tampil_strategi();
}
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;}
adaptif=1;
tampil_strategi();
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10); goto set_kp_bts_atas;
}
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _set_strategi;
//******************************************************************************
//******************************************************************************

set_kp_bts_atas:
sensor_off;
tampil_bts_atas();
tunggu_lepas(500);
_set_kp_bts_atas:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10); goto set_strategi;
}
if (up)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (kp_bts_atas<100) kp_bts_atas++; else kp_bts_atas=0;
tampil_bts_atas(); tunggu_lepas(250);
while (up)
{
if (kp_bts_atas<100) kp_bts_atas++; else {kp_bts_atas=0; tampil_bts_ata
s(); tunggu_lepas(250);}
tampil_bts_atas();
tunggu_lepas(25);
if (kp_bts_atas==0||kp_bts_atas==25||kp_bts_atas==50||kp_bts_atas==75||
kp_bts_atas==100) tunggu_lepas(250);
if ((kp_bts_atas%10)==0) tunggu_lepas(250);
}
}
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (kp_bts_atas>0) kp_bts_atas--; else kp_bts_atas=100;
tampil_bts_atas(); tunggu_lepas(250);
while (down)
{
if (kp_bts_atas>0) kp_bts_atas--; else {kp_bts_atas=100;tampil_bts_atas
(); tunggu_lepas(250);}
tampil_bts_atas();
tunggu_lepas(25);
if (kp_bts_atas==0||kp_bts_atas==25||kp_bts_atas==50||kp_bts_atas==75||
kp_bts_atas==100) tunggu_lepas(250);
if ((kp_bts_atas%10)==0) tunggu_lepas(250);
}
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
goto set_kp_bts_bawah;
}
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _set_kp_bts_atas;

set_kp_bts_bawah:
sensor_off;
tampil_bts_bawah();
tunggu_lepas(500);
_set_kp_bts_bawah:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10); goto set_kp_bts_atas;
}
if (up)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (kp_bts_bawah<100) kp_bts_bawah++; else kp_bts_bawah=0;
tampil_bts_bawah(); tunggu_lepas(250);
while (up)
{
if (kp_bts_bawah<100) kp_bts_bawah++; else {kp_bts_bawah=0; tampil_bts_
bawah(); tunggu_lepas(250);}
tampil_bts_bawah();
tunggu_lepas(25);
if (kp_bts_bawah==0||kp_bts_bawah==25||kp_bts_bawah==50||kp_bts_bawah==
75||kp_bts_bawah==100) tunggu_lepas(250);
if ((kp_bts_bawah%10)==0) tunggu_lepas(250);
}
}
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (kp_bts_bawah>0) kp_bts_bawah--; else kp_bts_bawah=100;
tampil_bts_bawah(); tunggu_lepas(250);
while (down)
{
if (kp_bts_bawah>0) kp_bts_bawah--; else {kp_bts_bawah=100;tampil_bts_b
awah(); tunggu_lepas(250);}
tampil_bts_bawah();
tunggu_lepas(25);
if (kp_bts_bawah==0||kp_bts_bawah==25||kp_bts_bawah==50||kp_bts_bawah==
75||kp_bts_bawah==100) tunggu_lepas(250);
if ((kp_bts_bawah%10)==0) tunggu_lepas(250);
}
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
leb=1;
delay_ms(10);
goto set_lebar;
}
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _set_kp_bts_bawah;

set_lebar:
sensor_off;
tampil_lebar();
tunggu_lepas(500);
_set_lebar:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (leb<2) {delay_ms(10); goto set_kp_bts_bawah;}
leb--; delay_ms(10); goto set_lebar;
}
if (up)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (leb==1) lebar1=1;
if (leb==2) lebar2=1;
if (leb==3) lebar3=1;
if (leb==4) lebar4=1;
if (leb==5) lebar5=1;
tampil_lebar();
while (up);
}
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (leb==1) lebar1=0;
if (leb==2) lebar2=0;
if (leb==3) lebar3=0;
if (leb==4) lebar4=0;
if (leb==5) lebar5=0;
tampil_lebar();
while (down);
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (leb>4) {delay_ms(10); goto jmlh_cabang;}
leb++; delay_ms(10); goto set_lebar;
}
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _set_lebar;
jmlh_cabang:
sensor_off;
tampil_jmlh_cabang();
tunggu_lepas(500);
_jmlh_cabang:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;};
leb=4; delay_ms(10); goto set_lebar;

};
if (up)
{
if (led==2){back_on; waktu_nyala=nyala;};
if (jum_siasat>=30) jum_siasat=0; else jum_siasat++;
tampil_jmlh_cabang(); tunggu_lepas(250);
};
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;};
if (jum_siasat<=0) jum_siasat=30; else jum_siasat--;
tampil_jmlh_cabang(); tunggu_lepas(250);
};
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;};
delay_ms(10); urut_cab=1; goto set_cabang;
};
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _jmlh_cabang;
set_cabang:
sensor_off;
tampil_cabang();
tunggu_lepas(500);
_set_cabang:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;};
if (urut_cab<=1) {delay_ms(10); goto jmlh_cabang;};
urut_cab--; delay_ms(10); goto set_cabang;
}
if (up)
{
if (led==2){back_on; waktu_nyala=nyala;};
if (siasat_arah[urut_cab]==0){siasat_arah[urut_cab]=1;}
else if (siasat_arah[urut_cab]==2){siasat_arah[urut_cab]=0;}
else siasat_arah[urut_cab]=1;
tampil_cabang(); tunggu_lepas(250);
}
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;};
if (siasat_arah[urut_cab]==0){siasat_arah[urut_cab]=2;}
else if (siasat_arah[urut_cab]==1){siasat_arah[urut_cab]=0;}
else siasat_arah[urut_cab]=2;
tampil_cabang(); tunggu_lepas(250);
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (urut_cab>=jum_siasat) {delay_ms(10); goto ask_save;};

urut_cab++; delay_ms(10); goto set_cabang;


}
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _set_cabang;
/*set_delay:
sensor_off;
tampil_delay();
tunggu_lepas(500);
_set_delay:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10); goto set_cabang1;
}
if (up)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (nil_delay>=1000) nil_delay=0; else nil_delay++;
tampil_delay(); tunggu_lepas(250);
while (up)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (nil_delay>=1000) nil_delay=0; else nil_delay++;
tampil_delay(); tunggu_lepas(10);
}
}
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (nil_delay<=0) nil_delay=1000; else nil_delay--;
tampil_delay(); tunggu_lepas(250);
while (down)
{
if (led==2){back_on; waktu_nyala=nyala;}
if (nil_delay<=0) nil_delay=1000; else nil_delay--;
tampil_delay(); tunggu_lepas(10);
}
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10); goto ask_save;
}
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}

goto _set_delay;*/
ask_save:
sensor_off
lcd_clear();
lcd_putsf("Salin ke EEPROM?");
while (ditekan); delay_ms(500);
m=10;
tampil_ask_save();
_ask_save:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10); urut_cab=jum_siasat; goto set_cabang;
}
if (up)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
if (m>9) m=0; else m++;
tampil_ask_save(); tunggu_lepas(500);
}
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
if (m<1) m=10; else m--;
tampil_ask_save(); tunggu_lepas(500);
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
if (m>=0&&m<10) goto confirm_save;
else goto ask_run;
}
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _ask_save;
confirm_save:
sensor_off
lcd_clear();
lcd_putsf("anda yakin?");
while (ditekan) delay_ms(10);
_confirm_save:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10); lcd_clear();
while (ditekan); delay_ms(100); goto ask_save;
}

if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
lcd_clear();
save();
while (enter) delay_ms(100);
lcd_putsf("Saved"); delay_ms(250);
lcd_clear();
lcd_putsf("Saved."); delay_ms(250);
lcd_clear();
lcd_putsf("Saved.."); delay_ms(250);
lcd_clear();
lcd_putsf("Saved..."); delay_ms(500);
goto ask_default;
}
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _confirm_save;
ask_default:
sensor_off
lcd_clear();
lcd_putsf("sbg mem. utama?");
sbg_def=0;
while (ditekan) delay_ms(10);
tampil_default();
_ask_default:
baca_ir();
if (back)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10); while (ditekan); delay_ms(100); goto ask_run;
}
if (up)
{
if (led==2){back_on; waktu_nyala=nyala;}
sbg_def=1;tampil_default();
}
if (down)
{
if (led==2){back_on; waktu_nyala=nyala;}
sbg_def=0;tampil_default();
}
if (enter)
{
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
if (sbg_def)
{
eeutama=m;
lcd_clear();
lcd_putsf("setting"); delay_ms(250);
lcd_clear();
lcd_putsf("setting."); delay_ms(250);

lcd_clear();
lcd_putsf("setting.."); delay_ms(250);
lcd_clear();
lcd_putsf("setting..."); delay_ms(250);
tunggu_lepas(500);
}
goto ask_run;
}
/*if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);
bismillah();
goto run_n;
}*/
goto _ask_default;
/*idle_mode:
sensor_off;
while (ditekan)
{
lcd_clear();
sprintf(lcd,"%d",adc[0]);
lcd_puts(lcd);
delay_ms(10);
}
_lcd_ready();
_lcd_write_data(0b00001000);
while (tidak_ditekan)
{
baca_ir();
if (perubahan==1)
{
perubahan=0;
lampu_depan_on; lampu_belakang_on; back_on; sensor_on;
delay_ms(500);
sensor_off; lampu_depan_off; lampu_belakang_off; back_off;
delay_ms(500);
}
else {sensor_off; lampu_depan_off; lampu_belakang_off; back_off;}
//
//
//
//

lcd_clear();
sprintf(lcd,"%d",adc[0]);
lcd_puts(lcd);
delay_ms(10);
delay_ms(100);
for (i=0;i<8;i++)
{
if((cahaya_lalu[i]+4)<adc[i]||(cahaya_lalu[i]-4)>adc[i])perubahan=1;
cahaya_lalu[i]=adc[i];
}
if (remote)
{
remote=0;
if (led==2){back_on; waktu_nyala=nyala;}
delay_ms(10);

bismillah();
goto run_n;
}
}
goto ask_run;*/
}
}