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

PIC18F4550 USB HID using CCS PIC C

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



Joined: 13 Jan 2018
Posts: 3

View user's profile Send private message

PIC18F4550 USB HID using CCS PIC C
PostPosted: Sun Jan 14, 2018 12:30 am     Reply with quote

Hi everyone I am Memo.
Can you help me please ?
I am trying to connect between pic18f4550 and pc by usb.
and i connect the pic with lcd. (The LCD is used to display the data received by the microcontroller). In this project the an external oscillator (8MHz) is used.

and this is the program:
Code:

// PIC18F4550 USB HID Examlpe CCS C code
// http://ccspicc.blogspot.com/
// electronnote@gmail.com
// Use at your own risk

//LCD module connections
#define LCD_RS_PIN PIN_D0
#define LCD_RW_PIN PIN_D1
#define LCD_ENABLE_PIN PIN_D2
#define LCD_DATA4 PIN_D3
#define LCD_DATA5 PIN_D4
#define LCD_DATA6 PIN_D5
#define LCD_DATA7 PIN_D6
//End LCD module connections

#define USB_CONFIG_HID_TX_SIZE 16                // Transmit packet size (bytes)
#define USB_CONFIG_HID_RX_SIZE 16                // Receive packet size (bytes)
#define USB_CONFIG_PID 1                         //Chnage Product Id
#define USB_CONFIG_VID 1234                      //Chnage Vendor Id
#define USB_STRINGS_OVERWRITTEN

#include <18F4550.h>
#fuses  HSPLL PLL2 CPUDIV1 USBDIV VREGEN NOMCLR
#use delay(clock = 48000000)
#include <lcd.c>
#define USB_STRING(x)  (sizeof(_unicode(x))+2), 3, _unicode(x)  // line 27
rom char USB_STRING_DESC[]={
    //string 0 (must always provide this string)
    //4(length of string index),3(desciptor type is string),9&4(Microsoft Defined for US-English)
    4, 3, 9, 4, 
    //string 1 - vendor (this is optional, but we specified it's use in the device descriptor)
    USB_STRING("CCS"),
    //string 2 - product (this is optional, but we specified it's use in the device descriptor)
    USB_STRING("USB HID Example"),
    //string 3 - serial number (this is optional, but we specified it's use in the device descriptor)
    USB_STRING("123456789")};
#include <usb_desc_hid.h>
#include<pic18_usb.h>
#include<usb.c>

char data[16];
void main(){
  lcd_init();                                    // Initialize LCD module- line 43
  lcd_putc('\f');                                // LCD clear
  lcd_gotoxy(1, 1);
  lcd_putc("USB HID Example");
  usb_init_cs();                                 // Initialize USB hardware
  delay_ms(1000);
  while(TRUE){
    usb_task();
    if(usb_enumerated()){                // If the device has been enumerated by the PC
      if(usb_kbhit(1)){                  // If endpoint1 has data in it's receive buffer
        lcd_gotoxy(1, 2);
        lcd_putc("                ");            // Clear 2nd line
        // Read up to 16 bytes from endpoint1 buffer and save it to variable data
        usb_get_packet(1, data, 16);
        lcd_gotoxy(1, 2);
        printf(lcd_putc, data);                  // Display the received bytes on LCD
        delay_ms(1000);                          // Wait 1 second
        // Return the received bytes back
        usb_put_packet(1, data, 16, USB_DTS_TOGGLE);
      }
    }
  }
}

When I compile this program
the message show:
error in line 27 Expression must evaluate to a constant uncode
error in line 43 Expecting a declaration
What is the problem?
empty



Joined: 13 Jan 2018
Posts: 6

View user's profile Send private message Visit poster's website

PostPosted: Sun Jan 14, 2018 12:40 am     Reply with quote

What is compiler version are you using?

Example original link:
https://simple-circuit.com/pic18f4550-usb-hid-example-ccs-c/
Ttelmah



Joined: 11 Mar 2010
Posts: 13673

View user's profile Send private message

PostPosted: Sun Jan 14, 2018 4:08 am     Reply with quote

The key point (which is why the 'what version' question), is this relies on the _unicode macro.

Quote:

5.033 Added new macro _unicode(), see readme.txt for details


So as posted will not work before V5.033.
memo



Joined: 13 Jan 2018
Posts: 3

View user's profile Send private message

PostPosted: Sun Jan 14, 2018 5:48 am     Reply with quote

the version is CCS 5.015
empty



Joined: 13 Jan 2018
Posts: 6

View user's profile Send private message Visit poster's website

PostPosted: Sun Jan 14, 2018 5:59 am     Reply with quote

As Ttelmah said you need version 5.033 or higher.
Actually it was tested with version 5.051.
memo



Joined: 13 Jan 2018
Posts: 3

View user's profile Send private message

PostPosted: Sun Jan 14, 2018 6:07 am     Reply with quote

How can I get these version ?
temtronic



Joined: 01 Jul 2010
Posts: 6290
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jan 14, 2018 6:42 am     Reply with quote

updates are free for awhile when you buy the compiler
Ttelmah



Joined: 11 Mar 2010
Posts: 13673

View user's profile Send private message

PostPosted: Sun Jan 14, 2018 10:00 am     Reply with quote

or you would have to modify the code to the older way of doing it. The usb_hid example supplied with the compiler shows how to format the descriptor without this macro.
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