Perancangan Alat Membuka dan Menutup Gerbang Berbasis Mikrokontroler ATmega8 Menggunkan Ponsel Android Via Bluetooth

LAMPIRAN 1

PROGRAM PADA ALAT

/*****************************************************
This program was produced by the
CodeWizardAVR V2.04.9 Evaluation
Automatic Program Generator
© Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project :
Version :
Date : 11/03/2016
Author : Freeware, for evaluation and non-commercial use only
Company :
Comments:

Chip type

: ATmega8


Program type

: Application

AVR Core Clock frequency: 11,059200 MHz
Memory model

: Small

External RAM size

:0

Data Stack size

: 256

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


Universitas Sumatera Utara

#include
#include
#include
#define ADC_VREF_TYPE 0x00

unsigned int 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 ADCW;
}
unsigned char Comm,Status,I,A,B,C,D;

unsigned int IR;
void main(void)
{

// Input/Output Ports initialization
// Port B initialization
PORTB=0x00;
DDRB=0xFF;

Universitas Sumatera Utara

// Port C initialization
PORTC=0x7F;
DDRC=0x00;

// Port D initialization
PORTD=0x00;
DDRD=0x00;

// Communication Parameters: 8 Data, 1 Stop, No Parity

// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x10;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x47;

// ADC initialization
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x82;
Status = 1;
while (1)
{
quit: if ((UCSRA & (1 5

if (Comm == '#') {I = 0;}

//reset I jika # ditekan

if (Comm == '*') {I = 0;if (A=='5'){if (B=='1'){if (C=='5'){if (D=='1'){


PORTD.4=1;delay_ms(150);PORTD.4=0;
ketika PinC.1 =1

//jika comm = * dan

while (PINC.1 == 1) {Status = 0;
PORTB=1;

// maka PortB = 1(menjalankan motor buka gate)

if ((UCSRA & (1