#include <avr/io.h>
#include <avr/delay.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
/********************* 共 阳 极
***0****1****2*****3****4****5****6****7****8****9*/
const unsigned char led[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; //led 段
码
const char dig[] = { 0x01,0x02,0x04,0x08,0x10,0x20}; //led 位选码
unsigned char bcd_dsp[6]={0,0,0}; //bcd 码显示缓存
unsigned char dsp[6]={0,0,0,0,0,0}; //显示缓存
unsigned char dsp_state; //显示选择:0 显示修改数据;1 显示时分秒;2 显示星期;3 显示年
月日
unsigned char time_dog,dog_none;//time_dog:
unsigned char modify_state=0,modify_bit=0,modify_enter=0,modify_key=0;
#define rst PD0
#define clk PD1
#define dat PD2
void out_byte(char addr,char data)//向 DS1302 写一个数
{
unsigned char i,temp;
DDRD|=(1<<rst);
DDRD|=(1<<clk);
DDRD|=(1<<dat);
PORTD&=~(1<<rst);
PORTD&=~(1<<clk);
PORTD|=(1<<rst);
for (i=0;i<8;i++) //发送读命令
{
temp=addr;
if((temp&(1<<i))!=0)
PORTD|=(1<<dat);
else
PORTD&=~(1<<dat);
PORTD|=(1<<clk);
PORTD&=~(1<<clk);
}
for (i=0;i<8;i++) //发送数据
{
temp=data;
if((temp&(1<<i))!=0)
PORTD|=(1<<dat);
else