日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]參考DS1302數(shù)據(jù)手冊(cè),盡管數(shù)據(jù)手冊(cè)是英文,但是很有幫助,再結(jié)合網(wǎng)上眾多的代碼寫出了下面這個(gè)例子,除了涓流充電(trickle charger)功能沒使用外,內(nèi)部的RAM和寄存器功能都使用到了,包括多字節(jié)方式(burst mode)

參考DS1302數(shù)據(jù)手冊(cè),盡管數(shù)據(jù)手冊(cè)是英文,但是很有幫助,再結(jié)合網(wǎng)上眾多的代碼寫出了下面這個(gè)例子,除了涓流充電(trickle charger)功能沒使用外,內(nèi)部的RAM和寄存器功能都使用到了,包括多字節(jié)方式(burst mode)。自認(rèn)為我寫的比網(wǎng)上大多數(shù)程序清晰,當(dāng)然已經(jīng)硬件測(cè)試過了。


1 #include

2

3 /*DS1302部分*/

4

5 //全部為寫入地址,讀取地址需要+1

6 #define YEAR 0x8c

7 #define MON 0x88

8 #define DATE 0x86

9 #define DAY 0x8a

10 #define HOUR 0x84

11 #define MIN 0x82

12 #define SEC 0x80

13 #define WP 0x8e

14 #define RAM(n) (0xc0+2*(n))

15 #define CLBT 0xbe

16 #define RAMBT 0xfe

17

18 //3個(gè)通信引腳

19 sbit SCLK=P2^1;

20 sbit IO=P2^0;

21 sbit RST=P2^4; //有的使能端叫CE

22

23 unsigned char readbyte(void);

24 void writebyte(unsigned char dat);

25 void write1302(unsigned char addr,unsigned char dat);

26 unsigned char read1302(unsigned char addr);

27

28

29 /*數(shù)碼管部分,6位共陰接在P0*/

30 sbit we=P2^7;

31 sbit du=P2^6;

32 void show(void);

33 void delayms(unsigned time);

34

35 unsigned char code table[] = {

36 0x3f , 0x06 , 0x5b , 0x4f,

37 0x66 , 0x6d , 0x7d , 0x07,

38 0x7f , 0x6f , 0x77 , 0x7c,

39 0x39 , 0x5e , 0x79 , 0x71,

40 0x00 };

41

42 unsigned char num[6]={0}; //用作數(shù)碼管顯示的數(shù)組

43

44 /*鍵盤部分,4個(gè)獨(dú)立鍵盤接在P3.4-P3.7*/

45 void keyscan(void);

46 bit showdate=0;

47 bit showday=0;

48

49 void main(void)

50 {

51 unsigned char temp;

52

53 write1302(WP,0x00); //允許寫入,關(guān)閉寫保護(hù)

54

55 //clock burst 方式賦初值

56 RST=0;

57 SCLK=0;

58 RST=1;

59 writebyte(CLBT);

60

61 writebyte(0x30);//秒分時(shí)

62 writebyte(0x59);

63 writebyte(0x23);

64

65 writebyte(0x28);//日月

66 writebyte(0x02);

67

68 writebyte(0x02);//星期

69

70 writebyte(0x32);//年

71

72 writebyte(0x00);

73 writebyte(0x00);

74 RST=0;

75

76 // 另一種賦初值方法

77 // write1302(HOUR,0x23);

78 // write1302(MIN,0x59);

79 // write1302(SEC,0x30);

80

81 while(1)

82 {

83 keyscan();

84 if(showdate)

85 {

86 temp=read1302(YEAR+1);

87 num[5]=temp>>4;

88 num[4]=temp&0x0f;

89 temp=read1302(MON+1);

90 num[3]=temp>>4;

91 num[2]=temp&0x0f;

92 temp=showday?read1302(DAY+1):read1302(DATE+1);

93 num[1]=temp>>4;

94 num[0]=temp&0x0f;

95 }

96 else

97 {

98 temp=read1302(HOUR+1);

99 num[5]=temp>>4;

100 num[4]=temp&0x0f;

101 temp=read1302(MIN+1);

102 num[3]=temp>>4;

103 num[2]=temp&0x0f;

104 temp=read1302(SEC+1);

105 num[1]=temp>>4;

106 num[0]=temp&0x0f;

107 }

108 show();

109 }

110

111 }

112

113

114 unsigned char readbyte(void)

115 {

116 unsigned char i,ret;

117 for(i=0;i<8;i++)

118 {

119 ret>>=1;

120 SCLK=1;

121 SCLK=0;

122 ret|=IO?0x80:0x00;

123 }

124 return ret;

125 }

126

127 void writebyte(unsigned char dat)

128 {

129 unsigned char i;

130 for(i=0;i<8;i++)

131 {

132 IO=dat&1;

133 SCLK=0;

134 SCLK=1;

135 dat>>=1;

136 }

137 }

138

139 void write1302(unsigned char addr,unsigned char dat)

140 {

141 RST=0;

142 SCLK=0;

143 RST=1;

144 writebyte(addr);

145 writebyte(dat);

146 RST=0;

147 }

148

149 unsigned char read1302(unsigned char addr)

150 {

151 unsigned char ret;

152 RST=0;

153 SCLK=0;

154 RST=1;

155 writebyte(addr);

156 ret=readbyte();

157 RST=0;

158 return ret;

159 }

160

161 void show(void)

162 {

163 unsigned char i;

164

165 for(i=0;i<6;i++)

166 {

167 P0=0xff;

168 we=1;

169 we=0;

170

171 P0=table[num[i]];

172 du=1;

173 du=0;

174

175 P0=~(0x20>>i);

176 we=1;

177 we=0;

178

179 delayms(1);

180 }

181 }

182

183 void delayms(unsigned time)

184 {

185 unsigned i,j;

186

187 for(i=time;i>0;i--)

188 for(j=110;j>0;j--)

189 ;

190 }

191

192 void keyscan(void)

193 {

194 unsigned char temp;

195 unsigned char reg[9];

196

197 if((P3|0x0f)!=0xff)

198 {

199 delayms(10);

200 if((temp=P3|0x0f)!=0xff)

201 {

202 while((P3|0x0f)!=0xff);

203 switch(temp)

204 {

205 case 0xef: //顯示時(shí)間還是日期

206 showdate=~showdate;

207 break;

208 case 0xdf: //日期最后兩位顯示日還是星期

209 showday=~showday;

210 break;

211 case 0xbf: //將時(shí)鐘寄存器保存到RAM

212 RST=0;

213 SCLK=0;

214 RST=1;

215 writebyte(CLBT+1);

216 for(temp=0;temp<9;temp++)

217 reg[temp]=readbyte();

218 RST=0;

219

220 //從20號(hào)RAM開始存入,起始RAM號(hào)隨意,只要不超過范圍即可

221 for(temp=0;temp<9;temp++)

222 write1302(RAM(20+temp),reg[temp]);

223

224 /* 也可以用 RAM burst 寫入

225 RST=0;

226 SCLK=0;

227 RST=1;

228 writebyte(RAMBT);

229 for(temp=0;temp<9;temp++)

230 writebyte(reg[temp]);

231 RST=0;

232 */

233

234 break;

235 case 0x7f: //從RAM恢復(fù)到時(shí)鐘寄存器

236 /* 對(duì)應(yīng)的 RAM burst 讀取

237 RST=0;

238 SCLK=0;

239 RST=1;

240

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

51單片機(jī)學(xué)習(xí)筆記———13.1DS1302實(shí)時(shí)時(shí)鐘原理部分

關(guān)鍵字: ds1302 時(shí)鐘

由于昨天照著手冊(cè)寫了一下DS1302的驅(qū)動(dòng)程序,發(fā)現(xiàn)耗時(shí)挺多的,并且在考場(chǎng)上不可能一步步去自己寫驅(qū)動(dòng),所以今天看了一下藍(lán)橋杯提供的DS1302官方驅(qū)動(dòng)程序,發(fā)現(xiàn)直接引用還是不行的,程序當(dāng)中有些小問題需要去修改。下面就對(duì)那...

關(guān)鍵字: ds1302 時(shí)鐘

DS1302時(shí)鐘模塊通信原理(SPI總線)

關(guān)鍵字: ds1302 時(shí)鐘

現(xiàn)在流行的串行時(shí)鐘電路很多,如DS1302、 DS1307、PCF8485等。這些電路的接口簡(jiǎn)單、價(jià)格低廉、使用方便,被廣泛地采用

關(guān)鍵字: ds1307 ds1302

現(xiàn)在流行的串行時(shí)鐘電路很多,如DS1302、 DS1307、PCF8485等。這些電路的接口簡(jiǎn)單、價(jià)格低廉、使用方便,被廣泛地采用。它可以對(duì)年、月、日、周、時(shí)、分、秒進(jìn)行計(jì)時(shí),且具有閏年補(bǔ)償?shù)榷喾N功能。

關(guān)鍵字: ds1302 時(shí)鐘芯片 電路

DS1302 我們前邊也有提起過,是三根線,分別是 CE、I/O 和 SCLK,其中 CE 是使能線,SCLK 是時(shí)鐘線,I/O 是數(shù)據(jù)線。前邊我們介紹過了 SPI 通信,同學(xué)們發(fā)現(xiàn)沒發(fā)現(xiàn),這個(gè) DS1302 的通信線定...

關(guān)鍵字: ds1302 通信時(shí)序

//引入文件***********************************************************#include "delay.h" #include "...

關(guān)鍵字: ds1302 pic16f84a 讀取時(shí)鐘芯片

1、DS1302時(shí)鐘芯片的講解待完成?。?!2、自己寫的DS1302芯片的配置文件//DS1302_SPIdriver.h//DS1302_SPIdriver.h#ifndef__SPIDRIVER_H__#define_...

關(guān)鍵字: ds1302 單片機(jī) 時(shí)鐘芯片

發(fā)現(xiàn)網(wǎng)上一些程序在16M晶振下不能工作,自己寫了個(gè),按照2V的時(shí)序?qū)懙?但只在5V和3.3V下測(cè)試過.以下是兩個(gè)主要的文件DS1302.h:/************ AVR DS1302程序 *************...

關(guān)鍵字: AVR ds1302 程序源代碼

proteus仿真之DS1302+8位數(shù)碼管顯示試驗(yàn)。仿真效果如下圖:源程序如下:/*51單片機(jī):DS1302+數(shù)碼管 Proteus 仿真程序。功能:數(shù)碼管時(shí)鐘顯示。仿真結(jié)果:(1)8位數(shù)碼管顯示設(shè)定的時(shí)間與日期。(2...

關(guān)鍵字: ds1302 proteus仿真 數(shù)碼管顯示
關(guān)閉