ADC를 테스트 하기 위해 VR, 스위치를 추가 해 보았다.
MC9S08QG의 이제 모든 기능을 테스트 해 볼수 있지 않을까...
소스코드
int keypress; int ADC_val_H; int ADC_val_L;
void main(void) {
// set up kbi PTAPE_PTAPE2 = 1; // enable pullup for kb2 PTAPE_PTAPE3 = 1; // enable pullup for kb3 KBIPE_KBIPE2 =1; // enable kb 2 KBIPE_KBIPE3 =1; // enable kb 3 KBISC_KBACK = 1; // clear kb interrupts KBISC_KBIE = 1; // enable Keyboard Interrupts
// set up adc ADCSC1_ADCH = 0x1f; // all channels selected disables the ADC ADCSC1_AIEN = 1; // enable ADC interrupt ADCSC1_ADCO = 0; // enable single conversion, 1 is continuous conversion
ADCSC2_ADTRG = 0; // select software trigger ADCSC2_ACFE = 0; // disable the compare function
ADCCFG_ADICLK = 0; // bus clock ADCCFG_ADIV = 1; // input clock/2 ADCCFG_MODE = 0x00; // 10 bit mode ADCCFG_ADLSMP = 1; // long sample time
APCTL1_ADPC2 = 1; //APCTL1 = 0x00; // Disable all pins as ADC inputs
EnableInterrupts; // enable interrupts
for(;;) { __RESET_WATCHDOG(); /* feeds the dog */ }/* loop forever */ /* please make sure that you never leave this function */
}// end main
//KBI ISR interrupt 18 void KBI_ISR(void) { keypress = PTAD; // read port a to find key
if (keypress & 8) ADCSC1_ADCH = 0; else ADCSC1_ADCH = 1;
KBISC_KBACK = 1; // clear kb interrupt }
interrupt 19 void ADC_ISR(void) { ADC_val_H = ADCRH; ADC_val_L = ADCRL;
ADCSC1_ADCH = 0x1f; // all channels selected disables the ADC } |