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.

Need Source for PS2 Mouse and Keyboard using 8051

Status
Not open for further replies.

FrEEk

Newbie level 6
Newbie level 6
Joined
Aug 11, 2002
Messages
14
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
31
ps2 keyboard source

Hi

i need a Source Code that implements the PS2 Mouse and Keyboard
functions to a 8051 Microcontroller.

Have only one seen such a Source ?




Thanks
 

barny

Member level 1
Member level 1
Joined
Apr 6, 2002
Messages
34
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
415
ps2 interface 8051

try



which has some source code. You might be able to xlate to 8051.
 

chaitanyathummar

Newbie level 1
Newbie level 1
Joined
Jul 16, 2008
Messages
1
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,283
Activity points
1,301
ps2 mouse source code

i am sending code for ps/2 to protocol it means it will work for ps/2 keyboard as well as ps/2 mouse

this program will trasnfer data (send by ps/2 device)on com port at 9600 baudrate



//Author:Chaitanya Thummar
// this is code for PS/2 protocol


#include <p89v51rx2.h>
#define HIGH 1
#define LOW 0

sbit data_bit=P3^3;
sbit clk=P3^2;

void MSDelay(unsigned char delay)
{
unsigned char i;
for(i=0;i<delay;i++)
{
}
}

void ps2_write(unsigned char command)
{
unsigned char i;
unsigned char parity = 1;
data_bit=HIGH;

clk=HIGH;
MSDelay(100);

clk=LOW;
MSDelay(100);

data_bit=LOW;
MSDelay(10);
clk=HIGH;
/* wait for device to take control of clock */
while (clk==HIGH); // this loop intentionally left blank
for (i=0; i < 8; i++)
{
if (command & 0x01)
{
data_bit=HIGH;
}else
{
data_bit=LOW;
}
// wait for clock
while (clk== LOW);
while (clk== HIGH);
parity = parity ^ (command & 0x01);
command = command >> 1;
}
// parity bit
if (parity)
{
data_bit=HIGH;
}else
{
data_bit=LOW;
}
//clock cycle - like ack.
while(clk==LOW);
while(clk==HIGH);
data_bit=HIGH;
MSDelay(10);
while (clk==HIGH);
// mode switch
while ((clk==LOW)||(data_bit== LOW));
// hold up incoming data
clk=LOW;
}
unsigned char ps2_read()
{
unsigned char data1 = 0x00;
unsigned char i;
unsigned char bit1 = 0x01;

// start clock
clk=HIGH;
data_bit=HIGH;
MSDelay(10);
while (clk == HIGH);
while (clk==LOW);//eat start bit
for (i=0; i < 8; i++)
{
while (clk==HIGH);
if(data_bit==HIGH)
{
data1 = data1 | bit1;
}
while (clk == LOW);
bit1= bit1<< 1;
}
// eat parity bit, ignore it.
while (clk==HIGH);
while (clk==LOW);
// eat stop bit
while (clk==HIGH);
while (clk==LOW);
clk=LOW; // hold incoming data
return data1;
}
void serial_init()
{
FCF=1;
SCON = 0x50; /* mode 1, 8-bit uart, enable receiver */
TMOD = 0x20; /* timer 1, mode 2, 8-bit reload */
TH1 = 253; /* reload value for 2400 baud */
ET0 = 0; /* we don't want this timer to make interrupts */
TR1 = 1; /* start the timer */
ES = 0; /* allow serial interrupts */
EA = 0; /* enable interrupts */
}

void main()
{
unsigned char count=0;
serial_init();
P2=0x00;
ps2_write(0xff);
while(count!=3)
{
SBUF=ps2_read();
while(TI==0);
TI=0;
count++;
}
ps2_write(0xf4);
while(1)
{
ps2_read();
while(TI==0);
TI=0;
count++;
}


}
 
  • Like
Reactions: nitishpatel

    V

    Points: 2
    Helpful Answer Positive Rating

    nitishpatel

    Points: 2
    Helpful Answer Positive Rating

shaheensha

Newbie level 2
Newbie level 2
Joined
Apr 1, 2009
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,297
hi........
i need details of interfacing a ps2 mouse with microcontroller 8051.
the above program didnt run in my c++ editor.
there is some problem with the header file.
 

nitishpatel

Newbie level 3
Newbie level 3
Joined
Mar 16, 2011
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,296
Thanks Barny and Chaitanya.. You ppl did a great help to me.. :)
 

anboli

Full Member level 2
Full Member level 2
Joined
Mar 9, 2012
Messages
144
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,298
Activity points
2,512
Re: ps2 mouse source code

thank you. it gave me a clear idea to interface with the controller. but in that i having one doubt, in the main program why did you gave the count loop for three times?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top