#include<reg52.h>
#define Dataport P0
sbit SPK=P1^2; //定义喇叭端口
unsigned char frq;
sbit Latch_seg = P2^2; //段
sbit Latch_bit = P2^3; //位
unsigned char arr_bit[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char arr_seg[10] = {0x3F,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f/*,0x77,0x7C,0x39,0x5E,0x79,0x71*/};
// 0 1 2 3 4 5 6 7 8 9
unsigned char arr_tel[16] = {0x06,0x07,0x07,0x7d,0x7f,0x06,0x5b,0x66,0x06,0x7f,0x4f,0x00,0x00,0x00,0x00,0x00};
// 1 7 7 6 8 1 2 4 1 8 3
unsigned long int j,k;
void DelayUs2x(unsigned char t)
{
while(--t);
}
/*------------------------------------------------
mS延时函数,含有输入参数 unsigned char t,无返回值
unsigned char 是定义无符号字符变量,其值的范围是
0~255 这里使用晶振12M,精确延时请使用汇编
------------------------------------------------*/
void DelayMs(unsigned char t)
{
while(t--)
{
//大致延时1mS
DelayUs2x(245);
DelayUs2x(245);
}
}
void isr_r0(void) interrupt 1
{
TH0 = 0xd8;
TL0 = 0xf0;
j++;
if(j == 100)
{
j = 0;
k++;
DelayUs2x(200);
DelayUs2x(200);
SPK=!SPK;
}
}
void delay(unsigned int i)
{
while(--i);
}
void tel()
{
unsigned int i;
while(1)
{
Dataport = arr_bit[i];
Latch_bit = 1;
Latch_bit = 0;
Dataport = arr_tel[(i+k)%16];
Latch_seg = 1;
Latch_seg = 0;
delay(200);
i++;
if(i == 8)
i = 0;
}
}
void clock()
{
unsigned int hour,min,sec = 0;
#define Dataport P0
sbit SPK=P1^2; //定义喇叭端口
unsigned char frq;
sbit Latch_seg = P2^2; //段
sbit Latch_bit = P2^3; //位
unsigned char arr_bit[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char arr_seg[10] = {0x3F,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f/*,0x77,0x7C,0x39,0x5E,0x79,0x71*/};
// 0 1 2 3 4 5 6 7 8 9
unsigned char arr_tel[16] = {0x06,0x07,0x07,0x7d,0x7f,0x06,0x5b,0x66,0x06,0x7f,0x4f,0x00,0x00,0x00,0x00,0x00};
// 1 7 7 6 8 1 2 4 1 8 3
unsigned long int j,k;
void DelayUs2x(unsigned char t)
{
while(--t);
}
/*------------------------------------------------
mS延时函数,含有输入参数 unsigned char t,无返回值
unsigned char 是定义无符号字符变量,其值的范围是
0~255 这里使用晶振12M,精确延时请使用汇编
------------------------------------------------*/
void DelayMs(unsigned char t)
{
while(t--)
{
//大致延时1mS
DelayUs2x(245);
DelayUs2x(245);
}
}
void isr_r0(void) interrupt 1
{
TH0 = 0xd8;
TL0 = 0xf0;
j++;
if(j == 100)
{
j = 0;
k++;
DelayUs2x(200);
DelayUs2x(200);
SPK=!SPK;
}
}
void delay(unsigned int i)
{
while(--i);
}
void tel()
{
unsigned int i;
while(1)
{
Dataport = arr_bit[i];
Latch_bit = 1;
Latch_bit = 0;
Dataport = arr_tel[(i+k)%16];
Latch_seg = 1;
Latch_seg = 0;
delay(200);
i++;
if(i == 8)
i = 0;
}
}
void clock()
{
unsigned int hour,min,sec = 0;