sf
eeprom.cpp@0:b71fbcf5b8e4, 2016-09-27 (annotated)
- Committer:
- floatlei
- Date:
- Tue Sep 27 09:41:21 2016 +0000
- Revision:
- 0:b71fbcf5b8e4
sf
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
floatlei | 0:b71fbcf5b8e4 | 1 | #include "eeprom.h" |
floatlei | 0:b71fbcf5b8e4 | 2 | |
floatlei | 0:b71fbcf5b8e4 | 3 | |
floatlei | 0:b71fbcf5b8e4 | 4 | Eeprom::Eeprom() |
floatlei | 0:b71fbcf5b8e4 | 5 | { |
floatlei | 0:b71fbcf5b8e4 | 6 | |
floatlei | 0:b71fbcf5b8e4 | 7 | } |
floatlei | 0:b71fbcf5b8e4 | 8 | |
floatlei | 0:b71fbcf5b8e4 | 9 | |
floatlei | 0:b71fbcf5b8e4 | 10 | unsigned int Eeprom::eeprom_countor_read(void) |
floatlei | 0:b71fbcf5b8e4 | 11 | { |
floatlei | 0:b71fbcf5b8e4 | 12 | unsigned int eeproma,eepromshuil; |
floatlei | 0:b71fbcf5b8e4 | 13 | |
floatlei | 0:b71fbcf5b8e4 | 14 | for(eeproma=0;eeproma<9;eeproma++) |
floatlei | 0:b71fbcf5b8e4 | 15 | { |
floatlei | 0:b71fbcf5b8e4 | 16 | if(EEPROM_VALUE_SHUILIANGDECIMAL(eeproma)!=EEPROM_MARK_SHUILDECIMAL) |
floatlei | 0:b71fbcf5b8e4 | 17 | break; |
floatlei | 0:b71fbcf5b8e4 | 18 | } |
floatlei | 0:b71fbcf5b8e4 | 19 | |
floatlei | 0:b71fbcf5b8e4 | 20 | eepromshuil=EEPROM_VALUE_SHUILIANGMAIN; |
floatlei | 0:b71fbcf5b8e4 | 21 | eepromshuil+=eeproma; |
floatlei | 0:b71fbcf5b8e4 | 22 | |
floatlei | 0:b71fbcf5b8e4 | 23 | return (unsigned short)eepromshuil; |
floatlei | 0:b71fbcf5b8e4 | 24 | } |
floatlei | 0:b71fbcf5b8e4 | 25 | |
floatlei | 0:b71fbcf5b8e4 | 26 | |
floatlei | 0:b71fbcf5b8e4 | 27 | unsigned int Eeprom::eeprom_countor_write(unsigned int watervalue) |
floatlei | 0:b71fbcf5b8e4 | 28 | { |
floatlei | 0:b71fbcf5b8e4 | 29 | unsigned int eepromb; |
floatlei | 0:b71fbcf5b8e4 | 30 | |
floatlei | 0:b71fbcf5b8e4 | 31 | /* |
floatlei | 0:b71fbcf5b8e4 | 32 | /FLASH_ErasePage(EEPROM_ADDR_PAGE0); |
floatlei | 0:b71fbcf5b8e4 | 33 | FLASH_ErasePage(EEPROM_ADDR_PAGE1); |
floatlei | 0:b71fbcf5b8e4 | 34 | FLASH_ErasePage(EEPROM_ADDR_SHUILIANGMAIN); |
floatlei | 0:b71fbcf5b8e4 | 35 | |
floatlei | 0:b71fbcf5b8e4 | 36 | HAL_FLASH_Program(1, EEPROM_ADDR_SHUILIANGMAIN, eepromshuil); |
floatlei | 0:b71fbcf5b8e4 | 37 | */ |
floatlei | 0:b71fbcf5b8e4 | 38 | |
floatlei | 0:b71fbcf5b8e4 | 39 | return eepromb; |
floatlei | 0:b71fbcf5b8e4 | 40 | } |
floatlei | 0:b71fbcf5b8e4 | 41 | |
floatlei | 0:b71fbcf5b8e4 | 42 | unsigned int Eeprom::eeprom_countor_addone(void) |
floatlei | 0:b71fbcf5b8e4 | 43 | { |
floatlei | 0:b71fbcf5b8e4 | 44 | unsigned int eepromb,eeproma,eepromshuil; |
floatlei | 0:b71fbcf5b8e4 | 45 | |
floatlei | 0:b71fbcf5b8e4 | 46 | __disable_irq(); |
floatlei | 0:b71fbcf5b8e4 | 47 | |
floatlei | 0:b71fbcf5b8e4 | 48 | eepromb=HAL_FLASH_Unlock(); |
floatlei | 0:b71fbcf5b8e4 | 49 | |
floatlei | 0:b71fbcf5b8e4 | 50 | for(eeproma=0;eeproma<10;eeproma++) |
floatlei | 0:b71fbcf5b8e4 | 51 | { |
floatlei | 0:b71fbcf5b8e4 | 52 | if(EEPROM_VALUE_SHUILIANGDECIMAL(eeproma)!=EEPROM_MARK_SHUILDECIMAL) |
floatlei | 0:b71fbcf5b8e4 | 53 | break; |
floatlei | 0:b71fbcf5b8e4 | 54 | |
floatlei | 0:b71fbcf5b8e4 | 55 | } |
floatlei | 0:b71fbcf5b8e4 | 56 | //pc.printf("eeproma=%d\n",eeproma); |
floatlei | 0:b71fbcf5b8e4 | 57 | |
floatlei | 0:b71fbcf5b8e4 | 58 | if(eeproma>8) |
floatlei | 0:b71fbcf5b8e4 | 59 | { |
floatlei | 0:b71fbcf5b8e4 | 60 | eepromshuil=EEPROM_VALUE_SHUILIANGMAIN; |
floatlei | 0:b71fbcf5b8e4 | 61 | eepromshuil+=10; |
floatlei | 0:b71fbcf5b8e4 | 62 | |
floatlei | 0:b71fbcf5b8e4 | 63 | for(eepromb=0;eepromb<9;eepromb++) |
floatlei | 0:b71fbcf5b8e4 | 64 | { |
floatlei | 0:b71fbcf5b8e4 | 65 | HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, EEPROM_ADDR_PAGE1+4*eepromb, 0); |
floatlei | 0:b71fbcf5b8e4 | 66 | wait(0.02); |
floatlei | 0:b71fbcf5b8e4 | 67 | } |
floatlei | 0:b71fbcf5b8e4 | 68 | |
floatlei | 0:b71fbcf5b8e4 | 69 | eepromb=HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, EEPROM_ADDR_SHUILIANGMAIN, 0); |
floatlei | 0:b71fbcf5b8e4 | 70 | wait(0.02); |
floatlei | 0:b71fbcf5b8e4 | 71 | eepromb=HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, EEPROM_ADDR_SHUILIANGMAIN, eepromshuil); |
floatlei | 0:b71fbcf5b8e4 | 72 | wait(0.02); |
floatlei | 0:b71fbcf5b8e4 | 73 | } |
floatlei | 0:b71fbcf5b8e4 | 74 | else |
floatlei | 0:b71fbcf5b8e4 | 75 | { |
floatlei | 0:b71fbcf5b8e4 | 76 | eepromb=HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, EEPROM_ADDR_SHUILIANGDECIMAL+eeproma*4, EEPROM_MARK_SHUILDECIMAL); |
floatlei | 0:b71fbcf5b8e4 | 77 | wait(0.02); |
floatlei | 0:b71fbcf5b8e4 | 78 | } |
floatlei | 0:b71fbcf5b8e4 | 79 | |
floatlei | 0:b71fbcf5b8e4 | 80 | eepromb=HAL_FLASH_Lock(); |
floatlei | 0:b71fbcf5b8e4 | 81 | |
floatlei | 0:b71fbcf5b8e4 | 82 | __enable_irq(); |
floatlei | 0:b71fbcf5b8e4 | 83 | |
floatlei | 0:b71fbcf5b8e4 | 84 | return eepromb; |
floatlei | 0:b71fbcf5b8e4 | 85 | } |