|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- /**
- ******************************************************************************
- **˵2.4Güд
- **ܣЭáдIC
- **ߣ֣
- **ڣ2017.08
- ******************************************************************************
- **/
-
- /* Includes ------------------------------------------------------------------*/
- #include "flash.h"
- #include "printf.h"
-
-
- // BYTE thenticated = FALSE;
- u16 StoreBuffer[STORE_DATA_NUM];
- u8 Save_Buffer[STORE_DATA_NUM*2];
- /*****************************************************************************************************
- ** : Startwritedata()
- ** : ʼflashд
- ** ӿڲ: addr
- ** ȫֱ:
- ** 壺ADDR_BASE
- ** :
- ** : 2010.5.13
- ------------------------------------------------------------------------------------------------------
- ** ע:ÿдǰȲҪ洢λڵҳǺEEPROMIJ֮ͬFlash߱Ĺܣ
- ֻȲдʱֻ֧ҳ
- addrַΧADDR_BASE ~ADDR_BASE+1022
- *****************************************************************************************************/
- void Startwritedata(DWORD addr)
- {
- FLASH_Unlock(); //ÿβFlashʱȽ
- FLASH_ErasePage(addr); //ҳ
- }
-
- /*****************************************************************************************************
- ** : Write_Complete()
- ** :
- ** ӿڲ:
- ** ȫֱ:
- ** 壺ADDR_BASE
- ** :
- ** : 2010.5.13
- ------------------------------------------------------------------------------------------------------
- ** ע:ÿдǰȲҪ洢λڵҳǺEEPROMIJ֮ͬFlash߱Ĺܣ
- ֻȲдʱֻ֧ҳ
- addrַΧADDR_BASE ~ADDR_BASE+1022
- *****************************************************************************************************/
- void Write_Complete(void)
- {
-
- FLASH_Lock(); //
-
- }
-
-
-
- /*****************************************************************************************************
- ** : SavePara()
- ** :һ Ϊ16λ
- ** ӿڲ: addr,data
- ** ȫֱ:
- ** 壺ADDR_BASE
- ** :
- ** : 2010.5.13
- ------------------------------------------------------------------------------------------------------
- ** ע:ÿдǰȲҪ洢λڵҳǺEEPROMIJ֮ͬFlash߱Ĺܣ
- ֻȲдʱֻ֧ҳ
- addrַΧADDR_BASE ~ADDR_BASE+1022
- *****************************************************************************************************/
- void SavePara(DWORD addr,WORD data)
- {
-
- FLASH_ProgramHalfWord(addr,data);//д16λ
-
- }
-
-
-
-
- /*****************************************************************************************************
- ** : GetPara()
- ** :
- ** ӿڲ: ȡ addr ַ
- ** ȫֱ:
- ** 壺ADDR_BASE
- ** ú:
- ** :
- ** : 2010.5.13
- ------------------------------------------------------------------------------------------------------
- ** ע: addrַΧADDR_BASE ~ADDR_BASE+1022
- *****************************************************************************************************/
- WORD GetPara(DWORD addr)
- {
- WORD data;
- data=(WORD)(*(DWORD*)addr); //ȡӦַе16λ
- return data;
- }
-
- /*****************************************************************************************************
- ** : Savestr_to_flash()
- ** : һݴ浽ָĵַ
- ** ӿڲ: addr,datalen
- ** ȫֱ:
- ** 壺
- ** :
- ** : 2010.5.13
- ------------------------------------------------------------------------------------------------------
- ** ע:ÿдǰȲҪ洢λڵҳǺEEPROMIJ֮ͬFlash߱Ĺܣ
- ֻȲдʱֻ֧ҳ
- addrַΧADDR_BASE ~ADDR_BASE+1022
- *****************************************************************************************************/
- void Savestr_to_flash(DWORD addr,WORD *str,WORD len)
- {
- BYTE i = 0;
- for(i = 0;i < len;i ++)
- {
- SavePara(addr,str[i]);
- addr += 2;
- }
- }
-
- /*****************************************************************************************************
- ** : Readstr_of_flash()
- ** : ijַʼȡһַ
- ** ӿڲ: addr,datalen
- ** ȫֱ:
- ** 壺
- ** :
- ** : 2010.5.13
- ------------------------------------------------------------------------------------------------------
- ** ע:ÿдǰȲҪ洢λڵҳǺEEPROMIJ֮ͬFlash߱Ĺܣ
- ֻȲдʱֻ֧ҳ
- addrַΧADDR_BASE ~ADDR_BASE+1022
- *****************************************************************************************************/
- void Readstr_of_flash(DWORD addr,WORD *str,WORD len)
- {
- BYTE i = 0;
- for(i = 0;i < len;i ++)
- {
- str[i] = GetPara(addr);
- addr += 2;
- }
- }
-
- /*****************************************************************************************************
- ** : SavePara_to_flash()
- ** : һЩ浽flash
- ** ӿڲ: addr,data,len
- ** ȫֱ:
- ** 壺
- ** :
- ** : 2010.5.13
- ------------------------------------------------------------------------------------------------------
- ** ע:ÿдǰȲҪ洢λڵҳǺEEPROMIJ֮ͬFlash߱Ĺܣ
- ֻȲдʱֻ֧ҳ
- addrַΧADDR_BASE ~ADDR_BASE+1022
- *****************************************************************************************************/
-
- void SavePara_to_flash(void)
- {
- BYTE i = 0;
- WORD flash_buf[STORE_DATA_NUM] = {0};
- for(i = 0;i < STORE_DATA_NUM;i ++)
- {
- flash_buf[i] = (WORD)StoreBuffer[i];//תҪд
- }
-
- Startwritedata(PC_NUM_ADDR);
- Savestr_to_flash(PC_NUM_ADDR,flash_buf,STORE_DATA_NUM);
- Write_Complete();
- }
-
- /*****************************************************************************************************
- ** : Readstr_of_flash()
- ** : ijַʼȡһַ
- ** ӿڲ: addr,datalen
- ** ȫֱ:
- ** 壺
- ** :
- ** : 2010.5.13
- ------------------------------------------------------------------------------------------------------
- ** ע:ÿдǰȲҪ洢λڵҳǺEEPROMIJ֮ͬFlash߱Ĺܣ
- ֻȲдʱֻ֧ҳ
- addrַΧADDR_BASE ~ADDR_BASE+1022
- *****************************************************************************************************/
- void Readpara_from_flash(void)
- {
- BYTE i = 0;
- WORD flash_buf[STORE_DATA_NUM] = {0}; //16λFLASHд
- // BYTE Save_Buffer[STORE_DATA_NUM*2]={0}; //8λ飬16λת
- Readstr_of_flash(PC_NUM_ADDR,flash_buf,STORE_DATA_NUM);
-
- for(i = 0;i < STORE_DATA_NUM;i ++)
- {
- Save_Buffer[2*i] = (WORD)flash_buf[i];
- // printf("Ͱλ %d=%d \r\n",i,Save_Buffer[2*i]); //ӡ16λݵĵͰλ
-
- // Save_Buffer[2*i + 1] = (WORD)(flash_buf[i] >>=8);
- // printf("߰λ=%u \r\n",Save_Buffer[2*i+1]); //ӡ߰λ
-
- }
-
- // printf("Ƶ = %d \r\n",Save_Buffer[2*0]); //ӡ16λݵĵͰλ
- // printf("ù = %d \r\n",Save_Buffer[2*1]); //ӡ16λݵĵͰλ
- // printf(" = %d \r\n",Save_Buffer[2*2]); //ӡ16λݵĵͰλ
- }
-
-
-
-
-
|