Professional Documents
Culture Documents
80
Las palabras clave y los puntos de inters de este firmware estan marcados
en negrita.
/////////////////////////////////////////////////////////////////////
////
//// ////
//// RR2_USB_Cdc_Monitor.c ////
//// ////
/////////////////////////////////////////////////////////////////////
////
#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)
#include ".\include\usb_cdc.h"
void main() {
delay_ms(300);
usb_cdc_init();
usb_init();
while(!usb_cdc_connected()) {}
do{
usb_task();
if (usb_enumerated()) {
printf(usb_cdc_putc, "\r\n\nEEPROM:\r\n"); // Display contents
of the first 64
for(i=0; i<=3; ++i) { // bytes of the data EEPROM in hex
for(j=0; j<=15; ++j) {
printf(usb_cdc_putc, "%2x ", read_eeprom( i*16+j ) );
}
printf(usb_cdc_putc, "\n\r");
}
printf(usb_cdc_putc, "\r\nLocation to change: ");
address = gethex_usb();
printf(usb_cdc_putc, "\r\nNew value: ");
value = gethex_usb();
write_eeprom( address, value );
}
}while (TRUE);
}
Los dos siguientes datos son los dos strings que definen
nuestro dispositivo y cuya estructura es idntica al caso
anterior:
rr2_USB_Cdc_Monitor.h
///////////////////////////////////////////////////////////////////////////
//// usb_desc_cdc.h ////
//// ////
//// An example set of device / configuration descriptors for use with ////
//// CCS's CDC Virtual COM Port driver (see usb_cdc.h) ////
//// ////
//// Two examples are provided: ////
//// ex_usb_serial.c ////
//// ex_usb_serial2.c ////
//// ////
///////////////////////////////////////////////////////////////////////////
//// ////
//// Version History: ////
//// ////
//// 10/28/05: ////
//// Bulk endpoint sizes updated to allow more than 255 byte ////
//// packets. ////
//// Changed device to USB 1.10 ////
//// ////
///////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,2005 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS ////
//// C compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, ////
//// reproduction or distribution is permitted without written ////
//// permission. Derivative programs created using this software ////
//// in object code form are not restricted in any way. ////
///////////////////////////////////////////////////////////////////////////
#IFNDEF __USB_DESCRIPTORS__
#DEFINE __USB_DESCRIPTORS__
#include <usb.h>
//////////////////////////////////////////////////////////////////
///
/// start config descriptor
/// right now we only support one configuration descriptor.
/// the config, interface, class, and endpoint goes into this array.
///
//////////////////////////////////////////////////////////////////
//endpoint descriptor
USB_DESC_ENDPOINT_LEN, //length of descriptor ==37
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==38
USB_CDC_COMM_IN_ENDPOINT | 0x80, //endpoint number and direction
0x03, //transfer type supported (0x03 is interrupt) ==40
USB_CDC_COMM_IN_SIZE,0x00, //maximum packet size supported ==41,42
250, //polling interval, in ms. (cant be smaller than 10) ==43
//endpoint descriptor
USB_DESC_ENDPOINT_LEN, //length of descriptor ==60
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==61
USB_CDC_DATA_OUT_ENDPOINT, //endpoint number and direction (0x02 = EP2 OUT)
==62
0x02, //transfer type supported (0x02 is bulk) ==63
// make8(USB_CDC_DATA_OUT_SIZE,0),make8(USB_CDC_DATA_OUT_SIZE,1), //maximum
packet size supported ==64, 65
USB_CDC_DATA_OUT_SIZE & 0xFF, (USB_CDC_DATA_OUT_SIZE >> 8) & 0xFF,
//maximum packet size supported ==64, 65
250, //polling interval, in ms. (cant be smaller than 10) ==66
//endpoint descriptor
USB_DESC_ENDPOINT_LEN, //length of descriptor ==53
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==54
USB_CDC_DATA_IN_ENDPOINT | 0x80, //endpoint number and direction (0x82 =
EP2 IN) ==55
0x02, //transfer type supported (0x02 is bulk) ==56
// make8(USB_CDC_DATA_IN_SIZE,0),make8(USB_CDC_DATA_IN_SIZE,1), //maximum
packet size supported ==57, 58
USB_CDC_DATA_IN_SIZE & 0xFF, (USB_CDC_DATA_IN_SIZE >> 8) & 0xFF, //maximum
packet size supported ==64, 65
250, //polling interval, in ms. (cant be smaller than 10) ==59
};
//****** BEGIN CONFIG DESCRIPTOR LOOKUP TABLES ********
//since we can't make pointers to constants in certain pic16s, this is an
offset table to find
// a specific descriptor in the above table.
//define how many interfaces there are per config. [0] is the first config,
etc.
const char USB_NUM_INTERFACES[USB_NUM_CONFIGURATIONS]={2};
//////////////////////////////////////////////////////////////////
///
/// start device descriptors
///
//////////////////////////////////////////////////////////////////
//device descriptor
char const USB_DEVICE_DESC[USB_DESC_DEVICE_LEN] ={
USB_DESC_DEVICE_LEN, //the length of this report
0x01, //constant DEVICE (0x01)
0x10,0x01, //usb version in bcd
0x02, //class code. 0x02=Communication Device Class ==4
0x00, //subclass code
0x00, //protocol code
USB_MAX_EP0_PACKET_LENGTH, //max packet size for endpoint 0. (SLOW SPEED
SPECIFIES 8)
0xD8,0x04, //vendor id (0x04D8 is Microchip)
0x0A,0x00, //product id
0x01,0x00, //device release number
0x01, //index of string description of manufacturer. therefore we point to
string_1 array (see below)
0x02, //index of string descriptor of the product
0x00, //index of string descriptor of serial number
USB_NUM_CONFIGURATIONS //number of possible configurations
};
//////////////////////////////////////////////////////////////////
///
/// start string descriptors
/// String 0 is a special language string, and must be defined. People in
U.S.A. can leave this alone.
///
/// You must define the length else get_next_string_character() will not
see the string
/// Current code only supports 10 strings (0 thru 9)
///
//////////////////////////////////////////////////////////////////