void main(void) { ES_Return_t ErrorType; BOARD_Init(); //printf("Starting Intern State Machine \n"); //printf("using the 2nd Generation Events & Services Framework\n"); //Hardware Init Bot_Init(); // Framework Init ErrorType = ES_Initialize(); if (ErrorType == Success) { ErrorType = ES_Run(); } //if we got to here, there was an error switch (ErrorType) { case FailedPointer: printf("Failed on NULL pointer"); break; case FailedInit: printf("Failed Initialization"); break; default: printf("Other Failure"); break; } for (;;) ; };
int main(void) { BOARD_Init(); unsigned char asciiSpray; unsigned int i; printf("\r\nUno Serial Test Harness\r\nAfter this Message the terminal should mirror any single character you type.\r\n"); // while(!IsTransmitEmpty()); unsigned int NopCount = 0; unsigned char CharCount = 0; #ifdef INUNDATION_TEST while (1) { NopCount = rand() % MAX_RAND + 1; //printf("%X\r\n",rand()); for (i = 0; i < NopCount; i++) { asm("Nop"); } for (CharCount = 32; CharCount < 128; CharCount++) { //printf("%c", CharCount); putchar(CharCount); } } #endif GetChar(); unsigned char ch = 0; while (1) { if (IsTransmitEmpty() == TRUE) if (IsReceiveEmpty() == FALSE) PutChar(GetChar()); } return 0; }
int main(void) { BOARD_Init(); printf("board_inited\n"); init_MDB(); AHRS_init(); printf("ahrs inited\n"); // timer_init(); //while(1); int i = 700; while (i >= -700) { while (IsReceiveEmpty()); printf("looped\n"); printf("current angle: %f\n",get_AHRS_angle()); printf("current speed: %f\n", get_AHRS_rate()); waitabit(1000); motor_command(i); printf("sent command %d\n\n", i); GetChar(); i = i - 100; } // while (1){ // while (IsReceiveEmpty()); // printf("looped\n"); // waitabit(1000); // printf("current speed: %d\n", motor_command(10000)); // GetChar(); // } }
int main(void) { BOARD_Init(); printf("If you can see this BOARD_Init Successfully ran\r\n"); TRISEbits.TRISE4 = 0; while (1) { LATEbits.LATE4 ^= 1; } }
int main(void) { //DEVCFG1bits.FCKSM = 0; int c = 0; // for (c = 0; c < 100000; c++) { // Nop(); // } BOARD_Init(); //INTEnableSystemMultiVectoredInt(); //SERIAL_Init(); //DEVCFG1bits.FCKSM //TIMERS_Init(); // SYSKEY = 0; // SYSKEY = 0xAA996655; // SYSKEY = 0x556699AA; // OSCCONbits.FRCDIV = 0b111; // OSCConfig(OSC_FRC_PLL, OSC_PLL_MULT_20, OSC_PLL_POST_1, OSC_PB_DIV_1); LED_Init(LED_BANK1); LED_SetBank(LED_BANK1,~2); //while(1); //SERIAL_Init(); //LATBbits.LATB7 = 1; TIMERS_Init(); unsigned char count=0; //while (1) { // LATCbits.LATC3 ^= 1; //} printf("Hello World\r\n"); while (1) { if (!IsTimerActive(0)) { // LATCbits.LATC5 ^= 1; //LATBbits.LATB9 ^= 1; InitTimer(0, 500); printf("TOP: %X\r\n",count); LED_SetBank(LED_BANK1,count); count++; } if (!IsReceiveEmpty()) { //LATBbits.LATB8 ^= 1; printf("%c", GetChar()); } } while (1); }
int main(void) { BOARD_Init(); init_ESC_pulse(); unsigned int i = 1700; for (i; i > 1300; i = i - 10) { printf("%d\n", i); set_ESC_pulse(i); GetChar(); while (IsReceiveEmpty()) { } } return 0; }
int main(void) { BOARD_Init(); // Configure Timer 1 using PBCLK as input. This default period will make the LEDs blink at a // pretty reasonable rate to start. OpenTimer1(T1_ON | T1_SOURCE_INT | T1_PS_1_8, 0xFFFF); // Set up the timer interrupt with a priority of 4. INTClearFlag(INT_T1); INTSetVectorPriority(INT_TIMER_1_VECTOR, INT_PRIORITY_LEVEL_4); INTSetVectorSubPriority(INT_TIMER_1_VECTOR, INT_SUB_PRIORITY_LEVEL_0); INTEnable(INT_T1, INT_ENABLED); // Enable interrupts for the ADC ConfigIntADC10(ADC_INT_PRI_2 | ADC_INT_SUB_PRI_0 | ADC_INT_ON); // Set B2 to an input so AN0 can be used by the ADC. TRISBCLR = 1 << 2; // Configure and start the ADC // Read AN0 as sample a. We don't use alternate sampling, so setting sampleb is pointless. SetChanADC10(ADC_CH0_NEG_SAMPLEA_NVREF | ADC_CH0_POS_SAMPLEA_AN2); OpenADC10( ADC_MODULE_ON | ADC_IDLE_CONTINUE | ADC_FORMAT_INTG16 | ADC_CLK_AUTO | ADC_AUTO_SAMPLING_ON, ADC_VREF_AVDD_AVSS | ADC_OFFSET_CAL_DISABLE | ADC_SCAN_OFF | ADC_SAMPLES_PER_INT_8 | ADC_BUF_16 | ADC_ALT_INPUT_OFF, ADC_SAMPLE_TIME_29 | ADC_CONV_CLK_PB | ADC_CONV_CLK_51Tcy2, ENABLE_AN2_ANA, SKIP_SCAN_ALL); EnableADC10(); /*************************************************************************************************** * Your code goes in between this comment and the following one with asterisks. **************************************************************************************************/ printf("Welcome to the Lab 6 Extra Credit blank. Please remove before starting."); /*************************************************************************************************** * Your code goes in between this comment and the preceding one with asterisks **************************************************************************************************/ while (1); }
void main() { BOARD_Init(); init_ESC_pulse(); printf("max pulse \n"); set_ESC_pulse(2000); GetChar(); while (IsReceiveEmpty()) { } printf("min pulse \n"); set_ESC_pulse(1000); GetChar(); while (IsReceiveEmpty()) { } printf("off pulse \n"); set_ESC_pulse(1500); }
int main(void) { BOARD_Init(); // Configure Timer 1 using PBCLK as input. This default period will make the LEDs blink at a // pretty reasonable rate to start. OpenTimer1(T1_ON | T1_SOURCE_INT | T1_PS_1_8, 0xFFFF); // Set up the timer interrupt with a priority of 4. INTClearFlag(INT_T1); INTSetVectorPriority(INT_TIMER_1_VECTOR, INT_PRIORITY_LEVEL_4); INTSetVectorSubPriority(INT_TIMER_1_VECTOR, INT_SUB_PRIORITY_LEVEL_0); INTEnable(INT_T1, INT_ENABLED); /*************************************************************************************************** * Your code goes in between this comment and the following one with asterisks. **************************************************************************************************/ int x = 0x01; LEDS_INIT(); //give the initial value checkItem.event = 0; checkItem.value = 0; int direction = RIGHT; while (1) { //set the value LEDS_SET(x); if (checkItem.event == 1) { checkItem.event = 0; //two directions if(direction == RIGHT){ x = x << 1; }else{ x = x >> 1; } } //edge case of 0x100 if((x == 0x100) && (direction == RIGHT)){ x = 0x40; direction = LEFT; } //edge case of 0x00 if((x == 0) && (direction == LEFT)){ x = 0x02; direction = RIGHT; } }
int main(void) { BOARD_Init(); // Configure Timer 2 using PBCLK as input. We configure it using a 1:16 prescalar, so each timer // tick is actually at F_PB / 16 Hz, so setting PR2 to F_PB / 16 / 100 yields a .01s timer. OpenTimer2(T2_ON | T2_SOURCE_INT | T2_PS_1_16, BOARD_GetPBClock() / 16 / 100); // Set up the timer interrupt with a medium priority of 4. INTClearFlag(INT_T2); INTSetVectorPriority(INT_TIMER_2_VECTOR, INT_PRIORITY_LEVEL_4); INTSetVectorSubPriority(INT_TIMER_2_VECTOR, INT_SUB_PRIORITY_LEVEL_0); INTEnable(INT_T2, INT_ENABLED); /****************************************************************************** * Your code goes in between this comment and the following one with asterisks. *****************************************************************************/ OledInit(); MorseInit(); while (1) { if (mflag) { if (mevent == MORSE_EVENT_DOT) { MorseDecode(MORSE_CHAR_DOT); } else if (mevent == MORSE_EVENT_DASH) { MorseDecode(MORSE_CHAR_DASH); } else if (mevent == MORSE_EVENT_INTER_LETTER) { templet[0] = MorseDecode(MORSE_CHAR_END_OF_CHAR); } else if (mevent == MORSE_EVENT_INTER_WORD) { MorseDecode(MORSE_CHAR_DECODE_RESET); } updateScreen(); mevent = 0; mflag = 0; } } /****************************************************************************** * Your code goes in between this comment and the preceding one with asterisks. *****************************************************************************/ while (1); }
int main(void) { BOARD_Init(); SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE); SERIAL_Init(); SPI_init(SPI_SS1_CLKRATE, 0, 0); int i, j; printf("SPI module test begins...\n"); //* SPI_changeClkRate() test: it works period of clock is 5MHz vs 500kHz uint8_t testDataAry[] = {0x0B, 0x0E, 0x0E, 0x0F}; while (1) { SPI_write(SPI_SS1_ID, testDataAry, 4); for (i = 0; i < 3000000; i++); SPI_write(SPI_SS2_ID, testDataAry, 4); for (i = 0; i < 3000000; i++); } //*/ printf("test ended\n"); return (EXIT_SUCCESS); }
void main(void) { ES_Return_t ErrorType; BOARD_Init(); // When doing testing, it is useful to annouce just which program // is running. printf("Starting the Exit HSM Test Harness \r\n"); printf("using the 2nd Generation Events & Services Framework\n\r"); // Your hardware initialization function calls go here Bot_Init(); Drive_Init(); // now initialize the Events and Services Framework and start it running ErrorType = ES_Initialize(); if (ErrorType == Success) { ErrorType = ES_Run(); } // //if we got to here, there was an error // switch (ErrorType) { case FailedPointer: printf("Failed on NULL pointer"); break; case FailedInit: printf("Failed Initialization"); break; default: printf("Other Failure"); break; } while (1) { ; } }
void main(void) { ES_Return_t ErrorType; uint8_t i; BOARD_Init(); // When doing testing, it is usefull to annouce just which program // is running. printf("Starting Timer Service Test Harness \r\n"); printf("using the 2nd Generation Events & Services Framework\n\r"); // Your hardware initialization function calls go here // now initialize the Events and Services Framework and start it running ErrorType = ES_Initialize(); timerServiceTestingState = init; for (i = 0; i <= TIMERS_USED; i++) { ES_Timer_InitTimer(i, (i + 1)*1000); //for second scale } if (ErrorType == Success) { ErrorType = ES_Run(); } //if we got to here, there was an error switch (ErrorType) { case FailedPointer: printf("Failed on NULL pointer"); break; case FailedInit: printf("Failed Initialization"); break; default: printf("Other Failure"); break; } for (;;) ; };
int main(void) { BOARD_Init(); SERIAL_Init(); //Init the motors, duh initMotors(); char input; dbprintf("Welcome to the Motor Test Harness\n"); dbprintf("Speed: 0-10, f: forward, s: backward\n"); dbprintf("r: right motor, l: left motor, b: battery\n"); while (1) { input = GetChar(); char_input(input); DELAY(A_BIT) } return 0; }
int main(void) { //unsigned char size = 0, i; BOARD_Init(); printf("Anima Small Scale FreeScale Accelerometer test\r\n"); TIMERS_Init(); LED_Init(LED_BANK1); int count=0; // while (1) { // if (!IsTimerActive(0)) { // // LATCbits.LATC5 ^= 1; // //LATBbits.LATB9 ^= 1; // InitTimer(0, 500); // printf("TOP: %X\r\n", count); // LED_SetBank(LED_BANK1, count); // count++; // // } // } // // while (1); free_accel_init(); printf("Scale is set to %d \r\n", free_GetScale()); free_SetScale(FREE_8GSCALE); printf("Scale is set to %d and should be %d\r\n", free_GetScale(), FREE_4GSCALE); free_SetScale(FREE_2GSCALE); printf("Scale is set to %d and should be %d\r\n", free_GetScale(), FREE_2GSCALE); printf("Rate is set to %d \r\n", free_GetRate()); free_SetRate(FREE_200HERTZ); printf("Rate is set to %d and should be %d\r\n", free_GetRate(), FREE_200HERTZ); free_SetRate(FREE_800HERTZ); printf("Rate is set to %d and should be %d\r\n", free_GetRate(), FREE_800HERTZ); //free_SetRate(FREE_1P56HERTZ); //while(1); char humanread = 1; short dataArray[3]; int i, j, data; for (i = 0; i != 1000; i++) for (j = 0; j != 500; j++) Nop(); while (1) { //if (UART2HalfEmpty()){ if (humanread == 1) { if (IsTransmitEmpty()) { free_GetTriplet(dataArray); printf("Accel: Cur X: %d \tCur Y: %d \tCur Z: %d\r\n", dataArray[0], dataArray[1], dataArray[2]); } } else { data = free_GetXData(); //UART2PutChar('$'); //UART2PutChar('#'); // UART2PutChar(data >> 8); // UART2PutChar(data & 0x00FF); //UART2PutChar('\r'); //UART2PutChar('\n'); } //for (i = 0; i != -1; i++) // Nop(); //} /*while(!UART2IsEmpty()) UART2PutChar(UART2GetChar());*/ } }
int main(void) { int i, j, k, count; unsigned char pat; BOARD_Init(); AD1PCFG = 0xFF; printf("\n\nLED Module Unit Test\n"); printf("\nInitializing LED module"); dbprintf("\nVerbose Debugging is ON"); LED_Init(); LED_AddBanks(LED_BANK1 | LED_BANK2 | LED_BANK3); //LED_RemoveBanks(LED_BANK1); for (count = 0; count < 10; count++) { printf("\npass %u", count); printf("\nTesting LED_OnBank"); for (j = 0; j < NUMLEDBANKS; j++) { LED_OnBank((1 << j), 0x0F); } DELAY(); printf("\nTesting LED OffBank"); for (j = 0; j < NUMLEDBANKS; j++) { LED_OffBank((1 << j), 0x0F); } DELAY(); LED_OnBank(LED_BANK1, 0x0F); DELAY(); LED_OffBank(LED_BANK1, 0x0F); LED_OnBank(LED_BANK2, 0x0F); DELAY(); LED_OffBank(LED_BANK2, 0x0F); LED_OnBank(LED_BANK3, 0x0F); DELAY(); LED_OffBank(LED_BANK3, 0x0F); LED_OnBank(LED_BANK2, 0x0F); DELAY(); LED_OffBank(LED_BANK2, 0x0F); LED_OnBank(LED_BANK1, 0x0F); DELAY(); LED_OffBank(LED_BANK1, 0x0F); DELAY(); LED_OnBank(LED_BANK1, 0x01); LED_OnBank(LED_BANK2, 0x01); LED_OnBank(LED_BANK3, 0x01); DELAY(); printf("\nTesting LED_InvertBank"); for (k = 0; k < 3; k++) { for (j = 0; j < NUMLEDBANKS; j++) { LED_InvertBank((1 << j), (0x03 << k)); } DELAY(); } for (k = 0; k < 3; k++) { for (j = 0; j < NUMLEDBANKS; j++) { LED_InvertBank((1 << j), (0x0C >> k)); } DELAY(); } printf("\nTesting LED_SetBank"); pat = 0x05; for (k = 0; k < 4; k++) { for (j = 0; j < NUMLEDBANKS; j++) { LED_SetBank((1 << j), pat); printf("Input was %X and Get was %X\r\n", (pat), LED_GetBank((1 << j))); pat ^= 0x0F; } DELAY(); } } LED_End(); printf("\nLED module unit test ended"); return 0; }
int main(void) { BOARD_Init(); SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE); SERIAL_Init(); SPI_Init(SPI_SS1_CLKRATE, 0, 0); TIMERS_Init(); printf("program begins...\n"); uint16_t i, j; /* timer test: sucess SET_OUTPUT_PIN(D, 10); TIMERS_Init(); while (1) { WRITE_HIGH(D, 10); InitTimer(1, 100); while (IsTimerActive(1)); WRITE_LOW(D, 10); InitTimer(1, 100); while (IsTimerActive(1)) ; } //*/ /* SPI read test 1: need to get 0x70 to ensure SPI reading is good printf("IMU: SPI read test 1\n"); IMU_Init(); uint8_t id; while (1) { id = MPU6500_readOneByte( MPU6500_RA_WHO_AM_I ); printf( "id should be 0x70: 0x%x\n", id ); InitTimer(1, 1000); while (IsTimerActive(1)) ; } //*/ /* SPI read test 2: need to get 0x70 to ensure SPI reading is good printf("IMU: SPI read test 2\n"); IMU_Init(); uint8_t id; while (1) { MPU6500_readBytes(SPI_SS2_ID, MPU6500_RA_WHO_AM_I, 1, &id); printf( "id should be 0x70: 0x%x\n", id ); InitTimer(1, 1000); while (IsTimerActive(1)) ; } //*/ /* inv_mpu test: porting invense IMU library printf("inv_mpu test: read test\n"); uint8_t buf[3] = {0}; uint8_t flag; while (1) { flag = mpu_read_reg(MPU6500_RA_WHO_AM_I, buf); printf("flag: %d\n", flag); printf( "id should be 0x70: 0x%x\n", buf[0]); InitTimer(2, 1000); while (IsTimerActive(2)) { //printf("timer is still active\n"); } } //*/ /* porting inv_mpu test: init and read gyro printf("inv_mpu test: read test\n"); uint16_t buf[3] = {0}; uint8_t flag = mpu_init(0); mpu_reset_fifo(); mpu_set_sensors(INV_XYZ_GYRO|INV_XYZ_ACCEL); mpu_configure_fifo(INV_XYZ_GYRO|INV_XYZ_ACCEL); printf("flag: %d\n", flag); uint16_t gyro[3], accel[3]; // flag = mpu_run_6500_self_test(gyro, accel, 0); printf("flag=%d, gyro: % 5d, % 5d, % 5d", flag, gyro[0], gyro[1], gyro[2]); printf(", accel: % 5d, % 5d, % 5d\n", accel[0], accel[1], accel[2]); while (1) { flag = mpu_get_gyro_reg(buf, 0); printf("flag=%d, gyro: % 5d, % 5d, % 5d", flag, buf[0], buf[1], buf[2]); mpu_get_accel_reg(buf, 0); printf(", accel: % 5d, % 5d, % 5d\n", buf[0], buf[1], buf[2]); InitTimer(2, 1000); while (IsTimerActive(2)); } //*/ /* test: reading multiple times from the same register: the internal pointer +1 when it read once int vals; uint16_t gyro[3], accel[3]; vals = mympu_open(200); printf("MPU Init: %d\n", vals); struct s_mympu mympu; uint8_t flag; while(1) { mpu_get_accel_reg(accel, 0); printf("all accel: % 5d, % 5d, % 5d\n", accel[0], accel[1], accel[2]); uint8_t tmp = MPU6500_readOneByte(MPU6500_RA_ACCEL_XOUT_H); accel[0] = tmp << 8; tmp = MPU6500_readOneByte(MPU6500_RA_ACCEL_XOUT_L); accel[0] |= tmp; tmp = MPU6500_readOneByte(MPU6500_RA_ACCEL_YOUT_H); accel[1] = tmp << 8; tmp = MPU6500_readOneByte(MPU6500_RA_ACCEL_YOUT_L); accel[1] |= tmp; tmp = MPU6500_readOneByte(MPU6500_RA_ACCEL_ZOUT_H); accel[2] = tmp << 8; tmp = MPU6500_readOneByte(MPU6500_RA_ACCEL_ZOUT_L); accel[2] |= tmp; printf("byte accel: % 5d, % 5d, % 5d\n", accel[0], accel[1], accel[2]); InitTimer(2, 100); while (IsTimerActive(2)); } //*/ /* test: reading multiple times from the same register: the internal pointer +1 when it read once int vals; uint8_t buf[20] = {0}; uint16_t gyro[3] = {0}, accel[3] = {0}; vals = mympu_open(200); printf("MPU Init: %d\n", vals); //IMU_Init(); uint8_t id = MPU6500_readOneByte( MPU6500_RA_WHO_AM_I ); printf( "id should be 0x70: 0x%x\n", id); struct s_mympu mympu = {0}; int flag; //MPU6500_writeOneByte( MPU6500_RA_USER_CTRL, 0x40 | 0x10 ); while(1) { flag = mympu_update(&mympu); //printf("yaw=[%d, %d], pitch=[%d,%d], roll=[%d,%d]\n", mympu.ypr[0], mympu.gyro[0], mympu.ypr[1], mympu.gyro[1], mympu.ypr[2], mympu.gyro[2]); //printf("flag=%d, yaw=% 11f, pitch=% 11f, roll=% 11f\n", flag, mympu.ypr[0], mympu.ypr[1], mympu.ypr[2]); printf("yaw=[%.3f, %.3f], pitch=[%.3f,%.3f], roll=[%.3f,%.3f]\n", mympu.ypr[0], mympu.gyro[0], mympu.ypr[1], mympu.gyro[1], mympu.ypr[2], mympu.gyro[2]); //flag = dmp_read_fifo(gyro, accel, buf, NULL,&vals,&vals); //buf[0] = MPU6500_readOneByte(MPU6500_RA_FIFO_COUNTH); //buf[1] = MPU6500_readOneByte(MPU6500_RA_FIFO_COUNTL); //uint16_t count = (buf[0] << 8) | buf[1]; //printf("fifo count: %d\n", count); //flag = mpu_read_fifo(gyro, accel, &vals, &vals, &vals); //flag = mpu_read_fifo_stream(10, buf, &vals); //read_fifo(buf, gyro, accel); //printf("flag=%d, gyro: % 5d, % 5d, % 5d", flag, gyro[0], gyro[1], gyro[2]); // printf(", accel: % 5d, % 5d, % 5", accel[0], accel[1], accel[2]); //printf(", quat: %d, %d, %d, %d\n", buf[0], buf[1], buf[2], buf[3]); InitTimer(2, 50); while (IsTimerActive(2)); } //*/ /* test: calibration by adding offset int vals = mympu_open(200); printf("MPU Init: %d\n", vals); uint8_t id = MPU6500_readOneByte( MPU6500_RA_WHO_AM_I ); printf( "id should be 0x70: 0x%x\n", id); struct s_mympu mympu = {0}; int flag; printf("waiting for initial drift\n"); InitTimer(2, 20000); // wait for 20s to pass initial drift while (IsTimerActive(2)); printf("get average offset\n"); float offsetX = 0, offsetY = 0, offsetZ = 0; float offsetPrev[3] = {0}; float alpha = 0; uint8_t k; for (k=1; k <= 200; k++) { flag = mympu_update(&mympu); //printf("yaw=% 3.3f, pitch=% 3.3f, roll=% 3.3f\n", //mympu.ypr[0], mympu.ypr[1], mympu.ypr[2]); alpha = ((float) k - 1.) / k; offsetX = alpha*offsetPrev[0] + (1. - alpha) * mympu.ypr[0]; offsetY = alpha*offsetPrev[1] + (1. - alpha) * mympu.ypr[1]; offsetZ = alpha*offsetPrev[2] + (1. - alpha) * mympu.ypr[2]; offsetPrev[0] = offsetX; offsetPrev[1] = offsetY; offsetPrev[2] = offsetZ; InitTimer(2, 50); while (IsTimerActive(2)); } printf("average: x offset= %3.3f, y offset= %3.3f, z offset= %3.3f\n", offsetX, offsetY, offsetZ); //offsetX = abs(offsetX); offsetY = abs(offsetY); //offsetZ = abs(offsetZ); while(1) { flag = mympu_update(&mympu); //printf("yaw=% 3.0f, pitch=% 3.0f, roll=% 3.0f\n", //printf("%4.1f, %4.1f, %4.1f\n", mympu.ypr[0] - offsetX, mympu.ypr[1] - offsetY, mympu.ypr[2] - offsetZ); printf("yaw=[%.3f, %.3f], pitch=[%.3f,%.3f], roll=[%.3f,%.3f]\n", mympu.ypr[0] - offsetX, mympu.gyro[0], mympu.ypr[1] - offsetY, mympu.gyro[1], mympu.ypr[2] - offsetZ, mympu.gyro[2]); InitTimer(2, 50); while (IsTimerActive(2)); } //*/ //* test: two SPI devices, OLED and IMU int vals = mympu_open(10); OLED_Init(); OpenTimer2(T2_ON | T2_SOURCE_INT | T2_PS_1_1, 0x2710); ConfigIntTimer2(T2_INT_ON | T2_INT_PRIOR_2); printf("MPU Init: %d\n", vals); uint8_t id = MPU6500_readOneByte( MPU6500_RA_WHO_AM_I ); printf( "id should be 0x70: 0x%x\n", id); UG_SetForecolor(0x0F); UG_SetBackcolor(0x00); UG_FontSelect(FONT_6X8); char str[50] = ""; while(1) { //mympu_update(&mympu); sprintf(str, "%.3f, %.3f, %.3f\n", mympu.ypr[0], mympu.ypr[1], mympu.ypr[2]); printf("%s\n",str); flag_writingScreen = 1; UG_PutString(0, 0, str); flag_writingScreen = 0; InitTimer(1, 200); while (IsTimerActive(1)); } //*/ /* flag = mpu_run_6500_self_test(gyro, accel, 0); printf("\nflag=%d, gyro: % 5d, % 5d, % 5d", flag, gyro[0], gyro[1], gyro[2]); printf(", accel: % 5d, % 5d, % 5d\n", accel[0], accel[1], accel[2]); MPU6500_writeOneByte(MPU6500_RA_XA_OFFS_H, (accel[0] & 0x7F80) >> 8); MPU6500_writeOneByte(MPU6500_RA_XA_OFFS_L_TC, accel[0] & 0x7F); MPU6500_writeOneByte(MPU6500_RA_YA_OFFS_H, (accel[1] & 0x7F80) >> 8); MPU6500_writeOneByte(MPU6500_RA_YA_OFFS_L_TC, accel[1] & 0x7F); MPU6500_writeOneByte(MPU6500_RA_ZA_OFFS_H, (accel[2] & 0x7F80) >> 8); MPU6500_writeOneByte(MPU6500_RA_ZA_OFFS_L_TC, accel[2] & 0x7F); MPU6500_writeOneByte(MPU6500_RA_XG_OFFS_USRH, gyro[0] >> 8); MPU6500_writeOneByte(MPU6500_RA_XG_OFFS_USRL, gyro[0] & 0xFF); MPU6500_writeOneByte(MPU6500_RA_YG_OFFS_USRH, gyro[1] >> 8); MPU6500_writeOneByte(MPU6500_RA_YG_OFFS_USRL, gyro[1] & 0xFF); MPU6500_writeOneByte(MPU6500_RA_ZG_OFFS_USRH, gyro[2] >> 8); MPU6500_writeOneByte(MPU6500_RA_ZG_OFFS_USRL, gyro[2] & 0xFF); //*/ printf("program ended...\n"); return 0; }
int main(void) { unsigned int wait = 0; int readcount = 0; unsigned int CurPin = 0; unsigned int PinListing = 0; char FunctionResponse = 0; char TestFailed = FALSE; //SERIAL_Init(); //INTEnableSystemMultiVectoredInt(); BOARD_Init(); mJTAGPortEnable(0); printf("\r\nUno A/D Test Harness\r\nThis will initialize all A/D pins and read them %d times\r\n", TIMES_TO_READ); //printf("Value of pcfg before test: %X\r\n", AD1PCFG); // while(!IsTransmitEmpty()); //AD_Init(BAT_VOLTAGE); //AD_Init(); printf("Testing functionality before initialization\r\n"); /*adding pins individually */ printf("AD_AddPins on each pin indvidually which results in failure: "); for (CurPin = 1; CurPin < ALLADPINS; CurPin <<= 1) { FunctionResponse = AD_AddPins(CurPin); if (FunctionResponse != ERROR) { TestFailed = TRUE; break; } } if (TestFailed) { printf("FAIL\r\n"); } else { printf("PASSED\r\n"); } TestFailed = FALSE; /*removing pins individually*/ printf("AD_RemovePins on each pin indvidually which results in failure: "); for (CurPin = 1; CurPin < ALLADPINS; CurPin <<= 1) { FunctionResponse = AD_RemovePins(CurPin); if (FunctionResponse != ERROR) { TestFailed = TRUE; break; } } if (TestFailed) { printf("FAIL\r\n"); } else { printf("PASSED\r\n"); } TestFailed = FALSE; /*listing pins while inactive*/ printf("AD_ActivePins which should return 0: "); PinListing = AD_ActivePins(); if (PinListing != 0x0) { printf("FAILED\r\n"); } else { printf("PASSED\r\n"); } // /*calling ned when inactive*/ // printf("AD_End which should fail: "); // FunctionResponse = AD_End(); // if (FunctionResponse != ERROR) { // printf("FAILED\r\n"); // } else { // printf("PASSED\r\n"); // } /*activating module*/ printf("initializing using AD_Init: "); FunctionResponse = AD_Init(); if (FunctionResponse != SUCCESS) { printf("FAILED\r\n"); } else { printf("PASSED\r\n"); } /*attempting to reactivate*/ printf("initializing using AD_Init again returns error: "); FunctionResponse = AD_Init(); if (FunctionResponse != ERROR) { printf("FAILED\r\n"); } else { printf("PASSED\r\n"); } printf("Testing Functionality after initialization\r\n"); /*active pins after activation only has battery*/ printf("Ad_ActivePins should only return BAT_VOLTAGE: "); PinListing = AD_ActivePins(); if (PinListing == BAT_VOLTAGE) { printf("PASSED\r\n"); } else { printf("FAILED\r\n"); } /*each pin added should succeed*/ printf("Adding each pin using AD_AddPins indivdually: "); for (CurPin = 1; CurPin < ALLADMINUSBATT; CurPin <<= 1) { PinListing = AD_ActivePins(); FunctionResponse = AD_AddPins(CurPin); if (FunctionResponse != SUCCESS) { TestFailed = TRUE; break; } while (AD_ActivePins() != (PinListing | CurPin)); } if (TestFailed) { printf("FAIL\r\n"); } else { printf("PASSED\r\n"); } /*removing each pin should succeed */ printf("Removing each pin using AD_RemovePins indivdually: "); for (CurPin = 1; CurPin < ALLADMINUSBATT; CurPin <<= 1) { PinListing = AD_ActivePins(); FunctionResponse = AD_AddPins(CurPin); if (FunctionResponse != SUCCESS) { TestFailed = TRUE; break; } while (AD_ActivePins() != (PinListing | CurPin)); } if (TestFailed) { printf("FAIL: %X\r\n", 0xFEED); } else { printf("PASSED\r\n"); } while (1); printf("We will now add the odd pins and wait for them to be activated"); AD_AddPins(ODD_ACTIVE); while (!(AD_ActivePins() & ODD_ACTIVE)) { if (IsTransmitEmpty()) { printf("%X\r\n", AD_ActivePins()); } } printf("The Odd pins are now active as shown by Active pins: %X\r\n", AD_ActivePins()); printf("We will now enable the even pins and wait for them to be activated"); AD_AddPins(EVEN_ACTIVE); while (!(AD_ActivePins() & EVEN_ACTIVE)); printf("The Even pins are now active as shown by Active pins: %X\r\n", AD_ActivePins()); char numtoread = NUM_AD_PINS; unsigned char cur = 0; DELAY(400000) while (readcount <= TIMES_TO_READ) { DELAY(100000); printf("\r\n"); for (cur = 0; cur < numtoread; cur++) { printf("%d\t", AD_ReadADPin(1 << cur)); } printf("\r\n"); readcount++; } printf("Done Reading Them\r\n"); AD_End(); printf("Value of pcfg after test: %X", AD1PCFG); return 0; }
int main(int argc, char *argv[]) // returns 1 if an error occurs, 0 otherwise { int error_code=0; board_t position; move_t moves[4]; int i; int steps=0; BOARD_Message_Init(); if (argc<2) { sprintf(message,"Program requires an argument (name of file containing position).\n"); BOARD_Message(); error_code=1; } { srand(0); HASH_Init(); #ifdef TESTING { HASH_Set_Size(32*1024*1024); } #else { HASH_Set_Size(512*1024*1024); } #endif BOARD_Init(&position); if (BOARD_Read_Position(&position, argv[1])) { sprintf(message,"Couldn't read position from file.\n"); BOARD_Message(); error_code=1; } else { if (position.move==0) { printf("Ra1 Rb1 Rc1 Rd1 Re1 Rf1 Rg1 Rh1 Ha2 Db2 Cc2 Md2 Ee2 Cf2 Dg2 Hh2\n"); } else if (position.move==1) { if ((position.board[75] & PIECE_MASK)==ELEPHANT_PIECE) { printf("ra8 rb8 rc8 rd8 re8 rf8 rg8 rh8 ha7 db7 cc7 ed7 me7 cf7 dg7 hh7\n"); } else { printf("ra8 rb8 rc8 rd8 re8 rf8 rg8 rh8 ha7 db7 cc7 md7 ee7 cf7 dg7 hh7\n"); } } else { position.steps=0; BOARD_Calculate_Hashkey(&position); EVAL_Eval(&position,TRUE); SEARCH_Start_Search(&position,moves,NULL); for (i=0; steps<4; i++) { BOARD_Send_Move(&moves[i]); printf(" "); steps+=moves[i].steps; } printf("\n"); } } } BOARD_Message_Exit(); return error_code; }