搜索
bottom↓
回复: 0

求助代码问题

[复制链接]

出0入0汤圆

发表于 2012-2-27 17:37:18 | 显示全部楼层 |阅读模式
我想用TLC2543采集信号,再用数码管显示出来。结果吧,数码管显示的及其不稳定,我本来以为是延时时间太长,现在把延时时间调整到最小,可是依然还是不稳定,而且,当通道0输入0时候,本来数码管该显示0000,但是就一直跳到。大家能帮忙看看这代码的问题吗?不胜感激啊
#include<reg52.h>
#include<intrins.h>
#include<string.h>
#define uchar unsigned char
#define uint  unsigned int

sbit AD_CLOCK=P3^3;
sbit AD_IN=P3^7;
sbit AD_OUT=P3^5;
sbit AD_CS=P3^6;
uchar table[10]={0xc0,0xf9,0xa4,0xb0,
  0x99,0x92,0x82,0xf8,
  0x80,0x90} ;

static const uchar ad_channel_select[]=
{0x08,0x18,0x28,0x38,0x48,0x58,0x68,0x78,0x88,
0x98,0xa8
};
uint ad2543(uchar chunnel_select)
{ uint din,j;
  uchar dout,i;
  din=0;
  dout=ad_channel_select[chunnel_select];
  for(j=0;j<100;j++);         //延时大于1uS.
  AD_CLOCK=0;
  AD_CS=0;
  for(i=0;i<12;i++)
  {
          if(dout&0x80)        AD_IN=1;
           else                 AD_IN=0;
           AD_CLOCK=1;
           dout<<=1;
           din<<=1;
           if(AD_OUT==1) din|=0x0001;
           AD_CLOCK=0;
  }
  AD_CS=1;
  for(j=0;j<100;j++);         //延时大于1uS.
  return(din);
}
void Delay_ms(uint ms)
{
  for(;ms--;);
}
void display(uint num)
{  
  P1=table[num/1000];
        P0=0x08;
   Delay_ms(1);        
    P1=table[(num%1000)/100];
        P0=0x04;
   Delay_ms(1);        
   P1=table[((num%1000)%100)/10];
        P0=0x02;
   Delay_ms(1);        
   P1=table[((num%1000)%100)%10];
        P0=0x01;
   Delay_ms(1);
  
}
void main(void)
{
uint ad;
while (1)
      {
   ad=ad2543(0);
              // ad=ad>>4;
                 ad=ad*1.2207;
           display(ad);

      }
}

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-20 00:17

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表