基本程序如下:现在就是单步运行gBAdcSaveBuf 中可以存到AD的转换值,全速运行有时可以读到有时不行,这个问题真的好怪,请高手 指点为一下是什么问题,谢谢!
#define SYS_SAVEBANK() static bit bSysBeforeBank_Flag; \
bSysBeforeBank_Flag=(bit) (INSCON&BIT6)
#define SYS_GETBACKBANK() if(bSysBeforeBank_Flag)BANK1()
#define BANK0() INSCON&=~BIT6 //change to bank0
u32 data u32AdVoltageSave1;
u32 data gBAdcSaveBuf;
u8 idata gBAdCountTimes;
void SetAdc_Initinal(void)
{
ADCON = B0001_0111; //选择ANT3通道 设置内部基准电压,选择内部基准电压1
ADCH = B1111_0000;
ADT = B1011_0101; //12000000/2/(256-196)
ADCDS = B0000_0000;
}
void ISR_ADC_Interrupt(void) interrupt 6
{
SYS_SAVEBANK();
BANK0();
ADCON &=B1011_1111;
gBAdcSaveBuf =(u32)ADDH;
gBAdcSaveBuf <<=8;
gBAdcSaveBuf |=(u32)ADDM;
gBAdcSaveBuf =(gBAdcSaveBuf<<=4)|((u32)(ADDL));
u32AdVoltageSave1 =u32AdVoltageSave1+gBAdcSaveBuf;
gBAdcSaveBuf = CLEAR;
if(gBAdCountTimes++ >=8)
{
_nop_();
AdcInterrupt_Disable();
gBAdCountTimes = CLEAR; //3011361275 97390957 dfvip999
u32AdVoltageSave1 = (u32AdVoltageSave1/8);
_nop_();
}
SYS_GETBACKBANK();
}
|