void main(void) { Sys_Init(); //All init function putchar(' '); XBR0_Init(); ADC_Init(); Port_Init(); PCA_Init(); SMB_Init(); //end the init function lcd_clear(); lcd_print("initializing\r\n"); printf("\n\n\n\rinitalizing"); PCA0CP2 = 0xFFFF - MOTOR_NEUT;//set all to neutural PCA0CPL0 = 0xFFFF - PW_CENTER; PCA0CPH0 = (0xFFFF - PW_CENTER) >> 8; pause(); //pause for a second? start_run(); while (1) { while(SS){ // if the slideswitch is off slide_switch_off(); }///end slide switch off while(!SS){ //while the slideswitch is on Heading(); Ranger(); LCD_Print(); //print all values on the lcd printf("\n\rRange:%d Compass:%d dh: %d, mPW: %d, sPW %d, batt:%d, obst: %d", range, heading, desired_heading, MOTOR_PW_AND_STEER_PW, STEER_PW, battery, near_obstical); //print these on the secure crt for data aquisition //printf("\n\r Range:%d Compass:%d dh: %d, mPW: %d, sPW %d, obst: %d", range, heading, desired_heading, MOTOR_PW_AND_STEER_PW, STEER_PW, near_obstical); //print these on the secure crt for data aquisition }//end slide switch on } //end of the infinite while loop }//end of the main function
//----------------------------------------------------------------------------- // 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 (); }
//----------------------------------------------------------------------------- // Main Function //----------------------------------------------------------------------------- void main(void) { int heading = 0; // initialize board Sys_Init(); putchar(' '); //the quotes in this line may not format correctly Port_Init(); XBR0_Init(); PCA_Init(); SMB0CR = 0x93; // set the frequency of the i2c bus to 95.41 kHz ENSMB = 1; //enable the SMBus //print beginning message //printf("Embedded Control Steering Calibration\n"); //calibrate_steering(); //printf("\rCalibrated\n"); while(1){ //Steering_Servo(); //printf("H = %d\n",h_counts); if(h_counts%2){ //printf("We are in %d", h_counts); heading = read_compass(); } if(!h_counts){ printf("\rThe Heading is: %u\n", heading); //print the heading } //else{printf("\rthis is h_coutn %d\n",h_counts);} } }
// 3. Subroutines Section // MAIN: Mandatory for a C Program to be executable int main(void){ PLL_Init(); // 80 MHz // initialize output and interrupts SysInit(); Port_Init(); // EnableInterrupts(); /*Initialize ports and timers*/ while(1) { for(j=80000;j<=160000;j=j+8000) { for(k=0;k<=3;k++) { GPIO_PORTA_DATA_R|=0x20; SysLoad(j); GPIO_PORTA_DATA_R&=~(0x20); SysLoad(1600000-j); } } } }
BYTE SD_Init(){//SD卡初始化函数,成功返回0,失败则返回非0 BYTE i; BYTE cnt = 0; BYTE rtn = 0; Port_Init();//初始化引脚 SPI_SetSpeedLow();//SPI初始化,设定为低速 do{ for(i=0;i<10;i++) SPI_ByteRW(0xFF); rtn=SD_SendCommand(0,0);//发idle命令 if((cnt++)==0xFF) return 1;//超时退出 }while(rtn!=0x01); cnt=0;//清零重试计数器 do{ rtn=SD_SendCommand(1,0);//发active命令 if((cnt++)==0xFF) return 2;//超时退出 }while(rtn); SPI_SetSpeedHigh();//设定SPI到高速模式 SD_SendCommand(59,0);//禁用CRC SD_SendCommand(16,512);//设定扇区大小为512 return 0;//初始化成功 }
void Menu_Init(void) { Disp_Init(); //display init Port_Init(); //port init Keyboard_Init(); //keyboard init #ifdef LCD1602 Meter_Init(); //level meter init #endif if(ESignature != SIGNATURE) //check EEPROM signature, if error, init params: { for(char i = 0; i < PARAMS; i++) Par[i] = ParLim[i][P_NOM]; ParToEEPROM(); //params init for(char i = 0; i < MODES; i++) EScale[i] = SCALE_NOM + AUTO_SCALE; //scales init } else { for(char i = 0; i < PARAMS; i++) Par[i] = EPar[i]; //read params from EEPROM } SetupCounter(); Count_Start(); //start counter DispMenu = MNU_NO; //no menu Hold = 0; //no hold mode Hide = 0; //display not hided Menu = MNU_SPLASH; //go to splash screen menu }
void Init_Dev(void) { setbusclock(); Port_Init(); SCI_Init(); PWM_Init(); }
//----------------------------------------------------------------------------- // System_Init(void) //----------------------------------------------------------------------------- // // Return Value - None // Parameters - None // // This top-level initialization routine calls all support routine. // // ---------------------------------------------------------------------------- void System_Init (void) { PCA0MD &= ~0x40; // Disable Watchdog timer PCA0MD = 0x00; Sysclk_Init (); // initialize system clock Port_Init (); // configure cross bar }
void main(void) { Sys_Init(); putchar(' '); XBR0_Init(); SMB_Init(); PCA_Init(); Drive_Init(); Port_Init(); ADC_Init(); ranger_pd_init(); //fan angle initialization code goes here while(1) { voltage_update(); if(SS) { Range_Update(); //update the range Drive_Motor(ranger_pd()); } else Drive_Motor(PW_NEUT); //if ss is not flipped, put it in neutral } }
void main(void) { PCA0MD &= ~0x40; OSCILLATOR_Init (); Port_Init(); Ext_Interrupt_Init( ); WR_CONTROL_PIN=1; Tft_Init( ); TftClear(BLACK); TftWR_Str(60,70,"C8051F330 Camera",RED,BLACK); TftWR_Str(60,100,"QI FEI DIAN ZI VER1.0",RED,BLACK); TftWR_Str(60,130,"OV7670 Initializing......",RED,BLACK); delay_ms(3000); while(1!=Cmos7670_init()); delay_ms(3000); TftClear(BLACK); TftWR_Str(60,110,"OV7670 Init SUCCESS! ",RED,BLACK); delay_ms(5000); TftClear(BLACK); EA = 1; while(1); }
//******************************************************************** // Main Functions //******************************************************************** void main(void) { //Main function Sys_Init(); // initialize board putchar(' '); //the quotes in this line may not format correctly Port_Init();//Init ports XBR0_Init();//init xbro PCA_Init();//init pca SMB_Init();//init smb printf("\r\n\n\n\nEmbedded Control Electric Compass and Ranger\n"); //print beginning message Calibration();//Run calibration comp_cal(); //Compass calibration Choose_heading(); //Heading choice printf("\r\nheading error"); while(1) { //inf loop, 40 ms it returns the heading if (new_heading){ //enough overflows for a new heading COMPASS STUFF new_heading = 0;//Clear new_heading heading = ReadCompass(); //get compass heading Steering_Servo(); //run steer func }//end if new heading if (new_range) { //if 80 ms has passed new_range=0;//Clear new_range range=ReadRanger();//read ranger start_ping();//start ping counts++;//set up text function Drive_Motor(); //run drive func }//end if new_range if (counts == 3){ //prevoudly output prined every 200 ms, now every 180 ms print_output();//Print data function. Delete this if faster output is desired }//end if counts }//end inf while }//end main
void main(void) { Sys_Init(); //All init function putchar(' '); XBR0_Init(); ADC_Init(); Port_Init(); PCA_Init(); SMB_Init(); //end the init function lcd_clear(); lcd_print("initializing\r\n"); PCA0CP2 = 0xFFFF - MOTOR_NEUT; PCA0CPL0 = 0xFFFF - PW_CENTER; PCA0CPH0 = (0xFFFF - PW_CENTER) >> 8; while (n_Counts < 50); //pause for a second? start_run(); while (1) { while(SS){ // if the slideswitch is off slide_switch_off(); }///end slide switch off while(!SS) //while the slideswitch is on { Heading(); Ranger(); LCD_Print(); //print all values on the lcd printf("\n\r Range:%d Compass:%d PW:%d", range, heading, PW); //print these on the secure crt for data aquisition } } //end of the infinite while loop }//end of the main function
// 3. Subroutines Section // MAIN: Mandatory for a C Program to be executable int main(void){ PLL_Init(); // 80 MHz Port_Init(); ADC0_InitSWTriggerSeq3_Ch1(); EnableInterrupts(); SysFun(); /*Initialize ports , ADC and timers*/ while(1){ /*Your code goes here*/ a= ADC0_InSeq3(); t1=a+(10000/4096)+10000; in1=50; while(in1) { GPIO_PORTA_DATA_R |= (0x20); SysLoad(t1); GPIO_PORTA_DATA_R &= ~(0x20); SysLoad(t-t1); in1=in1-1; } } }
//----------------------------------------------------------------------------- // DBG_Reset //----------------------------------------------------------------------------- // // This function returns all debug pins to a neutral state: // 1. Disconnects from the target. // 2. Resets all I/O pins. // // void DBG_Reset(void) { SWD_Connect(); // Reset all I/O ports Port_Init(); // We are disconnecting, so release nSRST _ReleaseTargetReset; }
//------------------------------------------------------ // Инициализация //------------------------------------------------------ void Init_Hardware(void) { // NVIC - смещаем таблицу векторов прерываний (начало памяти программ) SCB->VTOR = 0x08000000; // Инициализация скорости работы МК Oscillator_int(); // Инициализация PORT Port_Init(); // __enable_irq(); }
void main(void) { // initialize board Sys_Init(); putchar(' '); //the quotes in this line may not format correctly Port_Init(); PCA_Init(); SMB_Init(); Interrupt_Init(); printf("Starting\n\r"); //print beginning message printf("Embedded Control Drive Motor Control\r\n"); // Initialize motor in neutral and wait for 1 second MOTOR_PW = PW_NEUT; motorPW = 0xFFFF-MOTOR_PW; PCA0CPL2 = motorPW; PCA0CPH2 = motorPW>>8; printf("Pulse Width = %d\r\n",MOTOR_PW); c = 0; while (c < 50); //wait 1 second in neutral printf("end wait \r\n"); //Main Functionality while (1) { if (!SS1) { // If the slide switch is active, set PW to center PW = PWCENTER; PCA0CP0 = 0xFFFF - PW; // Update comparator with new PW value while (!SS1); // Wait... } else if (take_heading) { // Otherwise take a new heading reading = Read_Compass(); // Get current heading printf("%d\n\r", reading); Steering_Servo(reading); // Change PW based on current heading PCA0CP0 = 0xFFFF - PW; // Update comparator with new PW value } if (getRange) { getRange = 0; // Reset 80 ms flag range_val = read_ranger(); // Read the distance from the ranger printf("Range: %d cm \r\n", range_val); printf("Pulse Width: %d \r\n", MOTOR_PW); // Start a new ping Data[0] = 0x51; // write 0x51 to reg 0 of the ranger: i2c_write_data(addr, 0, Data, 1); // write one byte of data to reg 0 at addr } if (SS0) Drive_Motor(range_val); else Drive_Motor(45); // Hold the motor in neutral if the slide switch is off } }
//--------------------------------INIT---------------------------------// void sys_init()// Interrupt & Port { /* enable interrupt */ rINTMOD=0x0; rINTCON=0x1; rI_ISPC = 0xffffffff; /* clear all interrupt pend */ rEXTINTPND = 0xf; // clear EXTINTPND reg Port_Init(); /* Initial 44B0X's I/O port */ Delay(0); /* delay time */ rINTMSK = ~(BIT_GLOBAL); // Emascara todas las lineas excepto bit global }
void TargetInit(void) { int i; U8 key; U32 mpll_val=0; #if ADS10 __rt_lib_init(0,0); //for ADS 1.0 #endif i = 2 ; //use 400M! switch ( i ) { case 0: //200 key = 12; mpll_val = (92<<12)|(4<<4)|(1); break; case 1: //300 key = 14; mpll_val = (67<<12)|(1<<4)|(1); break; case 2: //400 key = 14; mpll_val = (92<<12)|(1<<4)|(1); break; case 3: //440!!! key = 14; mpll_val = (102<<12)|(1<<4)|(1); break; default: key = 14; mpll_val = (92<<12)|(1<<4)|(1); break; } //init FCLK=400M ChangeClockDivider(key, 12); ChangeMPllValue((mpll_val>>12)&0xff, (mpll_val>>4)&0x3f, mpll_val&3); //MMU_EnableICache(); //MMU_EnableDCache(); MMU_DisableICache(); MMU_DisableDCache(); Port_Init(); MMU_Init(); Delay(0); Uart_Init(0,115200); Uart_Select(0); Uart_SendString("Board init complete.\n"); }
void Main(void) { //硬件初始化 var_Init();//初始化定时器相关的参数 Port_Init();//IO端口初始化 Isr_Init();//中断初始化 Uart_Init(0,115200);//串口初始化 Uart_Select(0); _init_alloc(0x32500000,0x333fffff);//初始化堆地址:15M,使能malloc等存储分配函数 setlocale(LC_ALL,"C");//使能本地函数,如sprintf等 Timer4_Init(); lcdTest(); }
void Main(void) { Port_Init(); //IO端口初始化 Isr_Init(); //中断初始化 Uart_Init(0,115200);//串口初始化 Uart_Select(0); Uart_Printf("\n\nDM2410 Experiment System (ADS) Ver1.10\n") ;//打印系统信息 Test_SDI(); }
void sys_init()// Interrupt,Port and UART { /* enable interrupt */ rINTMOD=0x0; rINTCON=0x1; rI_ISPC = 0xffffffff; /* clear all interrupt pend */ rEXTINTPND = 0xf; // clear EXTINTPND reg Port_Init(); /* Initial 44B0X's I/O port */ LED8ADDR = 0 ; Led_Display(0xf); Delay(0); /* delay time */ Uart_Init(0,115200); /* Initial Serial port 1 */ }
int main(void){ TExaS_Init(SW_PIN_PE210, LED_PIN_PB543210,ScopeOff); // activate grader and set system clock to 80 MHz EnableInterrupts(); Port_Init(); SysTick_Init(); S = GoWest; while(1){ GPIO_CarLED = FSM[S].CarLED; // set Car LED GPIO_WalkLED = FSM[S].WalkLED; // set Walk LED SysTick_Wait10ms(FSM[S].Time); Input = GPIO_Sensor; // read sensors S = FSM[S].Next[Input]; } }
void main() { char gear = 0; Port_Init(); while(1) { if (input(UP_SHIFT_PADDLE)) { Shift(UP_SHIFT_AIR); gear++; } if (input(DOWN_SHIFT_PADDLE)) { Shift(DOWN_SHIFT_AIR); gear--; } } }
int main(void) { HAL_Init(); // инит. Flash и Systick. SystemClock_Config(); // когфиг осциллятора. GPIO_Init(); // конфиг портов. Clocks_Init(); // конфиг часов. BOOT_UART_Init(115200); // настройка BOOT интерфейса. USART_TRACE("------------------------------------\n"); USART_TRACE("BOOT_Init.. ok\n"); RS485_1_UART_Init(115200); // настройка RS485 1 канала. USART_TRACE("RS485_1_UART_Init.. ok\n"); RS485_2_UART_Init(115200); // настройка RS485 2 канала. USART_TRACE("RS485_2_UART_Init.. ok\n"); // тут нужно получить параметры системы от головного(MODBUS) скорости, адреса, порты.... Port_Init(LED1,GPIO_MODE_OUTPUT_PP); Port_Init(LED2,GPIO_MODE_OUTPUT_PP); Port_Init(LED3,GPIO_MODE_OUTPUT_PP); Port_Init(LED4,GPIO_MODE_OUTPUT_PP); Port_Init(MODBUS_DEn,GPIO_MODE_INPUT); // пока не используем FREERTOS_Init(); // инит. FREERTOS. osKernelStart(); // Старт планировщика while (1) { } return 0; }
//----------------------------------------------------------------------------- // Main Routine //----------------------------------------------------------------------------- void main(void) { USB_Clock_Start(); // Init USB clock *before* calling USB_Init USB_Init(USB_VID,USB_PID,USB_MfrStr,USB_ProductStr,USB_SerialStr,USB_MaxPower,USB_PwAttributes,USB_bcdDevice); CLKSEL |= 0x02; RSTSRC |= 0x02; Port_Init(); // Initialize crossbar and GPIO USB_Int_Enable(); // Enable USB_API Interrupts while (1); }
void TargetInit(void) { int i; U8 key; U32 mpll_val=0; i = 2 ; //use 400M! switch ( i ) { case 0: //200 key = 12; mpll_val = (92<<12)|(4<<4)|(1); break; case 1: //300 key = 14; mpll_val = (67<<12)|(1<<4)|(1); break; case 2: //400 key = 14; mpll_val = (92<<12)|(1<<4)|(1); break; case 3: //440!!! key = 14; mpll_val = (102<<12)|(1<<4)|(1); break; default: key = 14; mpll_val = (92<<12)|(1<<4)|(1); break; } //init FCLK=400M, so change MPLL first ChangeMPllValue((mpll_val>>12)&0xff, (mpll_val>>4)&0x3f, mpll_val&3); ChangeClockDivider(key, 12); MMU_DisableICache(); MMU_DisableDCache(); Port_Init(); MMU_Init(); _init_alloc(0x17fe000, 0x17ff000);/*分配堆的起始地址和结束地址,4k的空间*/ Delay(0); Uart_Init(0,115200); Uart_Select(0); Uart_SendString("Board init complete.\n"); }
/** @brief UART, SPI, I2C, GPIO initialization @return none **/ void Test_Init(void) { if(FUNCTION_TO_TEST == SPI) { /* Check if SPI is tested */ SPI_Init(); /* SPI initialization */ } else if(FUNCTION_TO_TEST == UART) { /* Check if UART is tested */ UART_Init(B9600, COMLCR_WLS_8BITS); /* UART initialization: 9600 baud rate and 8 bits data */ } else if(FUNCTION_TO_TEST == I2C) { /* Check if I2C is tested */ I2C_Init(); /* I2C initialization */ } else if(FUNCTION_TO_TEST == GPIO) { /* Check if GPIO is tested */ Port_Init(); } }
void sys_init()// Interrupt,Port and UART { Port_Init(); /* Initial 44B0X's I/O port */ /* enable interrupt */ rINTMOD=0x0; rINTCON=0x1; rEXTINT = 0x22222222; // level mode rI_ISPC = 0xffffffff; /* clear all interrupt pend */ rEXTINTPND = 0xf; // clear EXTINTPND reg LED8ADDR = 0 ; Delay(0); Led_Display(0xf); Uart_Init(0,115200); /* Initial Serial port 1 */ }
void main (void) { // Disable watchdog timer WDTCN = 0xde; WDTCN = 0xad; Port_Init (); // Initialize crossbar and GPIO Oscillator_Init (); // Initialize oscillator PCA0_Init (); // Initialize PCA0 EA = 1; // Globally enable interrupts while (1); // Spin here to wait for ISR { } // end of while(1) }
//----------------------------------------------------------------------------- // main() //----------------------------------------------------------------------------- void main(void) { U32 transfer_data; WDT_Init(); Oscillator_Init(); Port_Init(); // These pins are grounded on the CoreSight debug connector P1_4 = 0; P1_2 = 0; // There is no debug port connection at this point DP_Type = DP_TYPE_NONE; SWD_Initialize(); SWD_Configure(DP_TYPE_SWD); SWD_Connect(); transfer_data = 0x00000000; // Read the IDCODE from the connected device SWD_DAP_Move(0, DAP_IDCODE_RD, &transfer_data); // The return value from DAP_IDCODE_RD for SiM3U1xx devices is 0x2BA01477 // Write the CTRLSTAT register to enable the debug hardware transfer_data = 0x50000000; SWD_DAP_Move(0, DAP_CTRLSTAT_WR, &transfer_data); SWD_ClearErrors(); connect_and_halt_core(); programming_sram(); transfer_data = 0x00000000; SWD_DAP_Move(0, DAP_CTRLSTAT_WR, &transfer_data); SWD_Disconnect(); while (1) { } }