SKEMATIK RANGKAIAN 5V U L N
4 2
15
8
NOR CLOSED
5V
2 0 0 3
IGNITION COIL
Accu
12V
13
Klakson NOR OPEN
ISP CONNECTOR 5
4
3
2
1
A V R
PB0 PB1
MOSI MISO SCK
3 4 2
D B 3 9
5
2
14
2K
330 Ω 10uF 330 Ω
6
31
10uF 330 Ω 10uF 330 Ω
10 Vcc
1uF
10uF
14 15
22pF
12
10
7 8
PA6
9
4 MHz
7 M A 4 L E 5
1uF
16 M A X 2 3 2
PA4
8 5 3 5
47uF
1uF 1
PA2
A T M E G A
RST
5V
1uF
PA0
15
13 22pF PD6
Gnd
7805
12V
Vcc
On/Off Gnd
Kontak Motor
In 1 KΩ
5V Out
Gnd
100 Ω
#include <mega8535.h> // Standard Input/Output functions #include <stdio.h>
//deklarasi standart input output
#include <delay.h>
//deklarasi delay
#define enter putchar(13)
//mendefinisi putchar dengan simbol enter
#define mesin PORTB.0
//mendefinisi PORTB.0 dengan mesin
#define klakson PORTB.1
//mendefinisi PORTB.1 dengan klakson
// Declare your global variables here eeprom unsigned char combo[4]={1,2,3,4};
//menyimpan password di eeprom
unsigned char A[4]; unsigned char temp = 0; unsigned int status = 0;
//deklarasi variable status
unsigned int mcblk = 0;
//deklarasi variable misscal balik
unsigned long timecount = 0;
//deklarasi variable timer
unsigned int pass_bnr = 0;
//deklarasi variable password jika benar
void miss_call()
//fungsi misscall
{
//jika misscall balik sama dengan nol
if (mcblk == 0) { if (getchar() == 'R')
//meminta charakter dari ponsel
{ mcblk = 1;
//memberikan nilai miss call
} } if (pass_bnr && mcblk)
//validasi password dan misscall balik
{ pass_bnr = 0;
//memberikan nilai password dengan nol
status = 0;
//memberikan nilai status dengan nol
mcblk = 0;
//memberikan nilai misscal balik dengan nol
mesin = 0;
//mesin dapat dinyalakan
klakson = 0;
//klakson berhenti berbunyi
TIMSK=0x00;
//mematikan timer
} }
void password()
//fungsi password
{ if(!(PINA.0&&PINA.2&&PINA.4&&PINA.6)) { if(!PINA.0)
//jika push button 1 ditekan
{ A[temp]=1; } if(!PINA.2)
//jika push button 2 ditekan
{ A[temp]=2; } if(!PINA.4)
//jika push button 3 ditekan
{ A[temp]=3; } if(!PINA.6)
//jika push button 4 ditekan
{ A[temp]=4; } delay_ms(450); temp++;
//menambahkan nilai temp
}
if(temp == 4) {
//jika temp sudah bernilai 4
temp=0; if((A[0]==combo[0]) && (A[1]==combo[1]) && (A[2]==combo[2]) && (A[3]==combo[3]))
//validasi jika password sama dengan eeprom/benar
{ pass_bnr = 1;
//memberikan nilai password
if (timecount < 100)
//jika kuarang dari 10 detik
{ status = 0;
//menset status jadi nol
mcblk = 0;
//menset miss call balik jadi nol
timecount = 0;
//menset timer jadi nol
TIMSK = 0x00;
//mematikan timer
klakson = 1;
//menyalakan klakson
delay_ms(500); klakson = 0;
//mematikan klakson
} }
Else
//jika password salah
{ klakson = 1;
//menyalakan klakson
delay_ms(2500); klakson = 0;
//mematikan klakson
} } }
void telepon_mati()
//fungsi mematikan telpon
{ printf("ath"); enter; delay_ms(100);
//menutup panggillan
}
void telepon_lagi()
//fungsi telpon lagi
{ printf("atd08561179524;");
//melakukan panggilan ke no pemilik
enter; delay_ms(100); }
// External Interrupt 0 service routine interrupt [EXT_INT0] void ext_int0_isr(void)
//deklarasi interrupt 0
{ // Place your code here status = 1;
//memberikan status apabila kontak dilakukan
if (timecount == 0)
//mencek apakah timer sudah jalan atau belum
{ TIMSK=0x04;
//menjalankan timer
} }
// Timer 1 overflow interrupt service routine interrupt [TIM1_OVF] void timer1_ovf_isr(void)
//deklarasi timer 1
{ // Place your code here TCNT1 = 15535;
//menset register timer
timecount++;
//mencounter timer
password();
//memanggil fungsi password
if(timecount == 100)
//jika sudah detik ke 10
{ printf("atd08561179524;"); enter;
//mendial pemilik kendaraan
delay_ms(100); mesin = 1;
//mematikan mesin motor
klakson = 1;
//menyalakan klakson motor
}
if(mcblk == 0)
//mencek nilai apakah miss call balik sudah ada
{ if( timecount == 400)
//jika sudah detik ke 40
{ telepon_mati();
//memanggil fungsi menutup pangillan
}
if( timecount == 600)
//jika sudah detik ke 60
{ telepon_lagi();
//memanggil fungsi telpon
} }
if (timecount == 600)
//jika sudah detik ke 60
{ timecount = 100;
//mengembalikan ke detik 10
} }
void main(void)
//deklarasi program utama
{ // Declare your local variables here
// Inisialisasi Input/Output Ports // Inisialisasi Port A // Func0=In Func1=Out Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In
// State0=P State1=0 State2=P State3=T State4=P State5=T State6=P State7=T PORTA=0x55; DDRA=0x02;
// Inisialisasi Port B // Func0=Out Func1=Out Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In // State0=0 State1=0 State2=T State3=T State4=T State5=T State6=T State7=T PORTB=0x00; DDRB=0x03;
// Port C initialization // Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In // State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T PORTC=0x00; DDRC=0x00;
// Port D initialization // Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In // State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T PORTD=0x00; DDRD=0x00;
// Timer/Counter 0 initialization // Clock source: System Clock // Clock value: Timer 0 Stopped // Mode: Normal top=FFh // OC0 output: Disconnected TCCR0=0x00; TCNT0=0x00; OCR0=0x00;
// Inisialisasi Timer/Counter 1 // Clock source: System Clock // Clock value: 500.000 kHz // Mode: Normal top=FFFFh // OC1A output: Discon. // OC1B output: Discon. // Noise Canceler: Off // Input Capture on Falling Edge TCCR1A=0x00; TCCR1B=0x02; TCNT1H=0x00; TCNT1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00;
// Timer/Counter 2 initialization // Clock source: System Clock // Clock value: Timer 2 Stopped // Mode: Normal top=FFh // OC2 output: Disconnected ASSR=0x00; TCCR2=0x00; TCNT2=0x00; OCR2=0x00;
// Inisialisasi External Interrupt(s) // INT0: On // INT0 Mode: Rising Edge // INT1: Off
// INT2: Off GICR|=0x40; MCUCR=0x03; MCUCSR=0x00; GIFR=0x40;
// Inisialisasi Timer(s)/Counter(s) Interrupt(s) TIMSK=0x00;
// Inisialisasi USART // Communication Parameters: 8 Data, 1 Stop, No Parity // USART Receiver: On // USART Transmitter: On // USART Mode: Asynchronous // USART Baud rate: 9600 UCSRA=0x00; UCSRB=0x18; UCSRC=0x86; UBRRH=0x00; UBRRL=0x19;
// Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off // Analog Comparator Output: Off ACSR=0x80; SFIOR=0x00;
// Global enable interrupts #asm("sei")
while (1) { // Place your code here if(status == 1)
//jika status sama dengan 1
{ if (timecount > 100)
//jika timer dibawah 10 detik
{ miss_call(); } } }; }
//untuk memanggil fungsi miss call