⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ad_max197.c

📁 51单片机控ADC(MAX197)采集数据
💻 C
字号:
#define uchar unsigned char
#define uint  unsigned int
#define ulong unsigned long

#include<reg52.h>
#include<absacc.h>
#include<intrins.h>
#include"ad_max197.h"
//#include"lcd_12864.h"

#define AD_CMD  0x48  //选择通道0,输入范围0~5V。
                      //0,1,2位为通道选择位。3,4位为输入范围选择位(0:0~5V, 1:-5~+5V, 2:0~10V, 3:-10~+10V)
#define count 50
//uchar AD_Convert=0;

//void AD_READY(void) interrupt 2
//{
//   AD_Convert=1; 
//}

void main()
{   bit flag;
    uchar high_4,low_8,i;
    long  convert_number;
    float sample_value;

    //char high_4;
	//uchar low_8;
    //int  convert_number;
    //float sample_value;

    LCDInit();
	LCDClr();
    Disponechar(0,0,'A');
    Disponechar(1,0,'D');

	//EA=1;   //开中断
	//EX1=1;  //开外部中断1
	//IT1=1;  //设定外部中断1为负跳变触发

    while(1)
    
    AD_MAX197_Bipolar(0,1);
    //AD_MAX197_Polar(0,0);
/*
	while(1)
  {
    convert_number=0;
    for(i=0;i<count;i++)
   {
      XBYTE[0xfa00]=AD_CMD;             //置AD控制字
      while(AD_Convert==0);	
      AD_Convert=0;
      high_4=AD_SAMPLE_HIGH;             //接收高四位, P2_3=1;  P27 P22,P21,P20控制片选选通
      // Dispnumber(high_4,3,10,0);
      low_8=AD_SAMPLE_LOW;              //接收低八位, P2_3=0;  P27 P22,P21,P20控制片选选通
      // Dispnumber(low_8,3,10,1);

      if((high_4&0x08)==0x08)   //&逻辑运算,&&关系运算
      { 
	    high_4=0x0f-(high_4&0x0f);
        low_8=0x0100-low_8; 
		convert_number=convert_number - high_4*256 - low_8;   
      }                        //处理采集负电压时得到的补码
      else   convert_number=convert_number+ high_4*256 + low_8;
	}
       convert_number=convert_number/count;
       switch(AD_CMD&0x18)
       {
        case 0x08:convert_number=convert_number*2;break;
	    case 0x10:convert_number=convert_number*2;break;
	    case 0x18:convert_number=convert_number*4;break;
	    default: break;
       }
      sample_value=(uint)(convert_number*1.2207);

      Dispnumber_float(sample_value,4,3,10,2);
      if(convert_number<0) Disponechar(5,2,'-');
 	  else  Disponechar(5,2,'+');
  }
*/


}


/*******测时程序*********
	TMOD=0X10;
	TH1=0;
	TL1=0;
	TR1=1;
	process();
    TR1=0;
    Dispnumber(TH1*256+TL1,4,10,1);
	while(1);
***********************/
/*
    while(1)
   {
      sample_value=(uint)(AD_MAX197(1,1)*1.2207);
      Dispnumber_float(sample_value,4,3,10,2);
      if(flag==1) Disponechar(5,2,'-');
 	  else  Disponechar(5,2,'+');
   }
*/

⌨️ 快捷键说明

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