Good digital clock Program

Source: Internet
Author: User

# Include <at89x51. h>
Unsigned char code dispcode [] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x40 }; // 0123456789 off
Unsigned char dispbitcode [] = {0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f}; // select different bits for Illumination
Unsigned char dispbuf [8] = {0, 10, 0,}; // Initial Value
Unsigned char dispbitcnt;
Unsigned char second;
Unsigned char Minite;
Unsigned char hour;
Unsigned int tcnt;
Unsigned char mstcnt;
Unsigned char I, J;
Void main (void)
{
Tmod = 0x02;
Th0 = 0x06;
Tl0 = 0x06;
Tr0 = 1;
Et0 = 1; // t0 interrupt control bit
Ea = 1; // count 250 times
While (1)
{
If (p0_0 = 0)
{
For (I = 5; I> 0; I --)
For (j = 248; j> 0; j --);
If (p0_0 = 0)
{
Second ++;
If (second = 60)
{
Second = 0;
}
Dispbuf [0] = Second % 10;
Dispbuf [1] = Second/10; // display seconds
While (p0_0 = 0); // indicates that p0_0 is pressed to continue execution. Otherwise, skip
}}
If (p0_1 = 0)
{
For (I = 5; I> 0; I --)
For (j = 248; j> 0; j --);
If (p0_1 = 0)
{
Minite ++;
If (Minite = 60)
{
Minite = 0;
}
Dispbuf [3] = Minite % 10;
Dispbuf [4] = Minite/10;
While (p0_1 = 0 );
}
}
If (p0_2 = 0)
{
For (I = 5; I> 0; I --)
For (j = 248; j> 0; j --);
If (p0_2 = 0)
{
Hour ++;
If (hour = 24)
{Hour = 0 ;}
Dispbuf [6] = hour % 10;
Dispbuf [7] = hour/10;
While (p0_2 = 0 );
}}}}
Void T0 (void) interrupt 1 using 0 // interrupt entry
{
Mstcnt ++ ;,
If (mstcnt = 8) // 2 ms, refresh rate
{
Mstcnt = 0;
P1 = dispcode [dispbuf [dispbitcnt];
P3 = dispbitcode [dispbitcnt];
Dispbitcnt ++;
If (dispbitcnt = 8) // 2 ms
{
Dispbitcnt = 0;
}
}
Tcnt ++;
If (tcnt = 4000) // one second
{
Tcnt = 0;
Second ++;
If (second = 60)
{
Second = 0;
Minite ++;
If (Minite = 60)
{
Minite = 0;
Hour ++;
If (hour = 24)
{
Hour = 0;
}
}
}
Dispbuf [0] = Second % 10;
Dispbuf [1] = Second/10;
Dispbuf [3] = Minite % 10;
Dispbuf [4] = Minite/10;
Dispbuf [6] = hour % 10;
Dispbuf [7] = hour/10; // display various types of data
}
}

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.