LAMPIRAN A
GAMBAR RANGKAIAN KESELURUHAN SISTEM
LAMPIRAN B
PROGRAM KESELURUHAN SISTEM
Program Mikrokontroler
#include <mega8535.h> #include <delay.h> #include <stdio.h>
unsigned char data_serial[4], servo_masuk, servo_keluar; int a, indikator;
unsigned char datalcd[16];
// Alphanumeric LCD Module functions #asm
.equ __lcd_port=0x15 ;PORTC #endasm
#include <lcd.h>
#define RXB8 1 #define TXB8 0 #define UPE 2 #define OVR 3 #define FE 4 #define UDRE 5 #define RXC 7
#define FRAMING_ERROR (1<<FE) #define PARITY_ERROR (1<<UPE) #define DATA_OVERRUN (1<<OVR) #define DATA_REGISTER_EMPTY (1<<UDRE) #define RX_COMPLETE (1<<RXC)
// USART Receiver buffer #define RX_BUFFER_SIZE 8 char rx_buffer[RX_BUFFER_SIZE];
#if RX_BUFFER_SIZE<256
unsigned char rx_wr_index,rx_rd_index,rx_counter; #else
unsigned int rx_wr_index,rx_rd_index,rx_counter; #endif
// This flag is set on USART Receiver buffer overflow bit rx_buffer_overflow;
// USART Receiver interrupt service routine interrupt [USART_RXC] void usart_rx_isr(void) {
char status,data; status=UCSRA; data=UDR;
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0) {
if (++rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0; if (++rx_counter == RX_BUFFER_SIZE)
{
rx_counter=0; rx_buffer_overflow=1; };
if (indikator==2) {data_serial[3]=data; indikator=3; } if (indikator==1) {data_serial[2]=data; indikator=2; } if (indikator==0) {data_serial[1]=data; indikator=1; } };
}
#ifndef _DEBUG_TERMINAL_IO_
// Get a character from the USART Receiver buffer #define _ALTERNATE_GETCHAR_
#pragma used+ char getchar(void) {
char data;
while (rx_counter==0); data=rx_buffer[rx_rd_index];
if (++rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0; #asm("cli")
--rx_counter; #asm("sei") return data; }
#pragma used- #endif
// Standard Input/Output functions #include <stdio.h>
// Timer 0 overflow interrupt service routine interrupt [TIM0_OVF] void timer0_ovf_isr(void) {
// Place your code here a++;
if(a==900) {a=0;}
if(a<servo_masuk) {PORTB.0=1;} else {PORTB.0=0;} if(a<servo_keluar) {PORTB.1=1;} else {PORTB.1=0;} }
// Declare your global variables here
void main(void) {
// Input/Output Ports initialization // Port A initialization
PORTA=0x0C; DDRA=0x03;
// Port B initialization PORTB=0x0C; DDRB=0x03;
// Port C initialization PORTC=0x00; DDRC=0x00;
// Timer/Counter 0 initialization TCCR0=0x01; TCNT0=0x00; OCR0=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x01;
// USART initialization UCSRA=0x00; UCSRB=0x90; UCSRC=0x86; UBRRH=0x00; UBRRL=0x47;
// Analog Comparator initialization ACSR=0x80;
SFIOR=0x00;
// LCD module initialization lcd_init(16);
// Global enable interrupts #asm("sei")
servo_masuk=80; servo_keluar=80;
lcd_gotoxy(1,0); lcd_putsf("PROGRAM PARKIR"); delay_ms(1000); lcd_gotoxy(2,1); lcd_putsf("Loading."); delay_ms(1000); lcd_gotoxy(2,1); lcd_putsf("Loading.."); delay_ms(1000); lcd_gotoxy(2,1); lcd_putsf("Loading..."); delay_ms(1000); lcd_gotoxy(2,1); lcd_putsf("Loading...."); delay_ms(1000); lcd_gotoxy(2,1); lcd_putsf("Loading..."); delay_ms(1000); lcd_clear();
lcd_gotoxy(1,0); lcd_putsf("PROGRAM PARKIR");
lcd_gotoxy(2,1); lcd_putsf("SYSTEM READY"); delay_ms(1000); lcd_clear();
indikator=0;
while (1) {
// Place your code here
lcd_gotoxy(0,0); lcd_putsf("Dekatkan ID_CARD"); if(data_serial[1]!=0)
{
if(data_serial[1]==97) {
servo_masuk=30; lcd_clear();
lcd_gotoxy(0,0); lcd_putsf("Silahkan_Masuk"); sprintf(datalcd,"Saldo=Rp%d000",data_serial[2]); lcd_gotoxy(0,1); lcd_puts(datalcd);
delay_ms(5000); servo_masuk=80; lcd_clear();
data_serial[1]=0; indikator=0; }
else if (data_serial[1]==98) {
servo_keluar=30; lcd_clear();
sprintf(datalcd,"Saldo=Rp%d000",data_serial[2]); lcd_gotoxy(0,1); lcd_puts(datalcd);
delay_ms(2000); lcd_clear();
lcd_gotoxy(0,0); lcd_putsf("Selamat__Jalan"); lcd_gotoxy(0,1); lcd_putsf("Terima Kasih"); delay_ms(3000); servo_keluar=80; lcd_clear();
data_serial[1]=0; indikator=0; }
else if (data_serial[1]==99) {
servo_keluar=30; lcd_clear();
sprintf(datalcd,"Parkir=Rp%d000",data_serial[3]); lcd_gotoxy(0,0); lcd_puts(datalcd);
sprintf(datalcd,"Saldo=Rp%d000",data_serial[2]); lcd_gotoxy(0,1); lcd_puts(datalcd);
delay_ms(2000); lcd_clear();
lcd_gotoxy(0,0); lcd_putsf("Saldo < 5000"); lcd_gotoxy(0,1); lcd_putsf("Segera Isi Ulang"); delay_ms(2000);
lcd_clear();
lcd_gotoxy(0,0); lcd_putsf("Selamat__Jalan"); lcd_gotoxy(0,1); lcd_putsf("Terima Kasih"); delay_ms(1000); servo_keluar=80; lcd_clear();
data_serial[1]=0; indikator=0; }
else if (data_serial[1]==100) {
lcd_clear();
lcd_gotoxy(0,0); lcd_putsf("Tidak Dikenali"); lcd_gotoxy(0,1); lcd_putsf("Silahkan Daftar"); delay_ms(1000);
lcd_clear();
data_serial[1]=0; indikator=0; }
}
if(PINB.2==0) {
servo_masuk=30; lcd_clear();
lcd_gotoxy(1,1); lcd_putsf("Silahkan_Masuk"); delay_ms(1000); delay_ms(5000); servo_masuk=80; lcd_clear();
}
if(PINB.3==0) {
servo_keluar=30; lcd_clear();
lcd_gotoxy(1,1); lcd_putsf("Selamat__Jalan"); delay_ms(1000); delay_ms(5000); servo_keluar=80; lcd_clear();
Program Visual Basic
Dim sisa_saldo, saldo, tambah_saldo, jumlah_saldo As Double Dim lama_parkir, status, biaya, jumlah_biaya As Double Dim pendapatan, jumlah_pendapatan As Double Dim parkir, jumlah_parkir As Double
Dim jam_masuk, jam_keluar As Variant Dim tambah As Single
Dim lockkirim As Integer
Private Sub Command1_Click() On Error GoTo errr
MSComm1.CommPort = Combo1.Text MSComm1.PortOpen = True
MSComm1.DTREnable = True MSComm1.RTSEnable = True Timer1.Enabled = True MsgBox "Komunikasi OK" errr:
End Sub
Private Sub Command2_Click() Frame1.Visible = False Frame2.Visible = True Adodc1.Refresh Adodc1.Refresh Adodc1.Refresh
Command7.Visible = True Command8.Visible = True End Sub
Private Sub Command3_Click() If txtID.Text = "" Then MsgBox " Data Belum Diisi" Exit Sub
End If
Adodc1.Refresh
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("ID").Value = txtID.Text Adodc1.Recordset.Fields("masuk").Value = txtmasuk.Text Adodc1.Recordset.Fields("saldo").Value = txtsaldo.Text Adodc1.Recordset.Fields("nama").Value = txtnama.Text Adodc1.Recordset.Fields("BK").Value = txtBK.Text Adodc1.Recordset.Fields("status").Value = "0" Adodc1.Recordset.Update
Private Sub Command5_Click() If Text10 = "" Then
MsgBox " Saldo Belum Diisi" Text10.SetFocus
Exit Sub End If
If txtID.Text <> "" And Text3.Text <> "" And Text4.Text <> "" Then Else
MsgBox " ID Anda Belum Terdaftar" End If
Text3.Text = "" Text4.Text = ""
With Adodc1.Recordset On Error GoTo errr If .State = 0 Then .Open .MoveFirst
.Find "ID = '" & txtID.Text & "'" If Not .EOF Then
Text4.Text = !saldo Text3.Text = !masuk status = !status End If
End With
saldo = Adodc1.Recordset.Fields("saldo").Value tambah_saldo = Val(Text10.Text)
jumlah_saldo = saldo + tambah_saldo
Adodc1.Recordset.Fields("saldo").Value = jumlah_saldo Adodc1.Recordset.Update
Adodc1.Refresh Adodc1.Refresh Text10.Text = "" Text10.Enabled = False Text10.BackColor = &HC0C0C0 Command5.Enabled = False Command4.Enabled = True
Command4.Caption = "Tambah Saldo" Command5.BackColor = &HC0C0C0 tambah = 0
lockkirim = 0
errr:
End Sub
Command7.Visible = False Command8.Visible = False End Sub
Private Sub Command4_Click() If tambah = 0 Then
Command4.Caption = "Cancel" Command5.Enabled = True Command5.BackColor = &H80FF& Text10.Enabled = True
Text10.BackColor = &H80FF80 Text10.SetFocus
lockkirim = 1 tambah = 1 Else
Command4.Caption = "Tambah Saldo" Command5.Enabled = False
Command5.BackColor = &HC0C0C0 Text10.Text = ""
Text10.Enabled = False Text10.BackColor = &HC0C0C0 tambah = 0
lockkirim = 0 End If End Sub
Private Sub Command7_Click() Frame2.Visible = True Frame3.Visible = False Adodc2.Refresh Adodc2.Refresh Adodc2.Refresh End Sub
Private Sub Command8_Click() Frame3.Visible = True Frame2.Visible = False Adodc2.Refresh Adodc2.Refresh Adodc2.Refresh End Sub
Combo1.AddItem "8", 7 Combo1.AddItem "9", 8 Combo1.AddItem "10", 9 Combo1.AddItem "11", 10 Combo1.AddItem "12", 11 Frame1.Visible = False Frame2.Visible = True Frame3.Visible = False Text10.Enabled = False Text10.BackColor = &HC0C0C0 Command5.Enabled = False Command5.BackColor = &HC0C0C0 lockkirim = 0
End Sub
Private Sub Text2_Change()
Dim panjangteks, rpsaldo, rpparkir As Integer
panjangteks = Len(Text2.Text)
If (Text2.Text <> "") And (panjangteks = 12) Then txtID.Text = Text2.Text
Text3.Text = "" Text4.Text = ""
With Adodc1.Recordset On Error GoTo errr If .State = 0 Then .Open .MoveFirst
.Find "ID = '" & Text2.Text & "'" If Not .EOF Then
Text4.Text = !saldo Text3.Text = !masuk status = !status End If
End With
If Text4 <> "" Then If status = "0" Then
rpsaldo = Val(Text4.Text) / 1000
If lockkirim = 0 Then
MSComm1.Output = "a" & Chr(rpsaldo) End If
Adodc1.Recordset.Fields("masuk").Value = lblwaktu.Caption Adodc1.Recordset.Fields("status").Value = "1"
Adodc1.Recordset.Fields("keluar").Value = "" Adodc1.Recordset.Fields("biaya").Value = "" Adodc1.Recordset.Update
Text3 = lblwaktu.Caption Else
Adodc1.Recordset.Fields("keluar").Value = lblwaktu.Caption Adodc1.Recordset.Fields("status").Value = "0"
Adodc1.Recordset.Update Text3 = lblwaktu.Caption
jam_masuk = Adodc1.Recordset.Fields("masuk").Value jam_keluar = Adodc1.Recordset.Fields("keluar").Value
lama_parkir = (TimeValue(jam_keluar) - TimeValue(jam_masuk)) * 24 If lama_parkir <= 1 Then biaya = 1000
If lama_parkir > 1 And lama_parkir <= 2 Then biaya = 2000 If lama_parkir > 2 And lama_parkir <= 3 Then biaya = 3000 If lama_parkir > 3 Then biaya = 4000
Adodc1.Recordset.Fields("biaya").Value = biaya saldo = Adodc1.Recordset.Fields("saldo").Value sisa_saldo = saldo - biaya
Adodc1.Recordset.Fields("saldo").Value = sisa_saldo Adodc1.Recordset.Update
Adodc1.Refresh Adodc1.Refresh Adodc1.Refresh
If lockkirim = 0 Then If sisa_saldo >= 5000 Then rpsaldo = sisa_saldo / 1000 rpparkir = biaya / 1000
MSComm1.Output = "b" & Chr(rpsaldo) & Chr(rpparkir) Else
rpsaldo = sisa_saldo / 1000 rpparkir = biaya / 1000
MSComm1.Output = "c" & Chr(rpsaldo) & Chr(rpparkir) End If
End If
With Adodc2.Recordset On Error GoTo errr If .State = 0 Then .Open .MoveFirst
.Find "tanggal = '" & lbltanggal.Caption & "'" If Not .EOF Then
pendapatan = Adodc2.Recordset.Fields("pendapatan").Value parkir = Adodc2.Recordset.Fields("jumlah_parkir").Value jumlah_pendapatan = pendapatan + biaya
jumlah_parkir = parkir + 1
Adodc2.Recordset.Fields("pendapatan").Value = jumlah_pendapatan Adodc2.Recordset.Fields("jumlah_parkir").Value = jumlah_parkir Adodc2.Recordset.Fields("tanggal").Value = lbltanggal
Adodc2.Recordset.Update Adodc2.Refresh
Else
jumlah_pendapatan = biaya jumlah_parkir = 1
Adodc2.Recordset.Fields("pendapatan").Value = jumlah_pendapatan Adodc2.Recordset.Fields("jumlah_parkir").Value = jumlah_parkir Adodc2.Recordset.Fields("tanggal").Value = lbltanggal
Adodc2.Recordset.Update Adodc2.Refresh
End If End With Adodc2.Refresh Adodc2.Refresh Adodc2.Refresh Text4.Text = sisa_saldo status = 0
End If Else
MSComm1.Output = "d" End If
End If errr:
Text2.Text = "" End Sub
Private Sub Timer1_Timer() Text1.Text = MSComm1.Input If Text1.Text <> "" Then
Text2.Text = Right(Left(Text1.Text, 13), 12) End If
End Sub
Private Sub Timer2_Timer()