11.07.2011
Implementacja obsługi klawiatur pojemnościowych w LPC17xx firmy NXP
Listing 1. Fragment pliku config.h
/* in this file user has to define the different keypads used */ /* each needs to be mapped to a separated ADC channel */ /*-----------------------------------------*/ /* Keypad 1 */ /*-----------------------------------------*/ #define USE_KBD1 0 #if(USE_KBD1 == 1) #define KBD1_ASSIGNED_CHANNEL (x) #define CH7_ASSIGNED_KBD (y) #endif /*-----------------------------------------*/ /* Keypad 2 */ /*-----------------------------------------*/ #define USE_KBD2 0 #if(USE_KBD2 == 1) #define KBD2_ASSIGNED_CHANNEL (CH7) #define CH7_ASSIGNED_KBD (KBD2) #endif /*-----------------------------------------*/ /* Keypad 3 */ /*-----------------------------------------*/ #define USE_KBD3 0 #if(USE_KBD3 == 1) #define KBD3_ASSIGNED_CHANNEL (CH6) #define CH6_ASSIGNED_KBD (KBD3) #endif /*-----------------------------------------*/ /* Keypad 4 */ /*-----------------------------------------*/ #define USE_KBD4 0 #if(USE_KBD4 == 1) #define KBD4_ASSIGNED_CHANNEL (x) #define CH7_ASSIGNED_KBD (y) #endif /*-----------------------------------------*/ /* Keypad 5 */ /*-----------------------------------------*/ #define USE_KBD5 1 #if(USE_KBD5 == 1) #define KBD5_ASSIGNED_CHANNEL (CH2) #define CH2_ASSIGNED_KBD (KBD5) #endif /*-----------------------------------------*/ /* Keypad 6 */ /*-----------------------------------------*/ #define USE_KBD6 0 #if(USE_KBD6 == 1) #define KBD6_ASSIGNED_CHANNEL (CH3) #define CH3_ASSIGNED_KBD (KBD6) #endif /*-----------------------------------------*/ /* Keypad 7 */ /*-----------------------------------------*/ #define USE_KBD7 0 #if(USE_KBD7 == 1) #define KBD7_ASSIGNED_CHANNEL (x) #define CH7_ASSIGNED_KBD (y) #endif /*-----------------------------------------*/ /* Keypad 8 */ /*-----------------------------------------*/ #define USE_KBD8 0 #if(USE_KBD8 == 1) #define KBD8_ASSIGNED_CHANNEL (CH4) #define CH4_ASSIGNED_KBD (KBD8) #endif
Działanie programu rozpoczyna się od skonfigurowania mikrokontrolera. W kontekście algorytmu dla interfejsu użytkownika pierwszą wywoływaną funkcją jest initAdc(SystemFrequency) z pliku adc.c. Wewnątrz tej funkcji wykonywana jest konfiguracja wyprowadzeń i kanałów przetwornika A/C zgodnie z ustawieniami w pliku config.h (listing 2).
Listing 2. Ciało funkcji initADC()
void initAdc(uint32_t cpuFreq) { // uint8_t chIdx; /* peripheral clock has been already enabled in SystemIn */ _powerOnAdc(); /* configure the ADC clock as close to 13 MHz as possible */ _setAdcDivider(cpuFreq); /* disable adc interrupts */ _disableAllAdcInterrupts(); /* configure all used adc /GPIO pins to the default value */ /* configure GPIO mode output */ if (UNUSED_KPAD != Ch2KpadMap[CH0]) { _setCh0GpioDirOut(); _setCh0GpioPullup(); _setCh0GpioCharge(); _setCh0GpioMode(); } if (UNUSED_KPAD != Ch2KpadMap[CH1]) { _setCh1GpioDirOut(); _setCh1GpioPullup(); _setCh1GpioCharge(); _setCh1GpioMode(); } if (UNUSED_KPAD != Ch2KpadMap[CH2]) { _setCh2GpioDirOut(); _setCh2GpioPullup(); _setCh2GpioCharge(); _setCh2GpioMode(); } if (UNUSED_KPAD != Ch2KpadMap[CH3]) { _setCh3GpioDirOut(); _setCh3GpioPullup(); _setCh3GpioCharge(); _setCh3GpioMode(); } if (UNUSED_KPAD != Ch2KpadMap[CH4]) { _setCh4GpioDirOut(); _setCh4GpioPullup(); _setCh4GpioCharge(); _setCh4GpioMode(); } if (UNUSED_KPAD != Ch2KpadMap[CH5]) { _setCh5GpioDirOut(); _setCh5GpioPullup(); _setCh5GpioCharge(); _setCh5GpioMode(); } if (UNUSED_KPAD != Ch2KpadMap[CH6]) { _setCh6GpioDirOut(); _setCh6GpioPullup(); _setCh6GpioCharge(); _setCh6GpioMode(); } if (UNUSED_KPAD != Ch2KpadMap[CH7]) { _setCh7GpioDirOut(); _setCh7GpioPullup(); _setCh7GpioCharge(); _setCh7GpioMode(); } }