欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
芯圣SDK-HC89F0541單片機的DS1302 RTC計時
[打印本頁]
作者:
jinglixixi
時間:
2020-7-11 08:18
標題:
芯圣SDK-HC89F0541單片機的DS1302 RTC計時
本帖最后由 jinglixixi 于 2020-7-11 08:21 編輯
DS1302
計時模塊是一種小巧的帶后備電池的功能模塊,可在掉電的情況下一直維持著計時器的運行。
DS1302
與
SDK-HC89F0541
開發板的連接關系為:
RST --- P3_5
IO --- P3_4
SCK --- P3_3
為便于觀察計時結果,還使用串行通訊口來輸出計時內容。其中,
TXD
為
P16
,而
RXD
為
P17
,整體的連接構成如圖所示。
1.png
(321.07 KB, 下載次數: 34)
下載附件
2020-7-11 08:18 上傳
RTC
計時構成圖
串口發送字節的函數為:
void SendByte(uchar dat)
{
IE &=~ 0x10;
SBUF = dat;
while(!(SCON & 0x02));
SCON &=~ 0x02;
IE |= 0x10;
}
復制代碼
串口發送計時值得函數為:
void RTC_xs(void)
{
SendByte(readtime[0]+'0');
SendByte(readtime[1]+'0');
SendByte(readtime[2]+'0');
SendByte(readtime[3]+'0');
SendByte('-');
SendByte(readtime[4]+'0');
SendByte(readtime[5]+'0');
SendByte('-');
SendByte(readtime[6]+'0');
SendByte(readtime[7]+'0');
SendByte(' ');
SendByte(readtime[8]+'0');
SendByte(readtime[9]+'0');
SendByte(':');
SendByte(readtime[10]+'0');//s
SendByte(readtime[11]+'0');
SendByte(':');
SendByte(readtime[12]+'0');//s
SendByte(readtime[13]+'0');
SendByte('\r');
SendByte('\n');
}
復制代碼
使
DS1302
模塊產生圖示效果的主程序為:
void main(void)
{
WDTCCR = 0x00;
while((CLKCON&0x20)!=0x20);
CLKSWR = 0x51;
while((CLKSWR&0xC0)!=0x40);
CLKDIV = 0x01;
P3M3 = 0xC2;
P3M4 = 0xC2;
P3M5 = 0xC2;
P1M6 = 0xC2;
P1M7 = 0x62;
TXD_MAP = 0x16;
RXD_MAP = 0x17;
T4CON = 0x06;
TH4 = 0xFF;
TL4 = 0x98; // 9600bps
SCON2 = 0x02; // 8bit
SCON = 0x10;
IE |= 0x10;
EA = 1;
ds1302_init();
time_buf[1]=0x20;
time_buf[2]=0x07;
time_buf[3]=0x07;
time_buf[4]=0x14;
time_buf[5]=0x01;
time_buf[6]=0x30;
time_buf[7]=0x02;
ds1302_write_time();
while(1)
{
ds1302_read_time();
readtime[0]=(time_buf[0]>>4);
readtime[1]=(time_buf[0]&0x0F);
readtime[2]=(time_buf[1]>>4);
readtime[3]=(time_buf[1]&0x0F);
readtime[4]=(time_buf[2]>>4);
readtime[5]=(time_buf[2]&0x0F);
readtime[6]=(time_buf[3]>>4);
readtime[7]=(time_buf[3]&0x0F);
readtime[8]=(time_buf[4]>>4);
readtime[9]=(time_buf[4]&0x0F);
readtime[10]=(time_buf[5]>>4);
readtime[11]=(time_buf[5]&0x0F);
readtime[12]=(time_buf[6]>>4);
readtime[13]=(time_buf[6]&0x0F);
if(readtime[13]!=sec_buf)
{
sec_flag=0;
sec_buf=readtime[13];
RTC_xs(); ;
}
}
}
復制代碼
2.png
(18.34 KB, 下載次數: 34)
下載附件
2020-7-11 08:18 上傳
計時效果圖
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1