国产毛片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
快速回復 返回頂部 返回列表
主站蜘蛛池模板: 最近手机中文字幕1页 | free俄罗斯性hd| 欧美日韩亚洲国产一区二区综合 | 亚洲精品免费在线观看 | 欧美xx视频 | 亚洲另类中文字幕 | 男女男免费视频网站国产 | 亚洲尹人香蕉网在线视颅 | 日韩毛片最新看 | 99re视频精品 | 我与么公激情性完整视频 | 扒丝袜basiwa影院首页 | 极品色在线精品视频 | 一区二区在线视频 | 欧美精品v国产精品v | 美女胸又大又黄又www小说 | 九九免费精品视频在这里 | 99精品国产自在现线免费下载 | 黄色毛片一级片 | 99国产精品国产精品 | 中文字幕在线观看日本 | 日韩视频免费一区二区三区 | 欧美日韩视频在线一区二区 | 天天艹日日干 | 国产69精品久久久久999小说 | 夜夜狠狠 | 国产精品秒播无毒不卡 | 亚洲一区二区三区四 | 免费看黄网站在线 | 欧美成人全部视频 | 国产精品一区二区免费 | 色婷婷99综合久久久精品 | 国产精品久久免费视频 | 日本高清在线精品一区二区三区 | 啦啦啦高清在线影院 | 精品国产香蕉伊思人在线又爽又黄 | 日日干天天草 | 在线人成精品免费视频 | 免费视频精品一区二区三区 | 欧美成人 一区二区三区 | 久久99精品麻豆国产 |