Exemplo n.º 1
0
static void USB(void)
{
  byte rxCnt;
  //byte tmpBuff;
  rxCnt = BulkOut(1, rxBuffer, INPUT_BYTES);
  if (rxCnt == 0)
    return;

  ADCON0bits.ADON=1;  //switch on the adc module
  ADCON0bits.GO=1;//Start conversion
  while(ADCON0bits.GO); //wait for the conversion to finish
  ADCON0bits.ADON=0;  //switch off adc

  //tmpBuff = (byte) ADRESH;
  txBuffer[0] = (byte) ADRESH;
  txBuffer[1] = (byte) ADRESL;

  do {
    //rxCnt = BulkIn(1, &tmpBuff, 1);
    rxCnt = BulkIn(1, txBuffer, 2);
  } while (rxCnt == 0); 
  
  while (ep1Bi.Stat & UOWN)
    ProcessUSBTransactions();

  status();
}
Exemplo n.º 2
0
/**
 * main(void) - Main entry point of the firmware
 *
 * This is the main entrance of the firmware and it creates the mail loop.
 **/
void main(void)
{
  /**
   * Inits the PIC
   **/
  UserInit();
  /**
   * Inits the USB
   *
   * Full-speed mode and sets pull-up internal resistances of PORTB
   * Starts the USB DEATACHED, no wake ups, and no configured.
   * Configuring the USB is the job of the host.
   **/
  UCFG = 0x14;
  deviceState = DETACHED;
  remoteWakeup = 0x00;
  currentConfiguration = 0x00;
  
  adval = 'b';

  ADCON0=0x00;
  ADCON0bits.CHS0=0;   //Select ADC Channel
  ADCON0bits.CHS1=1;   //Select ADC Channel
  ADCON0bits.CHS2=1;   //Select ADC Channel
  ADCON0bits.CHS3=0;   //Select ADC Channel
  
  while (1) {
    /** 
     * Make sure the USB is available 
     **/
    EnableUSBModule();
    /**
     * As soon as we get out of test mode (UTEYE)
     * we process USB transactions
     **/
    if (UCFGbits.UTEYE != 1)
      ProcessUSBTransactions();
    
    /**
     * Now we can make our work
     **/
    ProcessIO();
    
    //adval=ADCRead(7);   //Read Channel 7
    //delay(100);

    //status();
    
  }
}
Exemplo n.º 3
0
void init_CDC()
{
	INTCON=0;
	INTCON2=0xC0;
	UCON=0;
	UCFG=0;
	UEP0=0;UEP1=0;UEP2=0;UEP3=0;UEP4=0;UEP5=0;
	UEP6=0;UEP7=0;UEP8=0;UEP9=0;UEP10=0;UEP11=0;
	UEP12=0;UEP13=0;UEP14=0;UEP15=0;
	// and wait 5 seconds
	Delayms(2000);
	// Initialize USB for CDC
	UCFG = 0x14; 				// Enable pullup resistors; full speed mode
	deviceState = DETACHED;
	remoteWakeup = 0x00;
	currentConfiguration = 0x00;
	// And enable USB module
	while(deviceState != CONFIGURED)
	{
	  EnableUSBModule();
	  ProcessUSBTransactions();
	}
}