Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

8051 C code for PC Keyboard Interface - Wanted !

Status
Not open for further replies.

Smokey

Member level 1
Member level 1
Joined
Dec 21, 2001
Messages
38
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
India
Activity points
318
keyboard interfacing with 8051

Hi!

I am looking for a ready to use 'C' code (Keil51 V7.x preferably) to interface a standard PC AT keyboard to a standard 8051 micro.

I plan to connect the Keyboard CLK line to an Ext. Interrupt on the 8051. and sample the data line (on a standard port pin with a pull-up) on every interrupt. Any code to enable something like this would be perfect !!

I need 2 way communication - to toggle LEDS on the Keyboard.

Smokey
 

keyboard interface with 8051

Hi,
For your reference **broken link removed**

Regards
Jackson
 

keyboard interfacing in c

Thanks !

I have seen this app note from Philips before.

For this project, I am looking for a 'C' version (preferably written under Keil51 V7.x). I need to embedd the code as part of a larger firmware. I would like to use the PC-Keyboard Interface as a separate module - to be compiled conditionally with an `ifdef' statement.

Smokey
 

keyboard interface 8051

will this do ?
pm me for details
 

pc keyboard micro code

Many Thanks !!

The code seems 'just what the doctor ordered !'

Smokey ... over & Out !
 

pc keyboard interface to 8051

/********************************************************************
Keyboard to I2C. Read data under interrupt from an IBM keyboard
LPC config = 0xf8
********************************************************************/
#include <reg764.h>
#include <mydefs.h>

//----------------------------------- I2C routines
extern void init_I2C(void);
extern void slaveI2C(void);

extern uchar code kbtable[]; // Conversion Table

//----------------------- Globals
bit rx_flag;
uchar kdata, key_data;

//------------------------ Pin defs
sbit KB_DAT = P0^3;

/*--------------------------------------------------------------------------
*************************** MAIN PROGRAM *********************************
------------------------------------------------------------------------*/
main() {

WDRST = 0x1e; // reset watchdog
WDRST = 0xe1;
WDCON = 0x06;etc
WDRST = 0x1e;
WDRST = 0xe1;

EX1 = IT1 = 1; // external interrupt
init_I2C();
EA = 1;

/*******************************************************************/
while (1) {
WDRST = 0x1e; // feed WatchDog
WDRST = 0xe1;
//--------------------------------------
if (rx_flag == 1) {
static uchar KDA[3];
rx_flag = 0;
KDA[2] = KDA[1]; KDA[1] = KDA[0]; KDA[0] = kdata; // push

if (KDA[0] != 0xf0 && KDA[0] != 0xe0) { // if actual data
if (KDA[1] == 0xe0) { // prev was extended
KDA[0] |= 0x80; // convert data to extended
KDA[1] = KDA[2]; // pull back 1 stage
}
if (KDA[1] == 0xf0) { // prev was Break code
key_data = 0x00; //
slaveI2C(); // place in I2C buffer
// KDA[0]= KDA[1]= KDA[2]= 0x00;
}
else { // valid data handling
key_data = kbtable[KDA[0]];
slaveI2C(); // place in I2C buffer
// KDA[0]= KDA[1]= KDA[2]= 0x00;
} }
}
//---------------------------------------
} }

/********************************************************************
Keyboard clock interrupt
Receives Synchronous data 11 bits (Start,8,P,Stop)
********************************************************************/
ext1_isr() interrupt 2 {
uchar code mask[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
static uchar kd; // the data Byte RXed
static uchar bit_cntr;
bit captBIT; // captured Data Bit

captBIT = KB_DAT;

if (bit_cntr == 0 && captBIT == 0) { // start BIT 0
bit_cntr = 1;
kd = 0; // Initialize data
}
else if (bit_cntr != 0 && bit_cntr < 9) { // 8 data bits
if (captBIT == 1) kd |= mask[bit_cntr-1]; // rotate
bit_cntr += 1;
}
else if (bit_cntr == 9) { // 9th bit (parity ?)
bit_cntr += 1;
}
else if (bit_cntr == 10 && captBIT == 1) { // stop bit
bit_cntr = 0;
kdata = kd;
rx_flag = 1;
}
else { // framing error
bit_cntr = 0;
}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top