找回密碼
         注冊(cè)會(huì)員
        搜索附件  

        x25045QA.pdf

         

        25045操作標(biāo)準(zhǔn)子程序集,25045中英文PDF,25045中英文資料:

        1. /*
        2. ;程 序 最 后 修 改 時(shí) 間  0-4-3 23:43
        3. ;軟 件 標(biāo) 題:25045操作標(biāo)準(zhǔn)子程序集41
        4. ;軟 件 說(shuō) 明:25045 I2C 串行EEPROM 驅(qū)動(dòng)
        5. ;_________________________________________
        6. ;原作者: 龐波     
        7. ;程序修改人:
        8. ;版本號(hào):
        9. ;_________________________________________
        10. */

        11. /*到現(xiàn)在為止所有的問(wèn)題都已經(jīng)解決,此版本已經(jīng)較為完善*/
        12. # include <stdio.h>
        13. # include <reg52.h>
        14. # define uchar unsigned char
        15. # define uint unsigned int
        16. sbit SO=P1^1;/*25045輸出*/
        17. sbit SI=P1^2;/*25045輸入*/
        18. sbit SCK=P1^3;/*25045時(shí)鐘*/
        19. sbit CS=P1^4;/*25045片選*/
        20. uchar code WREN_INST=0X06;
        21. /* Write enable latch instruction (WREN)*/
        22. uchar code WRDI_INST=0X04;
        23. /* Write disable latch instruction (WRDI)*/
        24. uchar code WRSR_INST=0X01;
        25. /* Write status register instruction (WRSR)*/
        26. uchar code RDSR_INST=0X05;
        27. /* Read status register instruction (RDSR)*/
        28. uchar code WRITE_INST=0X02;
        29. /* Write memory instruction (WRITE)*/
        30. /*寫(xiě)入25045的先導(dǎo)字,應(yīng)當(dāng)為0000A010,其中的A為寫(xiě)入25045的高位地址
        31. 將此WRITE_INST和寫(xiě)入高位地址相或后即為正確的寫(xiě)先導(dǎo)字*/
        32. uchar code READ_INST=0X03;
        33. /* Read memory instruction (READ)*/
        34. /*讀出25045的先導(dǎo)字,應(yīng)當(dāng)為0000A011,其中的A為讀出25045的高位地址
        35. 將此READ_INST和讀出高位地址相或后即為正確的讀先導(dǎo)字*/
        36. uint code BYTE_ADDR=0X55;
        37. /* Memory address for byte mode operations*/
        38. uchar code BYTE_DATA=0X11;
        39. /*Data byte for byte write operation*/
        40. uint  code PAGE_ADDR=0X1F;
        41. /* Memory address for page mode operations*/
        42. /*頁(yè)面寫(xiě)入的其始地址*/
        43. uchar code PAGE_DATA1=0X22;
        44. /* 1st data byte for page write operation*/
        45. uchar code PAGE_DATA2=0X33;
        46. /* 2nd data byte for page write operation*/
        47. uchar code PAGE_DATA3=0X44;
        48. /* 3rd data byte for page write operation*/
        49. uchar code STATUS_REG=0X20;
        50. /* Status register,設(shè)置DOG時(shí)間設(shè)置為200毫秒,無(wú)寫(xiě)保護(hù)*/
        51. /*這是狀態(tài)寄存器的值,他的意義在于第5,第4位為WDI1,WDI0代表DOG的時(shí)間,00為1.4秒,01為600毫秒,10為200毫秒,00為disabled
        52. 第3位和第2位為BL1,BL0,是寫(xiě)保護(hù)設(shè)置位,00為無(wú)保護(hù),01為保護(hù)180-1FF,10為保護(hù)100-1FF,11為保護(hù)000-1FF.第1位為WEL,
        53. 當(dāng)他為1時(shí)代表已經(jīng)"寫(xiě)使能"設(shè)置了,現(xiàn)在可以寫(xiě)了,只讀位.第0位為WIP,當(dāng)他為1時(shí)代表正在進(jìn)行寫(xiě)操作,是只讀*/
        54. uchar code  MAX_POLL=0x99;
        55. /* Maximum number of polls*/
        56. /*最大寫(xiě)過(guò)程時(shí)間,確定25045的最大的寫(xiě)入過(guò)程的時(shí)間*/
        57. uchar code INIT_STATE=0x09;
        58. /* Initialization value for control ports*/
        59. uint code SLIC=0x30;
        60. /* Address location of SLIC*/
        61. void wren_cmd(void);/*寫(xiě)使能子程序*/
        62. void wrdi_cmd(void);/*寫(xiě)使能復(fù)位*/
        63. void wrsr_cmd(void);/*復(fù)位時(shí)間位和數(shù)據(jù)保護(hù)位寫(xiě)入狀態(tài)寄存器*/
        64. uchar rdsr_cmd(void);/*讀狀態(tài)寄存器*/
        65. void byte_write(uchar aa,uint dd);/*字節(jié)寫(xiě)入,aa為寫(xiě)入的數(shù)據(jù),dd為寫(xiě)入的地址*/
        66. uchar byte_read(uint dd);/*字節(jié)讀出,dd為讀出的地址,返回讀出的數(shù)據(jù)*/
        67. void page_write(uchar aa1,uchar aa2,uchar aa3,uchar aa4,uint dd);/*頁(yè)寫(xiě)入*/
        68. void sequ_read(void);/*連續(xù)讀出*/
        69. void rst_wdog(void);/*DOG復(fù)位*/
        70. void outbyt(uchar aa);/*輸出一個(gè)字節(jié)到25045中,不包括先導(dǎo)字等*/
        71. uchar inputbyt();/*由25045輸入一個(gè)字節(jié),不包括先導(dǎo)字等額外的東西*/
        72. void wip_poll(void);/*檢查寫(xiě)入過(guò)程是否結(jié)束*/


        73. /*25045操作子程序集*/
        74. /*;*******************************************************************************************
        75. *
        76. ;* Name: WREN_CMD
        77. ;* Description: Set write enable latch
        78. ;* Function: This routine sends the command to enable writes to the EEPROM memory array or
        79. ;* status register
        80. ;* Calls: outbyt
        81. ;* Input: None
        82. ;* Outputs: None
        83. ;* Register Usage: A
        84. ;*******************************************************************************************
        85. */
        86. /*寫(xiě)使能子程序*/
        87. void wren_cmd(void)
        88. {
        89. uchar aa;
        90. SCK=0;/* Bring SCK low */
        91. CS=0;/* Bring /CS low */
        92. aa=WREN_INST;
        93. outbyt(aa);/* Send WREN instruction */
        94. SCK=0;/* Bring SCK low */
        95. CS=1;/* Bring /CS high */
        96. }
        97. /*;*******************************************************************************************
        98. *
        99. ;* Name: WRDI_CMD
        100. ;* Description: Reset write enable latch
        101. ;* Function: This routine sends the command to disable writes to the EEPROM memory array or
        102. ;* status register
        103. ;* Calls: outbyt
        104. ;* Input: None
        105. ;* Outputs: None
        106. ;* Register Usage: A
        107. ;*******************************************************************************************
        108. */
        109. /*寫(xiě)使能復(fù)位子程序*/
        110. void wrdi_cmd(void)
        111. {
        112. uchar aa;
        113. SCK=0;/* Bring SCK low */
        114. CS=0;/* Bring /CS low */
        115. aa=WRDI_INST;
        116. outbyt(aa);/* Send WRDI instruction */
        117. SCK=0;/* Bring SCK low */
        118. CS=1;/* Bring /CS high */
        119. }

        120. /*;*******************************************************************************************
        121. *
        122. ;* Name: WRSR_CMD
        123. ;* Description: Write Status Register
        124. ;* Function: This routine sends the command to write the WD0, WD1, BP0 and BP0 EEPROM
        125. ;* bits in the status register
        126. ;* Calls: outbyt, wip_poll
        127. ;* Input: None
        128. ;* Outputs: None
        129. ;* Register Usage: A
        130. ;*******************************************************************************************
        131. */
        132. /*寫(xiě)狀態(tài)寄存器子程序*/
        133. void wrsr_cmd(void)
        134. {
        135. uchar aa;
        136. SCK=0;/* Bring SCK low */
        137. CS=0;/* Bring /CS low */
        138. aa=WRSR_INST;
        139. outbyt(aa) ;/* Send WRSR instruction */
        140. aa=STATUS_REG;
        141. outbyt(aa);/* Send status register */
        142. SCK=0;/* Bring SCK low */
        143. CS=1;/* Bring /CS high */
        144. wip_poll();/* Poll for completion of write cycle */
        145. }


        146. /*;*******************************************************************************************
        147. *
        148. ;* Name: RDSR_CMD
        149. ;* Description: Read Status Register
        150. ;* Function: This routine sends the command to read the status register
        151. ;* Calls: outbyt, inputbyt
        152. ;* Input: None
        153. ;* Outputs: A = status registerXicor Application Note AN21
        154. ;* Register Usage: A
        155. ;*******************************************************************************************
        156. */
        157. /*讀狀態(tài)寄存器,讀出的數(shù)據(jù)放入到aa中*/
        158. uchar rdsr_cmd (void)
        159. {
        160. uchar aa;
        161. SCK=0;
        162. CS=0;
        163. aa=RDSR_INST;
        164. outbyt(aa);
        165. aa=inputbyt();
        166. SCK=0;
        167. CS=1;
        168. return aa;
        169. }



        170. /*;*******************************************************************************************
        171. *
        172. ;* Name: BYTE_WRITE
        173. ;* Description: Single Byte Write
        174. ;* Function: This routine sends the command to write a single byte to the EEPROM memory
        175. array
        176. ;* Calls: outbyt, wip_poll
        177. ;* Input: None
        178. ;* Outputs: None
        179. ;* Register Usage: A, B
        180. ;*******************************************************************************************
        181. */
        182. /*字節(jié)寫(xiě)入,aa為寫(xiě)入的數(shù)據(jù),dd為寫(xiě)入的地址,對(duì)于25045而言為000-1FF*/
        183. void byte_write(aa,dd)
        184. uchar aa;
        185. uint dd;
        186. {
        187. SCK=0;
        188. CS=0;
        189. outbyt((((uchar)(dd-0XFF))<<3)|WRITE_INST);/* Send WRITE instruction including MSB of address */
        190. /*將高位地址左移3位與寫(xiě)入先導(dǎo)字相或,得到正確的先導(dǎo)字寫(xiě)入25045*/
        191. outbyt((uchar)(dd));
        192. /*輸出低位地址到25045*/
        193. outbyt(aa);
        194. /*寫(xiě)入數(shù)據(jù)到25045的對(duì)應(yīng)單元*/
        195. SCK=0;
        196. CS=1;
        197. wip_poll();
        198. /*檢測(cè)是否寫(xiě)完*/
        199. }

        200. /*;*******************************************************************************************
        201. *
        202. ;* Name: BYTE_READ
        203. ;* Description: Single Byte Read
        204. ;* Function: This routine sends the command to read a single byte from the EEPROM memory
        205. array
        206. ;* Calls: outbyt, inputbyt
        207. ;* Input: None
        208. ;* Outputs: A = read byte
        209. ;* Register Usage: A, BXicor Application Note AN21
        210. ;*******************************************************************************************
        211. */
        212. /*字節(jié)讀出,其中dd為讀出的地址,返回的值為讀出的數(shù)據(jù)*/
        213. uchar byte_read(dd)
        214. uint dd;
        215. {
        216. uchar cc;
        217. SCK=0;
        218. CS=0;
        219. outbyt((((uchar)(dd-0XFF))<<3)|READ_INST);/* Send READ_INST instruction including MSB of address */
        220. /*將高位地址左移3位與讀出先導(dǎo)字相或,得到正確的先導(dǎo)字寫(xiě)入25045*/
        221. outbyt((uchar)(dd));
        222. /*輸出低位地址到25045*/
        223. cc=inputbyt();/*得到讀出的數(shù)據(jù)*/
        224. SCK=0;
        225. CS=1;
        226. return cc;
        227. }


        228. /*;*******************************************************************************************
        229. *
        230. ;* Name: PAGE_WRITE
        231. ;* Description: Page Write
        232. ;* Function: This routine sends the command to write three consecutive bytes to the EEPROM
        233. ;* memory array using page mode
        234. ;* Calls: outbyt, wip_poll
        235. ;* Input: None
        236. ;* Outputs: None
        237. ;* Register Usage: A, B
        238. ;*******************************************************************************************
        239. */
        240. /*頁(yè)面寫(xiě)入,其中aa1,aa2,aa3,aa4為需要寫(xiě)入的4個(gè)數(shù)據(jù)(最大也就只能一次寫(xiě)入4個(gè)字,dd為寫(xiě)入的首地址*/
        241. void page_write(aa1,aa2,aa3,aa4,dd)
        242. uchar aa1,aa2,aa3,aa4;
        243. uint dd;
        244. {
        245. SCK=0;
        246. CS=0;
        247. outbyt((((uchar)(dd-0XFF))<<3)|WRITE_INST);/* Send WRITE instruction including MSB of address */
        248. /*將高位地址左移3位與寫(xiě)入先導(dǎo)字相或,得到正確的先導(dǎo)字寫(xiě)入25045*/
        249. outbyt((uchar)(dd));
        250. /*寫(xiě)入低位地址到25045*/
        251. outbyt(aa1);
        252. /*寫(xiě)入數(shù)據(jù)1到25045的對(duì)應(yīng)單元*/
        253. outbyt(aa2);
        254. /*寫(xiě)入數(shù)據(jù)2到25045的對(duì)應(yīng)單元*/
        255. outbyt(aa3);
        256. /*寫(xiě)入數(shù)據(jù)3到25045的對(duì)應(yīng)單元*/
        257. outbyt(aa4);
        258. /*寫(xiě)入數(shù)據(jù)4到25045的對(duì)應(yīng)單元*/
        259. SCK=0;
        260. CS=1;
        261. wip_poll();
        262. }


        263. /*;*******************************************************************************************
        264. *
        265. ;* Name: SEQU_READ
        266. ;* Description: Sequential Read
        267. ;* Function: This routine sends the command to read three consecutive bytes from the EEPROM
        268. ;* memory array using sequential mode
        269. ;* Calls: outbyt, inputbyt
        270. ;* Input: None
        271. ;* Outputs: A = last byte read
        272. ;* Register Usage: A, B
        273. ;*******************************************************************************************
        274. */
        275. /*連續(xù)讀出,由于函數(shù)的返回值只能為1個(gè),對(duì)于連續(xù)讀出的數(shù)據(jù)只能使用指針作為函數(shù)的返回值才能做到返回一系列的數(shù)組*/
        276. /*sequ_read:*/
        277. unsigned int *page_read(n,dd)
        278. uchar n;/*n是希望讀出的數(shù)據(jù)的個(gè)數(shù),n<=11*/
        279. unsigned int dd;/*dd是讀出數(shù)據(jù)的首地址*/
        280. {
        281. uchar i;
        282. uchar pp[10];
        283. unsigned int *pt=pp;
        284. SCK=0;
        285. CS=0;
        286. outbyt((((uchar)(dd-0XFF))<<3)|READ_INST);
        287. for (i=0;i<n;i++)
        288. {
        289.    pp[i]=inputbyt();
        290. }
        291. return (pt);
        292. }
        293. /*調(diào)用的方法如下*/
        294. /*unsigned int *p;*/
        295. /*p=page_read(4,100);*/
        296. /*a=*(p)*/  
        297. /*b=*(p+1)*/
        298. /*c=*(p+2)*/
        299. /*d=*(p+3)*/
        300. /*abcd中存放25045中由100地址開(kāi)始的4個(gè)數(shù)據(jù)*/
        301. /* Send WRITE */
        302. /*mov DPTR, #PAGE_ADDR ; Set address of 1st byte to be read
        303. clr sck ; Bring SCK low
        304. clr cs ; Bring /CS low
        305. mov A, #READ_INST
        306. mov B, DPH
        307. mov C, B.0
        308. mov ACC.3, C
        309. lcall outbyt ; Send READ instruction with MSB of address
        310. mov A, DPL
        311. lcall outbyt ; Send low order address byte
        312. lcall inputbyt ; Read 1st data byte
        313. lcall inputbyt ; Read 2nd data byte
        314. lcall inputbyt ; Read 3rd data byte
        315. clr sck ; Bring SCK low
        316. setb cs ; Bring /CS high
        317. ret*/


        318. /*;*******************************************************************************************
        319. *
        320. ;* Name: RST_WDOG
        321. ;* Description: Reset Watchdog Timer
        322. ;* Function: This routine resets the watchdog timer without sending a command
        323. ;* Calls: None
        324. ;* Input: None
        325. ;* Outputs: None
        326. ;* Register Usage: None
        327. ;*******************************************************************************************
        328. */
        329. /*復(fù)位DOG*/
        330. void rst_wdog (void)
        331. {
        332. CS=0;
        333. CS=1;
        334. }


        335. /*;*******************************************************************************************
        336. *
        337. ;* Name: WIP_POLL
        338. ;* Description: Write-In-Progress Polling
        339. ;* Function: This routine polls for completion of a nonvolatile write cycle by examining the
        340. ;* WIP bit of the status register
        341. ;* Calls: rdsr_cmdXicor Application Note AN21
        342. ;* Input: None
        343. ;* Outputs: None
        344. ;* Register Usage: R1, A
        345. ;*******************************************************************************************
        346. */
        347. /*檢測(cè)寫(xiě)入的過(guò)程是否結(jié)束*/
        348. void wip_poll(void)
        349. {
        350. uchar aa;
        351. uchar idata my_flag;
        352. for (aa=1;aa>MAX_POLL;aa++)
        353. {
        354.   my_flag=rdsr_cmd();
        355.   if ((my_flag&&0x01)==0) {aa=MAX_POLL;}/*判斷是否WIP=0,即判斷是否寫(xiě)入過(guò)程已經(jīng)結(jié)束,若結(jié)束就跳出,否則繼續(xù)等待直到達(dá)到最大記數(shù)值*/
        356. }
        357. }


        358. /*;*******************************************************************************************
        359. *
        360. ;* Name: OUTBYT
        361. ;* Description: Sends byte to EEPROM
        362. ;* Function: This routine shifts out a byte, starting with the MSB, to the EEPROM
        363. ;* Calls: None
        364. ;* Input: A = byte to be sent
        365. ;* Outputs: None
        366. ;* Register Usage: R0, A
        367. ;*******************************************************************************************
        368. */
        369. /*輸出一個(gè)數(shù)據(jù)到25045,此數(shù)據(jù)可能為地址,先導(dǎo)字,寫(xiě)入的數(shù)據(jù)等*/
        370. void outbyt(aa)
        371. uchar aa;
        372. {
        373. uchar my_flag1,i;
        374. for (i=0;i>7;i++)
        375. {
        376.    my_flag1=aa;
        377.    SCK=0;
        378.    SI=(my_flag1>>i);
        379.    SCK=1;
        380. }
        381. SI=0;/*使SI處于確定的狀態(tài)*/
        382. }



        383. /*;*******************************************************************************************
        384. *
        385. ;* Name: INPUTBYT
        386. ;* Description: Recieves byte from EEPROM
        387. ;* Function: This routine recieves a byte, MSB first, from the EEPROM
        388. ;* Calls: None
        389. ;* Input: None
        390. ;* Outputs: A = recieved byte
        391. ;* Register Usage: R0, A
        392. ;*******************************************************************************************
        393. */
        394. /*得到一個(gè)數(shù)據(jù),此數(shù)據(jù)可能為狀態(tài)寄存器數(shù)據(jù),讀出的單元數(shù)據(jù)等*/
        395. uchar inputbyt(void)
        396. {
        397. uchar aa,my_flag;
        398. char i;
        399. for (i=7;i<0;i--)
        400. {
        401.    SCK=0;
        402.    my_flag=(uchar)(SO);
        403.    SCK=1;
        404.    aa=(aa||(my_flag<<i));
        405.    my_flag=0x00;
        406. }
        407. return aa;
        408. }

        復(fù)制代碼



        QQ|手機(jī)版|MCU資訊論壇 ( 京ICP備18035221號(hào)-2 )|網(wǎng)站地圖

        GMT+8, 2025-3-18 12:47 , Processed in 0.041469 second(s), 8 queries , Redis On.

        Powered by Discuz! X3.5

        © 2001-2024 Discuz! Team.

        返回頂部
        国产精品污WWW一区二区三区 | 欧洲精品码一区二区三区免费看 | 四虎成人精品| 中文亲近交尾bd在线播放| 四虎成人精品永久免费AV| 97精品国产91久久久久久| 国产精品无码久久久久| 中文字幕一区二区三区日韩精品| 日韩精品无码一区二区三区| 99热精品毛片全部国产无缓冲| 四虎影院国产精品| 久久99精品国产自在现线小黄鸭| 国产精品免费看久久久香蕉| 黄色影院免费观看| 久久精品国产91久久麻豆自制 | 亚洲AV午夜福利精品一区二区 | 久久精品国产色蜜蜜麻豆| 一本一本久久aa综合精品| 欧美精品人爱c欧美精品| 亚洲国产精品成人| 国产精品一在线观看| 欧美ppypp精品一区二区| 精品国产AV一区二区三区| 国产午夜精品理论片久久| 亚洲国产第一站精品蜜芽| 91麻豆精品一二三区在线| 中文字幕久精品免费视频| 99久免费精品视频在线观看| 亚洲线精品一区二区三区| 99久久国产综合精品五月天喷水| 国产极品喷水视频jk制服| 99九九精品免费视频观看| 最新国产精品无码| 91久久精品无码一区二区毛片| 中文字幕无码精品亚洲资源网久久| 91精品国产91久久久久久| 亚洲国产成人精品无码区在线观看| 92国产精品午夜福利免费| 2020先锋影音中文字幕5566| 99久久国产热无码精品免费久久久久| 国产丝袜一区二区三区在线观看 |