Thông báo

Collapse
No announcement yet.

Cần trợ giúp làm USB Joystick với PIC 18F4550

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • #16
    Nguyên văn bởi ngochoangims Xem bài viết
    queduong , duong_act cho mình hỏi hai code dưới đây sai chỗ nào mà ko chạy được (mình dùng MicroC Pro 6.3), mạch chỉ làm cho 8 nút bấm, các nút này được gán bằng cách quy đổi giá trị adc tại cổng AN0 :

    1. Code chính thực hiện chương trình (Main.c):

    Code:
    //
    unsigned char readbuff[64] absolute 0x500;
    unsigned char writebuff[64] absolute 0x540;
    unsigned char pov;
    unsigned char buttons;
    //
    void interrupt()
    {
    USB_Interrupt_Proc(); // USB servicing is done inside the interrupt
    }
    
    void main()
    {
    HID_Enable(&readbuff,&writebuff); // Enable HID communication
    
    while(1)
    {
    pov = ADC_Get_Sample(0) / 4;
    if(pov >= 0 && pov <= 32) buttons = 0b00000001;
    if(pov >= 33 && pov <= 64) buttons = 0b00000010;
    if(pov >= 65 && pov <= 96) buttons = 0b00000011;
    if(pov >= 97 && pov <= 128) buttons = 0b00000100;
    if(pov >= 129 && pov <= 160) buttons = 0b00000101;
    if(pov >= 161 && pov <= 192) buttons = 0b00000110;
    if(pov >= 193 && pov <= 224) buttons = 0b00000111;
    if(pov >= 225 && pov <= 230) buttons = 0b00001000;
    writebuff[0] = buttons;
    while(!HID_Write(&writebuff,1));
    }
    }
    2. Code Hid USB Joystick report descriptor (USB_DSC.c):

    Code:
    const unsigned int USB_VENDOR_ID = 0x1234;
    const unsigned int USB_PRODUCT_ID = 0x0001;
    const char USB_SELF_POWER = 0x80; // Self powered 0xC0, 0x80 bus powered
    const char USB_MAX_POWER = 50; // Bus power required in units of 2 mA
    const char HID_INPUT_REPORT_BYTES = 64;
    const char HID_OUTPUT_REPORT_BYTES = 64;
    const char USB_TRANSFER_TYPE = 0x03; //0x03 Interrupt
    const char EP_IN_INTERVAL = 1;
    const char EP_OUT_INTERVAL = 1;
    
    const char USB_INTERRUPT = 1;
    const char USB_HID_EP = 1;
    const char USB_HID_RPT_SIZE = 45; // Con số này tính bằng cách nào?? thấy Mod queduong điền trong auto keyboard như vậy
    
    /* Device Descriptor */
    const struct {
    char bLength; // bLength - Descriptor size in bytes (12h)
    char bDescriptorType; // bDescriptorType - The constant DEVICE (01h)
    unsigned int bcdUSB; // bcdUSB - USB specification release number (BCD)
    char bDeviceClass; // bDeviceClass - Class Code
    char bDeviceSubClass; // bDeviceSubClass - Subclass code
    char bDeviceProtocol; // bDeviceProtocol - Protocol code
    char bMaxPacketSize0; // bMaxPacketSize0 - Maximum packet size for endpoint 0
    unsigned int idVendor; // idVendor - Vendor ID
    unsigned int idProduct; // idProduct - Product ID
    unsigned int bcdDevice; // bcdDevice - Device release number (BCD)
    char iManufacturer; // iManufacturer - Index of string descriptor for the manufacturer
    char iProduct; // iProduct - Index of string descriptor for the product.
    char iSerialNumber; // iSerialNumber - Index of string descriptor for the serial number.
    char bNumConfigurations; // bNumConfigurations - Number of possible configurations
    } device_dsc = {
    0x12, // bLength
    0x01, // bDescriptorType
    0x0200, // bcdUSB
    0x00, // bDeviceClass
    0x00, // bDeviceSubClass
    0x00, // bDeviceProtocol
    8, // bMaxPacketSize0
    USB_VENDOR_ID, // idVendor
    USB_PRODUCT_ID, // idProduct
    0x0001, // bcdDevice
    0x01, // iManufacturer
    0x02, // iProduct
    0x00, // iSerialNumber
    0x01 // bNumConfigurations
    };
    
    /* Configuration 1 Descriptor */
    const char configDescriptor1[]= {
    // Configuration Descriptor
    0x09, // bLength - Descriptor size in bytes
    0x02, // bDescriptorType - The constant CONFIGURATION (02h)
    0x29,0x00, // wTotalLength - The number of bytes in the configuration descriptor and all of its subordinate descriptors
    1, // bNumInterfaces - Number of interfaces in the configuration
    1, // bConfigurationValue - Identifier for Set Configuration and Get Configuration requests
    0, // iConfiguration - Index of string descriptor for the configuration
    USB_SELF_POWER, // bmAttributes - Self/bus power and remote wakeup settings
    USB_MAX_POWER, // bMaxPower - Bus power required in units of 2 mA
    
    // Interface Descriptor
    0x09, // bLength - Descriptor size in bytes (09h)
    0x04, // bDescriptorType - The constant Interface (04h)
    0, // bInterfaceNumber - Number identifying this interface
    0, // bAlternateSetting - A number that identifies a descriptor with alternate settings for this bInterfaceNumber.
    2, // bNumEndpoint - Number of endpoints supported not counting endpoint zero
    0x03, // bInterfaceClass - Class code
    0, // bInterfaceSubclass - Subclass code
    0, // bInterfaceProtocol - Protocol code
    0, // iInterface - Interface string index
    
    // HID Class-Specific Descriptor
    0x09, // bLength - Descriptor size in bytes.
    0x21, // bDescriptorType - This descriptor's type: 21h to indicate the HID class.
    0x01,0x01, // bcdHID - HID specification release number (BCD).
    0x00, // bCountryCode - Numeric expression identifying the country for localized hardware (BCD) or 00h.
    1, // bNumDescriptors - Number of subordinate report and physical descriptors.
    0x22, // bDescriptorType - The type of a class-specific descriptor that follows
    USB_HID_RPT_SIZE,0x00, // wDescriptorLength - Total length of the descriptor identified above.
    
    // Endpoint Descriptor
    0x07, // bLength - Descriptor size in bytes (07h)
    0x05, // bDescriptorType - The constant Endpoint (05h)
    USB_HID_EP | 0x80, // bEndpointAddress - Endpoint number and direction
    USB_TRANSFER_TYPE, // bmAttributes - Transfer type and supplementary information
    0x40,0x00, // wMaxPacketSize - Maximum packet size supported
    EP_IN_INTERVAL, // bInterval - Service interval or NAK rate
    
    // Endpoint Descriptor
    0x07, // bLength - Descriptor size in bytes (07h)
    0x05, // bDescriptorType - The constant Endpoint (05h)
    USB_HID_EP, // bEndpointAddress - Endpoint number and direction
    USB_TRANSFER_TYPE, // bmAttributes - Transfer type and supplementary information
    0x40,0x00, // wMaxPacketSize - Maximum packet size supported
    EP_OUT_INTERVAL // bInterval - Service interval or NAK rate
    };
    
    const struct {
    char report[USB_HID_RPT_SIZE];
    }hid_rpt_desc =
    {
    0x05, 0x01, // USAGE_PAGE (Generic Desktop)
    0x09, 0x04, // USAGE (Joystick)
    0xa1, 0x01, // COLLECTION (Application)
    0xa1, 0x00, // COLLECTION (Physical)
    0x05, 0x09, // USAGE_PAGE (Button)
    0x19, 0x01, // USAGE_MINIMUM (Button 1)
    0x29, 0x08, // USAGE_MAXIMUM (Button 8)
    0x15, 0x00, // LOGICAL_MINIMUM (0)
    0x25, 0x01, // LOGICAL_MAXIMUM (1)
    0x75, 0x01, // REPORT_SIZE (1)
    0x95, 0x08, // REPORT_COUNT (8)
    0x81, 0x02, // INPUT (Data,Var,Abs)
    0xc0, // END_COLLECTION
    0xc0 // END_COLLECTION
    };
    
    //Language code string descriptor
    const struct {
    char bLength;
    char bDscType;
    unsigned int string[1];
    } strd1 = {
    4,
    0x03,
    {0x0409}
    };
    
    
    //Manufacturer string descriptor
    const struct{
    char bLength;
    char bDscType;
    unsigned int string[11];
    }strd2={
    24, //sizeof this descriptor string
    0x03,
    {'d','i','e','n','t','u','v','i','e','t','n'}
    };
    
    //Product string descriptor
    const struct{
    char bLength;
    char bDscType;
    unsigned int string[6];
    }strd3={
    14, //sizeof this descriptor string
    0x03,
    {'U','S','B','S','W','C'}
    };
    
    //Array of configuration descriptors
    const char* USB_config_dsc_ptr[1];
    
    //Array of string descriptors
    const char* USB_string_dsc_ptr[3];
    
    void USB_Init_Desc(){
    USB_config_dsc_ptr[0] = &configDescriptor1;
    USB_string_dsc_ptr[0] = (const char*)&strd1;
    USB_string_dsc_ptr[1] = (const char*)&strd2;
    USB_string_dsc_ptr[2] = (const char*)&strd3;
    }
    Bạn nên sửa chỗ này :
    const char USB_HID_RPT_SIZE = 45 thành : const char USB_HID_RPT_SIZE = 26 Vì bên dưới có 26 bytes thôi ( Chỗ hid_rpt_desc ... rảnh ngồi mà đếm ). và Report byte in/out cũng sửa 64 thành 1 sẽ đẩy cao tốc độ ( vì bạn truyền có mỗi 1 byte thôi ). --- Và một điều nữa : Trong bảng chữ cái hoặc ký tự trên bàn phím ... giá trị từ 1 đến 8 một số nó chẳng ra cái của khỉ gì đâu. Nên dùng các giá trị từ 4 trở lên sẽ có được các kí tự a, b, c, d ..v.v Lúc đó ta có thể kiểm tra đơn giản bằng cách mở Notepad lên ... bấm phím xem nó có hiện đúng chữ không.
    Module RF chuyên dụng điều khiển, truyền dữ liệu, thiết kế đề tài, dự án điện tử - chuyển giao công nghệ... ĐT: 0904964977 - email: dientuqueduong@yahoo.com

    Comment


    • #17
      Nguyên văn bởi queduong Xem bài viết

      Bạn nên sửa chỗ này :
      const char USB_HID_RPT_SIZE = 45 thành : const char USB_HID_RPT_SIZE = 26 Vì bên dưới có 26 bytes thôi ( Chỗ hid_rpt_desc ... rảnh ngồi mà đếm ). và Report byte in/out cũng sửa 64 thành 1 sẽ đẩy cao tốc độ ( vì bạn truyền có mỗi 1 byte thôi ). --- Và một điều nữa : Trong bảng chữ cái hoặc ký tự trên bàn phím ... giá trị từ 1 đến 8 một số nó chẳng ra cái của khỉ gì đâu. Nên dùng các giá trị từ 4 trở lên sẽ có được các kí tự a, b, c, d ..v.v Lúc đó ta có thể kiểm tra đơn giản bằng cách mở Notepad lên ... bấm phím xem nó có hiện đúng chữ không.
      Code đã được sửa đúng như Mod hướng dẫn và windows đã nhận được driver.

      Còn việc gửi các số 1 - 8 ở đây thì không lo, vì em dùng code chỉ sử dụng nút bấm của joystick .
      pov = ADC_Get_Sample(0);
      if(pov >= 0 && pov <= 128) buttons = 0b00000001; //bam nut 1
      if(pov >= 129 && pov <= 256) buttons = 0b00000010; //bam nut 2
      if(pov >= 257 && pov <= 384) buttons = 0b00000100; //bam nut 3
      if(pov >= 385 && pov <= 512) buttons = 0b00001000; //bam nut 4
      if(pov >= 513 && pov <= 640) buttons = 0b00010000; //bam nut 5
      if(pov >= 641 && pov <= 768) buttons = 0b00100000; //bam nut 6
      if(pov >= 769 && pov <= 896) buttons = 0b01000000; //bam nut 7
      if(pov >= 897 && pov <= 1024) buttons = 0b10000000; //bam nut 8

      Cái này nó hơi khác kiểu của bàn phím một tý, vì mỗi nút chủ là 1 bít theo cách khai báo trong button của Joystick/

      Mod cố gắng giúp em một lần cho xong được dự án này, các cái sau em không dám làm phiền đâu, em đã thức không biết bao nhiêu đêm đọc sách từ tiếng việt đến tiếng anh về lập trình C và PIC để làm. Em học đại học mỏ địa chất ngành khai thác mỏ, ko có nhiều kiến thức về điện mà chỉ là tự học từ bao năm nay theo sở thích thôi.

      Còn đoạn Vì bên dưới có 26 bytes thôi ( Chỗ hid_rpt_desc ... rảnh ngồi mà đếm ). thì quả thực là em không biết cách đếm thế nào, em cũng nghi nghi phải đếm chỗ đó mà đếm các kiểu con đà điểu nó vấn không có cách nào ra 26, em thử cộng hết các số trong cột thứ 2 lại thì nó cũng không ra như thế. Em cũng tham khảo code của vài người thì cũng ngồi đếm mà không ra số như họ viết.

      Qua các vấn đề trên em nhờ Mod 2 việc cụ thể là:
      1 - Hướng dẫn giúp em hoàn thiện một dự án này thôi ạ. Trên windów nó đã hiện cái game controler có 8 nút đúng ý em. Nhưng test không thấy các nút đó nhận (trên màn hình nút phải chuyển từ đỏ sẫm sang đỏ tươi nếu nút đó đang bấm) . Bỏ các code trong phần ADC của file nguồn và gửi giá trị cố định lên để test thì Ok . Ví dụ gửi 0b11111111 thì cả 8 nút đều đỏ (bấm). Nhưng cho phần code của adc như đã viết thì không thấy nút sáng khi thay đổi điện áp cổng AN0
      2 - Hướng dẫn em cách đếm con số 26 bên trên như mod đã chỉ ra. Hiểu cách đếm em có thể làm cái khác sau này
      PS: sau khi ngồi nghiên cứu khá lâu cái code của Mod em hiểu ra vấn đề cách đếm là cứ có một cái 0x.. nào đó thì là 1 byte. Em đếm đúng kiểu đó thì ra cái của em có 26 thật. Cái code của mod cũng 45 và code mẫu khác cũng đúng . chả có lẽ là đếm thể thật sao. (Vid dụ 0x81, 0x02, thì là 2 byte)
      - Hướng dẫn tự tạo chart thêu
      Chuyên bán buôn - bán lẻ kit thêu tranh chữ thập -

      Comment


      • #18
        Nhờ mod xoá giúp bài lạc đề nhé !

        Comment


        • #19
          Nguyên văn bởi duong_act Xem bài viết
          Nhờ mod xoá giúp bài lạc đề nhé !
          Có lạc gì đâu ạ, em vẫn làm đúng những gì đã hỏi từ đầu tới giờ mà, trong quá trình làm vướng đến đâu lại hỏi đến đó. Em trông cậy vào các bác chứ em biết hỏi ai bây giờ. Em đã thành công khoảng 80% đến thời điểm này rồi, khó nhất cái usb hid report descriptor cho máy tính nhận đúng driver và thu được tín hiệu thì đã làm đc. Phần còn lại lỗi chút đâu đó nhờ các bác giúp.
          Chắc chắn đoạn code dưới có gì đó không ổn nên nó khổng gửi giá trị lên PC.

          Em thay thử:
          writebuff[0] = buttons;
          thành:
          writebuff[0] = 0b00000001;
          Thì kiểm tra là đúng nút 1 được bấm trên màn hình test của máy tính
          Nhưng để nguyên thì không gửi đc mới lạ


          Code:
          unsigned char readbuff[1] absolute 0x500;
          unsigned char writebuff[1] absolute 0x540;
          unsigned char pov;
          unsigned char buttons;
          
          void interrupt()
          {
               USB_Interrupt_Proc();        // USB servicing is done inside the interrupt
          }
          
          void main()
          {
                  HID_Enable(&readbuff,&writebuff);       // Enable HID communication
          
                  while(1)
                  {
                  pov = ADC_Get_Sample(0);
                  if(pov >= 0 && pov <= 128)              buttons = 0b00000001;   //bam nut 1
                  if(pov >= 129 && pov <= 256)            buttons = 0b00000010;   //bam nut 2
                  if(pov >= 257 && pov <= 384)            buttons = 0b00000100;   //bam nut 3
                  if(pov >= 385 && pov <= 512)            buttons = 0b00001000;   //bam nut 4
                  if(pov >= 513 && pov <= 640)            buttons = 0b00010000;   //bam nut 5
                  if(pov >= 641 && pov <= 768)            buttons = 0b00100000;   //bam nut 6
                  if(pov >= 769 && pov <= 896)            buttons = 0b01000000;   //bam nut 7
                  if(pov >= 897 && pov <= 1024)           buttons = 0b10000000;   //bam nut 8
                  writebuff[0] = buttons;
                  while(!HID_Write(&writebuff,1));
                  }
          }
          - Hướng dẫn tự tạo chart thêu
          Chuyên bán buôn - bán lẻ kit thêu tranh chữ thập -

          Comment


          • #20
            Em đã thành công. Cảm ơn queduongduong_act
            - Hướng dẫn tự tạo chart thêu
            Chuyên bán buôn - bán lẻ kit thêu tranh chữ thập -

            Comment


            • #21
              Chúc mừng bạn nhé, cố gắng phát huy
              Module RF chuyên dụng điều khiển, truyền dữ liệu, thiết kế đề tài, dự án điện tử - chuyển giao công nghệ... ĐT: 0904964977 - email: dientuqueduong@yahoo.com

              Comment


              • #22
                Nguyên văn bởi queduong Xem bài viết
                Chúc mừng bạn nhé, cố gắng phát huy
                Mình đối diện với một vấn đề mới khi triển khai mạch thật. Đã dùng Kitpc2 nạp báo thành công. Tuy nhiên cắm cổng usb vào máy tính không thấy máy tính báo gì cả (cứ như không hề cắm vậy). Chuyện gì có thể xảy ra nhỉ, chả lẽ cổng USB của con PIC này bị hỏng? Vừa mua 120k chưa làm gì mà ko chạy được có đau không ạ. Hay là còn vấn đề gì Mod ơi. Em đã cắm thạch anh, tụ điện đúng sơ đồ và mạch ráp thử kết quả là như không có gì cắm vào máy tính/
                - Hướng dẫn tự tạo chart thêu
                Chuyên bán buôn - bán lẻ kit thêu tranh chữ thập -

                Comment


                • #23
                  Nguyên văn bởi ngochoangims Xem bài viết
                  Mình đối diện với một vấn đề mới khi triển khai mạch thật. Đã dùng Kitpc2 nạp báo thành công. Tuy nhiên cắm cổng usb vào máy tính không thấy máy tính báo gì cả (cứ như không hề cắm vậy). Chuyện gì có thể xảy ra nhỉ, chả lẽ cổng USB của con PIC này bị hỏng? Vừa mua 120k chưa làm gì mà ko chạy được có đau không ạ. Hay là còn vấn đề gì Mod ơi. Em đã cắm thạch anh, tụ điện đúng sơ đồ và mạch ráp thử kết quả là như không có gì cắm vào máy tính/
                  ​Đã cấu hình mấy cái dao động, PLL_MUL, USB_DIV, CPU_DIV, VREGEN trên MikroC chưa ?

                  Comment


                  • #24
                    Nguyên văn bởi duong_act Xem bài viết

                    ​Đã cấu hình mấy cái dao động, PLL_MUL, USB_DIV, CPU_DIV, VREGEN trên MikroC chưa ?
                    Phần cứng: PIC 18F4550, Thạch anh ngoài 20MHz. - Em đã khắc phục được phần cứng bằng cách mua Bộ KIT phát triển về để chỉ việc cắm và dùng .


                    Bây giờ mạch thật đã chạy như ý ạ

                    1. Mã nguồn chính - hoàn chỉnh
                    Code:
                    //
                    unsigned char readbuff[1] absolute 0x500;
                    unsigned char writebuff[1] absolute 0x540;
                    unsigned int pov;
                    unsigned int buttons;
                    //
                    void interrupt()
                    {
                    USB_Interrupt_Proc(); // USB servicing is done inside the interrupt
                    }
                    
                    void main()
                    {
                    HID_Enable(&readbuff,&writebuff); // Enable HID communication
                    ADC_init();
                    while(1)
                    {
                    pov = ADC_Get_Sample(0);
                    if(pov >= 10 && pov <= 128) buttons = 1; //bam nut 1
                    else if(pov >= 129 && pov <= 256) buttons = 2; //bam nut 2
                    else if(pov >= 257 && pov <= 384) buttons = 4; //bam nut 3
                    else if(pov >= 385 && pov <= 512) buttons = 8; //bam nut 4
                    else if(pov >= 513 && pov <= 640) buttons = 16; //bam nut 5
                    else if(pov >= 641 && pov <= 768) buttons = 32; //bam nut 6
                    else if(pov >= 769 && pov <= 896) buttons = 64; //bam nut 7
                    else if(pov >= 897 && pov <= 1015) buttons = 128; //bam nut 8
                    else    {buttons = 0;} //khong bam nut
                    writebuff[0] = buttons;
                    while(!HID_Write(&writebuff,1));
                    }
                    }
                    2. Mã nguồn file USBdsc.c - chạy thử ok trên proteus
                    Code:
                    const unsigned int USB_VENDOR_ID = 0x1234;
                    const unsigned int USB_PRODUCT_ID = 0x0001;
                    const char USB_SELF_POWER = 0x80;            // Self powered 0xC0,  0x80 bus powered
                    const char USB_MAX_POWER = 50;               // Bus power required in units of 2 mA
                    //const char HID_INPUT_REPORT_BYTES = 1;
                    //const char HID_OUTPUT_REPORT_BYTES = 1;
                    const char USB_TRANSFER_TYPE = 0x03;         //0x03 Interrupt
                    const char EP_IN_INTERVAL = 1;
                    const char EP_OUT_INTERVAL = 1;
                    
                    const char USB_INTERRUPT = 1;
                    const char USB_HID_EP = 1;
                    const char USB_HID_RPT_SIZE = 23;
                    
                    /* Device Descriptor */
                    const struct {
                        char bLength;               // bLength         - Descriptor size in bytes (12h)
                        char bDescriptorType;       // bDescriptorType - The constant DEVICE (01h)
                        unsigned int bcdUSB;        // bcdUSB          - USB specification release number (BCD)
                        char bDeviceClass;          // bDeviceClass    - Class Code
                        char bDeviceSubClass;       // bDeviceSubClass - Subclass code
                        char bDeviceProtocol;       // bDeviceProtocol - Protocol code
                        char bMaxPacketSize0;       // bMaxPacketSize0 - Maximum packet size for endpoint 0
                        unsigned int idVendor;      // idVendor        - Vendor ID
                        unsigned int idProduct;     // idProduct       - Product ID
                        unsigned int bcdDevice;     // bcdDevice       - Device release number (BCD)
                        char iManufacturer;         // iManufacturer   - Index of string descriptor for the manufacturer
                        char iProduct;              // iProduct        - Index of string descriptor for the product.
                        char iSerialNumber;         // iSerialNumber   - Index of string descriptor for the serial number.
                        char bNumConfigurations;    // bNumConfigurations - Number of possible configurations
                    } device_dsc = {
                          0x12,                   // bLength
                          0x01,                   // bDescriptorType
                          0x0200,                 // bcdUSB
                          0x00,                   // bDeviceClass
                          0x00,                   // bDeviceSubClass
                          0x00,                   // bDeviceProtocol
                          8,                      // bMaxPacketSize0
                          USB_VENDOR_ID,          // idVendor
                          USB_PRODUCT_ID,         // idProduct
                          0x0001,                 // bcdDevice
                          0x01,                   // iManufacturer
                          0x02,                   // iProduct
                          0x00,                   // iSerialNumber
                          0x01                    // bNumConfigurations
                      };
                    
                    /* Configuration 1 Descriptor */
                    const char configDescriptor1[]= {
                        // Configuration Descriptor
                        0x09,                   // bLength             - Descriptor size in bytes
                        0x02,                   // bDescriptorType     - The constant CONFIGURATION (02h)
                        0x29,0x00,              // wTotalLength        - The number of bytes in the configuration descriptor and all of its subordinate descriptors
                        1,                      // bNumInterfaces      - Number of interfaces in the configuration
                        1,                      // bConfigurationValue - Identifier for Set Configuration and Get Configuration requests
                        0,                      // iConfiguration      - Index of string descriptor for the configuration
                        USB_SELF_POWER,         // bmAttributes        - Self/bus power and remote wakeup settings
                        USB_MAX_POWER,          // bMaxPower           - Bus power required in units of 2 mA
                    
                        // Interface Descriptor
                        0x09,                   // bLength - Descriptor size in bytes (09h)
                        0x04,                   // bDescriptorType - The constant Interface (04h)
                        0,                      // bInterfaceNumber - Number identifying this interface
                        0,                      // bAlternateSetting - A number that identifies a descriptor with alternate settings for this bInterfaceNumber.
                        2,                      // bNumEndpoint - Number of endpoints supported not counting endpoint zero
                        0x03,                   // bInterfaceClass - Class code
                        0,                      // bInterfaceSubclass - Subclass code
                        0,                      // bInterfaceProtocol - Protocol code
                        0,                      // iInterface - Interface string index
                    
                        // HID Class-Specific Descriptor
                        0x09,                   // bLength - Descriptor size in bytes.
                        0x21,                   // bDescriptorType - This descriptor's type: 21h to indicate the HID class.
                        0x01,0x01,              // bcdHID - HID specification release number (BCD).
                        0x00,                   // bCountryCode - Numeric expression identifying the country for localized hardware (BCD) or 00h.
                        1,                      // bNumDescriptors - Number of subordinate report and physical descriptors.
                        0x22,                   // bDescriptorType - The type of a class-specific descriptor that follows
                        USB_HID_RPT_SIZE,0x00,  // wDescriptorLength - Total length of the descriptor identified above.
                    
                        // Endpoint Descriptor
                        0x07,                   // bLength - Descriptor size in bytes (07h)
                        0x05,                   // bDescriptorType - The constant Endpoint (05h)
                        USB_HID_EP | 0x80,      // bEndpointAddress - Endpoint number and direction
                        USB_TRANSFER_TYPE,      // bmAttributes - Transfer type and supplementary information    
                        0x40,0x00,              // wMaxPacketSize - Maximum packet size supported
                        EP_IN_INTERVAL,         // bInterval - Service interval or NAK rate
                    
                        // Endpoint Descriptor
                        0x07,                   // bLength - Descriptor size in bytes (07h)
                        0x05,                   // bDescriptorType - The constant Endpoint (05h)
                        USB_HID_EP,             // bEndpointAddress - Endpoint number and direction
                        USB_TRANSFER_TYPE,      // bmAttributes - Transfer type and supplementary information
                        0x40,0x00,              // wMaxPacketSize - Maximum packet size supported    
                        EP_OUT_INTERVAL         // bInterval - Service interval or NAK rate
                    };
                    
                    const struct {
                      char report[USB_HID_RPT_SIZE];
                    }hid_rpt_desc =
                      {
                        0x05, 0x01,             // USAGE_PAGE (Generic Desktop)
                        0x09, 0x04,             // USAGE (Joystick)
                        0xa1, 0x01,             // COLLECTION (Application)
                        //0xa1, 0x00,             // COLLECTION (Physical)
                        0x05, 0x09,             // USAGE_PAGE (Button)
                        0x19, 0x01,             // USAGE_MINIMUM (Button 1)
                        0x29, 0x08,             // USAGE_MAXIMUM (Button 8)
                        0x15, 0x00,             // LOGICAL_MINIMUM (0)
                        0x25, 0x01,             // LOGICAL_MAXIMUM (1)
                        0x75, 0x01,             // REPORT_SIZE (1)
                        0x95, 0x08,             // REPORT_COUNT (8)
                        0x81, 0x02,             // INPUT (Data,Var,Abs)
                        //0xc0,                    // END_COLLECTION
                        0xc0                    // END_COLLECTION
                      };
                    
                    //Language code string descriptor
                    const struct {
                      char bLength;
                      char bDscType;
                      unsigned int string[1];
                      } strd1 = {
                          4,
                          0x03,
                          {0x0409}
                        };
                    
                    
                    //Manufacturer string descriptor
                    const struct{
                      char bLength;
                      char bDscType;
                      unsigned int string[16];
                      }strd2={
                        34,           //sizeof this descriptor string
                        0x03,
                        {'M','i','k','r','o','e','l','e','k','t','r','o','n','i','k','a'}
                      };
                    
                    //Product string descriptor
                    const struct{
                      char bLength;
                      char bDscType;
                      unsigned int string[15];
                    }strd3={
                        32,          //sizeof this descriptor string
                        0x03,
                        {'U','S','B',' ','H','I','D',' ','L','i','b','r','a','r','y'}
                     };
                    
                    //Array of configuration descriptors
                    const char* USB_config_dsc_ptr[1];
                    
                    //Array of string descriptors
                    const char* USB_string_dsc_ptr[3];
                    
                    void USB_Init_Desc(){
                      USB_config_dsc_ptr[0] = &configDescriptor1;
                      USB_string_dsc_ptr[0] = (const char*)&strd1;
                      USB_string_dsc_ptr[1] = (const char*)&strd2;
                      USB_string_dsc_ptr[2] = (const char*)&strd3;
                    }
                    3. Hình ảnh thiết lập config cho Project - Hình ảnh chạy mô phỏng proteus:




                    - Hướng dẫn tự tạo chart thêu
                    Chuyên bán buôn - bán lẻ kit thêu tranh chữ thập -

                    Comment


                    • #25
                      Cảm ơn mod queduongduong_act một lần nữa. Em đã thực sự thành công ngoài mạch thật ạ.
                      - Hướng dẫn tự tạo chart thêu
                      Chuyên bán buôn - bán lẻ kit thêu tranh chữ thập -

                      Comment


                      • #26
                        Bạn chụp cái edit projects và lỗi cái chấm than màu vàng lên xem sao ?
                        Module RF chuyên dụng điều khiển, truyền dữ liệu, thiết kế đề tài, dự án điện tử - chuyển giao công nghệ... ĐT: 0904964977 - email: dientuqueduong@yahoo.com

                        Comment


                        • #27
                          Nguyên văn bởi queduong Xem bài viết
                          Bạn chụp cái edit projects và lỗi cái chấm than màu vàng lên xem sao ?

                          Mình đổi cái PID và VID của USB trong USBdsc.c thì hết lỗi vàng, như vậy nguyên nhân là cái PID 1234 và VID 0001 theo mặc định đã bị nhận thành thiết bị khác nhiều lần trong quá trình thử nghiệm nên driver trên win bị lỗi. Đổi xong thì OK
                          - Hướng dẫn tự tạo chart thêu
                          Chuyên bán buôn - bán lẻ kit thêu tranh chữ thập -

                          Comment


                          • #28
                            nút bấm http://forum.mikroe.com/viewtopic.ph...278577#p278577
                            - Hướng dẫn tự tạo chart thêu
                            Chuyên bán buôn - bán lẻ kit thêu tranh chữ thập -

                            Comment

                            Về tác giả

                            Collapse

                            ngochoangims Tìm hiểu thêm về ngochoangims

                            Bài viết mới nhất

                            Collapse

                            Đang tải...
                            X