SC92846xB内建一个12bit 11通道的高精度逐次逼近型ADC ,外部的10路ADC和IO口和其他功能复用。ADC内部还有一个通道可选择到1/4Vdd。配合内部2.4V电压用于测量VDD电压。
*************************************************
ADCCFG0 |= 0x38; //ADC配置
ADCCFG1 = 0x00;
ADCCFG2 |= 0x07;
ADCCON = 0x03;
ADCCON |= 0x80;
IE |= 0x40;
EA = 1;
ADCCON |= 0x40;
//ADC 中断函数 //获得adc采样值并累加,切换ADC通道
void adcScan(void) interrupt 6
{
ADCCON &= (~0x20);
adcVal[arrayNum] = (ADCVH << 4)|(ADCVL >> 4);
adcCount += adcVal[arrayNum];
arrayNum ++;
if(arrayNum == 10)
{
arrayNum = 0;
//取RGB做判断
//rgbRVal = 4096 - (adcRvAver >> 3);
//adcRvAver = 0;
adcStep ++;
enTr** =1;
}
else
{
ADCCON |= 0x40;
}
}
//***********主程序中对采样完数据做滤波,去除采样的最大值和最小值
if(enTr** )
{
enTr** = 0;
adcMax = adcVal[0]; //找到数组中最大,最小值
adcMin = adcVal[0];
for(i = 0; i < 10;i++)
{
if(adcMax <= adcVal)
{
adcMax = adcVal;
}
if(adcMin >= adcVal)
{
adcMin = adcVal;
}
}
adcCount = adcCount - adcMin - adcMax;
}
SC92F846XB提供了一个16位的乘除法器,由扩展累加器EX0-EX3,扩展B寄存器EXB和运算控制器OPERCON组成。
OPERCON = 0x00;
EXA0 = (unsigned char)(g_val);
EXA1 = (unsigned char)(g_val >> 8);
EXA2 = 0x00;
EXA3 = 0x00;
EXBL = 0xff;
EXBH = 0x00;
OPERCON = 0x80;
while((OPERCON & 0x80) != 0);
OPERCON = 0x60;
EXA3 = 0x00; //bu qi 32bit
EXBL = (unsigned char)(c_val);
EXBH = (unsigned char)(c_val >> 8);
OPERCON = OPERCON | 0x80;
while((OPERCON & 0x80) != 0);
rgb_gval = EXA0;
使用上有啥不明白的地方可以添加qq群,向群主咨询
|