#include /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations *//*----------------------------------------------------------definitions ------------------------------------------------ -----------------------------------------------------------*/typedef unsigned char UINT8;typedef signed char SINT8;typedef unsigned int UINT16;typedef int SINT16;typedef unsigned long int UINT32;typedef long int SINT32;#define TRESHOLD12 512 //ca. 2,5V#define TRESHOLD13 256 //ca. 1,25V/*----------------------------------------------------------Interrupt Vector Numbers definitions---------------------------------------------------------------------------------- */#define ISR_VEC_TPM1OVF 11#define ISR_VEC_ADC 23/*----------------------------------------------------------define LED's --------------------------------------------------------------------------------------------------------- */#define LED2 PTBD_PTBD3#define LED1 PTCD_PTCD5/*----------------------------------------------------------globals -------------------------------------------------------------------------------------------------------------- */UINT16 ADC_RESULT;/*----------------------------------------------------------interrupts ------------------------------------------------- -----------------------------------------------------------*/interrupt 23 void intADC(void) //ISR_VEC_TPM1OVF{ ADC_RESULT = ADCR; LED1 = 0; // LED1 on }void init_adc(void) { ADCCFG_ADLPC = 0; // high speed, no low power consumption ADCCFG_ADIV = 1; // clock/2 ADCCFG_ADLSMP = 1; // long sample time ADCCFG_MODE = 0x02; // 10bit-mode ADCCFG_ADICLK = 0; // i/o bus clock ADCSC2_ADTRG = 0; // software trigger ADCSC2_ACFE = 0; // disable compare function ADCSC2_ACFGT = 0; // compare function greater than disabled ADCSC1_AIEN = 1; // enable ADC Interrupt //ADCSC1_AIEN = 0; // disable ADC Interrupt ADCSC1_ADCH = 0x1f; // disable ADC ADCSC1_ADCO = 0; // enable single conversion (continuous conversions disabled) LED2 = 1; LED2 = 0; APCTL1 = 0x00; APCTL2_ADPC12 = 1; // disable I/O-control on AD-ports 12 and 13 APCTL2_ADPC13 = 1; // all other ports remain GPIOs.}/* main -------------------------------------------------- */void main(void) { UINT16 ADC12; UINT8 aux; PTBDD_PTBDD3 = 1; // configure Ports with green led as outputs PTCDD_PTCDD5 = 1; LED1 = 1; // turn off LED1 LED2 = 0; init_adc(); EnableInterrupts; /* enable interrupts */ /* include your code here */ for(;;) { //start conversion on channel 12 -------------------------- ADCSC1_ADCH = 12; //dummy operations aux=5; // interrupt occurs here when debugging in realt time with the P&E Micro debuger aux=6+aux; ADC12=ADC_RESULT; //set LED according to ADC-treshold if(ADC12>TRESHOLD12) LED2 = 0; else LED2 = 1; __RESET_WATCHDOG(); /* feeds the dog */ } /* loop forever */ /* please make sure that you never leave main */}
解決済! 解決策の投稿を見る。
. . .//start conversion on channel 12 -------------------------- ADCSC1_ADCH = 12; //dummy operations aux=5; // interrupt occurs here when debugging in realt time with the P&E Micro debuger aux=6+aux; ADC12=ADC_RESULT; //set LED according to ADC-treshold if(ADC12>TRESHOLD12) . . .
. . . //start conversion on channel 12 -------------------------- ADCSC1_ADCH = 12; //wait until COCO-bit is set. while (!ADCSC1_COCO) { //just wait, do nothing } aux=5; aux=6+aux; ADC12=ADC_RESULT; //set LED according to ADC-treshold if(ADC12>TRESHOLD12) . . .
. . .//start conversion on channel 12 -------------------------- ADCSC1_ADCH = 12; //dummy operations aux=5; // interrupt occurs here when debugging in realt time with the P&E Micro debuger aux=6+aux; ADC12=ADC_RESULT; //set LED according to ADC-treshold if(ADC12>TRESHOLD12) . . .
. . . //start conversion on channel 12 -------------------------- ADCSC1_ADCH = 12; //wait until COCO-bit is set. while (!ADCSC1_COCO) { //just wait, do nothing } aux=5; aux=6+aux; ADC12=ADC_RESULT; //set LED according to ADC-treshold if(ADC12>TRESHOLD12) . . .