|
我用單片機的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位
|
|