Home > Avr, Microcontroller > AVR KeyPad 3×4

AVR KeyPad 3×4


#include <mega324.h>
#include <delay.h>
#include <stdio.h>
//mulai inisialisai PIN Key Pad
#define kolom1    PORTA.0              // out      1
#define kolom2    PORTA.1
#define kolom3    PORTA.2

#define baris1    PINA.4               // in       Pull
#define baris2    PINA.5
#define baris3    PINA.6
#define baris4    PINA.7

unsigned char tombol,kolom,x;        // variabel tombol u/ simpan hasil yg ditekan (dalam kode Ascii)
void cek_baris()                     // 48 adalah konversi tampilan charakter
{
if  (baris1 == 0)
{
tombol = kolom + 48;
x=1;
}
else if (baris2==0)
{
tombol=kolom+3+48;
x=1;
}
else if (baris3==0)
{
tombol=kolom+6+48;
x=1;
}
else if  (baris4==0)
{
tombol=kolom+9+48;
x=1;
}
else
{
tombol=0;
x=0;
}
if (tombol==58) tombol=42; //*
if (tombol==59) tombol=48; //0
if (tombol==60) tombol=35; //#
}

void scan_keypad()
{
x=0;
while(x==0)
{
kolom1=0;kolom=1;
cek_baris();
kolom1=1;
if (tombol==0)
{
kolom2=0;kolom=2;
cek_baris();
kolom2=1;
}
if(tombol==0)
{
kolom3=0;kolom=3;
cek_baris();
kolom3=1;
}
};
delay_ms(100);
}
void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=Out Func1=Out Func0=Out
// State7=P State6=P State5=P State4=P State3=T State2=1 State1=1 State0=1
PORTA=0xF7;
DDRA=0×07;

// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=1 State6=1 State5=1 State4=1 State3=1 State2=1 State1=1 State0=1
PORTB=0xFF;
DDRB=0xFF;

// Port C 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
PORTC=0×00;
DDRC=0×00;

// 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=0×00;
DDRD=0×00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=0×00;
TCCR0B=0×00;
TCNT0=0×00;
OCR0A=0×00;
OCR0B=0×00;

// 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=0×00;
TCCR1B=0×00;
TCNT1H=0×00;
TCNT1L=0×00;
ICR1H=0×00;
ICR1L=0×00;
OCR1AH=0×00;
OCR1AL=0×00;
OCR1BH=0×00;
OCR1BL=0×00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2A output: Disconnected
// OC2B output: Disconnected
ASSR=0×00;
TCCR2A=0×00;
TCCR2B=0×00;
TCNT2=0×00;
OCR2A=0×00;
OCR2B=0×00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
// Interrupt on any change on pins PCINT0-7: Off
// Interrupt on any change on pins PCINT8-15: Off
// Interrupt on any change on pins PCINT16-23: Off
// Interrupt on any change on pins PCINT24-31: Off
EICRA=0×00;
EIMSK=0×00;
PCICR=0×00;

// Timer/Counter 0 Interrupt(s) initialization
TIMSK0=0×00;
// Timer/Counter 1 Interrupt(s) initialization
TIMSK1=0×00;
// Timer/Counter 2 Interrupt(s) initialization
TIMSK2=0×00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0×80;
ADCSRB=0×00;

while (1)
{
// Place your code here

scan_keypad();

if (tombol==’1′) PORTB=0×10;    // Contoh pemakaian void scan_keypad()
if (tombol==’2′) PORTB=0×20;    // Jika terjadi Bounching pada penekanan Keypad,
if (tombol==’3′) PORTB=0×30;    // coba atur nilai delay pada void scan_keypad()
if (tombol==’4′) PORTB=0×40;
if (tombol==’5′) PORTB=0×50;    // Salam Kanggo arek2
if (tombol==’6′) PORTB=0×60;
if (tombol==’7′) PORTB=0×70;
if (tombol==’8′) PORTB=0×80;
if (tombol==’9′) PORTB=0×90;
if (tombol==’*') PORTB=0xA0;
if (tombol==’0′) PORTB=0xB0;
if (tombol==’#') PORTB=0xC0;
};
}

Related posts:

  1. AVR Keypad 4×4 Auto Scan (Interrupt Timer) /*************************************************************************** File : keypad-4x4-int-timer.c Description : Main module Project : Keypad Matrix 4x4 Auto Scan (Interrupt Timer) Version : 1.1.5 Author : nashrul@nashrul.co.cc Date : 2006 - 2008 ***************************************************************************/ #include <mega16.h> #include <lcd.h> #include <delay.h> #include <stdio.h> #define kolom1  PORTA.0              // out      1 #define kolom2    PORTA.1 #define kolom3    PORTA.2 #define baris1    PINA.4               // in       Pull #define baris2    PINA.5 #define baris3    PINA.6 #define baris4    PINA.7 #asm .equ __lcd_port=0×18 ;PORTB #endasm char buf[17]; unsigned char sss, ss, mm, tt, key, [...]...
  2. AVR Half Duplex Software UART (9600 bps, 8N1) /********************************************* This program was produced using CodeVision AVR V1.23.6b Standard © Copyright 1998-2002 HP InfoTech s.r.l. http://www.hpinfotech.ro e-mail:office@hpinfotech.ro , hpinfotech@xnet.ro Project : UART3: Half Duplex Software UART (9600 bps, 8N1) Version : 1.3 Date : October 2002 Author : Radu Hristea (radu.hristea@aptrans-group.com; transeast@programmer.net) Company : TransEast s.r.l. Comments: Total size = 321 words (including the demo program) The receive line is buffered (the [...]...
  3. AVR SHT 11 (Temperature & Humidity Sensor) /*************************************************************************** File : sht-11.c Description : Main module Project : SHT 11 Temperature & Humidity Sensor Version : 2.0.1 Author : nashrul@nashrul.co.cc Date [...]...
  4. Free Download CodeVisionAVR V2.03.4 CodeVisionAVR V2 Standard Features Application that runs under Windows® 2000, XP, Vista and Windows 7, 32bit and 64bit Easy to use Integrated Development Environment and ANSI C compatible Compiler Editor with auto indentation, syntax highlighting for both C and AVR assembler, function parameters and structure/union members autocomplete Supported data types: bit, bool, char, int, short, long, float Fast floating point [...]...
  5. Serial Communication RS232 Description With serial communication you can exchange data with the AVR-microcontroller and your PC. Allmost all AVR-microcontroller have a UART (Universal Asynchronous Reciever/Transmitter) on board of the chip (accept for the AT1200 and some ATTiny microcontrollers). The data transmission between the PC and the microcontroller is serial and asynchronous, serial means that the bits are send [...]...
  6. Multiple Serial Communication on Avr Mcu Multiple Serial Communication on Avr Mcu?????????? This question comes up from time to time, and I want to give a simple solution in this problem. My friend needs MCU with 4 UART (@ 38.4 KBaud each respectively) to their robot projects in Battle Division KRCI (Kontes Robot Cerdas Indonesia) 2010. 4 UART is a problem, because the [...]...
  1. April 28th, 2010 at 03:48 | #1

    :razz:

  1. No trackbacks yet.
icon_wink.gif icon_neutral.gif icon_mad.gif icon_twisted.gif icon_smile.gif icon_eek.gif icon_sad.gif icon_rolleyes.gif icon_razz.gif icon_redface.gif icon_surprised.gif icon_mrgreen.gif icon_lol.gif icon_idea.gif icon_biggrin.gif icon_evil.gif icon_cry.gif icon_cool.gif icon_arrow.gif icon_confused.gif icon_question.gif icon_exclaim.gif 

Switch to our mobile site