|
我用單片機(jī)的ADC測(cè)量電壓將測(cè)得值發(fā)送給電腦,00為標(biāo)志,收到的數(shù)據(jù)理應(yīng)是電壓高8位,電壓低8位,00,然后電壓高8位電壓低8位,00;這樣循環(huán),但實(shí)際收到的數(shù)據(jù)是電壓高8位電壓低8位,00;電壓低8位00;電壓低8位00;之后循環(huán),再也沒收到電壓高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位發(fā)送完成標(biāo)志清0
SBUF0=0;//發(fā)送數(shù)據(jù)0
}
_nop_();
send=1;//高8位發(fā)送完成標(biāo)識(shí)置1
SBUF0=mVH;//發(fā)送高8位
n=~n;//指示燈閃爍(后續(xù)為了驗(yàn)證上面一句語(yǔ)句有沒有走到加上的)
}
}
void UART0_Interrupt (void) interrupt 4
{
Delay_ms (2);
if (TI0==!0)
{ if(send)
{
send=0;//高8位發(fā)送完成標(biāo)識(shí)清0
unsend=1;//低8位發(fā)送完成標(biāo)識(shí)置1
SBUF0=mV;//發(fā)送低8位
}
TI0=0;
}
else if(RI0==!0)
{
RI0=0;
}
}
******************************************************
程序開始跑后指示燈是有閃爍的,但是電腦串口接收到的數(shù)據(jù)如上面所描述,沒有高8位
|
|