看來沒人去看我上傳的程式碼。
對不起大家了,我貼上我的碼,佔用點版面:
Int.c中的碼:
unsigned int ADC_Val_Int;
#pragma vector=ADC1_EOC_vector //For ADC1 EOC Interrupt
__interrupt void ADC1_Int(void)
{
unsigned int ADCH,ADCL;
ADCH =ADC_DRH;
ADCL =ADC_DRL;
ADC_Val_Int =(ADCH<<2) + ADCL ;
//ADC_CR1_ADON=ON; //Single Mode Need
}
//-----------------------
setup.c中的碼:
void ADC_Init(void)
{
unsigned int i;
ADC_CR1_ADON=0; //A/D Converter on/off
//0: Disable ADC conversion/calibration and go to power down mode.
//1: Enable ADC and to start conversion
ADC_CR1=0;
ADC_CR1_SPSEL=0;//Prescaler selection(0~7)
//Master Clock/2,/3,/4,/6,/8,/10,/12,/18
//ADC_CR1_CONT=0; //Continuous conversion For Single
ADC_CR1_CONT=1; //Continuous conversion For ADC Interrupt
//0: Single conversion mode
//1: Continuous conversion mode
ADC_CR2_ALIGN=0;//Data alignment
//0: Left alignment 8MSB in ADC_DRH, 2LSB in ADC_DRL
//1: Right alignment 2MSB in ADC_DRH, 8LSB in ADC_DRL
ADC_CR3_DBUF=0; //Data buffer
//0: Disable
//1: Enable
ADC_CSR_CH=4; //ADC Channel Select:ADC4
ADC_CSR_EOCIE=ON; //Interrupt enable for EOC For ADC Interrupt
ADC_TDRL=1; //Schmitt trigger
//0: Schmitt trigger enabled
//1: Schmitt trigger disabled
//ADC Module Initial
ADC_CR1_ADON=ON; //A/D Converter on/off
for(i=0;i<100;i++); //Delay, wait for ADC
ADC_CR1_ADON=ON;
}
|