国产毛片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視頻專區
  • 使用SAM-IoT Wx v2開發板演示AWS IoT Core應用程序
  • 使用Harmony3加速TCP/IP應用的開發培訓教程
  • 集成高級模擬外設的PIC18F-Q71家族介紹培訓教程
  • 探索PIC16F13145 MCU系列——快速概覽
  • 貿澤電子(Mouser)專區

相關在線工具

關于我們  -  服務條款  -  使用指南  -  站點地圖  -  友情鏈接  -  聯系我們
電子工程網 © 版權所有   京ICP備16069177號 | 京公網安備11010502021702
快速回復 返回頂部 返回列表
主站蜘蛛池模板: 青青艹在线| 美国免费黄色片 | 视频精品一区二区三区 | 精品乱人伦一区二区三区 | 四虎影院永久网址 | 久久99精品久久久久久 | 另类婷婷 | 国产成人成人一区二区 | 久久久久国产成人精品亚洲午夜 | 人人干人人模 | 精品国产一区二区三区久 | 国外欧美一区另类中文字幕 | 花季传媒v3.024 | 特级毛片免费看 | 久久青春 | 久久人| 一本大道香蕉大vr在线吗视频 | 欧美视频在线一区 | 国产99er66在线视频 | 国产一区二三区 | 91免费版在线观看 | 男人天堂综合网 | 亚洲综合色秘密影院秘密影院 | 亚洲国产欧美在线观看 | 韩国日本一区二区 | 242sao.cam| 欧美在线一区视频 | 欧美视频二区 | 欧美一级视频在线 | 99久久成人国产精品免费 | 国产专区自拍 | 亚洲三级在线播放 | 九九精品免费视频 | 国产视频久久久久 | 最好免费观看韩国+日本 | 久久久毛片免费全部播放 | 久久99国产综合精品 | 色黄网站aaaaaa级毛片 | 一级日韩一级欧美 | 国产福利午夜自产拍视频在线 | 在线播放网站 |