原创
这些天太忙,试了一下ht1380,感觉不错,送给大家吧(
2007-9-3 15:49
1513
5
5
分类:
消费电子
#include <AT89X52.H>
//HT1380实时时钟驱动程序
sbit ht1380_clk=P1^0;
sbit ht1380_dat=P1^1;
sbit ht1380_rst=P1^2;
sbit a0=ACC^0;
sbit a1=ACC^1;
sbit a2=ACC^2;
sbit a3=ACC^3;
sbit a4=ACC^4;
sbit a5=ACC^5;
sbit a6=ACC^6;
sbit a7=ACC^7;
void ht1380_out(unsigned char dd) {
ACC=dd;
ht1380_dat=a0;
ht1380_clk=1;
ht1380_clk=0;
ht1380_dat=a1;
ht1380_clk=1;
ht1380_clk=0;
ht1380_dat=a2;
ht1380_clk=1;
ht1380_clk=0;
ht1380_dat=a3;
ht1380_clk=1;
ht1380_clk=0;
ht1380_dat=a4;
ht1380_clk=1;
ht1380_clk=0;
ht1380_dat=a5;
ht1380_clk=1;
ht1380_clk=0;
ht1380_dat=a6;
ht1380_clk=1;
ht1380_clk=0;
ht1380_dat=a7;
ht1380_clk=1;
ht1380_clk=0;
}
unsigned char ht1380_in(void) {
ht1380_dat=1;
a0=ht1380_dat;
ht1380_clk=1;
ht1380_clk=0;
a1=ht1380_dat;
ht1380_clk=1;
ht1380_clk=0;
a2=ht1380_dat;
ht1380_clk=1;
ht1380_clk=0;
a3=ht1380_dat;
ht1380_clk=1;
ht1380_clk=0;
a4=ht1380_dat;
ht1380_clk=1;
ht1380_clk=0;
a5=ht1380_dat;
ht1380_clk=1;
ht1380_clk=0;
a6=ht1380_dat;
ht1380_clk=1;
ht1380_clk=0;
a7=ht1380_dat;
return(ACC);
}
unsigned char read_ht1380(unsigned char ord) {
unsigned char dd="0";
ht1380_clk=0;
ht1380_rst=0;
ht1380_rst=1;
ht1380_out(ord);
dd=ht1380_in();
ht1380_rst=0;
ht1380_clk=1;
return(dd);
}
void write_ht1380(unsigned char ord,unsigned char dd) {
ht1380_clk=0;
ht1380_rst=0;
ht1380_rst=1;
ht1380_out(ord);
ht1380_out(dd);
ht1380_rst=0;
ht1380_clk=1;
}
下面的是使用,上电就要清写保护,启动晶阵,如有备电下一次就不必了,否则上电必须
ord=0x8e; //清写保护
dd=0x00;
write_ht1380(ord,dd);
ord=0x80; //启动晶振+秒初始化
dd=0x00;
write_ht1380(ord,dd);
...
...
ord=0x8e; //确认写保护
dd=0x80;
write_ht1380(ord,dd);
文章评论(0条评论)
登录后参与讨论