基于MXT8051通用配料控制器的設(shè)計(jì)
根據(jù)圖4所示的時(shí)序邏輯,讀取通道A,增益128倍,其讀取函數(shù)如下:
本文引用地址:http://www.ex-cimer.com/article/117161.htmunsigned int ReadCount()
{
unsigned int ADval;
unsigned long Count;
unsigned char i;
PCR0 = 0xFB; //避免與I2C總線沖突
ADSK = 0;
Count = 0;
while(ADDO);
for (i=0;i<24;i++)
{
ADSK = 1;
Count = Count<<1;
ADSK = 0;
if(ADDO) Count++;
}
ADSK = 1;
;
ADSK = 0;
//判斷是否為負(fù)值,并顯示符號(hào)
if((Count & 0x800000) == 0x800000)
{
Count = ~(Count - 1);
LCDDATA16 |= 0x80;
}
else
{
LCDDATA16 = 0x00;
}
ADval = (int)(Count >> 8);//取高十六位有效值
B_AdFinish = 1;
return(ADval);
}
主程序流程如圖5所示。
程序主要由初始化代碼和主循環(huán)代碼構(gòu)成。
稱重傳感器相關(guān)文章:稱重傳感器原理
評(píng)論