49
4.6 Program Lengkap
Berikut adalah program yang bekerja dalam rangkaian yang dibuat. Apabila program dibawah di download ke mikrokontroler, maka rangkaian yang dibuat
dapat bekerja dengan baik.
This program was created by the CodeWizardAVR V3.12 Advanced
Automatic Program Generator © Copyright 1998-2014 Pavel Haiduc, HP InfoTech s.r.l.
http:www.hpinfotech.com
Project : Version :
Date : 05072015 Author :
Company : Comments:
Chip type : ATmega8535 Program type : Application
AVR Core Clock frequency: 8.000000 MHz Memory model : Small
External RAM size : 0 Data Stack size : 128
include mega8535.h include stdio.h
include delay.h
50
include stdlib.h define reset PIND.7
define t1 PIND.4 define t2 PIND.5
define t3 PIND.6 define pump PORTD.3
Alphanumeric LCD functions include alcd.h
unsigned char temp[8]; int data,set1=0, set2=0, set3=0, state=0, loop, waktu;
float liter=0; char buff[8];
Declare your global variables here
void mainvoid {
Declare your local variables here InputOutput Ports initialization
Port A initialization Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=Out
Bit2=In Bit1=In Bit0=In DDRA=0DDA7 | 0DDA6 | 0DDA5 | 0DDA4 |
1DDA3 | 0DDA2 | 0DDA1 | 0DDA0; State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=0 Bit2=P
Bit1=P Bit0=P PORTA=0PORTA7 | 0PORTA6 | 0PORTA5 |
0PORTA4 | 0PORTA3 | 1PORTA2 | 1PORTA1 | 1PORTA0;
Port B initialization
51
Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
DDRB=0DDB7 | 0DDB6 | 0DDB5 | 0DDB4 | 0DDB3 | 0DDB2 | 0DDB1 | 0DDB0;
State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
PORTB=0PORTB7 | 0PORTB6 | 0PORTB5 | 0PORTB4 | 0PORTB3 | 0PORTB2 | 0PORTB1 |
0PORTB0;
Port C initialization Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In
Bit2=In Bit1=In Bit0=In DDRC=0DDC7 | 0DDC6 | 0DDC5 | 0DDC4 |
1DDC3 | 0DDC2 | 0DDC1 | 0DDC0; State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T
Bit1=T Bit0=T PORTC=1PORTC7 | 1PORTC6 | 1PORTC5 |
1PORTC4 | 0PORTC3 | 0PORTC2 | 0PORTC1 | 0PORTC0;
Port D initialization Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In
Bit2=In Bit1=In Bit0=In DDRD=0DDD7 | 0DDD6 | 0DDD5 | 0DDD4 |
1DDD3 | 0DDD2 | 0DDD1 | 0DDD0; State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T
Bit1=T Bit0=T PORTD=1PORTD7 | 1PORTD6 | 1PORTD5 |
1PORTD4 | 0PORTD3 | 0PORTD2 | 0PORTD1 | 0PORTD0;
TimerCounter 0 initialization
52
Clock source: System Clock Clock value: Timer 0 Stopped
Mode: Normal top=0xFF OC0 output: Disconnected
TCCR0=0WGM00 | 0COM01 | 0COM00 | 0WGM01 | 0CS02 | 0CS01 | 0CS00;
TCNT0=0x00; OCR0=0x00;
TimerCounter 1 initialization Clock source: T1 pin Falling Edge
Mode: Normal top=0xFFFF OC1A output: Disconnected
OC1B output: Disconnected Noise Canceler: Off
Input Capture on Falling Edge Timer1 Overflow Interrupt: Off
Input Capture Interrupt: Off Compare A Match Interrupt: Off
Compare B Match Interrupt: Off TCCR1A=0COM1A1 | 0COM1A0 | 0COM1B1 |
0COM1B0 | 0WGM11 | 0WGM10; TCCR1B=0ICNC1 | 0ICES1 | 0WGM13 |
0WGM12 | 1CS12 | 1CS11 | 0CS10; TCNT1H=0x00;
TCNT1L=0x00; ICR1H=0x00;
ICR1L=0x00; OCR1AH=0x00;
OCR1AL=0x00; OCR1BH=0x00;
OCR1BL=0x00; TimerCounter 2 initialization
53
Clock source: System Clock Clock value: Timer2 Stopped
Mode: Normal top=0xFF OC2 output: Disconnected
ASSR=0AS2; TCCR2=0WGM20 | 0COM21 | 0COM20 | 0WGM21
| 0CS22 | 0CS21 | 0CS20; TCNT2=0x00;
OCR2=0x00;
TimersCounters Interrupts initialization TIMSK=0OCIE2 | 0TOIE2 | 0TICIE1 |
0OCIE1A | 0OCIE1B | 0TOIE1 | 0OCIE0 | 0TOIE0;
External Interrupts initialization INT0: Off
INT1: Off INT2: Off
MCUCR=0ISC11 | 0ISC10 | 0ISC01 | 0ISC00;
MCUCSR=0ISC2;
USART initialization USART disabled
UCSRB=0RXCIE | 0TXCIE | 0UDRIE | 0RXEN | 0TXEN | 0UCSZ2 | 0RXB8 | 0TXB8;
Analog Comparator initialization Analog Comparator: Off
The Analog Comparators positive input is connected to the AIN0 pin
The Analog Comparators negative input is
54
connected to the AIN1 pin ACSR=1ACD | 0ACBG | 0ACO | 0ACI |
0ACIE | 0ACIC | 0ACIS1 | 0ACIS0; SFIOR=0ACME;
ADC initialization ADC disabled
ADCSRA=0ADEN | 0ADSC | 0ADATE | 0ADIF | 0ADIE | 0ADPS2 | 0ADPS1 | 0ADPS0;
SPI initialization SPI disabled
SPCR=0SPIE | 0SPE | 0DORD | 0MSTR | 0CPOL | 0CPHA | 0SPR1 | 0SPR0;
TWI initialization TWI disabled
TWCR=0TWEA | 0TWSTA | 0TWSTO | 0TWEN | 0TWIE;
Alphanumeric LCD initialization Connections are specified in the
Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
RS - PORTC Bit 0 RD - PORTC Bit 1
EN - PORTC Bit 2 D4 - PORTC Bit 3
D5 - PORTC Bit 4 D6 - PORTC Bit 5
D7 - PORTC Bit 6 Charactersline: 16
lcd_init16;
55
while 1 {
if reset==0{pump=0;state=0;set1=0;data=0,liter=0;
loop=0;} while state==0
{ lcd_gotoxy0,0;
lcd_putsfPilih Pengisian; delay_ms50;
if t1==0{set1=1;state=1;} if t2==0{set2=1;state=1;}
if t3==0{set3=1;state=1;} lcd_clear;
} while set1==1
{ data=TCNT1;
liter=data0.0019455;0.0019455=1514; ftoaliter,2,temp;
if liter=1 {
pump=0; liter=1;
} else
{ pump=1;
loop++; waktu=loop0.05464100;
itoawaktu,buff;
56
lcd_gotoxy0,0; lcd_putsfwaktu :;
lcd_gotoxy13,0; lcd_putsfms;
lcd_gotoxy8,0; lcd_putsbuff;
delay_ms50; }
ftoaliter,2,temp; lcd_gotoxy8,1;
lcd_putstemp; lcd_gotoxy13,1;
lcd_putsfL; lcd_gotoxy0,1;
lcd_putsfVolume:; if
reset==0{pump=0;state=0;set1=0;data=0,liter=0;TCNT1=0 ; loop=0;}
} while set2==1
{ data=TCNT1;
liter=data0.0019455;0.0019455=1514; ftoaliter,2,temp;
if liter=2 {
pump=0; liter=2;
} else
{ pump=1;
57
loop++; waktu=loop0.05464100;
itoawaktu,buff; lcd_gotoxy0,0;
lcd_putsfwaktu :; lcd_gotoxy13,0;
lcd_putsfms; lcd_gotoxy8,0;
lcd_putsbuff; delay_ms50;
} ftoaliter,2,temp;
lcd_gotoxy8,1; lcd_putstemp;
lcd_gotoxy13,1; lcd_putsfL;
lcd_gotoxy0,1; lcd_putsfVolume:;
if reset==0{pump=0;state=0;set2=0;data=0,liter=0;TCNT1=0
;loop=0;} }
while set3==1 {
data=TCNT1; liter=data0.0019455;0.0019455=1514;
ftoaliter,2,temp; if liter=3
{ pump=0;
liter=3; }
58
else {
pump=1; loop++;
waktu=loop0.05464100; itoawaktu,buff;
lcd_gotoxy0,0; lcd_putsfwaktu :;
lcd_gotoxy13,0; lcd_putsfms;
lcd_gotoxy8,0; lcd_putsbuff;
delay_ms50; }
ftoaliter,3,temp; lcd_gotoxy8,1;
lcd_putstemp; lcd_gotoxy13,1;
lcd_putsfL; lcd_gotoxy0,1;
lcd_putsfVolume:; if
reset==0{pump=0;state=0;set3=0;data=0,liter=0;TCNT1=0 ;loop=0;}
}
} }
59
4.7. Pengujian Alat