打印

帮忙解决

[复制链接]
2107|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
电压表的程序,但是没有成功!!帮忙解决!!谢谢!!
#include<reg52.h>
#define uchar  unsigned char
#define uint   unsigned int
uchar code  dispcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar  dispbuf[4]={0,0,0,0};
uchar  temp;
uchar  getdata;
uint    i,j;
void   delay();
sbit   OE=P3^0;
sbit   CLK=P3^1;
sbit   START=P3^2;
sbit   EOC=P3^3;
void  delay()///延时//
{
  uchar i;
  uchar j;
  for(i=0;i<=10;i++)
      for(j=0;j<=250;j++);
}
void   main()
{
     START=0;
  OE=0;
  ET0=1;
  ET1=1;
  EA=1;
  TMOD=0x12;//定时器T1工作1,定时器T0为工作2方式;
  TL0=216;
  TH0=216;
  TL1=(65536-4000)/256;
  TH1=(65536-4000)%256;
  TR1=1;
  TR0=1;
  START=1;
  START=0;
      while(1)
     {
         if(EOC==1)  //==A/D转换完成==//
         {
        OE=1; //允许取数据///
      getdata=P1;//取数据//
      OE=0;
      temp=getdata*500;
      temp=temp/256;
      dispbuf[0]=temp/100;
      dispbuf[1]=temp%100/10;
      dispbuf[2]=temp%100%10;
      START=1;
      START=0;
      }
     }
}
void t0(void) interrupt 1  using 0
{CLK=~CLK;}//时钟信号//
void t1(void) interrupt 3  using 0
{
      TL1=(65536-4000)/256;
      TH1=(65536-4000)%256; //重新装入//
   P2=0x01;
   P0=dispcode[dispbuf[0]];
   delay();
   P2=0x02;
   P0=dispcode[dispbuf[1]];
   delay();
   P2=0x04;
   P0=dispcode[dispbuf[2]];
   delay();
}

电压表.jpg (198.81 KB )

电压表.jpg

相关帖子

沙发
demaxiya| | 2012-11-23 09:45 | 只看该作者
CLK=~CLK改为CLK=!CLK试试 希望可以帮到你

使用特权

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

本版积分规则

6

主题

55

帖子

0

粉丝