arun_9998
Banned
- Joined
- Aug 25, 2008
- Messages
- 53
- Helped
- 11
- Reputation
- 22
- Reaction score
- 10
- Trophy points
- 1,288
- Location
- india
- Activity points
- 0
4*8 key matrix help
have any tell me can i make 8*4 key matrix
#ifndef KBOARD_H
#define KBOARD_H
#include "reg51.h"
#include "Delay.h"
//#include "Lcd.h"
#include <intrins.h>
#include<stdio.h>
/*****************************************************************************
*
* Constant Definitions.
*
*****************************************************************************/
/**
* Hardware keyboard port assignment.
* Adjust \b KEYPORT to match hardware.
* \hideinitializer
*/
#define KEYPORT P0
/*
* idkey() return this when no key is pressed.
*/
#define NOKEY 32
/*****************************************************************************
*
* Public Function Prototypes.
*
*****************************************************************************/
//extern char _getkey(void); // defined in stdio.h
/**
* 4 x 8 keyboard initialisation function.
* \param -
* \return -
*/
extern void kboard_init(void);
#endif
******************************************************************************/
#include "Kboard.h"
/*****************************************************************************
*
* Global Variables
*
*****************************************************************************/
/*
* Keyboard scan row/ column output and input pattern codes.
*/
static const unsigned char code 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 key position to ASCII representation codes.
*/
static const char code KEY_MAP[32] = {'1', '2', '3', '4',
'5', '6', '7', '8',
'9', 'A','B','C',
'D','E','F','G',
'H','I','J','K',
'L','M','N','O',
'P','Q','R','S',
'T','U','V','W' }; // CR BS
/*****************************************************************************
*
* Private Function Prototypes
*
*****************************************************************************/
static unsigned char kboard_makekey(void);
static void kboard_breakkey(void);
static unsigned char kboard_idkey(void);
/*****************************************************************************
*
* Private Function Implementation
*
*****************************************************************************/
/*****************************************************************************
*
* kboard_makekey()
*
*****************************************************************************/
static unsigned char kboard_makekey(void)
{
unsigned char key, newkey;
do
{
while((key = kboard_idkey()) == NOKEY);
#ifdef LCD_H
lcd_beep(5);
#endif
delay_ms(10);
} while((newkey = kboard_idkey()) != key);
return(key);
}
/*****************************************************************************
*
* kboard_breakkey()
*
*****************************************************************************/
static void kboard_breakkey(void)
{
do
{
while(kboard_idkey() != NOKEY);
delay_ms(10);
} while(kboard_idkey() != NOKEY);
}
/*****************************************************************************
*
* kboard_idkey()
*
*****************************************************************************/
static unsigned char kboard_idkey(void)
{
unsigned char key = 0xFF;
bit keyfound = 0;
do
{
key++;
KEYPORT &= 0xF0; // clear lower nibble
KEYPORT |= KEY_IO[key] & 0x0F; // output lower nibble
keyfound = ((KEYPORT & 0xF0) == (KEY_IO[key] & 0xF0));
} while((key < NOKEY) && (!keyfound));
return(key);
}
/*****************************************************************************
*
* Public Function Implementation
*
*****************************************************************************/
/*****************************************************************************
*
* kboard_init()
*
*****************************************************************************/
void kboard_init(void)
{
KEYPORT = 0xFF; // Set all bits as input
}
/*****************************************************************************
*
* _getkey()
*
*****************************************************************************/
char _getkey(void)
{
unsigned char key = NOKEY;
while(key == NOKEY)
{
key = kboard_makekey();
kboard_breakkey();
}
return (KEY_MAP[key]);
}
********************************************************************
********************************************************************
MAIN.C
****************************************************************************************************************************************
#include<reg51.h>
#include<stdio.h>
#include "Kboard.h"
void main()
{
unsigned int ch=0;
kboard_init();
while(1)
{
scanf("%d",&ch);
}
}
have any tell me can i make 8*4 key matrix
#ifndef KBOARD_H
#define KBOARD_H
#include "reg51.h"
#include "Delay.h"
//#include "Lcd.h"
#include <intrins.h>
#include<stdio.h>
/*****************************************************************************
*
* Constant Definitions.
*
*****************************************************************************/
/**
* Hardware keyboard port assignment.
* Adjust \b KEYPORT to match hardware.
* \hideinitializer
*/
#define KEYPORT P0
/*
* idkey() return this when no key is pressed.
*/
#define NOKEY 32
/*****************************************************************************
*
* Public Function Prototypes.
*
*****************************************************************************/
//extern char _getkey(void); // defined in stdio.h
/**
* 4 x 8 keyboard initialisation function.
* \param -
* \return -
*/
extern void kboard_init(void);
#endif
******************************************************************************/
#include "Kboard.h"
/*****************************************************************************
*
* Global Variables
*
*****************************************************************************/
/*
* Keyboard scan row/ column output and input pattern codes.
*/
static const unsigned char code 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 key position to ASCII representation codes.
*/
static const char code KEY_MAP[32] = {'1', '2', '3', '4',
'5', '6', '7', '8',
'9', 'A','B','C',
'D','E','F','G',
'H','I','J','K',
'L','M','N','O',
'P','Q','R','S',
'T','U','V','W' }; // CR BS
/*****************************************************************************
*
* Private Function Prototypes
*
*****************************************************************************/
static unsigned char kboard_makekey(void);
static void kboard_breakkey(void);
static unsigned char kboard_idkey(void);
/*****************************************************************************
*
* Private Function Implementation
*
*****************************************************************************/
/*****************************************************************************
*
* kboard_makekey()
*
*****************************************************************************/
static unsigned char kboard_makekey(void)
{
unsigned char key, newkey;
do
{
while((key = kboard_idkey()) == NOKEY);
#ifdef LCD_H
lcd_beep(5);
#endif
delay_ms(10);
} while((newkey = kboard_idkey()) != key);
return(key);
}
/*****************************************************************************
*
* kboard_breakkey()
*
*****************************************************************************/
static void kboard_breakkey(void)
{
do
{
while(kboard_idkey() != NOKEY);
delay_ms(10);
} while(kboard_idkey() != NOKEY);
}
/*****************************************************************************
*
* kboard_idkey()
*
*****************************************************************************/
static unsigned char kboard_idkey(void)
{
unsigned char key = 0xFF;
bit keyfound = 0;
do
{
key++;
KEYPORT &= 0xF0; // clear lower nibble
KEYPORT |= KEY_IO[key] & 0x0F; // output lower nibble
keyfound = ((KEYPORT & 0xF0) == (KEY_IO[key] & 0xF0));
} while((key < NOKEY) && (!keyfound));
return(key);
}
/*****************************************************************************
*
* Public Function Implementation
*
*****************************************************************************/
/*****************************************************************************
*
* kboard_init()
*
*****************************************************************************/
void kboard_init(void)
{
KEYPORT = 0xFF; // Set all bits as input
}
/*****************************************************************************
*
* _getkey()
*
*****************************************************************************/
char _getkey(void)
{
unsigned char key = NOKEY;
while(key == NOKEY)
{
key = kboard_makekey();
kboard_breakkey();
}
return (KEY_MAP[key]);
}
********************************************************************
********************************************************************
MAIN.C
****************************************************************************************************************************************
#include<reg51.h>
#include<stdio.h>
#include "Kboard.h"
void main()
{
unsigned int ch=0;
kboard_init();
while(1)
{
scanf("%d",&ch);
}
}