int main ( void ) { /* 全てのA/D変換ポートをI/Oに使用できるように設定 */ AD1PCFG = 0xffff; /* クロックをPLL prescaler (1:1)で使用する */ CLKDIV = 0x0000; /* PORTB RB15を出力に設定 */ mPORTBOutputConfig(IOPORT_BIT_15); /* PORTBに0を出力 */ mPORTBWrite(0); /* タイマー割り込みを有効に */ ConfigIntTimer2(T2_INT_ON|T2_INT_PRIOR_1); /* タイマーを設定 */ OpenTimer2(T2_ON | T2_PS_1_64 ,0x9000); /* メインループ */ while (1) { /* IDLEモードに移行 */ mPWRMGNT_GotoIdleMode(); } }
int main ( void ) { // Initialize the processor and peripherals. if ( InitializeSystem() != TRUE ) { UART2PrintString( "\r\n\r\nCould not initialize USB Custom Demo App - system. Halting.\r\n\r\n" ); while (1); } if ( USBHostInit(0) == TRUE ) { UART2PrintString( "\r\n\r\n***** USB Custom Demo App Initialized *****\r\n\r\n" ); } else { UART2PrintString( "\r\n\r\nCould not initialize USB Custom Demo App - USB. Halting.\r\n\r\n" ); while (1); } btClientData.State = BT_STATE_IDLE; btClientData.Initialized = FALSE; mPORTAOutputConfig(0x3); mPORTAWrite(0x0); mPORTBOutputConfig(0x10); // OC 1 PPSOutput(PPS_RP4, PPS_OC1); //Enable Interrupt SetPriorityIntOC1(4); EnableIntOC1; OpenTimer2(T2_ON | T2_PS_1_8 ,0xffff); // OpenOC1(OC_IDLE_CON | OC_TIMER2_SRC | OC_PWM_EDGE_ALIGN ,OC_SYNC_TRIG_IN_TMR2,0,0); SetDCOC1PWM(0xc00,0); // Main Processing Loop while (1) { BTClientTasks(); // Maintain USB Host State USBHostTasks(); DelayMs(1); } return 0; } // main
// main int main ( void ) { // Initialize the processor and peripherals. // Init Clock // CPU 32MHz // Peripheral 8MHz CLKDIV = 0x0000; unsigned int pll_startup_counter = 600; CLKDIVbits.PLLEN = 1; while(pll_startup_counter--); // Configure U2RX - put on pin 17 (RP8) RPINR19bits.U2RXR = 8; // Configure U2TX - put on pin 16 (RP7) RPOR3bits.RP7R = 5; // Analog IN Disable AD1PCFG = 0xffff; EnablePullUpCN12; // Port output setup mPORTBOutputConfig(0x8000); // Init UART UART2Init(); // Init USB if ( USBHostInit(0) != TRUE ) { UART2PrintString( "ERR USBHostInit\r\n" ); while (1); } /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_EMBEDDED); // init HCI hci_transport_t * transport = hci_transport_usb_instance(); bt_control_t * control = NULL; hci_uart_config_t * config = NULL; remote_device_db_t * remote_db = NULL;//(remote_device_db_t *) &remote_device_db_memory; hci_init(transport, config, control, remote_db); // init L2CAP l2cap_init(); l2cap_register_packet_handler(bt_packet_handler); // init RFCOMM rfcomm_init(); rfcomm_register_packet_handler(bt_packet_handler); rfcomm_register_service_internal(NULL, rfcomm_channel_nr, 100); // reserved channel, mtu=100 // init SDP, create record for SPP and register with SDP sdp_init(); memset(spp_service_buffer, 0, sizeof(spp_service_buffer)); service_record_item_t * service_record_item = (service_record_item_t *) spp_service_buffer; sdp_create_spp_service( (uint8_t*) &service_record_item->service_record, 1, "SPP"); // printf("SDP service buffer size: %u\n\r", (uint16_t) (sizeof(service_record_item_t) + de_get_len((uint8_t*) &service_record_item->service_record))); sdp_register_service_internal(NULL, service_record_item); // usbhost data_source_t usbhost; usbhost.process = &usbhost_process; run_loop_add_data_source(&usbhost); data_source_t swtask; swtask.process = &sw_process; run_loop_add_data_source(&swtask); // go! run_loop_execute(); return 0; } // main