#include "ht1380.h"
/*************短时间延时***********************************/
void dly_HT1380(void)
{
asm("nop");
asm("nop");
asm("nop");
asm("nop");
}
/*************向HT1380中写一个字节*************************/
void HT1380_write(uint8_t data)
{
uint8_t i="0";
set_HT1380_io_ddr();
clr_HT1380_io();
for(i=8;i>0;i--)
{
dly_HT1380();
if(data&0x01)
{
set_HT1380_io();
}
dly_HT1380();
set_HT1380_sclk();
dly_HT1380();
clr_HT1380_sclk();
dly_HT1380();
clr_HT1380_io();
data>>=1;
}
}
/*************从HT1380中读一个字节*************************/
int HT1380_read(void)
{
uint8_t data="0";
uint8_t i="0";
clr_HT1380_io_ddr();//让io变成输入
for(i=8;i>0;i--)
{
set_HT1380_sclk();
dly_HT1380();
data >>= 1;
if(in_HT1380_io())
{
data |= 0x80;
}
else
{
data &= 0x07f;
}
clr_HT1380_sclk();
dly_HT1380();
}
return(data);
}
/**********从HT1380中读日期和时间******************************/
void HT1380_read_time(void)
{
clr_HT1380_sclk();
set_HT1380_io_ddr();
clr_HT1380_rst();
dly_HT1380();
set_HT1380_rst(); //
HT1380_write(0xbf);
dly_HT1380();
clr_HT1380_io_ddr();
dly_HT1380();
second=HT1380_read(); //秒
minute=HT1380_read(); //分
hour=HT1380_read(); //时
day=HT1380_read(); //日
month=HT1380_read();//月
week=HT1380_read(); //周
year=HT1380_read(); //年
dly_HT1380();
clr_HT1380_rst();
}
/**********向HT1380写日期和时间******************************/
void HT1380_write_time(void)
{
clr_HT1380_sclk();
set_HT1380_io_ddr();
clr_HT1380_rst();
dly_HT1380();
set_HT1380_rst(); //
HT1380_write(0x8e);
HT1380_write(0x00);
dly_HT1380();
clr_HT1380_rst();
dly_HT1380();
set_HT1380_rst(); //
HT1380_write(0x80);
HT1380_write(0x00);
dly_HT1380();
clr_HT1380_rst();
dly_HT1380();
set_HT1380_rst(); //
HT1380_write(0xbe);
HT1380_write(second); // 秒
HT1380_write(minute); //分
HT1380_write(hour); //时
HT1380_write(day); //日
HT1380_write(month); //月
HT1380_write(week); //周
HT1380_write(year); //年
HT1380_write(0x00);
dly_HT1380();
clr_HT1380_rst();
}
https://static.assets-stash.eet-china.com/album/old-resources/2009/4/18/69a848c6-bbd0-4825-b347-eb1a5bbf325b.rar
tengjingshu_112148725 2009-4-18 18:21