标题: 两位秒表 [打印本页]

作者: 157359    时间: 2018-10-26 15:56
标题: 两位秒表
#include<STC15.H>#define uchar unsigned char#define uint unsigned intuchar code DSY_DUAN[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};
unsigned char digbuf[]={0,0};
uint cnt,second;void delayms(uint z)
{         
     uint i,j;         
     for(i=z;i>0;i--)          
    for(j=115;j>0;j--);
}
void shujuchuli()
{         
    digbuf[0]=second%10;          
    digbuf[1]=second/10;  
}
void display()
{         uint t;       
        for(t=0;t<2;t++)       
{               
        P2=~(0x01<<t);          
        P0=DSY_DUAN[digbuf[t]];     
        delayms(1);          
        P0=0x00;       
}  
}
void Timer0() interrupt 1
{            TH0=(65536-50000);          
          TL0=(65536-50000);          
          cnt++;         
          if(cnt==40)               
            {               
                cnt=0;               
                second++;               
                if(second==99)               
{                       
               second=0;   
}
}
}
void main()
{          
       TMOD=0x01;          
       TH0=(65536-50000);          
       TL0=(65536-50000);          
        EA=1;          
        ET0=1;          
        TR0=1;       
         while(1)
        {               
            shujuchuli();               
            display();       
}
}




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