标题: 单片机定时器查询方式例程,有一点问题,求帮助 [打印本页]

作者: 0302170113    时间: 2018-9-7 20:25
标题: 单片机定时器查询方式例程,有一点问题,求帮助
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define Dig P0
sbit gA=P2^2;
sbit gB=P2^3;
sbit gC=P2^4;
uchar count,num;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f};
void main()
{   
   
    count=0;
    num=0;
    gA=1;gB=1;gC=1;
    TMOD=0X01;
    TH0=(65536-50000)/256;
    TL0=(65536-50000)%256;
    //EA=1;
    //ET0=1;
    TR0=1;
    //TF0=0;
    P0=table[0];
    while(1)
    {   
         while(~TF0)
         TH0=(65536-50000)/256;
         TL0=(65536-50000)%256;
         TF0=0;
         count++;
      if(count==20)
      {
        count=0;
        num++;
        if(num==10)               
           num=0;
           P0=table[num];                  
      }
      
     }         
}


作者: wulin    时间: 2018-9-7 21:01
改成这样:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define Dig P0
sbit gA=P2^2;
sbit gB=P2^3;
sbit gC=P2^4;
uchar count,num;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f};
void main()
{  
    count=0;
    num=0;
    gA=1;gB=1;gC=1;
    TMOD=0X01;
    TH0=(65536-50000)/256;
    TL0=(65536-50000)%256;
    //EA=1;
    //ET0=1;
    TR0=1;
    //TF0=0;
    Dig=table[0];
        while(1)
        {   
//                while(!TF0)
                if(TF0==1)
                {
                        TH0=(65536-50000)/256;
                        TL0=(65536-50000)%256;
                        TF0=0;
                        count++;
                        if(count==20)
                        {
                                count=0;
                                num++;
                                if(num==10)               
                                        num=0;
                                Dig=table[num];                  
                        }
                }
        }         
}

作者: 0302170113    时间: 2018-9-7 22:35
谢谢指点




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