|
我用单片机的ADC测量电压将测得值发送给电脑,00为标志,收到的数据理应是电压高8位,电压低8位,00,然后电压高8位电压低8位,00;这样循环,但实际收到的数据是电压高8位电压低8位,00;电压低8位00;电压低8位00;之后循环,再也没收到电压高8位;有没有大佬帮忙看看程序哪里出了问题。
**********************************************************************
void ADC0_ISR (void) interrupt 10
{
static unsigned long accumulator = 0; // accumulator for averaging
static unsigned int measurements = 2048; // measurement counter
//static unsigned int measurements = 4095;
unsigned long result=0;
// unsigned long mV; // measured voltage in mV
unsigned long mVH;
static unsigned int RH;
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^12)-1 (bits)
// mV = result * 2200 / 4095;
mV = result * 2200 / 4095;
mVH=(mV>>8);
// printf("P1.1 voltage: %ld mV\n",mV);
RI0=0;
TI0=0;
if(unsend)
{
unsend=0;//低8位发送完成标志清0
SBUF0=0;//发送数据0
}
_nop_();
send=1;//高8位发送完成标识置1
SBUF0=mVH;//发送高8位
n=~n;//指示灯闪烁(后续为了验证上面一句语句有没有走到加上的)
}
}
void UART0_Interrupt (void) interrupt 4
{
Delay_ms (2);
if (TI0==!0)
{ if(send)
{
send=0;//高8位发送完成标识清0
unsend=1;//低8位发送完成标识置1
SBUF0=mV;//发送低8位
}
TI0=0;
}
else if(RI0==!0)
{
RI0=0;
}
}
******************************************************
程序开始跑后指示灯是有闪烁的,但是电脑串口接收到的数据如上面所描述,没有高8位
|
|