国产毛片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://m.qingdxww.cn/thread-2884-1-1.html     【打印本頁】

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

廠商推薦

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

相關在線工具

關于我們  -  服務條款  -  使用指南  -  站點地圖  -  友情鏈接  -  聯系我們
電子工程網 © 版權所有   京ICP備16069177號 | 京公網安備11010502021702
快速回復 返回頂部 返回列表
主站蜘蛛池模板: 在线国产91| 女教师韩国无删减完整版 | 欧美日韩乱妇高清免费 | 黄色成人在线网站 | 黄色网页免费 | 老人free性hd老 | 麻豆精品视频在线观看 | 久久伊人草 | 韩剧伦理年轻的嫂子6在线观看 | 欧美综合自拍亚洲综合图片区 | 中文一区二区视频 | 青青伊人影院 | 亚洲网站在线播放 | 精品国产高清a毛片 | h在线看免费视频网站男男 h在线看 | 韩国毛片网站 | 欧美日韩综合在线视频免费看 | 四虎影视在线免费观看 | 高清日本无a区 | 亚洲区免费 | 成人免费黄色网 | 摸一摸操一操 | 一日本道加勒比高清一二三 | 亚洲最新视频在线观看 | 黄色片视频在线播放 | 亚洲欧美日韩一区高清中文字幕 | 国产毛片在线看 | 黄视频在线免费看 | 亚洲欧美在线精品 | 欧美日韩一区二区视频免费看 | sihu影院永久在线影院 | 极品国产一区二区三区 | 恐怖片在线观看高清 | 66成人| 四虎影视1304t | 国产欧美成人一区二区三区 | 91精品人成在线观看 | 亚洲va在线va天堂va四虎 | 欧美日韩国产一区二区三区播放 | 天堂最新版www在线观看 | 免费三级网站 |