max197.h
来自「这是一个数字电子称的程序」· C头文件 代码 · 共 40 行
H
40 行
#define AD_H XBYTE[0x8100]
#define AD_L XBYTE[0x8000]
#define AD_CMD AD_H
sbit AD_Convert=P1^6;
#define ADUNIT0 1.221
#define ADUNIT12 1.221*2
#define ADUNIT3 1.221*4
#define AD_Wait() _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_()
int2char adv;//ad读回的值
void AD_Start(uchar chanel,uchar range)
//=============ad启动,chanel是通道号,range为采样范围控制字(0:0~5V, 1:-5~+5V, 2:0~10V, 3:-10~+10V)
{
AD_CMD=(uchar)((range<<3) + chanel) |0x40;
}
//============= 读取ad的转换结果,返回值为补码
uint AD_Read()
{
adv.hl[0]=AD_H;
adv.hl[1]=AD_L;
return adv.time;
}
//========================================应用层函数============================
uint AD_S_Read(uchar chanel,uchar range)
//ad 启动与读取函数
{
AD_Start(chanel,range);
AD_Wait();
return AD_Read();
}
void AD_Cb(uint * temp)//负数的补码转换
{
//*temp=0x1000-*temp;
*temp=*temp^0xffff;
*temp=*temp+1;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?