/*****************************************************
This program was produced by the
CodeWizardAVR V2.04.4a Advanced
Automatic Program Generator
© Copyright 1998-2009 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 1/19/2011
Author : -
Company : home
Comments:
Chip type : ATmega8535
Program type : Application
AVR Core Clock frequency: 4.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 128
*****************************************************/
#include <mega8535.h>
#include <delay.h>
#include <stdio.h>
#define ir PIND.7
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>
// Declare your global variables here
void main(void)
{
int i,ulang;
long int hitung;
unsigned char buf[16];
PORTD.7 = 1;
PIND.7 = 0; // SET INPUT
// LCD module initialization
lcd_init(16);
lcd_gotoxy(0,0);
lcd_putsf("uji tetes");
delay_ms(2000);
hitung = 0;
i = 0;
ulang = 0;
while (1)
{
// Place your code here
for ( i = 0; i <= 200; i++)
{
if (ir == 1 && ulang ==0)
{
ulang = 1;
hitung ++;
}
if ( ir == 0)ulang = 0; // reset nilai ulang
delay_ms(5);
}
sprintf(buf,"data: %-i Tts/S",hitung);
lcd_gotoxy(0,1);
lcd_puts(buf);
hitung = 0;
};
}
Rangkaiannya :
Programnya adalah sebagai berikut:
#include <mega8535.h>
#include <stdio.h>
#include <delay.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>
// Declare your global variables here
#define ir PIND.7
unsigned char keypad();
void baca_keypad(void);
unsigned char data;
void baca_tetes(void);
void kiri (void);
void kanan (void);
void buzer (void);
int data1,ulang;
long int hitung;
void main(void)
{
// Declare your local variables here
PORTA=0xff;
DDRA=0x0F;
PORTB = 0X03;
DDRB = 0X8F;
PORTD.7 = 1;
DDRD.7 = 0;
// LCD module initialization
lcd_init(16);
lcd_gotoxy(0,0);
lcd_putsf("test keypad");
ulang =0;
while (1)
{
// Place your code here
baca_keypad();
if ( data1 == 1 ) kiri();
if ( data1 == 2 ) kanan();
if (data1 == 3 ) baca_tetes();
};
}
flash unsigned char keypad()
{
PORTA = 0b11111110; //aktifkan baris1 (memberi logika 0 ke baris1)
delay_ms(10);
if(PINA.7==0) return (10);
if(PINA.6==0) return (11);
if(PINA.5==0) return (12);
if(PINA.4==0) return (13);
//========================
PORTA = 0b11111101; //aktifkan baris2
delay_ms(10);
if(PINA.7==0) return (3);
if(PINA.6==0) return (6);
if(PINA.5==0) return (9);
if(PINA.4==0) return (15);
//========================
PORTA = 0b11111011; //aktifkan baris3
delay_ms(10);
if(PINA.7==0) return (2);
if(PINA.6==0) return (5);
if(PINA.5==0) return (8);
if(PINA.4==0) return (0);
//========================
PORTA = 0b11110111; //aktifkan baris4
delay_ms(10);
if(PINA.7==0) return (1);
if(PINA.6==0) return (4);
if(PINA.5==0) return (7);
if(PINA.4==0) return (14);
}
void baca_keypad(void)
{
unsigned char buf[16];
data = keypad();
if ( data != 0)
{
buzer();
data1 = data;
sprintf(buf,"%-i",data1);
lcd_gotoxy(14,1);
lcd_puts(buf);
}
}
void kiri (void)
{
PORTB = 0X01; delay_ms(5);
PORTB = 0X03; delay_ms(5);
PORTB = 0X02; delay_ms(5);
PORTB = 0X06; delay_ms(5);
PORTB = 0X04; delay_ms(5);
PORTB = 0X0C; delay_ms(5);
PORTB = 0X08; delay_ms(5);
PORTB = 0X09; delay_ms(5);
PORTB = 0X01; delay_ms(5);
}
void kanan (void)
{
PORTB = 0X01; delay_ms(5);
PORTB = 0X09; delay_ms(5);
PORTB = 0X08; delay_ms(5);
PORTB = 0X0C; delay_ms(5);
PORTB = 0X04; delay_ms(5);
PORTB = 0X06; delay_ms(5);
PORTB = 0X02; delay_ms(5);
PORTB = 0X03; delay_ms(5);
PORTB = 0X01; delay_ms(5);
}
void buzer (void)
{
PORTB.7 = 1;
delay_ms(100);
PORTB.7 = 0;
}
void baca_tetes(void)
{
int i;
unsigned char buf[16];
for ( i = 0; i <= 200; i++)
{
if (ir == 1 && ulang ==0)
{
ulang = 1;
hitung ++;
}
if ( ir == 0)ulang = 0;
delay_ms(5);
}
sprintf(buf,"data: %-i Tts/S",hitung);
lcd_gotoxy(0,1);
lcd_puts(buf);
hitung = 0;
}
Silahkan kembangkan alat ini;
Semoga Bermanfaat .....
0 komentar:
Post a Comment
Aturan berkomentar :
1. Penggguna yang terdaftar
2. Gunakan bahasa yang santun dan sopan
3. Dilarang SPAM
4. Dilarang menaruh link aktif dan link porno
5. Jika ada suatu permasalahan lihat komentar lain atau bisa kirim via e-mail