#include #include #define uchar unsigned char
#define uint unsigned int
#include "DS1302_drive.h"
uchar K1_FLAG=0; //定义按键标志位,当按下K1键时,该位置1,K1键未按下时,该位为0。
uchar const bit_tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//位选表,用来选择哪一只数码管进行显示
uchar const seg_data[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff,0xbf};
//0~F、熄灭符和字符"-"的显示码(字形码) //0~F、熄灭符和字符"-"的显示码(字形码)
#define beep_0 (PORTD=PORTD&0x7f) //PD7上的蜂鸣器发声
#define beep_1 (PORTD=PORTD|0x80) //PD7上的蜂鸣器不发声
uchar disp_buf[8] ={0x00}; //定义显示缓冲区
uchar time_buf[7] ={0,0,0x12,0,0,0,0}; //DS1302时间缓冲区,存放秒、分、时、日、月、星期、年
uchar temp [2]={0}; //用来存放设置时的小时、分钟的中间值
/********函数功能:延时函数********/
void Delay_ms(uint xms)
{
int i,j;
for(i=0;i
{ for(j=0;j<1140;j++) ; }
}
/*********以下是蜂鸣器响一声函数********/
void beep()
{
beep_0; //蜂鸣器响
Delay_ms(100);
beep_1; //关闭蜂鸣器
Delay_ms(100);
}
/********端口设置函数********/
void port_init(void)
{
PORTA = 0xFF; //输出高电平
DDRA = 0xFF; //设为输出
PORTC = 0xff; //输出高电平
DDRC = 0xFF; //设为输出
DDRD =(0<
PORTD = 0xFF; //PD7输出高电平,其它为带上拉的输入
}
/********以下是走时转换函数,负责将走时数据转换为适合数码管显示的数据********/
void conv(uchar in1,uchar in2,uchar in3) //形参in1、in2、in3接收实参time_buf[2]、time_buf[1]、time_buf[0]传来的时/分/秒数据
{
disp_buf[0] =in1/10; // 小时十位
disp_buf[1] = in1%10; // 小时个位
disp_buf