📄 led clock.c.bak
字号:
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit DULA = P2^6;
sbit WELA = P2^7;
uint xms,i,j;
uchar num0,num1,num2,num3,num4,num5,shi,ge;
uchar S_num,M_num,H_num;
uchar S_shi,S_ge;
uchar M_shi,M_ge;
uchar H_shi,H_ge;
uchar code table []=
{
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
void display_S(uchar ,uchar );
void display_M(uchar ,uchar );
//void display_H(uchar ,uchar);
void delayms( uint);
//主程序
void main()
{
//RCAP2H=0x0c;
// RCAP2L=0x18;
TMOD = 0X11;
TH0 = (65536 - 45872)/256;
TL0 = (65536 - 45872)%256;
TH1 = (65536 - 45872)/256;
TL1 = (65536 - 45872)%256;
EA = 1;
ET0 = 1;
ET1 = 1;
TR0 = 1;
TR1 = 1;
//ET2=1; // 允许T2定时器中断 // 打开总中断
//TR2=1; // 启动T2定时器
while(1)
{
display_S(S_shi ,S_ge);
display_M(M_shi ,M_ge);
// display_H(H_shi ,H_ge);
}
}
// 延迟xms程序
void delayms(uint xms)
{
int i,j;
for (i = xms;i > 0;i-- )
for(j = 110;j > 0;j--);
}
//显示秒的十位个位的子函数
void display_S(uchar S_shi,uchar S_ge)
{
// 个位
DULA = 1;
P0 = table[S_ge];
DULA = 0;
P0 =0xff;
WELA = 1;
P0 = 0xdf;
WELA =0;
delayms(5);
//十位
DULA = 1;
P0 = table[S_shi];
DULA = 0;
P0 =0xff;
WELA = 1;
P0 = 0xef;
WELA =0;
delayms(5);
}
//显示分的十位个位的子函数
void display_M(uchar M_shi,uchar M_ge)
{
// 个位
DULA = 1;
P0 = table[M_ge];
DULA = 0;
P0 =0xff;
WELA = 1;
P0 = 0xf7;
WELA =0;
delayms(5);
//十位
DULA = 1;
P0 = table[M_shi];
DULA = 0;
P0 =0xff;
WELA = 1;
P0 = 0xfb;
WELA =0;
delayms(5);
}
/*
//显示时的十位个位的子函数
void display_H(uchar H_shi,uchar H_ge)
{
// 个位
DULA = 1;
P0 = table[H_ge];
DULA = 0;
P0 =0xff;
WELA = 1;
P0 = 0xfd;
WELA =0;
delayms(5);
//十位
DULA = 1;
P0 = table[H_shi];
DULA = 0;
P0 =0xff;
WELA = 1;
P0 = 0xfe;
WELA =0;
delayms(5);
}
*/
//间隔1s的计时中断
void timer0()interrupt 1
{
TH0 = (65536 - 45872)/256;
TL0 = (65536 - 45872)%256;
num0++;
if(num0 ==20)
{
num0 = 0;
S_num++;
if(S_num ==60)
// delayms(100);
S_num =0;
S_shi = S_num / 10;
S_ge = S_num % 10;
}
}
//间隔1M的中断
void timer1 ()interrupt 3
{
TH1 = (65536 - 45872)/256;
TL1 = (65536 - 45872)%256;
num1++;
if(num1 ==20)
{
num1 = 0;
num2++;
if(num2 == 60)
// delayms(100);
{
num2 =0;
M_num++;
if(M_num == 60)
// delayms(100);
M_num =0;
M_shi = M_num / 10;
M_ge = M_num % 10;
}
}
}
/*
//间隔1H的中断
void timer2 ()interrupt 5
{
TF2=0; // T2定时器发生溢出中断时,需要用户自己清除溢出标记,而51的其他定时器是自动清除的?
num3++;
if(num3==15) // T2定时器的预装载值为0x0BDC,溢出16次就是1秒钟。
{
num3=0;
num4++;
if (num4 == 60)
num4 = 0;
num5++;
if (num5 == 60)
{
num5 =0;
H_num++;
if (H_num == 24)
H_num =0;
H_shi = H_num / 10;
H_ge = H_num % 10;
}
}
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -