Digital Clock (Digital Display) Example: 23-59-23

Source: Internet
Author: User

# Include <reg52.h> // contains the header file, which generally does not need to be changed. The header file contains the definition of special function registers.
# Define uchar unsigned char
# Define uint unsigned int
Static unsigned char count;
Code unsigned char tab [] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f };
// Common overcast digital tube 0-9
Uchar smg [8]; // defines the buffer.
Uint minute = 30, hour = 12, second; // defined and initialized at 12:30:00
 
Void delay (unsigned int cnt)
{
While (-- cnt );
}
 
Void display ()
{


Smg [0] = tab [hour/10]; // displays the hour
Smg [1] = tab [hour % 10];
Smg [2] = 0x40; // display "-"
Smg [3] = tab [minute/10]; // display minutes
Smg [4] = tab [minute % 10];
Smg [5] = 0x40; // display "-"
Smg [6] = tab [second/10]; // display seconds
Smg [7] = tab [second % 10];

}


Void main ()
{
Uchar I;
TMOD | = 0x01; // timer 0 10 ms in 12 M crystal for timing
TH0 = 0xd8; // Initial Value
TL0 = 0xf0;
ET0 = 1;
TR0 = 1;
EA = 1;


Display ();


While (1)
{
For (I = 0; I <8; I ++) // display time
{
P0 = smg [I];
P2 = I;
Delay (100 );
}
 
If (count = 100)
{
Count = 0;
Second ++; display (); // second plus 1
If (second = 60)
{
Second = 0;
Minute ++; // Add 1
If (minute = 60)
{
Minute = 0;
Hour ++; // Add 1
If (hour = 24)
Hour = 0;
}

}

}


Display ();
}
 
}


Void timer () interrupt 1
{

TH0 = 0xd8; // assign a value again
TL0 = 0xf0;
Count ++;


}

 


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.