PICmicro & dsPIC >> PICmicro & dsPIC

frbowen



Reged: Jul 01 2004
Posts: 24
USB troubles
      Tue Jul 06 2004 02:40 PM

I am developing a PS2 to USB converter. On the PS2 side there will be keyboard. I am doing all of this using the 16C745. The PS2 port has been thoroughly tested and I grabbed the USB firmware from Microchip. I can't seem to get the two working together... Any ideas? Thanks in advance.

Code:
  
#include
#include "usb.h"
#include "usb_defs.h"
//
//###############################################################################

__CONFIG(WDTDIS & UNPROTECT & PWRTDIS & H4);

void Delay(long amount);

const unsigned char PS2toUSB[] = {
/* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, //0x0_
0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x1e, 0x00, 0x00, 0x00, 0x1d, 0x16, 0x04, 0x1a, 0x1f, 0x00, //0x1_
0x00, 0x06, 0x1b, 0x07, 0x08, 0x21, 0x20, 0x00, 0x00, 0x2c, 0x19, 0x09, 0x17, 0x15, 0x22, 0x00, //0x2_
0x00, 0x11, 0x05, 0x0b, 0x0a, 0x1c, 0x23, 0x00, 0x00, 0x00, 0x10, 0x0d, 0x18, 0x24, 0x25, 0x00, //0x3_
0x00, 0x00, 0x0e, 0x0c, 0x12, 0x27, 0x26, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x13, 0x2d, 0x00, //0x4_
0x00, 0x00, 0x00, 0x00, 0x2f, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x28, 0x30, 0x00, 0x31, 0x00, 0x00, //0x5_
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //0x6_
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};//0x7_

unsigned char output, tempOutput;
int EdgeCount;
unsigned char buffer [4];
int newDataFlag;

// Interrupt service routine. Branch off to different interrupts
interrupt ISR () {

GIE = 0;

if (USBIF && USBIE) {
if (ACTIVITY)
USBActivity ();
if (USB_RST && USB_RST_E) // USB reset must be serviced immediately
USBReset ();
if (TOK_DONE && TOK_DONE_E) {
if (USB_dev_req == SET_ADDRESS) // Finish Set Address
{
USB_dev_req = NULL;
USB_Curr_Config = 0;
UADDR = USB_address_pending;
UIE = 0x01; // enable just the reset interrupt
#ifdef SHOW_ENUM_STATUS // SHOW_ENUM_STATUS defined in usb_defs.h
RB2 = 1; // set bit 2 to show addressed
#endif
if (USB_address_pending > 0)
USWSTAT = ADDRESS_STATE;
else
USWSTAT = DEFAULT_STATE;
}
TOK_DONE = 0; // clear Token Done flag
}
USBIF = 0; // Clear USB interrupt flag
}

//Keyboard Interrupt....
if(INTF&&INTE)
{
if(EdgeCount >= 10)
{
EdgeCount = 0;

if((tempOutput != output)&&(output != 0x00))
{
newDataFlag = 1;
tempOutput = output;
}


output = 0x00;
}else{


if((EdgeCount > 0)&&(EdgeCount < 9))
output |= GetData(EdgeCount - 1);

EdgeCount++;

}


INTF = 0;
}

GIE = 1;



}


void main() {

unsigned char i;

TRISB = 0x01; // Make RB0 an input and the rest outputs
PORTB = 0;
TRISA = 0x10; // RA4 is and input
PORTA = 0x00;

//Make RC0 (Clock) and RC1 (Data) input pins
TRISC = 0x03;

PS2Init();

for (i = 0; i < 50; i ++); // Small delay (greater than 16us) in order to
InitUSB (); // allow SIE to come online before beginning USB
// initialization
OPTION = 0x07; // TMR0 prescaler 1:256

buffer[0] = 0x00;
buffer[1] = 0x00;
buffer[2] = 0x00;
buffer[3] = 0x00;

i = 0;
newDataFlag = 0;

while (1)
{
if (T0IF)
{ // Poll all functions every 10.9ms
T0IF = 0;
ServiceUSB(); // Service USB functions

if(ConfiguredUSB())
{
if(newDataFlag == 1)
buffer[0] = PS2toUSB[tempOutput];

PutEP1(BUFFERSIZE, buffer);

if(newDataFlag == 1)
{
buffer[0] = 0x00;
newDataFlag = 0;
}

}


}


}
}



Post Extras Print Post   Remind Me!     Notify Moderator


Entire topic
Subject Posted by Posted on
* USB troubles frbowen Tue Jul 06 2004 02:40 PM
. * * Re: USB troubles frbowen   Fri Jul 09 2004 12:40 PM

Extra information
1 registered and 32 anonymous users are browsing this forum.

Moderator:  mikerj, jtemples, jeff, Dan Henry, Andrew L 



Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is enabled
      UBBCode is enabled

Rating:
Thread views: 2294

Rate this thread

Jump to

Contact Us | Privacy statement HI-TECH Software

Powered by UBB.threads™ 6.5.5