#define USB_OTG_LINK_ADC0_MASK (1UL<<23) #define USB_OTG_LINK_ADC1_MASK (1UL<<24) #define USB_OTG_LINK_ADCT_FDIR LPC_GPIO0->DIR #define USB_OTG_LINK_ADCT_FSET LPC_GPIO0->SET #define USB_OTG_LINK_ADCT_FCLR LPC_GPIO0->CLR #define USB_OTG_LINK_ADCT_FIO LPC_GPIO0->PIN #define USB_OTG_LINK_ADC0_IOCON LPC_IOCON->P0_23 #define USB_OTG_LINK_ADC1_IOCON LPC_IOCON->P0_24 uint16_t adc_result0, adc_result1; FlagStatus done0, done1; ADC_Init(LPC_ADC, 50000); /* enable channel 0: */ ADC_ChannelCmd(LPC_ADC, 0, 1); ADC_ChannelCmd(LPC_ADC, 1, 1); /* start the conversion: */ ADC_StartCmd(LPC_ADC, 1); /* wait until channel 0's data is ready */ done0 = 0; done1 = 0; ADC0_State(1); ADC1_State(1); while (1) { while(!done0 && !done1) { done0 = ADC_ChannelGetStatus(LPC_ADC, 0, 1); done1 = ADC_ChannelGetStatus(LPC_ADC, 0, 1); } adc_result0 = ADC_ChannelGetData(LPC_ADC, 0); adc_result1 = ADC_ChannelGetData(LPC_ADC, 1); char value[20]; sprintf(value, "v: %d - %d", adc_result0, adc_result1); UARTPuts_(LPC_UART0, value); } void ADC1_State (int set) { if (set) LPC_GPIO0->SET = USB_OTG_LINK_ADC1_MASK; else LPC_GPIO0->CLR = USB_OTG_LINK_ADC1_MASK; } |