You are on page 1of 3

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

This program was produced by the


CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date
:
Author :
Company :
Comments:

TUGAS akhir
7/23/2016
tyery08
embeeminded.blogspot.com

Chip type
: ATmega32
Program type
: Application
AVR Core Clock frequency: 11.059200 MHz
Memory model
: Small
External RAM size
: 0
Data Stack size
: 512
*****************************************************/
#include <mega32.h>
// Alphanumeric LCD functions
#include <alcd.h>
// Declare your global variables here
#include <stdio.h>
#include <delay.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
// Declare your global variables here
int key;
char buff[33];
unsigned char keypad( )
{
//Kolom 1==================
PORTA = 0b11110111;
if(PINA.7==0) {key=10; goto run;}
if(PINA.6==0) {key=15; goto run;}
if(PINA.5==0) {key=0; goto run;}
if(PINA.4==0) {key=14; goto run;}
//Kolom 2=================
PORTA = 0b11111011;
if(PINA.7==0) {key=13; goto run;}
if(PINA.6==0) {key=9; goto run;}
if(PINA.5==0) {key=8; goto run;}
if(PINA.4==0) {key=7; goto run;}
//Kolom 3=================
PORTA = 0b11111101;
if(PINA.7==0) {key=12; goto run;}
if(PINA.6==0) {key=6; goto run;}
if(PINA.5==0) {key=5; goto run;}
if(PINA.4==0) {key=4; goto run;}
//Kolom 4=================

PORTD = 0b11111
110;
PORTA = 0b11111110;
if(PINA.7==0) {key=11; goto run;}
if(PINA.6==0) {key=3; goto run;}
if(PINA.5==0) {key=2; goto run;}
if(PINA.4==0) {key=1; goto run;}
run:
return key;
}
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=Out Func2=Out Func1=Out Func0=Out
// State7=T State6=T State5=T State4=T State3=0 State2=0 State1=0 State0=0
PORTA=0xF0;
DDRA=0x0F;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=O
ut
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTC=0x00;
DDRC=0xFF;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
//
//
//
//
//
//
//
//
//
//

Alphanumeric LCD initialization


Connections are specified in the
Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
RS - PORTC Bit 0
RD - PORTB Bit 1
EN - PORTC Bit 2
D4 - PORTC Bit 4
D5 - PORTC Bit 5
D6 - PORTC Bit 6
D7 - PORTC Bit 7

// Characters/line: 20
lcd_init(20);
while (1)
{
awal:
lcd_gotoxy(0,0);
lcd_putsf("Tekan Sembarang ");
set:
key=keypad();
lcd_gotoxy(0,1);
sprintf(buff,"%d ",key);
lcd_puts(buff);
delay_ms(5);
//key=keypad();// Place your code here
}
}

You might also like