You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /**
  2. ******************************************************************************
  3. **˵2.4Güд
  4. **ܣЭáдIC
  5. **ߣ֣
  6. **ڣ2017.08
  7. ******************************************************************************
  8. **/
  9. /* Includes ------------------------------------------------------------------*/
  10. #include "flash.h"
  11. #include "printf.h"
  12. // BYTE thenticated = FALSE;
  13. u16 StoreBuffer[STORE_DATA_NUM];
  14. u8 Save_Buffer[STORE_DATA_NUM*2];
  15. /*****************************************************************************************************
  16. ** : Startwritedata()
  17. ** : ʼflashд
  18. ** ӿڲ: addr
  19. ** ȫֱ:
  20. ** 壺ADDR_BASE
  21. ** :
  22. ** : 2010.5.13
  23. ------------------------------------------------------------------------------------------------------
  24. ** ע:ÿдǰȲҪ洢λڵҳǺEEPROMIJ֮ͬFlash߱޸Ĺܣ
  25. ֻȲдʱֻ֧ҳ
  26. addrַΧADDR_BASE ~ADDR_BASE+1022
  27. *****************************************************************************************************/
  28. void Startwritedata(DWORD addr)
  29. {
  30. FLASH_Unlock(); //ÿβFlashʱȽ
  31. FLASH_ErasePage(addr); //ҳ
  32. }
  33. /*****************************************************************************************************
  34. ** : Write_Complete()
  35. ** :
  36. ** ӿڲ:
  37. ** ȫֱ:
  38. ** 壺ADDR_BASE
  39. ** :
  40. ** : 2010.5.13
  41. ------------------------------------------------------------------------------------------------------
  42. ** ע:ÿдǰȲҪ洢λڵҳǺEEPROMIJ֮ͬFlash߱޸Ĺܣ
  43. ֻȲдʱֻ֧ҳ
  44. addrַΧADDR_BASE ~ADDR_BASE+1022
  45. *****************************************************************************************************/
  46. void Write_Complete(void)
  47. {
  48. FLASH_Lock(); //
  49. }
  50. /*****************************************************************************************************
  51. ** : SavePara()
  52. ** :һ Ϊ16λ
  53. ** ӿڲ: addr,data
  54. ** ȫֱ:
  55. ** 壺ADDR_BASE
  56. ** :
  57. ** : 2010.5.13
  58. ------------------------------------------------------------------------------------------------------
  59. ** ע:ÿдǰȲҪ洢λڵҳǺEEPROMIJ֮ͬFlash߱޸Ĺܣ
  60. ֻȲдʱֻ֧ҳ
  61. addrַΧADDR_BASE ~ADDR_BASE+1022
  62. *****************************************************************************************************/
  63. void SavePara(DWORD addr,WORD data)
  64. {
  65. FLASH_ProgramHalfWord(addr,data);//д16λ
  66. }
  67. /*****************************************************************************************************
  68. ** : GetPara()
  69. ** :
  70. ** ӿڲ: ȡ addr ַ
  71. ** ȫֱ:
  72. ** 壺ADDR_BASE
  73. ** ú:
  74. ** :
  75. ** : 2010.5.13
  76. ------------------------------------------------------------------------------------------------------
  77. ** ע: addrַΧADDR_BASE ~ADDR_BASE+1022
  78. *****************************************************************************************************/
  79. WORD GetPara(DWORD addr)
  80. {
  81. WORD data;
  82. data=(WORD)(*(DWORD*)addr); //ȡӦַе16λ
  83. return data;
  84. }
  85. /*****************************************************************************************************
  86. ** : Savestr_to_flash()
  87. ** : һݴ浽ָĵַ
  88. ** ӿڲ: addr,datalen
  89. ** ȫֱ:
  90. ** 壺
  91. ** :
  92. ** : 2010.5.13
  93. ------------------------------------------------------------------------------------------------------
  94. ** ע:ÿдǰȲҪ洢λڵҳǺEEPROMIJ֮ͬFlash߱޸Ĺܣ
  95. ֻȲдʱֻ֧ҳ
  96. addrַΧADDR_BASE ~ADDR_BASE+1022
  97. *****************************************************************************************************/
  98. void Savestr_to_flash(DWORD addr,WORD *str,WORD len)
  99. {
  100. BYTE i = 0;
  101. for(i = 0;i < len;i ++)
  102. {
  103. SavePara(addr,str[i]);
  104. addr += 2;
  105. }
  106. }
  107. /*****************************************************************************************************
  108. ** : Readstr_of_flash()
  109. ** : ijַʼȡһַ
  110. ** ӿڲ: addr,datalen
  111. ** ȫֱ:
  112. ** 壺
  113. ** :
  114. ** : 2010.5.13
  115. ------------------------------------------------------------------------------------------------------
  116. ** ע:ÿдǰȲҪ洢λڵҳǺEEPROMIJ֮ͬFlash߱޸Ĺܣ
  117. ֻȲдʱֻ֧ҳ
  118. addrַΧADDR_BASE ~ADDR_BASE+1022
  119. *****************************************************************************************************/
  120. void Readstr_of_flash(DWORD addr,WORD *str,WORD len)
  121. {
  122. BYTE i = 0;
  123. for(i = 0;i < len;i ++)
  124. {
  125. str[i] = GetPara(addr);
  126. addr += 2;
  127. }
  128. }
  129. /*****************************************************************************************************
  130. ** : SavePara_to_flash()
  131. ** : һЩ浽flash
  132. ** ӿڲ: addr,data,len
  133. ** ȫֱ:
  134. ** 壺
  135. ** :
  136. ** : 2010.5.13
  137. ------------------------------------------------------------------------------------------------------
  138. ** ע:ÿдǰȲҪ洢λڵҳǺEEPROMIJ֮ͬFlash߱޸Ĺܣ
  139. ֻȲдʱֻ֧ҳ
  140. addrַΧADDR_BASE ~ADDR_BASE+1022
  141. *****************************************************************************************************/
  142. void SavePara_to_flash(void)
  143. {
  144. BYTE i = 0;
  145. WORD flash_buf[STORE_DATA_NUM] = {0};
  146. for(i = 0;i < STORE_DATA_NUM;i ++)
  147. {
  148. flash_buf[i] = (WORD)StoreBuffer[i];//תҪд
  149. }
  150. Startwritedata(PC_NUM_ADDR);
  151. Savestr_to_flash(PC_NUM_ADDR,flash_buf,STORE_DATA_NUM);
  152. Write_Complete();
  153. }
  154. /*****************************************************************************************************
  155. ** : Readstr_of_flash()
  156. ** : ijַʼȡһַ
  157. ** ӿڲ: addr,datalen
  158. ** ȫֱ:
  159. ** 壺
  160. ** :
  161. ** : 2010.5.13
  162. ------------------------------------------------------------------------------------------------------
  163. ** ע:ÿдǰȲҪ洢λڵҳǺEEPROMIJ֮ͬFlash߱޸Ĺܣ
  164. ֻȲдʱֻ֧ҳ
  165. addrַΧADDR_BASE ~ADDR_BASE+1022
  166. *****************************************************************************************************/
  167. void Readpara_from_flash(void)
  168. {
  169. BYTE i = 0;
  170. WORD flash_buf[STORE_DATA_NUM] = {0}; //16λFLASHд
  171. // BYTE Save_Buffer[STORE_DATA_NUM*2]={0}; //8λ飬16λת
  172. Readstr_of_flash(PC_NUM_ADDR,flash_buf,STORE_DATA_NUM);
  173. for(i = 0;i < STORE_DATA_NUM;i ++)
  174. {
  175. Save_Buffer[2*i] = (WORD)flash_buf[i];
  176. // printf("Ͱλ %d=%d \r\n",i,Save_Buffer[2*i]); //ӡ16λݵĵͰλ
  177. // Save_Buffer[2*i + 1] = (WORD)(flash_buf[i] >>=8);
  178. // printf("߰λ=%u \r\n",Save_Buffer[2*i+1]); //ӡ߰λ
  179. }
  180. // printf("Ƶ = %d \r\n",Save_Buffer[2*0]); //ӡ16λݵĵͰλ
  181. // printf("ù = %d \r\n",Save_Buffer[2*1]); //ӡ16λݵĵͰλ
  182. // printf(" = %d \r\n",Save_Buffer[2*2]); //ӡ16λݵĵͰλ
  183. }