Digital tube 60S counting display--C language

Publisher:breakthrough2Latest update time:2016-10-27 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include   //   Header file containing 51 MCU register definitions

unsigned char code Tab[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff}; 
 // Segment code table of digital tube display 0~9

unsigned char int_time; //Record interrupt times
unsigned char second; //Store seconds
/************************************************************************
Function: Fast dynamic scanning delay, delay of about 0.6 milliseconds
********************************************************************/
void delay(void)
{
  unsigned char i;
  for(i=0;i<200;i++)
        ;
}
/***************************************************************************
Function: Display seconds
Input parameter: k
Output parameter: None
************************************************************************/
 void DisplaySecond(unsigned char k)
{
   
   P2=0xbf; //P2.6 pin outputs low level, DS6 lights up 
   P0=Tab[k/10]; //Display tens digit
   delay();
    delay();
       delay();
     delay();
      delay(); delay();
    delay();
       delay();
     delay();
   P2=0x7f; //P2.7 pin outputs low level, DS7 lights up 
   P0=Tab[k%10]; //Display the units digit
 delay();
     delay();
     delay();
      delay();
    delay(); delay();
    delay();
       delay();
     delay();
 P2=0xff; //Turn off all digital tubes

 P0=0xff; //Display units
   delay();
     delay();
      delay();
    delay(); delay ();
     delay();
    delay()
       ; delay();
     delay();
}     
  void main(void) //Main function
   {
   TMOD=0x01; //Use timer T0
   TH0=(65536-46083)/256; //Set the timer timing to 46083×1.085 microseconds
//=50000 microseconds=50 milliseconds
    TL0=(65536-46083)%256;
  EA=1; //Turn on total interrupt
  ET0=1; //Timer T0 interrupt enable
  TR0=1; //Start timer T0 and start running
  int_time=0; //Initialize the number of interrupts
  second=0; //Initialize seconds  
        while(1)
  {
        DisplaySecond(second); //Call the display subroutine of seconds
   }
    }  
//************************************************************
// Function: interrupt service routine of timer T0

//***********************************************************
  void interserve(void ) interrupt 1 using 1  
  {
    TR0=0; //Turn off timer T0
    int_time ++; //Every time an interrupt comes, the interruption count int_time is incremented by 1 
  if(int_time==20) //Enough interruptions, i.e. sampling the test result once every 1 second
   {
        int_time=0; //The interruption count is cleared to 0
     second++; //Increase the second by 1
     if(second==60)
       second =0; //If the second is equal to 60, it returns to 0
   }        
   TH0=(65536-46083)/256; //Re-initialize the counter T0
 TL0=(65536-46083)%256;
 TR0=1; //Start timer T0
 }  

Reference address:Digital tube 60S counting display--C language

Previous article:Digital tube scrolling display C language programming
Next article:Digital tube dynamic scanning display 12345678

Latest Microcontroller Articles
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号