国产毛片a精品毛-国产毛片黄片-国产毛片久久国产-国产毛片久久精品-青娱乐极品在线-青娱乐精品

MSP430和實時時鐘HT1381的接口程序

發布時間:2008-11-6 21:48    發布者:MSP430
HT1381是臺灣HT公司的一款串行實時時鐘IC,工作電壓: 2.0V~5.5V,最大輸入串行時鐘500kHz ( VDD=2V),2MHz(VDD=5V) ;工作電流:2V時小于300nA,5V時小于1mA。串行I/O 傳送,二種數據傳送方式:單字節或多字節(Burst方式),所有寄存器以BCD碼格式存儲具有接口簡單、功耗低、工作電壓范圍寬、計時精確、功能全、成本低等優點,因此在實際應用中被廣泛采用。該芯片提供秒、分、時、日、日期、月和年的信息。對于小于31天的月的月末日期能自動進行調整,還包括閏年校正功能。低功耗設計且時鐘的運行可以采用24小時格式或帶AM/PM指示的12小時的格式。 以下是接口程序,430測試頻率為4M。 #define NOP _NOP();_NOP() #define NowSec cNowTime[0] #define NowMin cNowTime[1] #define NowHour cNowTime[2] #define NowDate cNowTime[3] #define NowMonth cNowTime[4] #define NowYear cNowTime[5] #define SetSec cSetTime[0] #define SetMin cSetTime[1] #define SetHour cSetTime[2] #define SetDate cSetTime[3] #define SetMonth cSetTime[4] #define SetYear cSetTime[5] uchar Temp_Count; uchar cSetTime[6]; uchar cNowTime[6]; void Timer_Out_Byte(uchar OutByte); uchar Timer_In_Byte(void); void ReadRealtime(void) { NOP; HT1381_OUTPORT &=~Timer_SCL; //Timer_SCL=0; NOP; HT1381_OUTPORT |= Timer_Rest; //Timer_Rest=1; Timer_Out_Byte(0xBF); //Read, Burst Mode for(TimeCount=0;TimeCount<6;TimeCount++) { if (TimeCount==5) Timer_In_Byte(); //dummy read. cNowTime[TimeCount]=Timer_In_Byte(); //change BCD to uchar cNowTime[TimeCount]=(cNowTime[TimeCount]/0x10)*10+(cNowTime[TimeCount]%0x10); } NOP; HT1381_OUTPORT &=~Timer_Rest; //Timer_Rest=0; } void WriteRealtime(void) { NOP; HT1381_OUTPORT &=~Timer_Rest; //Timer_Rest=0; //for sure to close rest. NOP; HT1381_OUTPORT &=~Timer_SCL; //Timer_SCL=0; NOP; HT1381_OUTPORT |= Timer_Rest; //Timer_Rest=1; Timer_Out_Byte(0x8E); //Write,Single Mode Timer_Out_Byte(0x00); //Write, Protect Byte=0, Disable protect NOP; HT1381_OUTPORT &=~Timer_Rest; //Timer_Rest=0; NOP; HT1381_OUTPORT |= Timer_Rest; //Timer_Rest=1; Timer_Out_Byte(0x80); //Write,Single Mode Timer_Out_Byte(0x00); //Write, OSC enalbe, old second distroied NOP; HT1381_OUTPORT &=~Timer_Rest; //Timer_Rest=0; for(TimeCount=0;TimeCount<6;TimeCount++) { //change uchar to BCD cSetTime[TimeCount]=(cSetTime[TimeCount]/10)*0x10+(cSetTime[TimeCount]%10); } NOP; HT1381_OUTPORT |= Timer_Rest; //Timer_Rest=1; Timer_Out_Byte(0XBE); //Write,Burst Mode Timer_Out_Byte(SetSec & 0x7F); //OSC enable for sure. Timer_Out_Byte(SetMin); Timer_Out_Byte(SetHour & 0x7F); //24 Hour Mode Timer_Out_Byte(SetDate); Timer_Out_Byte(SetMonth); Timer_Out_Byte(0x00); Timer_Out_Byte(SetYear); Timer_Out_Byte(0x00); NOP; HT1381_OUTPORT &=~Timer_Rest; //Timer_Rest=0; NOP; HT1381_OUTPORT |= Timer_Rest; //Timer_Rest=1; Timer_Out_Byte(0x8E); //Write,Single Mode Timer_Out_Byte(0x80); //Write, Protect Byte=0, enable protect NOP; HT1381_OUTPORT &=~Timer_Rest; //Timer_Rest=0; } void Timer_Out_Byte(uchar OutByte) { uchar Timer_Count; for (Timer_Count=0;Timer_Count<8;Timer_Count++) { HT1381_DIRPORT |= Timer_SDA; //output if ((OutByte & 0x01) == 0) HT1381_OUTPORT &=~Timer_SDA; else HT1381_OUTPORT |= Timer_SDA; NOP; HT1381_OUTPORT |= Timer_SCL; NOP; HT1381_OUTPORT &=~Timer_SCL; //Timer_SCL=0; utByte = OutByte >> 1; } } uchar Timer_In_Byte(void) { uchar InByte,Timer_Count; InByte=0x00; HT1381_DIRPORT &=~Timer_SDA; //Timer_SDA=1;//input for (Timer_Count=0;Timer_Count<8;Timer_Count++) { InByte >>= 1; NOP; HT1381_OUTPORT |= Timer_SCL; if(HT1381_INPORT&Timer_SDA) InByte |= 0x80; else InByte &= 0x7F; NOP; HT1381_OUTPORT &=~Timer_SCL; //Timer_SCL=0; } return(InByte); } #define NOP _NOP();_NOP() #define NowSec cNowTime[0] #define NowMin cNowTime[1] #define NowHour cNowTime[2] #define NowDate cNowTime[3] #define NowMonth cNowTime[4] #define NowYear cNowTime[5] #define SetSec cSetTime[0] #define SetMin cSetTime[1] #define SetHour cSetTime[2] #define SetDate cSetTime[3] #define SetMonth cSetTime[4] #define SetYear cSetTime[5] uchar Temp_Count; uchar cSetTime[6]; uchar cNowTime[6]; void Timer_Out_Byte(uchar OutByte); uchar Timer_In_Byte(void); void ReadRealtime(void) { NOP; HT1381_OUTPORT &=~Timer_SCL; //Timer_SCL=0; NOP; HT1381_OUTPORT |= Timer_Rest; //Timer_Rest=1; Timer_Out_Byte(0xBF); //Read, Burst Mode for(TimeCount=0;TimeCount<6;TimeCount++) { if (TimeCount==5) Timer_In_Byte(); //dummy read. cNowTime[TimeCount]=Timer_In_Byte(); //change BCD to uchar cNowTime[TimeCount]=(cNowTime[TimeCount]/0x10)*10+(cNowTime[TimeCount]%0x10); } NOP; HT1381_OUTPORT &=~Timer_Rest; //Timer_Rest=0; } void WriteRealtime(void) { NOP; HT1381_OUTPORT &=~Timer_Rest; //Timer_Rest=0; //for sure to close rest. NOP; HT1381_OUTPORT &=~Timer_SCL; //Timer_SCL=0; NOP; HT1381_OUTPORT |= Timer_Rest; //Timer_Rest=1; Timer_Out_Byte(0x8E); //Write,Single Mode Timer_Out_Byte(0x00); //Write, Protect Byte=0, Disable protect NOP; HT1381_OUTPORT &=~Timer_Rest; //Timer_Rest=0; NOP; HT1381_OUTPORT |= Timer_Rest; //Timer_Rest=1; Timer_Out_Byte(0x80); //Write,Single Mode Timer_Out_Byte(0x00); //Write, OSC enalbe, old second distroied NOP; HT1381_OUTPORT &=~Timer_Rest; //Timer_Rest=0; for(TimeCount=0;TimeCount<6;TimeCount++) { //change uchar to BCD cSetTime[TimeCount]=(cSetTime[TimeCount]/10)*0x10+(cSetTime[TimeCount]%10); } NOP; HT1381_OUTPORT |= Timer_Rest; //Timer_Rest=1; Timer_Out_Byte(0XBE); //Write,Burst Mode Timer_Out_Byte(SetSec & 0x7F); //OSC enable for sure. Timer_Out_Byte(SetMin); Timer_Out_Byte(SetHour & 0x7F); //24 Hour Mode Timer_Out_Byte(SetDate); Timer_Out_Byte(SetMonth); Timer_Out_Byte(0x00); Timer_Out_Byte(SetYear); Timer_Out_Byte(0x00); NOP; HT1381_OUTPORT &=~Timer_Rest; //Timer_Rest=0; NOP; HT1381_OUTPORT |= Timer_Rest; //Timer_Rest=1; Timer_Out_Byte(0x8E); //Write,Single Mode Timer_Out_Byte(0x80); //Write, Protect Byte=0, enable protect NOP; HT1381_OUTPORT &=~Timer_Rest; //Timer_Rest=0; } void Timer_Out_Byte(uchar OutByte) { uchar Timer_Count; for (Timer_Count=0;Timer_Count<8;Timer_Count++) { HT1381_DIRPORT |= Timer_SDA; //output if ((OutByte & 0x01) == 0) HT1381_OUTPORT &=~Timer_SDA; else HT1381_OUTPORT |= Timer_SDA; NOP; HT1381_OUTPORT |= Timer_SCL; NOP; HT1381_OUTPORT &=~Timer_SCL; //Timer_SCL=0; utByte = OutByte >> 1; } } uchar Timer_In_Byte(void) { uchar InByte,Timer_Count; InByte=0x00; HT1381_DIRPORT &=~Timer_SDA; //Timer_SDA=1;//input for (Timer_Count=0;Timer_Count<8;Timer_Count++) { InByte >>= 1; NOP; HT1381_OUTPORT |= Timer_SCL; if(HT1381_INPORT&Timer_SDA) InByte |= 0x80; else InByte &= 0x7F; NOP; HT1381_OUTPORT &=~Timer_SCL; //Timer_SCL=0; } return(InByte); }
本文地址:http://www.qingdxww.cn/thread-2884-1-1.html     【打印本頁】

本站部分文章為轉載或網友發布,目的在于傳遞和分享信息,并不代表本網贊同其觀點和對其真實性負責;文章版權歸原作者及原出處所有,如涉及作品內容、版權和其它問題,我們將根據著作權人的要求,第一時間更正或刪除。
您需要登錄后才可以發表評論 登錄 | 立即注冊

廠商推薦

  • Microchip視頻專區
  • PIC18-Q71系列MCU概述
  • 5分鐘詳解定時器/計數器E和波形擴展!
  • 想要避免發生災難,就用MPLAB® SiC電源仿真器!
  • 無線充電基礎知識及應用培訓教程2
  • 貿澤電子(Mouser)專區

相關在線工具

關于我們  -  服務條款  -  使用指南  -  站點地圖  -  友情鏈接  -  聯系我們
電子工程網 © 版權所有   京ICP備16069177號 | 京公網安備11010502021702
快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产成人高清亚洲一区久久 | 四虎4hu影库永久地址 | 欧美国产日本精品一区二区三区 | 欧美卡1卡2卡三卡四免费 | 欧美在线观看www | 亚洲一区二区天海翼 | 色老头视频在线观看 | 国内精品91最新在线观看 | 国产欧美视频一区二区三区 | 国产成人午夜精品影院游乐网 | 思思99热在线观看精品 | 久久香蕉国产线看观看8青草 | 日本一区二区三区精品 | 麻豆影视视频高清在线观看 | 手机看片日韩日韩国产在线看 | 日韩高清不卡 | 三级毛片视频 | 日韩区 | 星空影院在线影视 | 国产日韩欧美亚洲综合在线 | 欧美高清另类 | 老司机精品在线 | 九九九九热精品免费视频 | 一区二区高清在线观看 | 97在线免费视频观看 | 久久久久久久999 | 搞黄网站免费看 | 国产成人精品一区二区三区 | 欧美日韩精品免费一区二区三区 | 色猫成人网 | www.日本黄 | 啪啪91视频 | 国产香蕉视频在线 | 日本在线观看免费观看完整版 | 国产精品公开免费视频 | 激情五月婷婷网 | 国产卡一卡二卡3卡4卡无卡视频 | 国产在线观看一区二区三区 | 亚洲国内精品自在线影视 | 国产乱码精品一区二区三上 | 国产精品好好热在线观看 |