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.

PS2 controller interface with PIC24FJ256GB110

Status
Not open for further replies.

averafter

Newbie level 3
Joined
Feb 3, 2010
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Malaysia
Activity points
1,330
Hi,

I faced problem with interfacing ps2 controller to pic24f controller, can anyone help me? Here is the code:


#include "D:\Program\testing.h"


#pin_select SS1OUT=pin_b15 //Pin 44
#pin_select SDI1=pin_d14 //Pin 47
#pin_select SDO1=pin_d15 //Pin 48
#pin_select SCK1OUT=pin_f4 //Pin 49


#use delay(4000000)
#use rs232(baud=9600,xmit=PIN_f3,rcv=PIN_f8,PARITY=N,BITS=8)


void ps2(void);
int8 reverseByte(int8);


#define ps2CMD PIN_D15
#define ps2ATTN PIN_B15
#define ps2DATA PIN_D14
#define ps2CLK PIN_F4


int8 ps2Byte[9];
int8 ps2Status;


void main()
{ setup_wdt(WDT_ON);
setup_timer1(TMR_DISABLED|TMR_DIV_BY_1);
setup_uart(9600);
setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_4);


While(true)
{

Restart:
output_high(Pin_B15);
ps2();

ps2Status = reverseByte(ps2Byte[2]);
if(ps2Status == 0x5A)
{
restart_wdt();
Output_high(Pin_F0);
delay_ms(1000);
}
else
{
goto restart;
}

}
}

void ps2 (void)
{
output_low(Pin_B15);
delay_us(20);

ps2Byte[0]=spi_read(0x80);
ps2Byte[1]=spi_read(0x42); //get controller ID
ps2Byte[2]=spi_read(0x00); //response from controller
ps2Byte[3]=spi_read(0x00);
ps2Byte[4]=spi_read(0x00);
ps2Byte[5]=spi_read(0x00);
ps2Byte[6]=spi_read(0x00);
ps2Byte[7]=spi_read(0x00);
ps2Byte[8]=spi_read(0x00);

output_high(Pin_B15);

}

int8 reverseByte(int8 x)
{
x = (x & 0x0F) << 4 | (x & 0xF0) >> 4;
x = (x & 0x33) << 2 | (x & 0xCC) >> 2;
x = (x & 0x55) << 1 | (x & 0xAA) >> 1;
return(x);
}

**I use 4M oscillator, output of the command, attention and clock waveforms seems ok, but there was not data send back to me from the ps2 controller.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top