Stopwatch timing function (simulation) single chip computer program

Publisher:泉趣人Latest update time:2012-10-11 Source: 21ic Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The following simulation effect diagram can be made according to the above circuit

Click to browse the next page

/**
//Imitate the stopwatch timing function, and the independent button can control the "pause/move" of the timing numbers. (The program does not consider the timing accuracy control)
/*P2.2~P2.4 are connected to the 138 decoder input port
/*P1.0 connects to independent button
/*P0 port output data
***/
#include
code unsigned char tab[]={0x3f,0x06,0x5b,0x4f,0x66,
                          0x6d,0x7d,0x07,0x7f,0x6f,0x40}; // Common cathode digital tube 0-9 '-' 'off' table
unsigned int count,a,b,sec,min,hour;
bit c_flag; // Pause/timing flag          

/*****T1 initialization*****/
void timer_1(void)
{
  TH1=0x0ec;
  TL1=0x078;
  TR1=1;
  }
/*****Data Count******/
void time_count(viod)
{
 if(hour==60){sec=0,min=0,hour=0;}
   else if(sec!=59) sec++;
      else if(min!=59) {sec=0,min++;}
     else {min=0,hour++;}
 }
/******Digital Adjustment*******/
void get_count(unsigned int x)
{
  a=x/10;
  b=x%10;
  }
/*******Key detection********/
void key_tach(void)
{
   int i,j;
   j=P1&0x01;
   if(j==0){
     for(i=0;i<=200;i++);
  j=P1&0x01;
  if(j==0)
   {if(c_flag==1) c_flag=0;
         else c_flag=1;}
   }
   }
/*******Display program********/
void display(viod)
{   
   int flag;
   P0=0x00;
   flag=count%8;
   switch(flag){
    case 0:P2=flag*4;
        get_count(hour);
     P0=tab[a];
     break;
 case 1:P2=flag*4;
     P0=tab[b];
     break;
 case 2:P2=flag*4;
     P0=tab[10];
     break;
 case 3:P2=flag*4;
        get_count(min);
     P0=tab[a];
     break;
 case 4:P2=flag*4;
     P0=tab[b];
     break;
 case 5:P2=flag*4;
     P0=tab[10];
     break;
 case 6:P2=flag*4;
        get_count(sec);
     P0=tab[a];
     break;
 case 7:P2=flag*4;
     P0=tab[b];
     break;
 default:return;
    }
   }
/*******Interrupt service routine********/
void int1() interrupt 3
{
   key_tach();
   if(c_flag==0)
   {
     if(count==7) {count=0;time_count();}
       else count++;}
    else
    {
        if(count==7) {count=0;}
        else count++;}
   display();
   timer_1();
   }

/******Main program*****/
void main()
{
  c_flag=0;
  count=0;
  sec=0;
  min=0;
  hour=0;
  TMOD=0x10;
  EA=1;
  ET1=1;
  timer_1();
  while(1);
  }
Reference address:Stopwatch timing function (simulation) single chip computer program

Previous article:Program for microcontroller to control the on and off of three LED lights
Next article:Slide type digital tube display

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号