找回密碼
         注冊會員
        搜索附件  

        x25045CN.pdf

         

        25045操作標準子程序集,25045中英文PDF,25045中英文資料:

        1. /*
        2. ;程 序 最 后 修 改 時 間  0-4-3 23:43
        3. ;軟 件 標 題:25045操作標準子程序集41
        4. ;軟 件 說 明:25045 I2C 串行EEPROM 驅動
        5. ;_________________________________________
        6. ;原作者: 龐波     
        7. ;程序修改人:
        8. ;版本號:
        9. ;_________________________________________
        10. */

        11. /*到現在為止所有的問題都已經解決,此版本已經較為完善*/
        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時鐘*/
        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. /*寫入25045的先導字,應當為0000A010,其中的A為寫入25045的高位地址
        31. 將此WRITE_INST和寫入高位地址相或后即為正確的寫先導字*/
        32. uchar code READ_INST=0X03;
        33. /* Read memory instruction (READ)*/
        34. /*讀出25045的先導字,應當為0000A011,其中的A為讀出25045的高位地址
        35. 將此READ_INST和讀出高位地址相或后即為正確的讀先導字*/
        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. /*頁面寫入的其始地址*/
        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,設置DOG時間設置為200毫秒,無寫保護*/
        51. /*這是狀態寄存器的值,他的意義在于第5,第4位為WDI1,WDI0代表DOG的時間,00為1.4秒,01為600毫秒,10為200毫秒,00為disabled
        52. 第3位和第2位為BL1,BL0,是寫保護設置位,00為無保護,01為保護180-1FF,10為保護100-1FF,11為保護000-1FF.第1位為WEL,
        53. 當他為1時代表已經"寫使能"設置了,現在可以寫了,只讀位.第0位為WIP,當他為1時代表正在進行寫操作,是只讀*/
        54. uchar code  MAX_POLL=0x99;
        55. /* Maximum number of polls*/
        56. /*最大寫過程時間,確定25045的最大的寫入過程的時間*/
        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);/*寫使能子程序*/
        62. void wrdi_cmd(void);/*寫使能復位*/
        63. void wrsr_cmd(void);/*復位時間位和數據保護位寫入狀態寄存器*/
        64. uchar rdsr_cmd(void);/*讀狀態寄存器*/
        65. void byte_write(uchar aa,uint dd);/*字節寫入,aa為寫入的數據,dd為寫入的地址*/
        66. uchar byte_read(uint dd);/*字節讀出,dd為讀出的地址,返回讀出的數據*/
        67. void page_write(uchar aa1,uchar aa2,uchar aa3,uchar aa4,uint dd);/*頁寫入*/
        68. void sequ_read(void);/*連續讀出*/
        69. void rst_wdog(void);/*DOG復位*/
        70. void outbyt(uchar aa);/*輸出一個字節到25045中,不包括先導字等*/
        71. uchar inputbyt();/*由25045輸入一個字節,不包括先導字等額外的東西*/
        72. void wip_poll(void);/*檢查寫入過程是否結束*/


        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. /*寫使能子程序*/
        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. /*寫使能復位子程序*/
        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. /*寫狀態寄存器子程序*/
        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. /*讀狀態寄存器,讀出的數據放入到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. /*字節寫入,aa為寫入的數據,dd為寫入的地址,對于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位與寫入先導字相或,得到正確的先導字寫入25045*/
        191. outbyt((uchar)(dd));
        192. /*輸出低位地址到25045*/
        193. outbyt(aa);
        194. /*寫入數據到25045的對應單元*/
        195. SCK=0;
        196. CS=1;
        197. wip_poll();
        198. /*檢測是否寫完*/
        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. /*字節讀出,其中dd為讀出的地址,返回的值為讀出的數據*/
        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位與讀出先導字相或,得到正確的先導字寫入25045*/
        221. outbyt((uchar)(dd));
        222. /*輸出低位地址到25045*/
        223. cc=inputbyt();/*得到讀出的數據*/
        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. /*頁面寫入,其中aa1,aa2,aa3,aa4為需要寫入的4個數據(最大也就只能一次寫入4個字,dd為寫入的首地址*/
        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位與寫入先導字相或,得到正確的先導字寫入25045*/
        249. outbyt((uchar)(dd));
        250. /*寫入低位地址到25045*/
        251. outbyt(aa1);
        252. /*寫入數據1到25045的對應單元*/
        253. outbyt(aa2);
        254. /*寫入數據2到25045的對應單元*/
        255. outbyt(aa3);
        256. /*寫入數據3到25045的對應單元*/
        257. outbyt(aa4);
        258. /*寫入數據4到25045的對應單元*/
        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. /*連續讀出,由于函數的返回值只能為1個,對于連續讀出的數據只能使用指針作為函數的返回值才能做到返回一系列的數組*/
        276. /*sequ_read:*/
        277. unsigned int *page_read(n,dd)
        278. uchar n;/*n是希望讀出的數據的個數,n<=11*/
        279. unsigned int dd;/*dd是讀出數據的首地址*/
        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. /*調用的方法如下*/
        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地址開始的4個數據*/
        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. /*復位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. /*檢測寫入的過程是否結束*/
        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,即判斷是否寫入過程已經結束,若結束就跳出,否則繼續等待直到達到最大記數值*/
        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. /*輸出一個數據到25045,此數據可能為地址,先導字,寫入的數據等*/
        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處于確定的狀態*/
        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. /*得到一個數據,此數據可能為狀態寄存器數據,讀出的單元數據等*/
        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. }

        復制代碼



        QQ|手機版|MCU資訊論壇 ( 京ICP備18035221號-2 )|網站地圖

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

        Powered by Discuz! X3.5

        © 2001-2024 Discuz! Team.

        返回頂部
        精品久人妻去按摩店被黑人按中出| 少妇人妻精品一区二区三区| 精品无码一区在线观看| 精品亚洲成a人片在线观看 | 免费观看大片bbb| 精品国产第一国产综合精品| 777欧美午夜精品影院| 无夜精品久久久久久| 国产精品美女久久久久久2018| 99久久免费国产精品| 亚洲视频在线中文视频| HEYZO无码综合国产精品| 国产精品国产三级国产潘金莲| 日韩在线精品视频| 久久精品成人免费看| 亚洲精品无码久久久| 国内精品51视频在线观看| 人人妻人人澡人人爽精品欧美| 精品人妻久久久久久888| 精品国产香蕉伊思人在线在线亚洲一区二区 | 四虎成人精品免费影院| 四虎亚洲国产成人久久精品| 99精品无人区乱码在线观看| 老年人精品视频在线| 国产精品特级毛片一区二区三区| 国产一区二区三区在线观看精品| **网站欧美大片在线观看| 91久久精品国产成人久久| 免费人成在线蜜桃视频| 99在线观看视频免费精品9| 亚洲欧洲国产精品香蕉网| 99久久精品国产一区二区| 亚洲AV永久纯肉无码精品动漫 | 日批视频在线观看| 国产福利精品视频自拍| 精品调教CHINESEGAY| 久久精品中文字幕一区| 国产精品久久网| 亚洲综合精品香蕉久久网| 国产在AJ精品| 99精品久久精品一区二区|