Single chip stopwatch program accurate to one thousandth of a second (with simulation)

Publisher:Xiaoxue666Latest update time:2015-07-01 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
This stopwatch program is a program included in the 51hei microcontroller development CD. It can be accurate to one thousandth of a second. The attachment contains simulation files and hex files. Download address: http://www.51hei.com/bbs/dpj-19342-1.html  

#include
#include
#define uint unsigned int
#define uchar unsigned char
sbit duxa=P2^6;
sbit wexa=P2^7;
sbit k1=P1^2;
sbit k2=P1^ 3;
sbit k3=P1^4;
uchar temp,qian,bai,shi,ge;
uint num,a,shu;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void init();
void delay(uint z);
void display(uchar num,uchar qian,uchar bai,uchar shi,uchar ge);
void main()
{   
    init();
    while(1)
    {
        display(num,qian,bai,shi,ge);
        if(k1==0)  
        {
            delay(1);
            TR0=0;
            delay(1 );
        }
        if(k2==0)
        {
            delay(1);
            TR0=1;
            delay(1);
        }
        if(k3==0)
        {
          delay(1);
          a=0;
          num=0;
          TR0=1 ;
          delay(1);
        
         }
            
    }
}
void init()
{
    num=0;
    temp=0xf0;
    TMOD=0x01;
    TH0=(65536-1000)/256;
    TL0=(65536-1000)%256;
    EA=1;
    ET0=1;
    TR0=1;
    bai=0;
    shi=0;
    ge=0;
    a=0;
    k1=1;
    k2=1;
    k3=1;
}
void delay(uint z)
{
    uint x,y;
    for(x=z;x>0;x--)
        for(y=110;y>0;y--);
}
void timer0() interrupt 1
{
    TH0=(65536-1000)/256 ;
    TL0=(65536-1000)%256;
    a++;
    
    if(a==9999)
        {
            a=0;
            num++;
            if(num==10)
                num=0;
            
        }  
    shu=a;
    qian=shu/1000;
    bai =shu%1000/100;
    shi=shu%100/10;
    ge=shu%10;
}

void display(uchar num,uchar qian,uchar bai,uchar shi,uchar ge)
{
        wexa=1;
        P0=0xfe;
        wexa=0;
        P0=0;
        duxa=1;
        P0=table[num];
        duxa=0;
        P0=0xff;
        delay(1);

        
        wexa=1;
        P0=0xfd;
        wexa=0;
        P0=0;
        duxa=1;
        P0=table[qian];
        duxa=0;
        P0=0xff;
        delay(1);


        wexa=1;
        P0=0xfb;
        wexa=0;
        P0=0;
        duxa=1;
        P0=table[bai];
        duxa=0;
        P0=0xff;
        delay(1);
       

        wexa=1;
        P0=0xf7;
        wexa=0;
        P0=0;
        duxa=1;
        P0=table[shi];
        duxa=0;
        P0=0xff;
        delay(1);

        wexa=1;
        P0=0xef;
        wexa=0;
        P0=0;
        duxa=1;
        P0=table[ge];
        duxa=0;
        P0=0xff;
        delay(1);
}

Reference address:Single chip stopwatch program accurate to one thousandth of a second (with simulation)

Previous article:51 single chip microcomputer drives 16*16 dot matrix to display happy birthday program
Next article:51 MCU Assembly: Multi-channel Delay Switch

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号