Laporan Vending Machine

  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Laporan Vending Machine as PDF for free.

More details

  • Words: 1,074
  • Pages: 18
LAPORAN VENDING MACHINE

INSTRUKSI PROGRAM /***************************************************** This program was produced by the CodeWizardAVR V1.25.3 Standard Automatic Program Generator © Copyright 1998-2007 Pavel Haiduc, HP InfoTech s.r.l. http://www.hpinfotech.com

Project : Version : Date

: 27/03/2009

Author : F4CG Company : F4CG Comments:

Chip type Program type Clock frequency

: ATmega16 : Application : 11,059200 MHz

Memory model

: Small

External SRAM size : 0 Data Stack size

: 256

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

#include <mega16.h> #include <stdio.h> #include <delay.h> // Alphanumeric LCD Module functions

#asm .equ __lcd_port=0x1B ;PORTA #endasm #include

// Declare your global variables here unsigned i,a,b,h,pilih; unsigned char led[]={0b11111110,0b11111101,0b11111011,0b11110111,0b11101111,0b1101 1111,0b10111111,0b01111111}; unsigned char data[100];

void main(void) { // Declare your local variables here unsigned char state=0;

// Input/Output Ports initialization // Port A initialization // Func7=In Func0=In

Func6=In

Func5=In

Func4=In

Func3=In

Func2=In

Func1=In

// State7=T State0=T

State6=T

State5=T

State4=T

State3=T

State2=T

State1=T

PORTA=0x00; DDRA=0x00;

// Port B initialization // Func7=Out Func6=Out Func1=Out Func0=Out // State7=0 State0=0

State6=0

Func5=Out

State5=0

Func4=Out

State4=0

Func3=Out

State3=0

State2=0

Func2=Out State1=0

PORTB=0x00; DDRB=0xFF;

// Port C initialization // Func7=In Func0=In

Func6=In

Func5=In

Func4=In

Func3=In

Func2=In

Func1=In

// State7=T State0=T

State6=T

State5=T

State4=T

State3=T

State2=T

State1=T

Func5=In

Func4=In

Func3=In

Func2=In

Func1=In

PORTC=0x00; DDRC=0x00;

// Port D initialization // Func7=In Func0=In

Func6=In

// State7=P State6=P State5=P State4=P State3=P State2=P State1=P State0=P PORTD=0xFF; 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;

// Timer/Counter 1 initialization // Clock source: System Clock // Clock value: Timer 1 Stopped // Mode: Normal top=FFFFh // OC1A output: Discon.

// OC1B output: Discon. // Noise Canceler: Off // Input Capture on Falling Edge // Timer 1 Overflow Interrupt: Off // Input Capture Interrupt: Off // Compare A Match Interrupt: Off // Compare B Match Interrupt: Off TCCR1A=0x00; TCCR1B=0x00; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=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;

// External Interrupt(s) initialization // INT0: Off // INT1: Off

// INT2: Off MCUCR=0x00; MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x00;

// Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; SFIOR=0x00;

// LCD module initialization lcd_init(16);

while (1) { // Place your code here if(state==0){ lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Selamat Datang"); lcd_gotoxy(0,1); lcd_putsf("Masukkan Uang"); delay_ms(100); state=1; } else if(state==1){ if(PIND.2==0){ PORTB=0;

//masukkan uang

i++; a=~i; PORTB=a; delay_ms(100); h=i*100; sprintf(data,"Uang Anda = %d",h); lcd_clear(); lcd_gotoxy(0,0); lcd_puts(data); delay_ms(100); state=2; } if(PIND.7==0){

//masukkan uang

PORTB=0; i--; a=~i; PORTB=a; delay_ms(100); h=i*100; sprintf(data,"Uang Anda = %d",h); lcd_clear(); lcd_gotoxy(0,0); lcd_puts(data); delay_ms(100); state=2; } }

else if(state==2){ if(PIND.2==0){ PORTB=0;

//masukkan uang lagi

i++; a=~i; PORTB=a; delay_ms(100); h=i*100; sprintf(data,"Uang Anda = %d",h); lcd_clear(); lcd_gotoxy(0,0); lcd_puts(data); delay_ms(100); } if(PIND.7==0){

//masukkan uang

PORTB=0; i--; a=~i; PORTB=a; delay_ms(100); h=i*100; sprintf(data,"Uang Anda = %d",h); lcd_clear(); lcd_gotoxy(0,0); lcd_puts(data); delay_ms(100); state=2; } if(PIND.3==0){ pilih=1; lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Fanta Anda Pilih"); lcd_gotoxy(0,1);

lcd_putsf("Harga Rp 500"); delay_ms(100); } if(PIND.4==0){ pilih=2; lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Sprite Anda Pilih"); lcd_gotoxy(0,1); lcd_putsf("Harga Rp 600"); delay_ms(100); } if(PIND.5==0){ pilih=3; lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Coca Anda Pilih"); lcd_gotoxy(0,1); lcd_putsf("Harga Rp 700"); delay_ms(100); }

if(PIND.6==0){ if(pilih==1){ for(b=0;b<=7;b++){ PORTB=led[b]; delay_ms(100); }

if(i==5){ lcd_clear();

//fanta

lcd_gotoxy(0,0); lcd_putsf("Uang Anda Pas"); lcd_gotoxy(0,1); lcd_putsf("Terima Kasih"); delay_ms(500); }

if(i==4||i==3||i==2||i==1||i==0){ lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Uang Anda Kurang"); lcd_gotoxy(0,1); lcd_putsf("Masukkan Uang Lagi"); delay_ms(500); }

if(i>5){ lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Uang Anda Lebih"); lcd_gotoxy(0,1); lcd_putsf("Kurangi Uangnya"); delay_ms(500); }}

if(pilih==2){ for(b=0;b<=7;b++){ PORTB=led[b]; delay_ms(100); }

//sprite

if(i==6){ lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Uang Anda Pas"); lcd_gotoxy(0,1); lcd_putsf("Terima Kasih"); delay_ms(500); }

if(i==5||i==4||i==3||i==2||i==1||i==0){ lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Uang Anda Kurang"); lcd_gotoxy(0,1); lcd_putsf("Masukkan Uang Lagi"); delay_ms(500); }

if(i>6){ lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Uang Anda Lebih"); lcd_gotoxy(0,1); lcd_putsf("Kurangi Uangnya"); delay_ms(500); }}

if(pilih==3){ for(b=0;b<=7;b++){ PORTB=led[b]; delay_ms(100);

//coca cola

}

if(i==7){ lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Uang Anda Pas"); lcd_gotoxy(0,1); lcd_putsf("Terima Kasih"); delay_ms(500); }

if(i==6||i==5||i==4||i==3||i==2||i==1||i==0){ lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Uang Anda Kurang"); lcd_gotoxy(0,1); lcd_putsf("Masukkan Uang Lagi"); delay_ms(500); }

if(i>7){ lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Uang Anda Lebih"); lcd_gotoxy(0,1); lcd_putsf("Kurangi Uangnya"); delay_ms(500); }}}} }; } ANALISIS PROGRAM

Pada praktikum kali ini kita akan mencoba untuk membuat analogi vending machine yang diaplikasikan pada minsis ATMega 16. Untuk tampilannya digunakan LCD untuk menampilkan pilihan menu dan segala aktivitas yang kita lakukan pada vending machine. Untuk listing program intinya adalah : if(state==0){ lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Selamat Datang"); lcd_gotoxy(0,1); lcd_putsf("Masukkan Uang"); delay_ms(100); state=1; } else if(state==1){ if(PIND.2==0){

//masukkan uang

PORTB=0; i++; a=~i; PORTB=a; delay_ms(100); h=i*100; sprintf(data,"Uang Anda = %d",h); lcd_clear(); lcd_gotoxy(0,0); lcd_puts(data); delay_ms(100); state=2; } if(PIND.7==0){ PORTB=0; i--;

//masukkan uang

a=~i; PORTB=a; delay_ms(100); h=i*100; sprintf(data,"Uang Anda = %d",h); lcd_clear(); lcd_gotoxy(0,0); lcd_puts(data); delay_ms(100); state=2; } }

else if(state==2){ if(PIND.2==0){

//masukkan uang lagi

PORTB=0; i++; a=~i; PORTB=a; delay_ms(100); h=i*100; sprintf(data,"Uang Anda = %d",h); lcd_clear(); lcd_gotoxy(0,0); lcd_puts(data); delay_ms(100); } if(PIND.7==0){ PORTB=0; i--; a=~i;

//masukkan uang

PORTB=a; delay_ms(100); h=i*100; sprintf(data,"Uang Anda = %d",h); lcd_clear(); lcd_gotoxy(0,0); lcd_puts(data); delay_ms(100); state=2; } if(PIND.3==0){ pilih=1; lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Fanta Anda Pilih"); lcd_gotoxy(0,1); lcd_putsf("Harga Rp 500"); delay_ms(100); } if(PIND.4==0){ pilih=2; lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Sprite Anda Pilih"); lcd_gotoxy(0,1); lcd_putsf("Harga Rp 600"); delay_ms(100); } if(PIND.5==0){ pilih=3; lcd_clear();

lcd_gotoxy(0,0); lcd_putsf("Coca Anda Pilih"); lcd_gotoxy(0,1); lcd_putsf("Harga Rp 700"); delay_ms(100); }

if(PIND.6==0){ if(pilih==1){

//fanta

for(b=0;b<=7;b++){ PORTB=led[b]; delay_ms(100); }

if(i==5){ lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Uang Anda Pas"); lcd_gotoxy(0,1); lcd_putsf("Terima Kasih"); delay_ms(500); }

if(i==4||i==3||i==2||i==1||i==0){ lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Uang Anda Kurang"); lcd_gotoxy(0,1); lcd_putsf("Masukkan Uang Lagi"); delay_ms(500); }

if(i>5){ lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Uang Anda Lebih"); lcd_gotoxy(0,1); lcd_putsf("Kurangi Uangnya"); delay_ms(500); }}

if(pilih==2){

//sprite

for(b=0;b<=7;b++){ PORTB=led[b]; delay_ms(100); }

if(i==6){ lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Uang Anda Pas"); lcd_gotoxy(0,1); lcd_putsf("Terima Kasih"); delay_ms(500); }

if(i==5||i==4||i==3||i==2||i==1||i==0){ lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Uang Anda Kurang"); lcd_gotoxy(0,1); lcd_putsf("Masukkan Uang Lagi");

delay_ms(500); }

if(i>6){ lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Uang Anda Lebih"); lcd_gotoxy(0,1); lcd_putsf("Kurangi Uangnya"); delay_ms(500); }}

if(pilih==3){

//coca cola

for(b=0;b<=7;b++){ PORTB=led[b]; delay_ms(100); }

if(i==7){ lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Uang Anda Pas"); lcd_gotoxy(0,1); lcd_putsf("Terima Kasih"); delay_ms(500); }

if(i==6||i==5||i==4||i==3||i==2||i==1||i==0){ lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Uang Anda Kurang");

lcd_gotoxy(0,1); lcd_putsf("Masukkan Uang Lagi"); delay_ms(500); }

if(i>7){ lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("Uang Anda Lebih"); lcd_gotoxy(0,1); lcd_putsf("Kurangi Uangnya"); delay_ms(500); }}}} }; Pada program inti dapat kita lihat bahwa, program dibagi menjadi tiga bagian yaitu state 0, state 1 dan state 2. Pada program di atas dapat kita lihat bahwa state pertama adalah bagian untuk tampilan LCD awal yang jika tidak ada penekanan Push Button maka tampilan akan berjalan terus. Untuk state kedua adalah bagian untuk memasukkan uang atau penekanan Push Button dan pengurangan uang. Sementara pada state ketiga adalah bagian untuk pilihan menu dan tampilan jika menu dipilih. Menu terdiri dari tiga yaitu fanta, sprite dan cola. Pada program di atas jika uang kurang dari harga yang ditentukan maka kita tidak akan bisa membeli dan mesin menyuruh kita untuk menambahkan uang. Begitu juga bila uang kita lebih maka mesin akan menyuruh kita untuk mengurangi uang. Setelah uang pas, maka kita bisa untuk membeli minuman.

Related Documents