You are on page 1of 11

Chip type

: ATmega16

Program type

: Application

AVR Core Clock frequency: 8.000000 MHz


Memory model

: Small

External RAM size

:0

Data Stack size

: 256

*****************************************************/
#include <mega16.h>
#include <stdio.h>
#include <delay.h>

// I2C Bus functions


#asm
.equ __i2c_port=0x15 ;PORTC
.equ __sda_bit=1
.equ __scl_bit=0
#endasm
#include <i2c.h>
#include <ds1307.h>
#include <alcd.h>

#define ADC_VREF_TYPE 0x60


// Read the 8 most significant bits
// of the AD conversion result
unsigned char read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage

delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCH;
}
// Declare your global variables here
void main(void)
{
unsigned char h, m, s, d, mo, y, temp[16],b1[8],b2[8],b3[8],b4[8];
float a1,a2,a3,a4,c1,c2,c3,c4;
PORTA=0b00001100;
DDRA=0x00;
PORTB=0x00;
DDRB=0x01;
PORTC=0x00;
DDRC=0x00;
PORTD=0x00;
DDRD=0xFF;

// ADC initialization
// ADC Clock frequency: 1000.000 kHz
// ADC Voltage Reference: AVCC pin
// ADC Auto Trigger Source: Free Running
// Only the 8 most significant bits of
// the AD conversion result are used

ADMUX=ADC_VREF_TYPE & 0xff;


ADCSRA=0xA3;
SFIOR&=0x1F;

// TWI initialization
// TWI disabled
TWCR=0x00;

// I2C Bus initialization


i2c_init();

// DS1307 Real Time Clock initialization


// Square wave output on pin SQW/OUT: Off
// SQW/OUT pin state: 0
rtc_init(0,0,0);

// Alphanumeric LCD initialization


// Connections specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTD Bit 0
// RD - PORTD Bit 1
// EN - PORTD Bit 2
// D4 - PORTD Bit 4
// D5 - PORTD Bit 5
// D6 - PORTD Bit 6
// D7 - PORTD Bit 7
// Characters/line: 16
lcd_init(16);

//rtc_set_time(11,00,00);
//rtc_set_date(5,1,16);
lcd_gotoxy(0,0);
lcd_clear();

while (1)
{
//KONTROL MOTOR
if (PINA.2==1&&PINA.3==1)
{
while(PINA.2==1&&PINA.3==1)
{
PORTB.0=1;
delay_us(920);
PORTB.0=0;
delay_ms(20);
};
}
else
{
while(PINA.2==0&&PINA.3==0)
{
PORTB.0=1;
delay_us(2120);
PORTB.0=0;
delay_ms(20);
};
};

//PROGRAM JAM

rtc_get_time(&h,&m,&s);
rtc_get_date(&d,&mo,&y);
lcd_clear();
lcd_gotoxy(2,0);
sprintf(temp,"JAM : %d:%d:%d",h,m,s);
lcd_puts(temp);
lcd_gotoxy(2,1);
sprintf(temp,"TGL : %d-%d-%d",d,mo,y);
lcd_puts(temp);
delay_ms(1000);
lcd_clear();

//MEMBACA LDR
a1=read_adc(4);
a2=read_adc(5);
a3=read_adc(6);
a4=read_adc(7);

c1=((float)a1/256)*5;
c2=((float)a2/256)*5;
c3=((float)a3/256)*5;
c4=((float)a4/256)*5;

//JUMLAH PARKIR
if (c1<=3.5)
{
if (c2<=3.5)
{
if (c3<=3.5)
{
if (c4<=3.5)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("PARKIR TERSEDIA");
lcd_gotoxy(3,1);
lcd_puts("JUMLAH = 4");
delay_ms(2000);
}
else
{ lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("PARKIR TERSEDIA");
lcd_gotoxy(3,1);
lcd_puts("JUMLAH = 3");
delay_ms(2000);
}
}
else
{
lcd_clear();

lcd_gotoxy(0,0);
lcd_puts("PARKIR TERSEDIA");
lcd_gotoxy(3,1);
lcd_puts("JUMLAH = 2");
delay_ms(2000);
}
}
else
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("PARKIR TERSEDIA");
lcd_gotoxy(3,1);
lcd_puts("JUMLAH = 1");
delay_ms(2000);
}
}
else
{
if (c2<=3.5)
{
if (c3<=3.5)
{
if (c4<=3.5)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("PARKIR TERSEDIA");

lcd_gotoxy(3,1);
lcd_puts("JUMLAH = 3");
delay_ms(2000);
}
else
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("PARKIR TERSEDIA");
lcd_gotoxy(3,1);
lcd_puts("JUMLAH = 2");
delay_ms(2000);
}
}
else
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("PARKIR TERSEDIA");
lcd_gotoxy(3,1);
lcd_puts("JUMLAH = 1");
delay_ms(2000);
}
}
else
{
if (c3<=3.5)
{

if (c4<=3.5)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("PARKIR TERSEDIA");
lcd_gotoxy(3,1);
lcd_puts("JUMLAH = 2");
delay_ms(2000);
}
else
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("PARKIR TERSEDIA");
lcd_gotoxy(3,1);
lcd_puts("JUMLAH = 1");
delay_ms(2000);
}
}
else
{
if (c4<=3.5)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("PARKIR TERSEDIA");
lcd_gotoxy(3,1);
lcd_puts("JUMLAH = 1");

delay_ms(2000);
}
else
{
lcd_clear();
lcd_gotoxy(2,0);
lcd_puts("PARKIR PENUH");
lcd_gotoxy(3,1);
lcd_puts("JUMLAH = 0");
delay_ms(2000);
}
}
}
}

//LOKASI PARKIR

if (c1<=3.5)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("PARKIR TERSEDIA");
lcd_gotoxy(3,1);
lcd_puts("LOKASI A1");
delay_ms(2000);
}
if (c2<=3.5)
{

lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("PARKIR TERSEDIA");
lcd_gotoxy(3,1);
lcd_puts("LOKASI A2");
delay_ms(2000);
}
if (c3<=3.5)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("PARKIR TERSEDIA");
lcd_gotoxy(3,1);
lcd_puts("LOKASI A3");
delay_ms(2000);
}
if (c4<=3.5)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("PARKIR TERSEDIA");
lcd_gotoxy(3,1);
lcd_puts("LOKASI A4");
delay_ms(2000);
}

}
}

You might also like