Home > Avr, Microcontroller > AVR Keypad 4×4 Auto Scan (Interrupt Timer)

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, old_key, temp_tt, temp_mm, temp_ss;
int menu_state = 0;
int time_state = 1;
int top_lcd = 0;
int trip = 4530;
int blink;
int bottom_lcd = 0;
int pulses = 0;
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{}
interrupt [TIM1_COMPA] void timer1_compa_isr(void)
{sss++;
if (sss>5){blink=0;}
if (sss=10){ss++;sss=0;blink = 1;}
if (ss==60){mm++;ss=0;}
if(mm==60) {tt++;mm=0;}
if (tt==24){tt=0;}
}

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(10);
}
void lcd_top()
{
if (top_lcd == 3)
top_lcd = 0;

switch (top_lcd)
{
case 0: // KELLO
lcd_gotoxy(0,0);
if (time_state == 0)
{
if (blink == 1)
sprintf(buf,”%02d-%02d-%02d”, temp_tt, temp_mm, temp_ss);
if (blink == 0)
sprintf(buf,”%02d %02d %02d”, temp_tt, temp_mm, temp_ss);
}
if (time_state == 1)
{
sprintf(buf,”%02d-%02d-%02d”, tt, mm, ss);
}
lcd_puts(buf);
break;
case 1: // TRIP
lcd_gotoxy(0,0);
sprintf(buf,” %5d”, trip);
lcd_puts(buf);
break;
case 2: // REITTI
lcd_gotoxy(0,0);
lcd_putsf(“L-1 25″);
}
}
void main(void)
{
PORTA=0xF0;
DDRA=0xF0;
PORTB=0×00;
DDRB=0×00;
PORTC=0×00;
DDRC=0×00;
PORTD=0×00;
DDRD=0×00;

TCCR0=0×01;
TCNT0=0×00;
OCR0=0×00;

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;

ASSR=0×00;
TCCR2=0×00;
TCNT2=0×00;
OCR2=0×00;

MCUCR=0×00;
MCUCSR=0×00;

TIMSK=0×11;

ACSR=0×80;
SFIOR=0×00;

// LCD module initialization
lcd_init(16);

// Global enable interrupts
#asm(“sei”)

for (;;)
{

};
}

Related posts:

  1. 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 [...]...
  2. 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 [...]...
  3. 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 [...]...
  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 04:16 | #1

    :razz:

  2. April 30th, 2010 at 13:47 | #2

    Suwun mbah……..

  3. April 30th, 2010 at 16:03 | #3

    OK trukzz……

  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