ad.h

来自「基于51单片机的心电监护仪程序」· C头文件 代码 · 共 37 行

H
37
字号
#ifndef __AD_H__
#define __AD_H__
byte send_byte (byte a)
{
	byte ii,mask=0x80,t,rb;	
		for(ii=0;ii<8;ii++)
		{
			SCLK=0;
			t=a&mask;
			DIN=(t==0)? 0:1;	    //send bit
			SCLK=1;
			rb=(DOUT==1)? rb|mask:rb&(~mask);	//receive bit
			SCLK=0;
			mask >>= 1;
		}
	return (rb);
}

/********************************/
byte AD_conversion ()
{
    byte RB0,RB1,RB2,result;
    AD_CS=0;
    RB0=send_byte(AD_contr);	    //start the AD conversion
	
    AD_CS=1;
    while (SSTRB==0)	{}	        //wait for the end of converstion
    AD_CS=0;
	
    RB1=send_byte(0x00);	
    RB2=send_byte(0x00);
    AD_CS=1;
    result=(RB1<<2)|(RB2>>6);	    //get the AD result
    return (result);
}

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?