void initializeSystem(void) { CyGlobalIntEnable; UART_Start(); PrISM_1_Start(); PrISM_2_Start(); Opamp_1_Start(); // Start the Bluetooth Stack CyBle_Start(CustomEventHandler); // Set up the LED. First set its output to be off so that the LED doesn't blink on. // Then set the drive mode to strong. PrISM_1_WritePulse0(255); PrISM_1_WritePulse1(255); PrISM_2_WritePulse0(255); RED_SetDriveMode(RED_DM_STRONG); GREEN_SetDriveMode(GREEN_DM_STRONG); BLUE_SetDriveMode(BLUE_DM_STRONG); // Start the ADC ADC_SAR_Seq_Start(); ADC_SAR_Seq_StartConvert(); ADC_SAR_Seq_IRQ_Enable(); // Enable an interupt for when the ADC has data ADC_SAR_Seq_IRQ_StartEx(ADC_SAR_Seq_ISR_LOC); // Start the Timer for the ADC ADC_Timer_Start(); elapsed = 0; }
// ADC void pollingADC() { ADC_SAR_Seq_StartConvert(); while (ADC_SAR_Seq_IsEndConversion(ADC_SAR_Seq_RETURN_STATUS) == 0u) { // 変換終了を待つ ; } adcResult[ADC_CH_POT1_N] = ADC_LIMIT(ADC_SAR_Seq_GetResult16(ADC_CH_POT1_N)); adcResult[ADC_CH_POT2_N] = ADC_LIMIT(ADC_SAR_Seq_GetResult16(ADC_CH_POT2_N)); adcResult[ADC_CH_POT3_N] = ADC_LIMIT(ADC_SAR_Seq_GetResult16(ADC_CH_POT3_N)); adcResult[ADC_CH_JOY1_N] = ADC_LIMIT(ADC_SAR_Seq_GetResult16(ADC_CH_JOY1_N)); adcResult[ADC_CH_JOY2_N] = ADC_LIMIT(ADC_SAR_Seq_GetResult16(ADC_CH_JOY2_N)); }
/*====================================================== * メインルーチン * *======================================================*/ int main() { char LCD_LINE[17] = ""; /* Init and start sequencing SAR ADC */ ADC_SAR_Seq_Start(); ADC_SAR_Seq_StartConvert(); /* Init and start I2C master */ I2CM_Start(); CyDelay(500); CyGlobalIntEnable; /* Start I2C LCD */ // LCDをRESET LCD_RESET_Write(0u); CyDelay(1); LCD_RESET_Write(1u); CyDelay(10); LCD_Init(32); LCD_Clear(); LCD_Puts("Pyun2Controller2"); LCD_SetPos(0, 1); LCD_Puts("Demonstration"); CyDelay(500); for(;;) { pollingADC(); pollingSW(); #ifdef _ADC_8BIT sprintf(LCD_LINE, "%02x %02x %02x : %02x %02x", adcResult[ADC_CH_POT1_N] >> 3, adcResult[ADC_CH_POT2_N] >> 3, adcResult[ADC_CH_POT3_N] >> 3, adcResult[ADC_CH_JOY1_N] >> 3, adcResult[ADC_CH_JOY2_N] >> 3 ); #else sprintf(LCD_LINE, "%03x%03x%03x:%03x%03x", adcResult[ADC_CH_POT1_N], adcResult[ADC_CH_POT2_N], adcResult[ADC_CH_POT3_N], adcResult[ADC_CH_JOY1_N], adcResult[ADC_CH_JOY2_N] ); #endif LCD_SetPos(0, 0); LCD_Puts(LCD_LINE); sprintf(LCD_LINE, "%s %s %s %s : %s %s ", buttonStatus.green ? "G" : "x", buttonStatus.yellow ? "Y" : "x", buttonStatus.red ? "R" : "x", buttonStatus.blue ? "B" : "x", buttonStatus.black ? "K" : "x", buttonStatus.white ? "W" : "x" ); LCD_SetPos(0, 1); LCD_Puts(LCD_LINE); //CyDelay(1000); } }