tica, Arial, sans-serif">sfr16 ADC0 = 0xbd; // ADC0 result
void main()
{
// unsigned int j;
Init_Device();
EA=1;
TR2=1;
TI0=1;
while(1)
{
//P4=~P4;
//for(j=0;j<50000;j++);
}
}
void ADC0_ISR (void) interrupt 10
{
static unsigned long accumulator = 0; // Accumulator for averaging
static unsigned int measurements = 2048; // Measurement counter
unsigned long result=0;
unsigned long mV; // Measured voltage in mV
unsigned int i,j;
AD0INT = 0; // Clear ADC0 conv. complete flag
accumulator += ADC0;
measurements--;
if(measurements==0)
{
measurements = 2048;
result = accumulator / 2048;
accumulator=0;
// The 10-bit ADC value is averaged across 2048 measurements.
// The measured voltage applied to P1.4 is then:
//
// Vref (mV)
// measurement (mV) = --------------- * result (bits)
// (2^10)-1 (bits)
mV = result * 3300 / 1023;
printf("P1.1 voltage: %ld mV
",mV);
for(i=0;i<10000;i++)
for(j=0;j<40;j++);
P4=~P4;
}
// Toggle LED
}
这是一个ADC的实例程序,printf那句在串口调试助手中为什么看不到结果,只能看到LED灯在闪烁
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>