// see usb_hw_layer.h for documentation void usb_init(void) { usb_init_cs(); do { usb_task(); } while (usb_state != USB_STATE_POWERED); }
//------------------------------------------------------------------------------ // Main Function: //------------------------------------------------------------------------------ void main() { //-------------------------------------------------------------------------- // PIC Initialization Section //-------------------------------------------------------------------------- Disable_Interrupts(GLOBAL); // all interrupts OFF Setup_adc(ADC_OFF); // ADC not needed Setup_adc_ports(NO_ANALOGS); // No ADC ports needed Setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); // Timer 0 set for 42.6us, Setup_timer_1(T1_DISABLED); // Timer 1 Set_Tris_A(TRISA_Enabled); // SPI Disabled Set_Tris_B(TRISB_Disable); // Flash SPI Disabled Set_Tris_C(TRISC_Disable); // Flash SPI Disabled Output_high(FLASH_SELECT); // Slash Select High Output_high(FLASH_CLOCK); // Pulse the clock Output_low(RTC_RST); // Disable RTC Output_High(FPGALoad); // FPGA Upload pin Output_High(FPGAReset); // FPGA reset off Output_High(TestLED); // indication of boot up spi_enabled = False; // ZBC to PIC SPI disabled initially spi_write = False; // ZBC to PIC SPI disabled initially Refresh_RTCSPI(); // Refresh data from RTC into SPI buffer //-------------------------------------------------------------------------- // USB Initialization Section //-------------------------------------------------------------------------- usb_init_cs(); // Initialize the USB Connection if(read_eeprom(BOOT_TYPE) > 0) { // We want boot from FLASH FlashToFPGA(); // If not hooked up to USB then try to init Output_Low(FPGAReset); // FPGA reset off Output_High(FPGAReset); // FPGA reset off Output_Low(TestLED); // Turn off Test LED } else { FGPA_SPI_Init(); // Put PIC in SPI Slave mode } //-------------------------------------------------------------------------- // Main Command Loop: //-------------------------------------------------------------------------- do { // Always do USB Task usb_task(); // so it will detect USB pluging in if(usb_enumerated()) { // Are we plugged into the USB port ? usb_rcvdata_task(); // If so, check for data } if(spi_enabled) { // if ZBC to PIC SPI enabled, then check if(SSP_HAS_DATA()) { Handle_SPI(); // Handle SPI request from ZBC } } // Otherwise... just } while(True); // Continue forever, what else can we do ? }
void main(void) { int i; set_tris_b(0x10000000); output_high(PIN_B0); delay_ms(500); output_low(PIN_B0); fprintf(A, "rs232 init...\n\r"); usb_init_cs(); while(1) { if(input(PIN_B7)) { output_high(PIN_B0); usb_task(); while(input(PIN_B7)) { if (usb_enumerated()) { if (usb_kbhit(1)) { receive_msg(); //usb_get_packet(1, rdata, 1); //fprintf(A, "%u", rdata[0]); //switch(rdata[0]) //{ // case 0x01: output_high(PIN_B0); break; // case 0x02: output_low(PIN_B0); break; //} } } } usb_detach(); output_low(PIN_B0); } } }