原创 六位数码显示频率计程序

2008-7-28 20:53 2565 7 7 分类: MCU/ 嵌入式
#include <AT89X52.H>
unsigned char code dispbit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,
                               0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x40};
unsigned char dispbuf[8]={0,0,0,0,0,0,0,10};
unsigned char temp[8];
unsigned char dispcount;
unsigned char T0count;
unsigned char timecount;
bit flag;
unsigned long x;
 
void main(void)
{
  unsigned char i;
 
  TMOD="0x15";
  TH0=0;
  TL0=0;
  TH1=(65536-5000)/256;
  TL1=(65536-5000)%256;
  EA="1";
  ET0=1;
  ET1=1;
  TR0=1;
  TR1=1;
            
  while(1)
   {
     if(flag==1)
       {
         flag="0";
         x=(T0count*65536+TH0*256+TL0)*16; //WHY?这里要显示六位  
         for(i=0;i<9;i++)
           {
             temp=0;
           }
         i="0";
         while(x/10)
           {
             temp=x%10;
             x="x/10";
             i++;
           }
         temp=x;
         for(i=0;i<7;i++)
           {
             dispbuf=temp;
           }
         timecount="0";
         T0count=0;
         TH0=0;
         TL0=0;
         TR0=1;
       }
   }
}
 
void t0(void) interrupt 1 using 0
{
  T0count++;
}
 
void t1(void) interrupt 3 using 0
{
  TH1=(65536-5000)/256;
  TL1=(65536-5000)%256;
  timecount++;
  if(timecount==200)
    {
      TR0=0;
      timecount="0";
      flag="1";
    }
  P2=0xff;
  P0=dispcode[dispbuf[dispcount]];
  P2=dispbit[dispcount];
  dispcount++;
  if(dispcount==8)
    {
      dispcount="0";
    }
}
PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
我要评论
0
7
×
广告
关闭 站长推荐上一条 /3 下一条