?? text1.c
字號:
#include <AT89X52.H>
unsigned char code SEG7[11]={0xC0,/*0*/
0xF9,/*1*/
0xA4,/*2*/
0xB0,/*3*/
0x99,/*4*/
0x92,/*5*/
0x82,/*6*/
0xF8,/*7*/
0x80,/*8*/
0x90,/*9*/
0xbf,/*-*/
};
unsigned short int tcount;
struct time
{
unsigned char second;
unsigned char minute;
unsigned char hour;
}time1;
void delay(k)
unsigned int k; //延時子程序
{
unsigned char j;
while((k--)!=0)
for(j=0;j<125;j++);
}
unsigned char n,x,y;
{
if(P1_1==0)
{
delay(50);
if(P1_1==0)
{
n++;
if(n==x)
n=0;
while(P1_1==0);
}
}
if(P1_2==0)
{
delay(50);
if(P1_2==0)
{
if(n==0)
n=y;
else
n--;
while(P1_2==0);
}
}
return n;
}
void display(DisSecondH,DisSecondL,DisMinutH,DisMinutL,DisHourH,DisHourL)
unsigned char DisSecondH,DisSecondL,DisMinutH,DisMinutL,DisHourH,DisHourL; //顯示子程序
{
P0=SEG7[DisSecondH]; //顯示秒鐘的十位
P2=0x80;
delay(2);
P0=SEG7[DisSecondL]; //顯示分鐘的個位
P2=0x40;
delay(2);
P0=0xbf; //顯示-
P2=0x20;
delay(2);
P0=SEG7[DisMinutH]; //顯示秒鐘的十位
P2=0x10;
delay(2);
P0=SEG7[DisMinutL]; //顯示分鐘的個位
P2=0x08;
delay(2);
P0=0xbf; //顯示-
P2=0x04;
delay(2);
P0=SEG7[DisHourH]; //顯示小時的個位
P2=0x02;
delay(2);
if(DisHourL==0)
P0=0xff;
else
P0=SEG7[DisHourL]; //顯示小時的十位
P2=0x01;
delay(2);
}
main()
{
unsigned char Flag;
TMOD = 0x01;
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
ET0 = 1;
EA = 1;
while(1)
{
if(P1_0 == 0) //設(shè)置標志位 Flag
{
delay(50);
if(P1_0 == 0)
{
TR0 = 0;
Flag++;
if(Flag > 3)
Flag = 0;
}
while(P1_0 == 0);
}
switch(Flag)
{
case 0:
TR0=1;
display(time1.second%10,time1.second/10,time1.minute%10,time1.minute/10,time1.hour%10,time1.hour/10);
break;
case 1: //時鐘小時調(diào)整
TR0=0;
time1.hour=TimeUpDown(time1.hour,24,23);
display(10,10,10,10,time1.hour%10,time1.hour/10);
break;
case 2: //時鐘分鐘調(diào)整
time1.minute=TimeUpDown(time1.minute,60,59);
display(10,10,time1.minute%10,time1.minute/10,10,10);
break;
case 3: //時鐘秒調(diào)整
time1.second=TimeUpDown(time1.second,60,59);
display(time1.second%10,time1.second/10,10,10,10,10);
break;
default:
break;
}
}
}
void t0(void) interrupt 1 using 0
{
tcount++;
if(tcount==10)
{
tcount=0;
time1.second++;
}
if (time1.second>=60)
{
time1.second=0;
time1.minute++;
}
if (time1.minute>=60)
{
time1.minute=0;
time1.hour++;
}
if(time1.hour>=24)
time1.hour=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -