这是最简单的时钟,无按键调时,只有计时部分
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delay(uint);
uchar num,num0,num1,num2,shi2,ge2,shi1,ge1,shi0,ge0;
void display( uchar,uchar,uchar,uchar,uchar,uchar);
void main()
{
TMOD=0X01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
display(shi2,ge2,shi1,ge1,shi0,ge0);
}
}
void display(uchar shi2,uchar ge2,uchar shi1,uchar ge1,uchar shi0,uchar ge0) {
dula=1;
P0=table[shi0];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(1);
dula=1;
P0=table[ge0];
dula=0;
这是最简单的时钟,无按键调时,只有计时部分
}
P0=0xff; wela=1; P0=0xfd; wela=0; delay(1); dula=1; P0=table[shi1]; dula=0; P0=0xff; wela=1; P0=0xfb; wela=0; delay(1); dula=1; P0=table[ge1]; dula=0; P0=0xff; wela=1; P0=0xf7; wela=0; delay(1); dula=1; P0=table[shi2]; dula=0; P0=0xff; wela=1; P0=0xef; wela=0; delay(1); dula=1; P0=table[ge2]; dula=0; P0=0xff; wela=1; P0=0xdf; wela=0; delay(1);
这是最简单的时钟,无按键调时,只有计时部分
void delay(uint time)
{
uint i,j;
for(i=time;i>0;i--) for(j=110;j>0;j--); }
void T0_time() interrupt 1 {
TH0=(65536-45872)/256; TL0=(65536-45872)%256; num++;
if(num==20)
{
num=0;
num2++;
if(num2==60) {
num2=0; num1++; if(num1==60) {
num1=0; num0++; if(num0==60) num0=0; }
}
}
shi0=num0/10;
ge0=num0%10;
shi1=num1/10;
ge1=num1%10;
shi2=num2/10;
ge2=num2%10;
}