Autor Tema: Controlador de luces :-/  (Leído 2970 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado rockman

  • PIC10
  • *
  • Mensajes: 2
Controlador de luces :-/
« en: 19 de Septiembre de 2012, 11:45:43 »
Hola queria pedir ayuda con mi proyecto  (Encender luces java)
este me da un error al momento de conectarlo Unknwn device
me dicen que el programa esta mal grabado que proteus le pone lineas extra para que funcione me lo pueden revisar por favor.

Yo uso java para enviar los bytes.
PIC-C para compilar.

este es el programa que compilo:




#include <18F4550.h>
#fuses XTPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL1,CPUDIV1,VREGEN
#use delay(clock=48000000)


#define USB_HID_DEVICE FALSE // deshabilitamos el uso de las directivas HID
#define USB_EP1_TX_ENABLE USB_ENABLE_BULK // turn on EP1(EndPoint1) for IN bulk/interrupt transfers
#define USB_EP1_RX_ENABLE USB_ENABLE_BULK // turn on EP1(EndPoint1) for OUT bulk/interrupt transfers
#define USB_EP1_TX_SIZE 32 // size to allocate for the tx endpoint 1 buffer
#define USB_EP1_RX_SIZE 32 // size to allocate for the rx endpoint 1 buffer


#include <pic18_usb.h> // Microchip PIC18Fxx5x Hardware layer for CCS's PIC USB driver
#include <header.h> // Configuración del USB y los descriptores para este dispositivo
#include <usb.c> // handles usb setup tokens and get descriptor reports


const int8 Lenbuf = 32;
int8 recbuf[Lenbuf];


void main(void) {
  delay_ms(500);
  usb_init();
  usb_task();
  usb_wait_for_enumeration();
  enable_interrupts(global);
  while (TRUE){
    if(usb_enumerated()){
      if (usb_kbhit(1)){
        usb_get_packet(1, recbuf, Lenbuf);
       //Led numero 1
       //Encender led 1 1
        if(recbuf[0]==1){
           output_high(PIN_A0);
        }
       //Apagar led 1 2
        if(recbuf[0]==2){
          output_low(PIN_A0);
        }        
       //Led numero 2
       //Encender led 2 3
        if(recbuf[0]==3){
           output_high(PIN_A1);
        }
       //Apagar led 2 4
        if(recbuf[0]==4){
          output_low(PIN_A1);
        }
        //Led numero 3
       //Encender led 3 5
        if(recbuf[0]==5){
           output_high(PIN_A2);
        }
       //Apagar led 3 6
        if(recbuf[0]==6){
          output_low(PIN_A2);
        }
       //Led numero 4
       //Encender led 4 7
        if(recbuf[0]==7){
           output_high(PIN_A3);
        }
       //Apagar led 4 8
        if(recbuf[0]==8){
          output_low(PIN_A3);
        }
        //Led numero 5
       //Encender led 5 9
        if(recbuf[0]==9){
           output_high(PIN_A4);
        }
       //Apagar led 5 10
        if(recbuf[0]==10){
          output_low(PIN_A4);
        }
        //Led numero 6
       //Encender led 6 11
        if(recbuf[0]==11){
           output_high(PIN_A5);
        }
       //Apagar led 6 12
        if(recbuf[0]==12){
          output_low(PIN_A5);
        }
        //Led numero 7
       //Encender led 7 13
        if(recbuf[0]==13){
           output_high(PIN_B0);
        }
       //Apagar led 7 14
        if(recbuf[0]==14){
          output_low(PIN_B0);
        }
        //Led numero 8
       //Encender led 8 15
        if(recbuf[0]==15){
           output_high(PIN_B1);
        }
       //Apagar led 8 16
        if(recbuf[0]==16){
          output_low(PIN_B1);
        }
        //Led numero 9
       //Encender led 9 17
        if(recbuf[0]==17){
           output_high(PIN_B2);
        }
       //Apagar led 9 18
        if(recbuf[0]==18){
          output_low(PIN_B2);
        }
        //Led numero 10
       //Encender led 10 19
        if(recbuf[0]==19){
           output_high(PIN_B3);
        }
       //Apagar led 10 20
        if(recbuf[0]==20){
          output_low(PIN_B3);
        }
        //Led numero 11
       //Encender led 11 21
        if(recbuf[0]==21){
           output_high(PIN_B4);
        }
       //Apagar led 11 22
        if(recbuf[0]==22){
          output_low(PIN_B4);
        }
        //Led numero 12
       //Encender led 12 23
        if(recbuf[0]==23){
           output_high(PIN_B5);
        }
       //Apagar led 12 24
        if(recbuf[0]==24){
          output_low(PIN_B5);
        }
        //Led numero 13
       //Encender led 13 25
        if(recbuf[0]==25){
           output_high(PIN_B6);
        }
       //Apagar led 13 26
        if(recbuf[0]==26){
          output_low(PIN_B6);
        }
        //Led numero 14
       //Encender led 14 27
        if(recbuf[0]==27){
           output_high(PIN_B7);
        }
       //Apagar led 14 28
        if(recbuf[0]==28){
          output_low(PIN_B7);
        }
        //Led numero 15
       //Encender led 15 29
        if(recbuf[0]==29){
           output_high(PIN_C0);
        }
       //Apagar led 15 30
        if(recbuf[0]==30){
          output_low(PIN_C0);
        }
        //Led numero 16
       //Encender led 16 31
        if(recbuf[0]==31){
           output_high(PIN_C1);
        }
       //Apagar led 16 32
        if(recbuf[0]==32){
          output_low(PIN_C1);
        }
        //Led numero 17
       //Encender led 17 33
        if(recbuf[0]==33){
           output_high(PIN_C2);
        }
       //Apagar led 17 34
        if(recbuf[0]==34){
          output_low(PIN_C2);
        }
        //Led numero 18
       //Encender led 18 35
        if(recbuf[0]==35){
           output_high(PIN_C6);
        }
       //Apagar led 18 36
        if(recbuf[0]==36){
          output_low(PIN_C6);
        }
        //Led numero 19
       //Encender led 19 37
        if(recbuf[0]==37){
           output_high(PIN_C7);
        }
       //Apagar led 19 38
        if(recbuf[0]==38){
          output_low(PIN_C7);
        }
        //Led numero 20
       //Encender led 20 39
        if(recbuf[0]==39){
           output_high(PIN_D0);
        }
       //Apagar led 20 40
        if(recbuf[0]==40){
          output_low(PIN_D0);
        }
        //Led numero 21
       //Encender led 21 41
        if(recbuf[0]==41){
           output_high(PIN_D1);
        }
       //Apagar led 21 42
        if(recbuf[0]==42){
          output_low(PIN_D1);
        }
        //Led numero 22
       //Encender led 22 7
        if(recbuf[0]==43){
           output_high(PIN_D2);
        }
       //Apagar led 22 44
        if(recbuf[0]==44){
          output_low(PIN_D2);
        }
        //Led numero 23
       //Encender led 23 45
        if(recbuf[0]==45){
           output_high(PIN_D3);
        }
       //Apagar led 23 46
        if(recbuf[0]==46){
          output_low(PIN_D3);
        }
        //Led numero 24
       //Encender led 24 47
        if(recbuf[0]==47){
           output_high(PIN_D4);
        }
       //Apagar led 24 48
        if(recbuf[0]==48){
          output_low(PIN_D4);
        }
        //Led numero 25
       //Encender led 25 49
        if(recbuf[0]==49){
           output_high(PIN_D5);
        }
       //Apagar led 25 50      
       if(recbuf[0]==50){
          output_low(PIN_D5);
        }
        //Led numero 26
       //Encender led 26 51    
       if(recbuf[0]==51){
           output_high(PIN_D6);    
           }
       //Apagar led 26 52
        if(recbuf[0]==52){
          output_low(PIN_D6);
        }
        //Led numero 27
       //Encender led 27 53
        if(recbuf[0]==53){
           output_high(PIN_D7);
        }
       //Apagar led 27 54
        if(recbuf[0]==54){
          output_low(PIN_D7);
        }
        //Led numero 28
       //Encender led 28 55
        if(recbuf[0]==55){
           output_high(PIN_E0);
        }
       //Apagar led 28 56
        if(recbuf[0]==56){
          output_low(PIN_E0);
        }
        //Led numero 29
       //Encender led 29 57
        if(recbuf[0]==57){
           output_high(PIN_E1);
        }
       //Apagar led 29 58
        if(recbuf[0]==58){
          output_low(PIN_E1);
        }
        //Led numero 30
       //Encender led 30 59
        if(recbuf[0]==59){
           output_high(PIN_E2);
        }
       //Apagar led 30 60
        if(recbuf[0]==60){
          output_low(PIN_E2);
        }  
      }//fin
    }
  }
}

este es el header

#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.
///
//////////////////////////////////////////////////////////////////

#DEFINE USB_TOTAL_CONFIG_LEN 32 //config+interface+class+endpoint

//configuration descriptor
char const USB_CONFIG_DESC[] = {
//config_descriptor for config index 1
USB_DESC_CONFIG_LEN, //length of descriptor size
USB_DESC_CONFIG_TYPE, //constant CONFIGURATION (0x02)
USB_TOTAL_CONFIG_LEN,0, //size of all data returned for this config
1, //number of interfaces this device supports
0x01, //identifier for this configuration. (IF we had more than one configurations)
0x00, //index of string descriptor for this configuration
0xC0, //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 reserved and bit7=1
0x32, //maximum bus power required (maximum milliamperes/2) (0x32 = 100mA)

//interface descriptor 0 alt 0
USB_DESC_INTERFACE_LEN, //length of descriptor
USB_DESC_INTERFACE_TYPE, //constant INTERFACE (0x04)
0x00, //number defining this interface (IF we had more than one interface)
0x00, //alternate setting
2, //number of endpoints, not counting endpoint 0.
0xFF, //class code, FF = vendor defined
0xFF, //subclass code, FF = vendor
0xFF, //protocol code, FF = vendor
0x00, //index of string descriptor for interface

//endpoint descriptor
USB_DESC_ENDPOINT_LEN, //length of descriptor
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (0x05)
0x81, //endpoint number and direction (0x81 = EP1 IN)
0x02, //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt)
USB_EP1_TX_SIZE,0x00, //maximum packet size supported
0x01, //polling interval in ms. (for interrupt transfers ONLY)

//endpoint descriptor
USB_DESC_ENDPOINT_LEN, //length of descriptor
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (0x05)
0x01, //endpoint number and direction (0x01 = EP1 OUT)
0x02, //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt)
USB_EP1_RX_SIZE,0x00, //maximum packet size supported
0x01, //polling interval in ms. (for interrupt transfers ONLY)

};

//****** 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.

//NOTE: DO TO A LIMITATION OF THE CCS CODE, ALL HID INTERFACES MUST START AT 0 AND BE SEQUENTIAL
// FOR EXAMPLE, IF YOU HAVE 2 HID INTERFACES THEY MUST BE INTERFACE 0 AND INTERFACE 1
#define USB_NUM_HID_INTERFACES 0

//the maximum number of interfaces seen on any config
//for example, if config 1 has 1 interface and config 2 has 2 interfaces you must define this as 2
#define USB_MAX_NUM_INTERFACES 1

//define how many interfaces there are per config.
  • is the first config, etc.

const char USB_NUM_INTERFACES[USB_NUM_CONFIGURATIONS]={1};

#if (sizeof(USB_CONFIG_DESC) != USB_TOTAL_CONFIG_LEN)
#error USB_TOTAL_CONFIG_LEN not defined correctly
#endif


//////////////////////////////////////////////////////////////////
///
/// start device descriptors
///
//////////////////////////////////////////////////////////////////

//device descriptor
char const USB_DEVICE_DESC[] ={
USB_DESC_DEVICE_LEN, //the length of this report
0x01, //constant DEVICE (0x01)
0x10,0x01, //usb version in bcd
0x00, //class code (if 0, interface defines class. FF is vendor defined)
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)
0x0B,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)
///
//////////////////////////////////////////////////////////////////

//the offset of the starting location of each string.
//offset[0] is the start of string 0, offset[1] is the start of string 1, etc.
const char USB_STRING_DESC_OFFSET[]={0,4,20};

#define USB_STRING_DESC_COUNT sizeof(USB_STRING_DESC_OFFSET)

char const USB_STRING_DESC[]={
//string 0 Codificacion de la tabla ???
4, //length of string index
USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
0x09,0x04, //Microsoft Defined for US-English
//string 1 --> la compañia del producto ???
16, //length of string index
USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
'j',0,
'P',0,
'i',0,
'c',0,
'U',0,
's',0,
'b',0,
//string 2 --> nombre del dispositivo
18, //length of string index
USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
'P',0,
'C',0,
'C',0,
'M',0,
' ',0,
'U',0,
'S',0,
'B',0,
};
#ENDIF