设为首页 加入收藏

TOP

时钟芯片HT1380 操作源码(一)
2014-11-24 02:56:04 来源: 作者: 【 】 浏览:1
Tags:时钟 芯片 HT1380 操作 源码

//读数据长度
#define Long_ReadData (uint8)3//7
//读取的数据转换成显示数据
#define ClockSwitch_TSEC(x) ((x>>4)&0X07)*10 + (x&0x0f)
#define ClockSwitch_TMIN(x) ((x>>4)&0X07)*10 + (x&0x0f)
#define ClockSwitch_THOR(x) ((x>>4)&0x03)*10 + (x&0x0f)


//显示数据转换成读取的数据 -- 设置时间时
#define ClockSwitchB_TSEC(x) (((x/10)<<4) + (x%10))
#define ClockSwitchB_TMIN(x) (((x/10)<<4) + (x%10))
#define ClockSwitchB_THOR(x) (((x/10)<<4) + (x%10))



#define HT1380OSC_ENB (uint8)0X00 //振荡使能
#define HT1380OSC_DIS (uint8)0X80
#define MCLOCK24H (uint8)0x00 //24H制
#define MCLOCK12H (uint8)0x80


//-----------------------------
#define HT1380SLK_HIGH P_SLK1380 = 1
#define HT1380SLK_LOW P_SLK1380 = 0


#define HT1380DAT_HIGH P_DAT1380Out = 1
#define HT1380DAT_LOW P_DAT1380Out = 0


#define HT1380RST_HIGH P_RST1380 = 1
#define HT1380RST_LOW P_RST1380 = 0
//读数据端口
#define HT1380DatIn P_DAT1380In


//-----------------------------------------
void delay1380(void)
{
uint8 i = 0 ;

for(i=1;i>0;i--)//10
{
_asm("nop");
_asm("nop");
_asm("nop");
_asm("nop");
_asm("nop");
_asm("nop");
_asm("nop");
}
}
/********************************************************************
*
* 名称: HT1380WriteByte
* 说明:
* 功能: 往HT1381写入1Byte数据
* 调用:
* 输入: ucDa 写入的数据
* 返回值: 无
***********************************************************************/
void HT1380WriteByte(uint8 Dat)
{
uint8 i = 0 ;

HT1380SLK_LOW ;
for(i=0;i<8;i++)
{
if(Dat & 0x01)
{
HT1380DAT_HIGH ;
}
else
{
HT1380DAT_LOW ;
}
Dat >>= 1 ;

HT1380SLK_HIGH ;
delay1380();
HT1380SLK_LOW ;
delay1380();

}
}
/********************************************************************
*
* 名称: uint8 HT1380ReadByte
* 说明:
* 功能: 从HT1381读取1Byte数据
* 调用:
* 输入:
* 返回值: ACC
***********************************************************************/
uint8 HT1380ReadByte(void)
{
uint8 i = 0 ;
uint8 Dat=0 ;

HT1380DAT_HIGH ; //数据置高后再读 双向口
delay1380();

if(HT1380DatIn)
{
Dat |= 0x80 ;
}

for(i=0;i<7;i++)
{
HT1380SLK_HIGH ;
delay1380();
HT1380SLK_LOW ;
delay1380();

Dat >>= 1 ;
if(HT1380DatIn)
{
Dat |= 0x80 ;
}

}

return Dat ;
}
/********************************************************************
*
* 名称: HT1380WriteByteAddr
* 说明: 先写地址,后写命令/数据
* 功能: 往HT1381写入数据
* 调用: HT1380WriteByte()
* 输入: ucAddr: HT1381地址, ucDa: 要写的数据
* 返回值: 无
***********************************************************************/
void HT1380WriteByteAddr(uint8 ucAddr, uint8 ucDa)
{
HT1380RST_LOW;
HT1380SLK_LOW;
HT1380RST_HIGH;
HT1380WriteByte(ucAddr); /* 地址,命令 */
HT1380WriteByte(ucDa); /* 写1Byte数据*/
HT1380SLK_HIGH;
HT1380RST_LOW;
}
/********************************************************************
*
* 名称: HT1380ReadByteAddr
* 说明: 先写地址,后读命令/数据
* 功能: 读取HT1381某地址的数据
* 调用: HT1380WriteByte() , HT1380ReadByte()
* 输入: ucAddr: HT1381地址
* 返回值: ucDa :读取的数据
***********************************************************************/
uint8 HT1380ReadByteAddr(uint8 ucAddr)
{
uint8 ucDa;
HT1380RST_LOW;
HT1380SLK_LOW;
HT1380RST_HIGH;
HT1380WriteByte(ucAddr); /* 地址,命令 */
ucDa = HT1380ReadByte(); /* 读1Byte数据 */
HT1380SLK_HIGH;
HT1380RST_LOW;

return(ucDa);
}


/********************************************************************
*
* 名称: HT1380SetTime
* 说明:
* 功能: 设置初始时间
* 调用: HT1380WriteByteAddr()
* 输入: pSecDa: 初始时间地址。初始时间格式为: 秒 分 时 日 月 星期 年
* 7Byte (BCD码) 1B 1B 1B 1B 1B 1B 1B
* 返回值: 无
*******

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇iOS获取当前时间 下一篇iPhone表情符号编码

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: