4 * 8 kunci matriks membantu

A

arun_9998

Guest
mempunyai saya bisa membuat 8 * 4 kunci matriks

# ifndef KBOARD_H
# define KBOARD_H

# include "reg51.h"
# include "Delay.h"
/ / # include "Lcd.h"
# include <intrins.h>
# include <stdio.h>

/************************************************* ****************************
*
* Constant Definisi.
*
************************************************** ***************************/

/ **
* Hardware keyboard port tugas.
* Mengatur \ b Keyport cocok untuk hardware.
* \ Hideinitializer
* /
# define Keyport P0

/ *
* Idkey () kembali saat ini tidak ada tombol yang ditekan.
* /
# define NOKEY 32/************************************************* ****************************
*
* Fungsi Publik prototip.
*
************************************************** ***************************/

/ / extern char _getkey (void); / / didefinisikan di stdio.h

/ **
* 4 x 8 fungsi inisialisasi keyboard.
* \ Param --
* \ Kembali --
* /
extern void kboard_init (void);

# endif
************************************************** ****************************/

# include "Kboard.h"

/************************************************* ****************************
*
* Global Variabel
*
************************************************** ***************************/
/ *
* Keyboard memindai baris / kolom keluaran dan masukan pola kode.
* /
static const unsigned char kode KEY_IO [32] = (0x70, 0xB0, 0xD0, 0xE0,
0x71, 0xB1, 0xD1, 0xE1,
0x72, 0xB2, 0xD2, 0xE2,
0x73, 0xB3, 0xD3, 0xE3,
0x74, 0xB4, 0xD4, 0XE4,
0x75, 0xB5, 0xD5, 0xE5,
0x76, 0xB6, 0xD6, 0xE6,
0x77, 0xB7, 0xD7, 0xE7);

/ *
* Keyboard ke posisi kunci ASCII perwakilan kode.
* /
static const char kode KEY_MAP [32] = ('1 ','2','3 ','4',
'5 ','6','7 ','8',
'9 ',' A ',' B ',' C ',
'D', 'E', 'M', 'G',
'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O',
'P', 'T', 'R', 'S',
'T', 'U', 'V', 'W'); / / CR BS

/************************************************* ****************************
*
* Fungsi prototip Swasta
*
************************************************** ***************************/
static unsigned char kboard_makekey (void);
static void kboard_breakkey (void);
static unsigned char kboard_idkey (void);/************************************************* ****************************
*
* Swasta Fungsi Pelaksanaan
*
************************************************** ***************************/

/************************************************* ****************************
*
* Kboard_makekey ()
*
************************************************** ***************************/
static unsigned char kboard_makekey (void)
(
unsigned char tombol, newkey;

melakukan
(
while ((key = kboard_idkey ()) == NOKEY);
# ifdef LCD_H
lcd_beep (5);
# endif
delay_ms (10);
) While ((newkey = kboard_idkey ())! = Kunci);

kembali (key);
)

/************************************************* ****************************
*
* Kboard_breakkey ()
*
************************************************** ***************************/
static void kboard_breakkey (void)
(
melakukan
(
sementara (kboard_idkey ()! = NOKEY);
delay_ms (10);
) While (kboard_idkey ()! = NOKEY);
)

/************************************************* ****************************
*
* Kboard_idkey ()
*
************************************************** ***************************/
static unsigned char kboard_idkey (void)
(
unsigned char tombol = 0xFF;
sedikit keyfound = 0;

melakukan
(
Tombol ;
Keyport & = 0xF0; / / jelas rendah mengunggis
Keyport | = KEY_IO [kunci] & 0x0F; / / output rendah mengunggis
keyfound = ((Keyport & 0xF0) == (KEY_IO [kunci] & 0xF0));

) While ((key <NOKEY) & & (! Keyfound));

kembali (key);
)/************************************************* ****************************
*
* Fungsi Umum Pelaksanaan
*
************************************************** ***************************/

/************************************************* ****************************
*
* Kboard_init ()
*
************************************************** ***************************/
void kboard_init (void)
(
Keyport = 0xFF; / / Set bit semua sebagai masukan
)

/************************************************* ****************************
*
* _getkey ()
*
************************************************** ***************************/
char _getkey (void)
(
unsigned char tombol = NOKEY;

while (tombol == NOKEY)
(
Tombol = kboard_makekey ();
kboard_breakkey ();
)

kembali (KEY_MAP [tombol]);
)
************************************************** ******************
************************************************** ******************
Main.c
************************************************** ************************************************** ************************************
# include <reg51.h>
# include <stdio.h>
# include "Kboard.h"

void main ()
(
unsigned int ch = 0;
kboard_init ();
sementara (1)
(
scanf ( "% d", & ch);
)
)<img src="http://images.elektroda.net/33_1248929215_thumb.jpg" border="0" alt=""/>
 

Welcome to EDABoard.com

Sponsor

Back
Top