void Main() { // Initialize the system: sys_init(); InitializeSystem(); // Initialize the output: TurnOnLCD(); Set8Led(0); // Initialize the data: InitializeGame(); // Initialize the input: SetOnKeyboardDown(OnKeyboardDown); InitializeKeyboardInterrupts(); SetOnButtonDown(OnButtonDown); SetOnButtonUp(OnButtonUp); InitializeButtonsInterrupts(); // Initialize the timers: SimpleInitializeTimerInterrupts(TIMER_ID0, MAX_TIME_COUNT, (unsigned)UpdateOnTimer); // Initialize the UART1: InitializeUART(BAUDS_115200); //ActivateInterruptsUART1((unsigned)OnReceiveUART); // Call the main loop: MainLoopWithPolling(); }
void InitializeUCSlave(void){ InitializeUART(); InitializeTime(); InitializeServo(); InitializeWatchdog(); InitializeVelocityControl(); //InitializeIMU(); EnableSensorFeedbackMessages = 0; }
// initialize hardware void Initialize() { // All of these items will affect the performance of your code and cause it to run significantly slower than you would expect. SYSTEMConfigPerformance(SYS_CLOCK); WriteCoreTimer(0); // Core timer ticks once every two clocks (verified) // set default digital port A for IO DDPCONbits.JTAGEN = 0; // turn off JTAG DDPCONbits.TROEN = 0; // ensure no tracing on //mPORTASetPinsDigitalOut(BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7); // todo - set this based on width of image. make rest inputs? mPORTBSetPinsDigitalOut(BIT_0|BIT_1|BIT_2|BIT_3|BIT_4|BIT_5|BIT_6|BIT_7|BIT_8|BIT_9|BIT_10|BIT_11|BIT_12|BIT_13|BIT_14|BIT_15); // Configure the device for maximum performance but do not change the PBDIV // Given the options, this function will change the flash wait states, RAM // wait state and enable prefetch cache but will not change the PBDIV. // The PBDIV value is already set via the pragma FPBDIV option above.. int pbClk = SYSTEMConfig( SYS_CLOCK, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE); InitializeUART(pbClk); mPORTASetPinsDigitalOut(BIT_1); // set internals // SetUARTClockDivider(flashOptions.baudDivisor); // prepare 32 bit timer 45 to trigger interrupts //OpenTimer45(T45_ON | T45_SOURCE_INT | T45_PS_1_1, interruptTime); // set up the timer interrupt and priority //ConfigIntTimer45(T4_INT_ON | T4_INT_PRIOR_7); // enable multivectored interrupts //INTEnableSystemMultiVectoredInt(); // start watchdog timer //tickle in interrupt, turn off during reset of device, causes a reset //The next statement enables the Watchdog Timer: // WDTCONbits.ON = 1; //sprintf(text,"Wait states %d\r\n.",BMXCONbits.BMXWSDRM); //PrintSerial(text); //BMXCONbits.BMXWSDRM = 0; // set RAM access to zero wait states //sprintf(text,"TODO _ REMOVE:override %d\r\n",pinOverride); //PrintSerial(text); //sprintf(text,"TODO _ REMOVE:actual %d\r\n",PORTAbits.RA1); //PrintSerial(text); }
int DasaRobot_MobilityUltrasonic::Initialize(Property parameter) { if(InitializeUART(parameter) != API_SUCCESS) { PrintMessage("ERROR : DasaRobot_MobilityUltrasonic::Initialize() -> Occur a error in InitializeUART().\n"); return API_ERROR; } if(SetParameter(parameter) != API_SUCCESS) { return API_ERROR; } return API_SUCCESS; }
int Robotis_DynamixelUART::Initialize(Property parameter) { if(InitializeUART(parameter) != API_SUCCESS) { PrintMessage("ERROR : Robotis_DynamixelUART::Initialize() -> Occur a error in InitializeUART().\n"); return API_ERROR; } if(SetParameter(parameter) != API_SUCCESS) { return API_ERROR; } return API_SUCCESS; }
int KITECH_SDM8::Initialize(Property parameter) { if(InitializeUART(parameter) != API_SUCCESS) { PrintMessage("ERROR : KITECH_SDM8::Initialize() -> Can't initialize a UART API\n"); return API_ERROR; } if(SetParameter(parameter) != API_SUCCESS) { PrintMessage("ERROR : KITECH_SDM8::Initialize() -> Can't setup a parameter\n"); return API_ERROR; } return API_SUCCESS; }
static UARTError __init_uart_console(void) { UARTError err = kUARTNoError; static int_t initialized = 0; if (initialized == 0) { err = InitializeUART( UART_CONSOLE_BAUD_RATE ); if (err == kUARTNoError) { initialized = 1; } } return( err ); }
// The following function sets up the LM4F to use RASLib void InitializeMCU(void) { // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. FPULazyStackingEnable(); // Set the clocking to run from PLL, using external oscillator SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); //Initialize System Timer InitializeSystemTime(); //Initialize GPIO Interrupt Handlers InitializeGPIO(); //Initialize UART for communication InitializeUART(115200); //Enable global interrupts IntMasterEnable(); }
int main(void) { //Local Variables bool displayMode = true;//True if display mode, false if in data entry mode //Push buttons bool upPB = false; bool rightPB = false; bool downPB = false; bool leftPB = false; bool modePB = false; //Push buttons shift registers uint16_t shiftRegSW2 = 0xFFFF; uint16_t shiftRegSW3 = 0xFFFF; uint16_t shiftRegSW4 = 0xFFFF; uint16_t shiftRegSW5 = 0xFFFF; uint16_t shiftRegSW6 = 0xFFFF; //Initial display message uint8_t displayArray [SAVED_MSG_LEN_MAX] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; uint8_t inputArray [17] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; //Mark the indexcies of the array uint8_t endIndex = 19; uint8_t currIndex = 0; uint8_t inputIndex = 0; uint8_t tempIndex = 0; //Flag for overflwoing max char array length bool overflow = false; //Init color uint8_t color; //ADCval1 uint32_t ADCval1 = 0; uint32_t ADCval2 = 0; //Current string char myString[21] = "hello world"; char myChar; int8_t stringIndex=-1; // Initialize the PLLs so the the main CPU frequency is 80MHz PLL_Init(); //Configure Port C initPortC(); //Configure the SYSTICK timer 12.5uS ticks SYSTICKConfig(1000, true); //Configure Timer0 1mS ticks TIMER0Config(80000); //Configure watchdog with 1s reset WatchdogTIMERConfig(); // Initialize the GPIO Ports initializeGPIOPort(PORTA, &portA_config); initializeGPIOPort(PORTB, &portB_config); initializeGPIOPort(PORTC, &portC_config); initializeGPIOPort(PORTD, &portD_config); initializeGPIOPort(PORTE, &portE_config); initializeGPIOPort(PORTF, &portF_config); // Initialize SPI0 interface initializeSPI(SSI0, PHASE, POLARITY); //Init ADC ADCInit(); initializeDisplay(); // Set up the UARTS for 115200 8N1 InitializeUART(UART0); InitializeUART(UART2); InitializeUART(UART5); // Since PD7 is shared with the NMI, we need to clear the lock register and // set the commit register so that all the pins alternate functions can // be used. GPIO_PORTD_LOCK_R = 0x4C4F434B; GPIO_PORTD_CR_R = 0xFF; initializeGPIOPort(PORTD, &portD_config); EnableInterrupts(); //Get initial ADC values pwm = GetADCval(POT_RIGHT) / 40; ADCval2 = GetADCval(POT_LEFT) / 575; // Print out the current string uartTxPoll(UART0,"Hello World\n\r"); while(1) { if(checkADC){ pwm = GetADCval(POT_RIGHT) / 40; ADCval2 = GetADCval(POT_LEFT) / 600; checkADC = false; } //On systick interrupt display the current character and poll the buttons if (refreshLED){ if (displayMode){ displayLEDChar(displayArray[currIndex], ADCval2); } else{ displayLEDChar(inputArray[inputIndex], ADCval2); } refreshLED = false; } if (buttonPoll){ //Check if any buttons have been pushed //If so debounce them buttonPoll = false; //SW2 shiftRegSW2 = debounce(PORTA, SW2, shiftRegSW2); upPB = checkPB(shiftRegSW2); //SW3 shiftRegSW3 = debounce(PORTA, SW3, shiftRegSW3); rightPB = checkPB(shiftRegSW3); //SW4 shiftRegSW4 = debounce(PORTD, SW4, shiftRegSW4); downPB = checkPB(shiftRegSW4); //SW5 shiftRegSW5 = debounce(PORTD, SW5, shiftRegSW5); leftPB = checkPB(shiftRegSW5); //SW6 shiftRegSW6 = debounce(PORTF, SW6, shiftRegSW6); modePB = checkPB(shiftRegSW6); }//End polling //Display Mode if (displayMode){ //Check if right button is pressed if(rightPB){ //Clear the button press rightPB = false; //Display the next character in order in green color = GREEN_EN; if(currIndex == endIndex) currIndex = 0; else currIndex++; } //Check if left button is pressed else if(leftPB){ //Clear the button press leftPB = false; //Display the next character in reverse order in red color = RED_EN; if(currIndex == 0) currIndex = endIndex; else currIndex--; } //Check if mode button is pushed if(modePB){ //Clear the button press modePB = false; //change mode and reset parameters displayMode = false; inputIndex = 0; currIndex = 0; endIndex = 0; overflow = false; tempIndex = 0; displayArray[0] = 0; } } //Input Mode else{ //Check if right button is pressed if(rightPB || leftPB){ //Clear the button press rightPB = false; leftPB = false; //Save the current input character in the display array if //there is enough space if (tempIndex >= SAVED_MSG_LEN_MAX){ tempIndex= 0; overflow = true; } displayArray[tempIndex] = inputArray[inputIndex]; tempIndex++; } //Check if up button is pressed else if(upPB){ //Clear the button press upPB = false; //Display the next character in order in input array if(inputIndex == 15) inputIndex = 0; else inputIndex++; } //Check if down button is pressed else if(downPB){ //Clear the button press downPB = false; //Display the next character in reverse order input array if(inputIndex == 0) inputIndex = 15; else inputIndex--; } if(modePB){ //Clear the button press modePB = false; //change mode to display and reset parameters displayMode = true; color = GREEN_EN; if(overflow){ endIndex = SAVED_MSG_LEN_MAX - 1; } else if (tempIndex != 0) endIndex = tempIndex - 1; } } } }
void firmware() { int i; char bufmgk[20]; int idxMgk = 0; FILE *pf; /* Thread code to be added here */ vos_delay_msecs(4000); // 4 second delay for USB key to boot open_drivers(); InitializeUART(); flash_init(); InitializeHID(); printf("DekaBoard Rev: 1B\n"); vfWriteFlash = 0; PROGRAM: if (FOpenUSBKey()) { pf = fopen("deka.svf", "r"); if (pf != NULL) { ProgramFPGA(pf); fclose(pf); } CloseUSBKey(); } else { ProgramFPGA(FILE_FLASH); } while(1) { char tmp; // First check if PROG button pressed vos_dev_read(hGPIO_PORT_B, &tmp, 1, NULL); if (!(tmp & 0x20)) goto PROGRAM; // Else handle input if (FUartData()) { fread(bufmgk, 1, 1, stdin); if (bufmgk[0] == STR_MAGIC[idxMgk]) { idxMgk++; } else { idxMgk = 0; } if(idxMgk == 20) { fwrite(UART_ACK, 1, 3, stdout); fgets(bufmgk, 20, stdin); if (strcmp(bufmgk, "PROG XSVF") == 0) { fgets(bufmgk, 20, stdin); vfWriteFlash = (strcmp(bufmgk, "FLASH") == 0); fwrite(UART_ACK, 1, 3, stdout); ProgramFPGA(stdin); vfWriteFlash = 0; printf("DONE\n"); } else { printf(UART_NACK); } idxMgk = 0; } } } }
int main(void){ char i; unsigned char data[16]; short wiichuck[7], xinit=0, yinit=0, l_vel, r_vel; int xpow, ypow; LockoutProtection(); InitializeMCU(); InitializeUART(); InitializeI2C(); InitializeServos(); SetServoPosition(SERVO_0, 140); InitializeMotors(true, false); InitializeEncoders(true, false); // UARTprintf("Initializing Nunchuck\n\n"); // I2CSend(0x52<<1, 2, 0x40, 0x00); // Wait(25); init_nunchuck(); // Wireless Nunchucks Zero @ 128 xinit = yinit = 128; while(1){ //Start Recalculating Values Wait(1); I2CSend(0x52<<1, 1, 0x00); Wait(1); I2CSend(0x52<<1, 1, 0x00); Wait(1); I2CSend(0x52<<1, 1, 0x00); if (I2CMasterErr(I2C0_MASTER_BASE) != I2C_MASTER_ERR_NONE){ UARTprintf("Send Zero Error:\n"); switch(I2CMasterErr(I2C0_MASTER_BASE)){ case I2C_MASTER_ERR_ADDR_ACK: UARTprintf(" I2C_MASTER_ERR_ADDR_ACK\n"); break; case I2C_MASTER_ERR_DATA_ACK: UARTprintf(" I2C_MASTER_ERR_DATA_ACK\n"); break; case I2C_MASTER_ERR_ARB_LOST: UARTprintf(" I2C_MASTER_ERR_ARB_LOST\n"); break; default: UARTprintf("WTF: %d\n", I2CMasterErr(I2C0_MASTER_BASE)); } // Reinitialize Nunchuck on error init_nunchuck(); }else{ Wait(1); I2CRecieve(0x52<<1, data, 6); // Nunchuck data is 6 bytes, but for whatever reason, MEMOREX Wireless Nunchuck wants to send 8... if (I2CMasterErr(I2C0_MASTER_BASE) != I2C_MASTER_ERR_NONE){ UARTprintf("Send Zero Error:\n"); switch(I2CMasterErr(I2C0_MASTER_BASE)){ case I2C_MASTER_ERR_ADDR_ACK: UARTprintf(" I2C_MASTER_ERR_ADDR_ACK\n"); break; case I2C_MASTER_ERR_DATA_ACK: UARTprintf(" I2C_MASTER_ERR_DATA_ACK\n"); break; case I2C_MASTER_ERR_ARB_LOST: UARTprintf(" I2C_MASTER_ERR_ARB_LOST\n"); break; } // Reinitialize Nunchuck on error init_nunchuck(); }else{ //for(i=0; i<6; i++) // data[i] = (data[i] ^ 0x17) + 0x17; // Nintendo decided to encrypt thir data... // Save Joystick Data wiichuck[0] = data[1]; // X Axis Joystick wiichuck[1] = data[0]; // Y Axis Joystick wiichuck[2] = (((unsigned short) data[2]) << 2) + (((unsigned short) data[5]) & (3<<2)); // X Axis Accel wiichuck[3] = (((unsigned short) data[3]) << 2) + (((unsigned short) data[5]) & (3<<4)); // Y Axis Accel wiichuck[4] = (((unsigned short) data[4]) << 2) + (((unsigned short) data[5]) & (3<<6)); // Z Axis Accel wiichuck[5] = data[5] & (1 << 1) ? 0 : 1; //'C' Button wiichuck[6] = data[5] & (1 << 0) ? 0 : 1; //'Z' Button //if (xinit == 0 && yinit == 0){ // xinit = wiichuck[0]-127; // yinit = wiichuck[1]-127; //}else{ xpow = (wiichuck[0]-xinit)/2; ypow = (wiichuck[1]-yinit)/2; l_vel = (xpow - ypow)*2; r_vel = (xpow + ypow)*2; l_vel = l_vel > 127 ? 127 : l_vel; r_vel = r_vel > 127 ? 127 : r_vel; l_vel = l_vel < -127 ? -127 : l_vel; r_vel = r_vel < -127 ? -127 : r_vel; //UARTprintf("X: %d\tY: %d\n", xpow*2, ypow*2); SetMotorPowers(l_vel / (wiichuck[5]==0 ? 2 : 1), r_vel / (wiichuck[5]==0 ? 2 : 1)); UARTprintf("Motor L: %d\tMotor R: %d\n", l_vel, r_vel); SetServoPosition(SERVO_0, wiichuck[6]==1 ? 255 : 140); UARTprintf("Nunchuck Data:\n"); for(i=0; i<7; i++){ UARTprintf(" %d\n", wiichuck[i]); }NL; Wait(100); } } } }
/* Main Function */ int main(void){ enum states{ setup, drawing, readusart, } currentstate = setup; unsigned char STRING1[]="YAY THIS"; unsigned char STRING2[]="WORKS!!!"; unsigned char STR1CMP[9]; unsigned char STR2CMP[9]; unsigned char x, i, j; unsigned char send[50]; while(1){ switch(currentstate){ case setup: initialize(); clearArray(); PORTB = 0b10000000; PORTC |= 0b10000000; ht1632_initialize(); PORTC |= 0b01000000; InitializeUART(); PORTC |= 0b00100000; sprintf(send, "Initialized...\n"); PORTC |= 0b00010000; SendStringUART(send); _delay_ms(200); PORTC = 0; strcpy(STRING1, "YAY THIS"); strcpy(STRING2, "WORKS!!!"); currentstate = drawing; break; case drawing: for(x=1;x<sizeof(STRING1);x++) { null_buffer(); for(i=0;i<8;i++){ for(j=0;j<8;j++){ set_buffer(STRING1[x-1]); if (~buffer[i][j] & (1<<0)) { ht1632_plot(j+(8*(x-1))-1,i,GREEN); PORTC = ~PORTC; } else { ht1632_plot(j+(8*(x-1))-1,i,BLACK); PORTC = ~PORTC; } } } } for(x=1;x<sizeof(STRING2);x++) { null_buffer(); for(i=0;i<8;i++){ for(j=0;j<8;j++){ set_buffer(STRING2[x-1]); if (~buffer[i][j] & (1<<0)) { ht1632_plot(j+(8*(x-1))-1,i+8,GREEN); PORTC = ~PORTC; } else { ht1632_plot(j+(8*(x-1))-1,i+8,BLACK); PORTC = ~PORTC; } } } } PORTC = 0; currentstate = readusart; break; case readusart: strcpy(STR1CMP, STRING1); strcpy(STR2CMP, STRING2); NewScreen(STRING1, STRING2); if((strcmp(STRING1, "RESETRES") == 0)){ currentstate = setup; }else if((strcmp(STRING1, STR1CMP) != 0) | (strcmp(STRING2, STR2CMP) != 0)){ currentstate = drawing; } break; } } }