int main(void) { //Initialise the FRDM-KL26Z Board hardware_init(); FRDM_KL26Z_LEDs_Configure(); PIT_Configure_interrupt_mode(2); PRINTF("ADC new TESTING\r\n"); adc_config_with_software_trigger(); while(1) { //enable adc clock SIM_SCGC6 bit 27 for ADC0 //configure adc trigger in SIM_OPT7 if using h/w triggers //configure ADC1_CFG1 to configure clock and # of conversion bits //configure ADC1_SC2 for h/w s/w trigger //write to ADC1_SCA register to configure interrupt, channel and source type } /* Never leave main */ return 0; }
int main() { volatile int temp; volatile int rand_no; int x; hardware_init(); FRDM_KL26Z_LEDs_Configure(); FRDM_KL26Z_SW2_Configure(0,FALLING_EDGE); FRDM_KL26Z_SW1_Configure(PULLUP,FALLING_EDGE); PIT_Configure_interrupt_mode(0.01); NVIC_ClearPendingIRQ(31); NVIC_EnableIRQ(31); LED_set(GREEN,OFF); while(1) { switch(currentstate) { case INIT: sw_count=0; sw2_count=0; PRINTF("SW1 to start"); while(sw_count==0) {} LED_set(GREEN,OFF); currentstate = PLAY; break; case PLAY: PRINTF("when led on, press sw2"); srand(timer_tick); rand_no = rand()%5000; temp=timer_tick; while((timer_tick-temp<rand_no) && (sw2_count==0) ) {} if(sw2_count>0) { currentstate=INIT; break; } LED_set(GREEN,ON); temp=timer_tick; while(((sw2_count==0)&&timer_tick-temp<5000)) {} if(timer_tick-temp>=5000) { PRINTF("too slow"); currentstate=INIT; } else { PRINTF("reaction time: %d MSec \n" ,(timer_tick-temp)); LED_set(GREEN,OFF); currentstate = INIT; } break; default: break; } } return 0; }