}
date1 = ACC;
return date1;
}
void write_byte_1302(unsigned char com)
{
unsigned char idata i;
ACC=com;
for(i=8;i> 0;i--)
{
SCLK_1302 = 0;
_nop_();
IO_1302 = ACC0;
SCLK_1302 = 1;
_nop_();
ACC=ACC> > 1;
}
}
void init_1302()
{
RST_1302 = 0;
_nop_();
SCLK_1302 = 0;
_nop_();
RST_1302 = 1;
_nop_();
write_byte_1302(0x8e);
_nop_();
write_byte_1302(0x00);
SCLK_1302 = 1;
_nop_();
RST_1302 = 0;
}
unsigned char read_by_1302(unsigned char addr_rd)
{
unsigned char addr;
unsigned char date_rd;
addr = addr_rd;
RST_1302 = 0;
_nop_();
SCLK_1302 = 0;
_nop_();
RST_1302 = 1;
_nop_();
write_byte_1302(addr);
_nop_();
date_rd = read_byte_1302();
SCLK_1302 = 1;
_nop_(); //
RST_1302 = 0;
return date_rd ;
}
void write_by_1302(unsigned char addr_wr,unsigned char date_wr)
{
unsigned char addr;
unsigned char date;
addr = addr_wr;
date = date_wr;
RST_1302 = 0;
_nop_();
SCLK_1302 = 0;
_nop_();
RST_1302 = 1;
write_byte_1302(addr);
_nop_();
write_byte_1302(date);
SCLK_1302 = 1;
_nop_();
RST_1302 = 0;
}
void renew_1302()
{
unsigned char date;
unsigned char idata count;
unsigned char idata addr;
addr=0x80;
//com_1302(0xbf);
// write_byte_1302(0xbf);
for(count=0;count < 7;count++)
{
//date = time_new[count];
date = time[count];
write_by_1302(addr,date);
// write_byte_1302(date);
addr = addr +2;
// com_1302(count*2+0x80);
}
// _NOP_();
// _NOP_();
// RST_1302 = 0;
}
void main()
{
// unsigned char idata i;
init_1302();
uart_init( ) ;
EA=1;
//write_by_1302(0x86,0x0f);
renew_1302();
write_by_1302(0x8e,0x80);
while(1)
{
led3 = 1;
led1 = 0;
led2 = 1;
//read_ar_1302();//程序进入死循环?????
// com_1302(0xbf);
//read_ar_1302();
time[0]=read_by_1302(0x81);
uart_send_char( time[0]);
delay_ms(200);
time[1]=read_by_1302(0x83);
uart_send_char( time[1]);
delay_ms(200);
time[2]=read_by_1302(0x85);
uart_send_char( time[2]);
delay_ms(200);
time[3]=read_by_1302(0x87);
uart_send_char( time[3]);
delay_ms(200);
time[4]=read_by_1302(0x89);
uart_send_char( time[4]);
delay_ms(200);
time[5]=read_by_1302(0x8b);
uart_send_char( time[5]);
delay_ms(200);
time[6]=read_by_1302(0x8d);
uart_send_char( time[6]);
delay_ms(200);
time[6]=read_by_1302(0xc3);
uart_send_char( time[6]);
delay_ms(200);
time[6]=read_by_1302(0xc1);
uart_send_char( time[6]);
delay_ms(200);
rst_wdog();
delay_ms(200);
rst_wdog();
led3 = 0;
led1 = 1;
led2 = 0;
delay_ms(200);
rst_wdog();
delay_ms(200);
rst_wdog();
}
}