Anda di halaman 1dari 4

MEMBUAT PROGRAM PASSWORD DENGAN AVR

Program :
/*****************************************************
This program was produced by the
CodeWizardAVR V2.03.9 Standard
Automatic Program Generator
Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 7/11/2012
Author : Tianur
Company : Politeknik Caltex Riau
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 <delay.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>

// Standard Input/Output functions


#include <stdio.h>
// Declare your global variables here
int key=20,step,a,b,x,a1,b1;
char buff[33];
unsigned char keypad( )
{
//Kolom 1==================
PORTB = 0b11110111;
if(PINB.7==0) {key=10; goto run;} //tambah
if(PINB.6==0) {key=15; goto run;} //=
if(PINB.5==0) {key=0; goto run;} //0
if(PINB.4==0) {key=14; goto run;} //ON
//Kolom 2=================
PORTB = 0b11111011;
if(PINB.7==0) {key=13; goto run;} //Bagi
if(PINB.6==0) {key=3; goto run;} //3
if(PINB.5==0) {key=2; goto run;} //2
if(PINB.4==0) {key=1; goto run;} //1
//Kolom 3=================
PORTB = 0b11111101;
if(PINB.7==0) {key=12; goto run;} //kali
if(PINB.6==0) {key=6; goto run;} //6
if(PINB.5==0) {key=5; goto run;} //5
if(PINB.4==0) {key=4; goto run;} //4
//Kolom 4=================
PORTB = 0b11111110;
if(PINB.7==0) {key=11; goto run;} //Kurang
if(PINB.6==0) {key=9; goto run;} //9
if(PINB.5==0) {key=8; goto run;} //8
if(PINB.4==0) {key=7; goto run;} //7
run:
return key;
}
void main(void)
{
// Declare your local variables here
PORTA=0x01;
DDRA=0x01;
PORTB=0xF0;
DDRB=0x0F;
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: Off
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x08;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;
// LCD module initialization

lcd_init(16);
while (1)
{
// Place your code here
if(step == 0)
{
key=keypad();
if(key < 10)
{
a1=b;
b1=a1*10;
a=key;
key=20;
b=b1+a;
sprintf(buff,"%d",a);
lcd_puts(buff);
x++;
if(x>=4)
{
step = 1; //untuk melanjutkan ke step 1
PORTA.0=0; //indikator tombol sudah ditekan 4x

}
delay_ms(200);

}
if(key == 14) //Tombol ON ==> reset
{
//reset semua data
step=0;
a=0;
b=0;
a1=0;
b1=0;
x=0;
lcd_clear();
lcd_gotoxy(0,0);
PORTA.0=1;
step = 0; //untuk kembali ke step awal
}
}
if(step == 1)
{
key=keypad();
if(key == 14) //Tombol ON ==> reset
{
//reset semua data
step=0;
a=0;
b=0;
a1=0;
b1=0;
x=0;
lcd_clear();
lcd_gotoxy(0,0);
PORTA.0=1;
step = 0; //untuk kembali ke step awal
}

if(key == 15 && b==1234) //Jika pass=1234 ==> benar


{
printf("%4d ", b);
//kirim data serial
lcd_gotoxy(0,0);
delay_ms(500);
sprintf(buff,"*Password Benar*");
lcd_puts(buff);
lcd_gotoxy(0,1);
sprintf(buff,"Loop ke awal ");
lcd_puts(buff);
delay_ms(1000);
//reset semua data setelah 1 detik
step=0;
a=0;
b=0;
a1=0;
b1=0;
x=0;
lcd_clear();
PORTA.0=1;
step = 0; //untuk kembali ke step awal
lcd_gotoxy(0,0);
}
if(key == 15 && b!=1234) //Jika pass selain 1234 ==> salah
{
lcd_clear();
lcd_gotoxy(0,0);
delay_ms(500);
sprintf(buff,"*Password Salah*");
lcd_puts(buff);
lcd_gotoxy(0,1);
sprintf(buff,"Loop ke awal ");
lcd_puts(buff);
delay_ms(1000);
//reset semua data setelah 1 detik
step=0;
a=0;
b=0;
a1=0;
b1=0;
x=0;
lcd_clear();
PORTA.0=1;
step = 0; //untuk kembali ke step awal
lcd_gotoxy(0,0);
}
}
}

};

Anda mungkin juga menyukai