CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Simple HID USB Class Program not working pls help...

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
07arunsharma



Joined: 05 Mar 2012
Posts: 18
Location: India

View user's profile Send private message Send e-mail

Simple HID USB Class Program not working pls help...
PostPosted: Wed Mar 28, 2012 11:31 am     Reply with quote

Hello!! Everyone!!!

I am new to CCS PIC-C and wants to do some usb programming with it.
Earlier i had used mikroC but doesn;t like that much..

I had write a simple code, which displays the data on lcd which is sent from PC, suppose i send "arun sharma" it must be displayed on LCD.

But i a unable to do so properly.
Here is my Code

Code:

//rhydoLABZ PIC18F4550 Development Board

#include <18F4550.h>
#device ADC=8
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)
   

//RS232 Configuration
#use rs232(baud=9600, UART1, errors)

#define LED1 PIN_B7
#define LED2 PIN_B6
#define LED3 PIN_B5

//Transmit and Receive Packet Size
#define USB_CONFIG_HID_TX_SIZE 16
#define USB_CONFIG_HID_RX_SIZE 16

/*******VENDOR ID AND PRODUCT ID********/
#define USB_CONFIG_PID 1      //Chnage Vendor Id and Product Id
#define USB_CONFIG_VID 4660      //So that they will work with my Application
/***************************************/

/*******LCD Pin Configuration******/
#define LCD_ENABLE_PIN PIN_C2
#define LCD_RS_PIN PIN_C1
#define LCD_RW_PIN PIN_C0
#define LCD_DATA4 PIN_D4
#define LCD_DATA5 PIN_D5
#define LCD_DATA6 PIN_D6
#define LCD_DATA7 PIN_D7
/***********************************/

#include<pic18_usb.h>
#include<usb_desc_hid.h>
#include<usb.c>
#include<lcd.c>

//Macro Definition for LED ON and OFF
#define LED_ON(x) output_low(x)
#define LED_OFF(x) output_high(x)

void usb_debug_task(void)
{
   static int8 last_connected;
      static int8 last_enumerated;
      int8 new_connected;
      int8 new_enumerated;

      new_connected = usb_attached();
      new_enumerated = usb_enumerated();

   if (new_enumerated)
         LED_ON(LED1);
      else
         LED_OFF(LED1);

      if (new_connected && !last_connected)
         printf("\r\n\nUSB connected, waiting for enumaration...");
      if (!new_connected && last_connected)
         printf("\r\n\nUSB disconnected, waiting for connection...");
      if (new_enumerated && !last_enumerated)
       printf("\r\n\nUSB enumerated by PC/HOST");
      if (!new_enumerated && last_enumerated)
       printf("\r\n\nUSB unenumerated by PC/HOST, waiting for enumeration...");

      last_connected=new_connected;
      last_enumerated=new_enumerated;
}

void main(void)
{
   
   unsigned char in_data[16];
   unsigned int i;
   set_tris_b(0x00);   //Port-B as Output Port
   set_tris_c(0x10);
   output_b(0x00);
   LED_OFF(LED1);
   LED_OFF(LED2);
   LED_OFF(LED3);
   lcd_init();      //Initialize the LCD Module
   lcd_gotoxy(3,1);
   lcd_putc("PIC18F4550");
   Delay_ms(1000);
   lcd_gotoxy(3,2);
   lcd_putc("USB EXAMPLE!");
   
   printf("\r\n\nUSB Test Program--->Written in CCS PIC-C");
   printf("\r\nEMBEDDED LABORATORY\r\n");
   usb_init_cs();
   Delay_ms(1000);
   lcd_putc("\fRECEIVED DATA:-");
   Delay_ms(1);
   while(1)
   {
      usb_task();
      usb_debug_task();
      if(usb_enumerated())
      {
         if(usb_kbhit(1))
         {
            lcd_gotoxy(2,1);
            lcd_putc("                ");
            usb_get_packet(1,in_data,2);
            printf("\r\nReceived Data: ");
            for(i=0;i<16;i++)
            {
               printf("%c",in_data[i]);   
               //Send the Recevied Data to Serial Port
               lcd_gotoxy(1,2);
               lcd_putc(in_data[i]);
            }
            //Now Clear the in_data array
            for(i=0;i<16;i++)
            {
               in_data[i] = '\0';   //Null Character
            }

         }
         }       
   }
}         
   


I am using the application given with mikroC to communicate from PC and also the given on this site
http://sites.google.com/site/coolembeddedlaboratory/home/visual-basic

according to me the application are working fine,

this program works satisfactory when i had not change the
#define USB_CONFIG_HID_TX_SIZE 16
#define USB_CONFIG_HID_RX_SIZE 16

and retain them to the value of 2
But that doesn't fulfill my requirements.
at least a array of size 16 is must for me...

Can any one tell me why my program doesn't works.

NOTE:-
#define USB_CONFIG_HID_TX_SIZE 2
#define USB_CONFIG_HID_RX_SIZE 2
By using this
#define USB_CONFIG_HID_TX_SIZE 16
#define USB_CONFIG_HID_RX_SIZE 16

everything works fine..

Pls Help

Thanks in Advance
_________________
Arun Sharma
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group