标题: Proteus仿真 具有清零功能秒表相关 [打印本页]

作者: 田所浩二单推人    时间: 2021-6-17 11:19
标题: Proteus仿真 具有清零功能秒表相关
仿真图如下 不知道为什么没法+1和清零
代码如下
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
sbit K9=P2^4;
sbit K10=P2^5;
sbit K11=P2^6;
uchar code segtab[]=
{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,
0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff,0xbf};
uchar dbuf[4]={0,0,0,0x10};

void delay(void)
{   uchar i;
    for(i=0;i<200;i++);
}
void disp(void)
{  uchar n,bsel;
   bsel=0x01;
   for(n=0;n<4;n++)
   {   P0=segtab[dbuf[n]];
       P2=bsel|0xf0;
       bsel=_crol_(bsel,1);
       delay();
       P0=0xff;
   }
}
void main(void)
{   uchar i;
    int count=0;
    unsigned int t;
    while(1)
    {disp();
    if((P2&0x30)!=0x30)
    {  for(i=0;i<10;i++)disp();
        if((P2&0x30)!=0x30)
        {   if(K9==0)
            {  count++;
               if(count>999)count=-999;
            }
       if(K10==0)
       {   count--;
       if(count<-999)count=999;
       }
                         else
                                 count=0;
       if(count>=0)
       {    dbuf[3]=0x10;
            t=count;
       }
       else
       { dbuf[3]=0x11;
            t=-count;
       }
       dbuf[2]=t/100;
       dbuf[1]=(t%100)/10;
       dbuf[0]=t%10;
       while((P2&0x30)!=0x30)disp();
    }
    }
    }
}

计数器.jpg (92.3 KB, 下载次数: 43)

计数器.jpg





欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1