| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 392 人关注过本帖
标题:帮看一下这个程序那里出了问题?很急呀
取消只看楼主 加入收藏
gnniiby
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-6-22
收藏
 问题点数:0 回复次数:0 
帮看一下这个程序那里出了问题?很急呀
#include <reg52.h>
#include <intrins.h>    //延时函数用
#define ad_con P2       //A/D控制口
#define addata P0         //A/D数据记入读入口
#define Disdata P1        //显示数据段码输出口
#define uchar unsigned char  
#define uint unsigned int
sbit ALE=P2^3;            //锁存地址控制位
sbit START=P2^4;             //启动一次转换位
sbit OE=P2^5;                //0809输出数据 控制位
sbit EOC=P3^7;                 //转换结束标志位
sbit DISX=Disdata^7;           //LED小数点
sbit A=P2^7;
sbit BO=P3^5;
sbit CO=P3^6;
//
//
uchar code dis_7[11]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xff};
/*共阳7段LED段码表0.1.2.3.4.5.6.7.8.9.不亮*/
uchar code scan_con[4]={0xfe,0xfd,0xfb,0xf7};                     //4位列扫描控制字
//11111110
//11111101
//11111011
//11110111
uchar data ad_data[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};  //定义8个数据内存单元
uint data dis[5]={0x00,0x00,0x00,0x00,0x00};                      //定义4个显示数据单元和1个数据存储单元
//
//
/**********1ms延时子函数***********/
delaylms(uint t)    //t=1
    {
        uint i,j;
        for(i=0;i<t;i++)
            for(j=0;j<120;j++)
                ;
    }
//
//
/************显示扫描子函数***************/
scan()
    {
        uchar k,n;
        int h;
        dis[3]=0x01;                     //通道初值为1
        for(n=0;n<8;n++)                 //每次显示8个数据
            {
                dis[2]=ad_data[n]/51;  //测得值转换为3位BCD码,最大为5.00V
                dis[4]=ad_data[n]%51;  //余数暂存
                dis[4]=dis[4]*10;      //计算小数第一位
                dis[1]=dis[4]/51;      
                dis[4]=dis[4]%51;
                dis[4]=dis[4]*10;      //计算小数第二位
                dis[0]=dis[4]/51;
                if(dis[2]>=4&&dis[1]>6&&dis[0]>=0)
                    A=1;  
                else     
                    A=0;
                for(h=0;h<500;h++)            //每个通道显示时间控制约为一秒
                    {
                        for(k=0;k<4;k++)         //4位LED扫描控制
                            {
                                Disdata=dis_7[dis[k]];
                                if(k==2)
                                    {
                                        DISX=0;
                                    }
                                P3=scan_con[k];   //P3.O-P3.3控制四个数码管的输出 即控制输出电平的高低
                                delaylms(1);
                                P3=0xff;
                            }   
                    }
            dis[3]++;                 //通道值加1
            }
    }
//
//
/*************通道选择函数*********************/
tongdao(uint n)
        {
            uint m,i;
            dis[3]=n+1;
            dis[2]=ad_data[n]/51;  //测得值转换为3位BCD码,最大为5.00V
            dis[4]=ad_data[n]%51;  //余数暂存
            dis[4]=dis[4]*10;      //计算小数第一位
            dis[1]=dis[4]/51;      
            dis[4]=dis[4]%51;
            dis[4]=dis[4]*10;      //计算小数第二位
            dis[0]=dis[4]/51;
            if(dis[2]>=4&&dis[1]>6&&dis[0]>=0)
                A=1;  
            else
                A=0;
            for(m=0;m<500;m++)        //每个通道显示时间控制约为一秒
                {
                    for(i=0;i<4;i++)         //4位LED扫描控制
                        {
                            Disdata=dis_7[dis[i]];
                            if(i==2)
                                {
                                    DISX=0;
                                }
                            P3=scan_con[i];   //P3.O-P3.3控制四个数码管的输出 即控制输出电平的高低
                            delaylms(1);
                            P3=0xff;
                        }   
                }
        }
        /*************0809转换子函数*******************/
test()
    {  
        uchar m;
        uchar s=0x00;
        ad_con=s;
        for(m=0;m<8;m++)
            {
                ALE=1;
                _nop_();
                _nop_();
                ALE=0;    //转换通道地址锁存
                START=1;
                _nop_();
                _nop_();
                START=0; //开始转换命令
                _nop_();
                _nop_();
                _nop_();
                _nop_(); //延时4US
                while(EOC==0);                    //等待转换结束
                OE=1;
                ad_data[m]=addata;
                OE=0;
                s++;
                ad_con=s;  //取A/D值,地址加1
            }
        ad_con=0x00;//控制复位
    }
//
//
main()
    {
        uint n,i,j;
        n=0;
        P0=0xff;             //初始化窗口
        P1=0x00;
        P2=0xff;
        P3=0xff;
        i=BO;
       while()
            {
                test();             //测量转换一次
                  if(i==0)
                     for(;;)
                        {    j=CO;
                            if(j==0)
                             {
                                n++;
                              }
                             tongdao(n);
                                if(n>7)
                                  n=0;     
                                if(i==0) break;                            
                            }            
                  else
                  {
                    scan();       //显示八个通道值一次
                  }
             }
    }
//
2008-06-22 19:46
快速回复:帮看一下这个程序那里出了问题?很急呀
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016704 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved