Electronic – USB Keyboard with 18F2550

keyboardpicpic-ccsusb

I'm trying to build my own mechanical keyboard. Everyone uses Teensy as for as i can see. I wanna use PIC18F2550 instead. I'm using CCS C btw. The problem is, i can't send more than 5 bits at all. Tried to send different arrays, they collide somehow. Increasing report count from "usb_desc_keyboard.h" doesn't work. "usb_puts" function didn't work either.

When i send multiple arrays, one by one, PIC sends key characters. No problem there. But it doesn't make the same response as a regular keyboard. Normally, first type takes longer time than others. This way PIC sends characters continuously. I wanna send 64 bits together. Is that possible?

I'm using matrix method for button interactions, got no problem there.

EDIT:

I added code. tx_msg array size is 7. I want to increase this to 64.
Found this guy claiming he did it. http://www.microchip.com/forums/m368006.aspx
Gonna try this when i get home.

void usb_keyboard_task(void) 
{
   static int8 tx_msg[7]={0,0,0,0,0,0,0};
   static int8 leds;

   if(!input(pin_B0))
      tx_msg[2]=0x04;
   else
      tx_msg[2]=0;

   usb_put_packet(1,tx_msg,sizeof(tx_msg),USB_DTS_TOGGLE);

   //receive NUM LOCK, CAPS LOCK, etc LED status from PC.
   //we won't do anything with it.
   if (usb_kbhit(2)) 
   {
      usb_get_packet(2, &leds, 1);
   }   
}

void main(void) 
{    
   setup_adc_ports(NO_ANALOGS);
   set_tris_a(0b0000000);
   set_tris_b(0b11111111);
   port_b_pullups(0b11111111);   
   usb_init_cs();   

   output_high(pin_A0);

   while (TRUE)
   {       
      usb_task();
      usb_debug_task();
      if(usb_enumerated())
      {
         usb_keyboard_task();
         delay_ms(50);
      }
   } 
} 

Best Answer

I finally did it. Let me share with you how i've managed. First of all i used "usb_puts" function not "usb_put_package". You need to make a single change in "usb_desc_keyboard.h". Rearrange "report count" according to your need.

0x95, 0x0C, //report count (5) //47,48

In default version this was "0x05". It can send 5 keys states with usb. In my prototype there are 12 buttons. A 3x4 matrix. With couple experiments i raised this number.

static int8 tx_msg[14]={0,0,0,0,0,0,0,0,0,0,0,0,0,0}; tx_msg[0],tx_msg[1] is reserved, i actually don't know.

So we start using from tx_msg[2] and send datas.

Here is some example code:

void usb_send()
{
   static int8 tx_msg[14]={0,0,0,0,0,0,0,0,0,0,0,0,0,0};      

   static int8 leds;
   //receive NUM LOCK, CAPS LOCK, etc LED status from PC.
   //we won't do anything with it.
   if (usb_kbhit(2)) 
   {
      usb_get_packet(2, &leds, 1);
   }     

   //make necessary changes in tx_msg here.

   if(!input(pin_B3))
      tx_msg[13]=0x0F;
   else
      tx_msg[13]=0;

   usb_puts(1,tx_msg,sizeof(tx_msg),timeout);     
}