标题: 单片机双数码管1分钟计时新手入门 [打印本页]

作者: 业务繁忙    时间: 2020-6-9 14:00
标题: 单片机双数码管1分钟计时新手入门
#include<reg51.h>
unsigned char code c[]={0xc0,0xf9,0xA4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char code cd[]={0x90,0x80,0xf8,0x82,0x92,0x99,0xb0,0xA4,0xf9,0xc0};
unsigned char second;
unsigned  char tcount;

void  main()
{
    TMOD=0x01;
        TH0=(65536-50000)/256;
        TL0=(65536-50000)%256;
    ET0=1;
        EA=1;
        TR0=1;
        tcount=0;
        second=0;
        P0=c[second/10];//0
        P2=c[second%10];//0
        while(1)//50ms
        {
           if(TF0==1)           //开启查询
           {
                    tcount++;
             if(tcount==20)//1s
        {
                tcount=0;
                second++;//1
                   if(second==60)
                    {
                        second=0;
                        }
                P0=c[second/10];
            P2=c[second%10];
            }
           TF0=0;   //手动置0
           TH0=(65336-50000)/256;
           TL0=(65336-50000)%256;           
           }        
        }
}
void t0(void) interrupt 1 using 0
{

}


双数码管.zip

76.58 KB, 下载次数: 3, 下载积分: 黑币 -5






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