打印

ADC转换的问题

[复制链接]
2018|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
51yao|  楼主 | 2008-8-18 10:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
沙发
51yao|  楼主 | 2008-8-18 10:05 | 只看该作者

还有

而且奇怪的是如果这几个检测值里面有两个5V的话,第一个5V的值就出错了(变成2.49V)。如果只出现一个5V,那么检测出来的电压值都是正确的

使用特权

评论回复
板凳
51yao|  楼主 | 2008-8-18 11:03 | 只看该作者

自己顶

使用特权

评论回复
地板
51yao|  楼主 | 2008-8-18 15:34 | 只看该作者

就是不明白,转换少通道和多通道有啥区别。好奇怪。

谁能给点提示呢?

使用特权

评论回复
5
dai_weis| | 2008-8-18 21:04 | 只看该作者

先上图

使用特权

评论回复
6
51yao|  楼主 | 2008-8-19 09:19 | 只看该作者

ADC的图

我实际搭有接上液晶屏。用P0口经4094到LCD。

使用特权

评论回复
7
51yao|  楼主 | 2008-8-19 10:07 | 只看该作者

采样三个通道的程序,无论什么值都能正常。

但是采样多点通道,测量某些值,如果两个电压值都为5V,就会出现其中一个值变换了。每次都是,多通道里面就会有这么一路出现错误,其他都正常。
#include<reg52.h>
#include<absacc.h>
#define uchar unsigned char
#define uint unsigned int
#define  IN0 XBYTE[0x78ff]  //设置AD0809的通道0地址
#define  IN1 XBYTE[0x79ff]  //设置AD0809的通道1地址
#define  IN2 XBYTE[0x7aff]  //设置AD0809的通道2地址
sbit ad_busy=P3^2;          //EOC状态
sbit sync_int=P3^3;     //第二测试点在P4^3
sbit OE=P3^7;

uchar y;
uchar flag;
sbit  E2=P1^6;     //LCD右半屏使能端
sbit  E1=P1^5;     //LCD左半屏使能端
sbit  R_W=P3^5;    //LCD的R/W端
sbit  A0=P3^4;     //LCD的A0端,1/0为:写数据/指令
sbit  CD4094_CLK=P0^5;   //CD4094的时钟输入端
sbit  CD4094_DATA=P0^6;   //CD4094的数据输入端
sbit   CD4094_STR=P0^7;   //LED PANEL DATA BUS

uchar xdata *ad_adr;

double a;
uchar idata table[4]={0};    
uchar *p;
uchar X_Add;    //页地址加
uchar Y_Add;    //列地址加
uchar Page_End;
uchar  X_Address;  //LCD页地址
uchar  Y_Address;  //LCD列地址

uchar code work[352]={0x00,0x00,0xE0,0xF0,0xF0,0x18,0x08,0x08,0x08,0x08,0x08,0x38,0xF0,0xE0,0xC0,0x00,
                0x00,0x01,0x0F,0x1F,0x1F,0x30,0x20,0x20,0x20,0x20,0x20,0x38,0x1F,0x0F,0x07,0x00,//0

                0x00,0x00,0x00,0x00,0x10,0x10,0x10,0xF8,0xF8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,
                0x00,0x00,0x00,0x00,0x20,0x20,0x20,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x20,0x00,0x00,//1

                0x00,0x00,0x20,0x70,0x78,0x08,0x08,0x08,0x08,0x08,0x88,0xF8,0xF8,0x70,0x00,0x00,
                0x00,0x00,0x30,0x30,0x38,0x3C,0x34,0x36,0x32,0x33,0x31,0x31,0x30,0x38,0x08,0x00,//2

                0x00,0x00,0x30,0x30,0x38,0x08,0x88,0x88,0x88,0x88,0xD8,0xF8,0x70,0x20,0x00,0x00,
                0x00,0x00,0x18,0x18,0x38,0x20,0x21,0x21,0x21,0x21,0x21,0x3B,0x1E,0x1E,0x04,0x00,//3

                0x00,0x00,0x00,0x00,0x80,0x80,0x40,0x60,0x30,0xF0,0xF8,0xF8,0x00,0x00,0x00,0x00,
                0x00,0x00,0x06,0x07,0x05,0x04,0x24,0x24,0x24,0x3F,0x3F,0x3F,0x24,0x24,0x24,0x00,//4

                0x00,0x00,0x00,0xF8,0xF8,0x88,0x88,0x88,0xC8,0xC8,0x88,0x88,0x88,0x08,0x00,0x00,
                0x00,0x00,0x18,0x1D,0x39,0x20,0x20,0x20,0x20,0x20,0x20,0x3B,0x1F,0x0F,0x06,0x00,//5

                0x00,0x00,0xC0,0xE0,0xF0,0x98,0x88,0x88,0x88,0x88,0x98,0x98,0xB8,0x10,0x00,0x00,
                0x00,0x03,0x0F,0x1F,0x1F,0x31,0x20,0x20,0x20,0x20,0x20,0x31,0x1F,0x1F,0x0E,0x00,//6

                0x00,0x00,0x30,0x38,0x18,0x18,0x08,0x08,0x08,0x88,0xC8,0x68,0x38,0x18,0x08,0x00,
                0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x3E,0x3F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,//7

                0x00,0x00,0x70,0xF0,0xD8,0xC8,0x88,0x88,0x88,0x88,0x88,0x88,0xF8,0x70,0x20,0x00,
                0x00,0x08,0x1E,0x1E,0x33,0x21,0x21,0x21,0x21,0x21,0x23,0x23,0x1E,0x1E,0x0C,0x00,//8

                0x00,0x40,0xF0,0xF0,0x18,0x08,0x08,0x08,0x08,0x08,0x08,0x18,0xF0,0xE0,0xC0,0x00,
                0x00,0x00,0x11,0x3B,0x3B,0x32,0x22,0x22,0x22,0x22,0x33,0x1D,0x0F,0x07,0x03,0x00,//9

                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//.
                
                };

/************模拟串口模式0,移位时钟程序****************/
SEND_CD4094(temp_data)
{
   uchar count=8;
   CD4094_CLK=0;
   do
   {
      if(temp_data&0x80)   CD4094_DATA=1;
      else                 CD4094_DATA=0;
      CD4094_CLK=0;
      ;
      CD4094_CLK=1;
      temp_data=temp_data<<1;
      count--;
   }
   while(count);

}
/*************LCD屏显的控制************************/
PANNL_CHIP_DRIVER(uchar REG_4094)
{
  //EA=0;
  SEND_CD4094(REG_4094);
  CD4094_STR=1;
  //delay(1);
  CD4094_STR=0;
}     



void  WRI(uchar uci)    //写指令
{
   A0=0;
  PANNL_CHIP_DRIVER(uci);
   E1=1;
   E2=1;
  // delay(1);
   E1=0;
   E2=0;
}
void  WRD(uchar ucd)     //写数据
{
    A0=1;
   PANNL_CHIP_DRIVER(ucd);
  
}
//左右屏的选择//
void Select_Screen(uchar screen)

   switch(screen)   
   {
       case 0: E1=1;       //全屏
            E2=1;
            //delay(1); 
            E1=0;
            E2=0;
            break;
    case 1: E1=1;      //左半屏

            //E2=1;
            //delay(1); 
            E1=0;
            //E2=0;
            break;
    case 2: //E1=1;    //右半屏
            //WRI(0);
            E2=1;
           // delay(1); 
            //E1=0;
            E2=0;
            break;
    } 
}

void Display_All(uchar lcd_data)//显示或熄灭全屏
{
   WRI(0xe2);   //复位
    X_Address=0xb8;   //页地址 初址0xb8 
    Y_Address=0x00;   //列地址 初址0x00 (设置出现问题)
   
   for(X_Add=4;X_Add>0;X_Add--)
   {
      WRI(0xe2);   //复位
      WRI(X_Address);  //页地址
      WRI(Y_Address);  //列地址
      WRI(0xe0);   //“读-修改-写”模式设置,列地址加一
      for(Y_Add=61;Y_Add>0;Y_Add--)//列地址加61次,满足一屏的列数
      { 
        WRD(lcd_data); //写数据  
            Select_Screen(0);
      }
       WRI(0xee);  //end
   X_Address++;
      
  }
}

/*初始LCD*/
void Init_Lcd()
{
    //CD4094_STR5_PIN=0;  //关继电器
    R_W=0;      //写有效
    WRI(0xaf);  //显示模式设置 
    WRI(0xc0);   //START = 0 设置显示起始行(行地址设置出现问题)0xc0为起始行
    WRI(0xa4);   //静态驱动关
    WRI(0xa9);    //duty=1/32    
    WRI(0xa0);   //反向显示(正向为0a0H)与原来成镜像
    WRI(0xe2);   //reset,从第一页开始显示,如果不是就从第三页开始显示

}

 

      /*汉字显示模块*//////////显示第一屏
Display_Left(uchar y_begin,uchar y_end,uchar page,uchar sele)//y_begin为起始列地址,y_end为终止列地址,page为页地址,数组的元素号k为行,j为列
{
           uint u=0,m=0,n=0xe7;
           uint  ii;
           uchar i=0;
           for(X_Add=2;X_Add>0;X_Add--)   //页地址加1次,满足一汉字的行数
           {                        
               i=0;
               WRI(0xc0);       //起始行地址
               WRI(y_begin+0);  //起始列地址
               WRI(page+0xb8);        //起始页地址
               WRI(0xe0);     //“读-修改-写”模式设置,列地址加
               u=table*32+m*16;
               p=&work;
               //u++;
               //p=&word[k][j+m*16];
               for(Y_Add=0;Y_Add<(y_end-y_begin)+1;Y_Add++)//判断是否计算到y_end列了,如果是,就换页
               {       
                      //i++;                      
                      Select_Screen(sele);//选择哪个屏
                      WRD(*(p)); //列地址开始自加一  //打开“读-修改-写”
                      if((++ii)%16==0){   //判断是否写完一个字了?
                      ++i;
                      p=&work[table*32+m*16];
                      //n++;                      
                      ii=0;
                      }else     {p++;n++;}
                      
                }    
                  n=0;
               ii=0;//记得清零
                ///列地址开始自加一  //打开“读-修改-写”        
               WRI(0xee);   //关闭“读-修改-写”模式,并把列地址指针恢复到打开“读-修改-写”模
               page++;             //换页       
               m++;
               //n=0;
               //u=y_end-y_begin+16*n;     //数组的元素号
               
           }        
          
           // return(u);
}

void frequence(double freq)
{
   //freq=01726.2;
   table[0]=(uint)freq/100;       //个位
   table[1]=10;//小数点
   table[2]=(uint)freq/10%10;      //小数点个位
   table[3]=(uint)freq%10;       //小数点十位
   //table[3]=(uint)freq%10;          //个位
   freq=0;
}

void ad0809() //采样结果放指针中的A/D采集函数
{
    //if(flag)
      //{
        //ad_adr++;
    //    ad_adr=&IN2;
       // flag=0;
     // }
 
     *ad_adr=0;           //启动转换:奇怪了,影响EOC的值,一启动就EOC变低

}
void delay(uint u1)
{
   uchar y;
   while(u1--)
   {
      for(y=0;y<125;y++);
   }
}
////显示第1,2,3通道
void disp_1()
{
   ad_adr=&IN1;
                  
   *ad_adr=0;
               
   frequence(a*5*100/255);
                  
   Display_Left(0,61,0,1);
}
void disp_2()
{
   ad_adr=&IN2;
                  
   *ad_adr=0;
              
   frequence(a*5*100/255);
                  
   Display_Left(0,61,2,1);
}
void disp_3()
{
   ad_adr=&IN0;
                  
   *ad_adr=0;
               
   frequence(a*5*100/255);
                  
   Display_Left(0,61,2,2);
}

void int_0() interrupt 0 
{        
       OE=0;                    //读有效
       a=*ad_adr;               //读取数据
       EA=0;
       delay(50);
       OE=1; 
       //v=a*5*100/225;//扩大一百倍
       
       switch(y)
       {
          case 1: {
                    disp_1();
                    y++;
                    break;
                  }
          case 2: {
                   //if(a!=0x33) flag=0;
                   disp_2();
                   y++;                  
                   break;
                  }
          case 3: {
                   //if(a!=0x66) flag=0;
                   disp_3();
                   y=1;
                   break;
                  }
          default:    {y++;}
       }
       
}

void main()
{

     //static uchar idata ad[10];

     Init_Lcd();       //初始化
     Display_All(0x00);//熄灭全屏

     IT0=1;
     EX0=1;
     flag=1;

     EA=1;
     ad_adr=&IN0;
     while(1)
     {
     ad0809(); 
     EA=1;
      //if(flag)
      //{ EA=1;}

      }              //采样AD0809通道的值
     //while(1);
}

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

42

主题

148

帖子

0

粉丝