发表于:2002-05-30 15:24:00
1楼
8316 A/D采样的例子,加delay(1)是因为I/O速度慢的缘故。参看说明书关于寄存器的描述一起看。
_ACL8316_AD(int ad_ch,int ad_gain)
{int Gain,DRTY,ad_data;
outportb(BASE+10,ad_ch);
delay(1);
outportb(BASE+8,0x00);
delay(1);
outportb(BASE+12,0x00);
delay(1);
inportb(BASE+12);
switch(Gain)
{ case 1: ad_gain=0; break;
case 2: ad_gain=1; break;
case 4: ad_gain=2; break;
case 8: ad_gain=3; break;
}
outportb(BASE+9,ad_gain);
delay(1);
do
{DRTY=inportb(BASE+8)&0x80;
delay(1);}
while(DRTY==0);
ad_data=inport(BASE+4);
return ad_data;
}