//----------------------------------------------------------------------------- // Init_Device //----------------------------------------------------------------------------- // // Return Value : None // Parameters : None // // Calls all device initialization functions. // //----------------------------------------------------------------------------- void Init_Device (void) { Watchdog_Init (); // Disable the Watchdog Timer first Oscillator_Init (); Port_Init (); SPI0_Init (); }
void Nrf_Spi0_Init(void) { SPI0_Init(); NRF24l01_CE_Init NRF24l01_CSN_Init NRF24l01_IQR_Init }
void main() { unsigned int i; WDTCN=0xDE; WDTCN=0xAD; SYSCLK_Init(); PORT_Init(); SPI0_Init(); Mp3Reset(); P7 &= ~0x40; for (i = 0; i < 15000; ++i) send_dat(music[i]); flush_buffer(); while(1); }
// init - initialise sensor // initCommAPI parameter controls whether SPI interface is initialised (set to false if other devices are on the SPI bus and have already initialised the interface) boolean initOF() { int retry = 0; digitalWrite(CSPIN,HIGH); // disable device (Chip select is active low) SPI0_Init(); // reset the device //reset(); // check the sensor is functioning if( retry < 3 ) { if( read_register(ADNS3080_PRODUCT_ID) == 0x17 ) return true; retry++; } return false; }
void Peripherals_Init(void) { #ifdef NVIC_AUTOINIT NVIC_Init(); #endif /* NVIC_AUTOINIT */ #ifdef SIM_AUTOINIT SIM_Init(); #endif /* SIM_AUTOINIT */ #ifdef MCM_AUTOINIT MCM_Init(); #endif /* MCM_AUTOINIT */ #ifdef PMC_AUTOINIT PMC_Init(); #endif /* PMC_AUTOINIT */ #ifdef PORTA_AUTOINIT PORTA_Init(); #endif /* PORTA_AUTOINIT */ #ifdef PORTB_AUTOINIT PORTB_Init(); #endif /* PORTB_AUTOINIT */ #ifdef PORTC_AUTOINIT PORTC_Init(); #endif /* PORTC_AUTOINIT */ #ifdef PORTD_AUTOINIT PORTD_Init(); #endif /* PORTD_AUTOINIT */ #ifdef PORTE_AUTOINIT PORTE_Init(); #endif /* PORTE_AUTOINIT */ #ifdef ADC0_AUTOINIT ADC0_Init(); #endif /* ADC0_AUTOINIT */ #ifdef ADC1_AUTOINIT ADC1_Init(); #endif /* ADC1_AUTOINIT */ #ifdef AIPS0_AUTOINIT AIPS0_Init(); #endif /* AIPS0_AUTOINIT */ #ifdef AIPS1_AUTOINIT AIPS1_Init(); #endif /* AIPS1_AUTOINIT */ #ifdef AXBS_AUTOINIT AXBS_Init(); #endif /* AXBS_AUTOINIT */ #ifdef CAN0_AUTOINIT CAN0_Init(); #endif /* CAN0_AUTOINIT */ #ifdef CMP0_AUTOINIT CMP0_Init(); #endif /* CMP0_AUTOINIT */ #ifdef CMP1_AUTOINIT CMP1_Init(); #endif /* CMP1_AUTOINIT */ #ifdef CMP2_AUTOINIT CMP2_Init(); #endif /* CMP2_AUTOINIT */ #ifdef CMT_AUTOINIT CMT_Init(); #endif /* CMT_AUTOINIT */ #ifdef CRC_AUTOINIT CRC_Init(); #endif /* CRC_AUTOINIT */ #ifdef DAC0_AUTOINIT DAC0_Init(); #endif /* DAC0_AUTOINIT */ #ifdef DMAMUX_AUTOINIT DMAMUX_Init(); #endif /* DMAMUX_AUTOINIT */ #ifdef DMA_AUTOINIT DMA_Init(); #endif /* DMA_AUTOINIT */ #ifdef ENET_AUTOINIT ENET_Init(); #endif /* ENET_AUTOINIT */ #ifdef EWM_AUTOINIT EWM_Init(); #endif /* EWM_AUTOINIT */ #ifdef FB_AUTOINIT FB_Init(); #endif /* FB_AUTOINIT */ #ifdef FMC_AUTOINIT FMC_Init(); #endif /* FMC_AUTOINIT */ #ifdef FTFE_AUTOINIT FTFE_Init(); #endif /* FTFE_AUTOINIT */ #ifdef FTM0_AUTOINIT FTM0_Init(); #endif /* FTM0_AUTOINIT */ #ifdef FTM1_AUTOINIT FTM1_Init(); #endif /* FTM1_AUTOINIT */ #ifdef FTM2_AUTOINIT FTM2_Init(); #endif /* FTM2_AUTOINIT */ #ifdef FTM3_AUTOINIT FTM3_Init(); #endif /* FTM3_AUTOINIT */ #ifdef I2C0_AUTOINIT I2C0_Init(); #endif /* I2C0_AUTOINIT */ #ifdef I2C1_AUTOINIT I2C1_Init(); #endif /* I2C1_AUTOINIT */ #ifdef I2C2_AUTOINIT I2C2_Init(); #endif /* I2C2_AUTOINIT */ #ifdef I2S0_AUTOINIT I2S0_Init(); #endif /* I2S0_AUTOINIT */ #ifdef LLWU_AUTOINIT LLWU_Init(); #endif /* LLWU_AUTOINIT */ #ifdef LPTMR0_AUTOINIT LPTMR0_Init(); #endif /* LPTMR0_AUTOINIT */ #ifdef MPU_AUTOINIT MPU_Init(); #endif /* MPU_AUTOINIT */ #ifdef PDB0_AUTOINIT PDB0_Init(); #endif /* PDB0_AUTOINIT */ #ifdef PIT_AUTOINIT PIT_Init(); #endif /* PIT_AUTOINIT */ #ifdef PTA_AUTOINIT PTA_Init(); #endif /* PTA_AUTOINIT */ #ifdef PTB_AUTOINIT PTB_Init(); #endif /* PTB_AUTOINIT */ #ifdef PTC_AUTOINIT PTC_Init(); #endif /* PTC_AUTOINIT */ #ifdef PTD_AUTOINIT PTD_Init(); #endif /* PTD_AUTOINIT */ #ifdef PTE_AUTOINIT PTE_Init(); #endif /* PTE_AUTOINIT */ #ifdef RCM_AUTOINIT RCM_Init(); #endif /* RCM_AUTOINIT */ #ifdef RNG_AUTOINIT RNG_Init(); #endif /* RNG_AUTOINIT */ #ifdef RTC_AUTOINIT RTC_Init(); #endif /* RTC_AUTOINIT */ #ifdef SDHC_AUTOINIT SDHC_Init(); #endif /* SDHC_AUTOINIT */ #ifdef SMC_AUTOINIT SMC_Init(); #endif /* SMC_AUTOINIT */ #ifdef SPI0_AUTOINIT SPI0_Init(); #endif /* SPI0_AUTOINIT */ #ifdef SPI1_AUTOINIT SPI1_Init(); #endif /* SPI1_AUTOINIT */ #ifdef SPI2_AUTOINIT SPI2_Init(); #endif /* SPI2_AUTOINIT */ #ifdef SystemControl_AUTOINIT SystemControl_Init(); #endif /* SystemControl_AUTOINIT */ #ifdef SysTick_AUTOINIT SysTick_Init(); #endif /* SysTick_AUTOINIT */ #ifdef UART0_AUTOINIT UART0_Init(); #endif /* UART0_AUTOINIT */ #ifdef UART1_AUTOINIT UART1_Init(); #endif /* UART1_AUTOINIT */ #ifdef UART2_AUTOINIT UART2_Init(); #endif /* UART2_AUTOINIT */ #ifdef UART3_AUTOINIT UART3_Init(); #endif /* UART3_AUTOINIT */ #ifdef UART4_AUTOINIT UART4_Init(); #endif /* UART4_AUTOINIT */ #ifdef UART5_AUTOINIT UART5_Init(); #endif /* UART5_AUTOINIT */ #ifdef USB0_AUTOINIT USB0_Init(); #endif /* USB0_AUTOINIT */ #ifdef USBDCD_AUTOINIT USBDCD_Init(); #endif /* USBDCD_AUTOINIT */ #ifdef VREF_AUTOINIT VREF_Init(); #endif /* VREF_AUTOINIT */ #ifdef WDOG_AUTOINIT WDOG_Init(); #endif /* WDOG_AUTOINIT */ }
/** * @brief 初始化SD相关的引脚和设备。SD的片选接到PE12 * @param * @retval None */ void SD_SPI_Init(void) { /* 初始化SPI0 */ SPI0_Init(); }
void main (void) { int reflection,LDs_count,omron_count,angel; int old_fix,fix,left,right; unsigned char reflect,status,k; char old_flag,flag; WDTCN = 0xDE; // disable watchdog timer WDTCN = 0xAD; SYSCLK_Init (); // Initialize system clock to 16MHz ExtCrystalOsc_Init (); // switch system clock Port_Init (); // Initialize crossbar and GPIO SPI0_Init(); LED_Init(); // Initialize OLED Sensors_Init(); Rudder_Init(); Motor_Init(); Measurement_Init(); Test_Helper_Init(); EA = 1; // Enable global interrupts CR = 1; // start to output PWM P31 = 1; PUT_LINE("OMRON:",omron_count); PUT_LINE("reflection:",reflection); PUT_LINE("LDs_count:",LDs_count); PUT_LINE("Tunnel1:",tunnel_length[0]); PUT_LINE("Tunnel2:",0); PUT_LINE("Tunnel3:",0); //PUT_LINE("angel:",angel); //PUT_LINE("fix:",fix); while (1) { // Spin forever DIRECTION = 0; PCA0CPH1 = 0xE0; flag = 0; while (1) { // dectecting reflect = get_LD_reflection(); old_flag = flag; flag = 0; // conner emergency if(reflect < 25){ if(!LEFT3 && RIGHT3) flag = 1; if(!RIGHT3 && LEFT3) flag = -1; if(flag) break; } // go straight forward: if(!LEFT1 || !LEFT2 || !LEFT3) flag = 1; if(!RIGHT1 && LEFT2) flag = -1; if(!RIGHT2 && LEFT3) flag = -1; if(!RIGHT3) flag = -1; k = 7; if(reflect > 50){ k = 10; } if(reflect > 85){ if(flag > 0) if(++left > 32766) { left = left - right; right = 0; } if(flag < 0) if(++right > 32766) { right = right - left; left = 0; } old_fix = fix; fix = left - right; if(fix > 20) fix = 20; if(fix < -20) fix = -20; fix = ((fix + RUDDER_FIX) + old_fix)/2; } //UPDATE_VALUE(5,fix); if(MAX_REFLECTION > reflect) angel = MAX_REFLECTION - reflect; else angel = 0; angel = flag * k * angel / 10 + fix; //UPDATE_VALUE(4,angel); set_angel(angel); // debug info omron_count = Get_OMRON_Count(); reflection = get_LD_reflection(); LDs_count = TL1 + LD2_count; UPDATE_VALUE(0,omron_count); UPDATE_VALUE(1,reflection); UPDATE_VALUE(2,LDs_count/3); tmp = tunnel_length[1] * 464 / 1683; UPDATE_VALUE(3,tmp); tmp = tunnel_length[2] * 464 / 1683; UPDATE_VALUE(4,tmp); tmp = tunnel_length[3] * 464 / 1683; UPDATE_VALUE(5,tmp); } reflect = get_LD_reflection(); if(reflect < 10){ // 60 degree PCA0CPH1 = 0xB8; set_angel(flag * 127); Clear_OMRON_Count(); while(omron_count <= 300); while(1){ if(flag > 0 && !LEFT1) { while(!RIGHT1); break; } if(flag < 0 && !RIGHT1) { while(!LEFT1); break; } } }else{ // 90 degree DIRECTION = 1; PCA0CPH1 = 0x38; Clear_OMRON_Count(); set_angel(-flag * 127); while(1){ omron_count = Get_OMRON_Count(); UPDATE_VALUE(0,omron_count); if(omron_count >= 410) //1062 break; } DIRECTION = 0; PCA0CPH1 = 0xB8; //Clear_OMRON_Count(); set_angel(flag * 127); // escape from conner while(1){ if(flag > 0 && !LEFT1){ while(!RIGHT1); break; } if(flag < 0 && !RIGHT1){ while(!LEFT1); break; } // if } // while } // if else: 60 or 90 degree } // main loop } // main
void Peripherals_Init(void) { #ifdef NVIC_AUTOINIT NVIC_Init(); #endif /* NVIC_AUTOINIT */ #ifdef SIM_AUTOINIT SIM_Init(); #endif /* SIM_AUTOINIT */ #ifdef MCM_AUTOINIT MCM_Init(); #endif /* MCM_AUTOINIT */ #ifdef PMC_AUTOINIT PMC_Init(); #endif /* PMC_AUTOINIT */ #ifdef PORTA_AUTOINIT PORTA_Init(); #endif /* PORTA_AUTOINIT */ #ifdef PORTB_AUTOINIT PORTB_Init(); #endif /* PORTB_AUTOINIT */ #ifdef PORTC_AUTOINIT PORTC_Init(); #endif /* PORTC_AUTOINIT */ #ifdef PORTD_AUTOINIT PORTD_Init(); #endif /* PORTD_AUTOINIT */ #ifdef PORTE_AUTOINIT PORTE_Init(); #endif /* PORTE_AUTOINIT */ #ifdef ADC0_AUTOINIT ADC0_Init(); #endif /* ADC0_AUTOINIT */ #ifdef ADC1_AUTOINIT ADC1_Init(); #endif /* ADC1_AUTOINIT */ #ifdef CMP0_AUTOINIT CMP0_Init(); #endif /* CMP0_AUTOINIT */ #ifdef CMP1_AUTOINIT CMP1_Init(); #endif /* CMP1_AUTOINIT */ #ifdef CRC_AUTOINIT CRC_Init(); #endif /* CRC_AUTOINIT */ #ifdef DAC0_AUTOINIT DAC0_Init(); #endif /* DAC0_AUTOINIT */ #ifdef DMAMUX_AUTOINIT DMAMUX_Init(); #endif /* DMAMUX_AUTOINIT */ #ifdef DMA_AUTOINIT DMA_Init(); #endif /* DMA_AUTOINIT */ #ifdef EWM_AUTOINIT EWM_Init(); #endif /* EWM_AUTOINIT */ #ifdef FTFA_AUTOINIT FTFA_Init(); #endif /* FTFA_AUTOINIT */ #ifdef FTM0_AUTOINIT FTM0_Init(); #endif /* FTM0_AUTOINIT */ #ifdef FTM1_AUTOINIT FTM1_Init(); #endif /* FTM1_AUTOINIT */ #ifdef FTM2_AUTOINIT FTM2_Init(); #endif /* FTM2_AUTOINIT */ #ifdef GPIOA_AUTOINIT GPIOA_Init(); #endif /* GPIOA_AUTOINIT */ #ifdef GPIOB_AUTOINIT GPIOB_Init(); #endif /* GPIOB_AUTOINIT */ #ifdef GPIOC_AUTOINIT GPIOC_Init(); #endif /* GPIOC_AUTOINIT */ #ifdef GPIOD_AUTOINIT GPIOD_Init(); #endif /* GPIOD_AUTOINIT */ #ifdef GPIOE_AUTOINIT GPIOE_Init(); #endif /* GPIOE_AUTOINIT */ #ifdef I2C0_AUTOINIT I2C0_Init(); #endif /* I2C0_AUTOINIT */ #ifdef LLWU_AUTOINIT LLWU_Init(); #endif /* LLWU_AUTOINIT */ #ifdef LPTMR0_AUTOINIT LPTMR0_Init(); #endif /* LPTMR0_AUTOINIT */ #ifdef PDB0_AUTOINIT PDB0_Init(); #endif /* PDB0_AUTOINIT */ #ifdef RCM_AUTOINIT RCM_Init(); #endif /* RCM_AUTOINIT */ #ifdef SMC_AUTOINIT SMC_Init(); #endif /* SMC_AUTOINIT */ #ifdef SPI0_AUTOINIT SPI0_Init(); #endif /* SPI0_AUTOINIT */ #ifdef SystemControl_AUTOINIT SystemControl_Init(); #endif /* SystemControl_AUTOINIT */ #ifdef SysTick_AUTOINIT SysTick_Init(); #endif /* SysTick_AUTOINIT */ #ifdef UART0_AUTOINIT UART0_Init(); #endif /* UART0_AUTOINIT */ #ifdef UART1_AUTOINIT UART1_Init(); #endif /* UART1_AUTOINIT */ #ifdef WDOG_AUTOINIT WDOG_Init(); #endif /* WDOG_AUTOINIT */ }