You are on page 1of 5

LAMPIRAN 2

LISTING PROGRAM KESELURUHAN

/*****************************************************
#include <mega8535.h>
#include <alcd.h>
#include <delay.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#asm
.equ _lcd_port=0x18 ;portb
#endasm

#define PD3 PORTD.3

char status,b;
unsigned char speed;
unsigned int counter,pwm[6]={0,400,450,500,550,600};

// Declare your global variables here


void level()
{
switch(speed)
{
case 0: lcd_gotoxy(0,1);
lcd_putsf(" LEVEL : 0 ");
break;
case 1:lcd_gotoxy(0,1);
lcd_putsf(" LEVEL : 1 ");
break;
case 2:lcd_gotoxy(0,1);
lcd_putsf(" LEVEL : 2 ");
break;
case 3:lcd_gotoxy(0,1);
lcd_putsf(" LEVEL : 3 ");
break;
case 4: lcd_gotoxy(0,1);
lcd_putsf(" LEVEL : 4 ");
break;
case 5:lcd_gotoxy(0,1);
lcd_putsf(" LEVEL : 5 ");
break;
default: lcd_gotoxy(0,1);
lcd_putsf("");
break;
}
}

void kecepatan()
{
if ((PINA.1==0)&&(speed<5))
{
speed=speed+1;
level();
delay_ms(30);
}

if ((PINA.0==0)&&(speed>0))
{
speed=speed-1;
level();
delay_ms(30);
}

OCR1A=pwm[speed];
}
void cek_kecepatan()
{
delay_ms(20);
if(speed==5)
{
while(speed!=2)
{
speed=speed-1;
OCR1A=pwm[speed];
level();
delay_ms(50);
}
}
else if(speed==4)
{
while(speed!=2)
{
speed=speed-1;
OCR1A=pwm[speed];
level();
delay_ms(50);
}
}
else if(speed==3)
{
while(speed!=2)
{
speed=speed-1;
OCR1A=pwm[speed];
level();
delay_ms(50);
}
}
OCR1A=pwm[speed];
}

void cek()
{
b='a';
while(b=='a')
{
if(PINC.4==1)
{
counter=0;
}
else
{
counter=counter+1;
delay_ms(10);
};
if(counter==4)
{
lcd_gotoxy(0,0);
lcd_putsf(" Anda Melewati ");
lcd_gotoxy(0,1);
lcd_putsf("Zona Aman Skolah");
delay_ms(100);
b='b';
status='n';
lcd_clear();
}
if ((PINA.1==0)&&(speed<2)&&(status=='o'))
{
speed=speed+1;
level();
delay_ms(30);
}
else if ((PINA.0==0)&&(speed>0)&&(status=='o'))
{
speed=speed-1;
level();
delay_ms(30);
}
OCR1A=pwm[speed];
}
}
void main(void)
{
PORTA=0x0F;
DDRA=0x00;
PORTB=0x00;
DDRB=0x00;
PORTC=0xF0;
DDRC=0x00;
PORTD=0x00;
DDRD=0x20;

TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

TCCR1A=0x83;
TCCR1B=0x09;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

MCUCR=0x00;
MCUCSR=0x00;

TIMSK=0x00;

ACSR=0x80;
SFIOR=0x00;
lcd_init(16);
status='n';
speed=0;
while (1)
{
kecepatan();
level();
if((PINC.4==1)&&(status='n'))
{
lcd_gotoxy(0,0);
lcd_putsf("Zona Aman Skolah");
cek_kecepatan();
status='o';
while(status=='o')
{
cek();

}
}
OCR1A=pwm[speed];
}
}

You might also like