Example of program which uses library "Flash" for storing data to internal flash of MCU NXP LPC1768 based on IAP protocol.

Dependencies:   Flash mbed

Committer:
bosko1523
Date:
Sun Jan 15 20:44:16 2017 +0000
Revision:
1:1a9df16ad1c9
Parent:
0:cd065c06ce89
Example of program which uses library "Flash" for storing data to internal flash of MCU NXP LPC1768 based on IAP protocol.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bosko1523 0:cd065c06ce89 1 #include "mbed.h"
bosko1523 0:cd065c06ce89 2 #include "Flash.h"
bosko1523 0:cd065c06ce89 3
bosko1523 0:cd065c06ce89 4 BusOut display(LED1, LED2, LED3, LED4);
bosko1523 0:cd065c06ce89 5 InterruptIn cntUp(p5);
bosko1523 0:cd065c06ce89 6 Timer debounceUp;
bosko1523 0:cd065c06ce89 7 Flash flash;
bosko1523 0:cd065c06ce89 8
bosko1523 0:cd065c06ce89 9 char retainData[MEM_SIZE];
bosko1523 0:cd065c06ce89 10 uint8_t counter;
bosko1523 0:cd065c06ce89 11
bosko1523 0:cd065c06ce89 12 void countUp(void) {
bosko1523 0:cd065c06ce89 13 if (debounceUp.read_ms() > 500) {
bosko1523 0:cd065c06ce89 14
bosko1523 0:cd065c06ce89 15 if (counter > 15)
bosko1523 0:cd065c06ce89 16 counter = 0;
bosko1523 0:cd065c06ce89 17 else
bosko1523 0:cd065c06ce89 18 counter++;
bosko1523 0:cd065c06ce89 19
bosko1523 0:cd065c06ce89 20 retainData[0] = counter;
bosko1523 0:cd065c06ce89 21 flash.writeFlash(retainData);
bosko1523 0:cd065c06ce89 22
bosko1523 0:cd065c06ce89 23 debounceUp.reset();
bosko1523 0:cd065c06ce89 24 }
bosko1523 0:cd065c06ce89 25 }
bosko1523 0:cd065c06ce89 26
bosko1523 0:cd065c06ce89 27 int main() {
bosko1523 0:cd065c06ce89 28 cntUp.rise(&countUp);
bosko1523 0:cd065c06ce89 29 debounceUp.start();
bosko1523 0:cd065c06ce89 30
bosko1523 0:cd065c06ce89 31 flash.readFlash(retainData);
bosko1523 0:cd065c06ce89 32 counter = retainData[0];
bosko1523 0:cd065c06ce89 33
bosko1523 0:cd065c06ce89 34 while(1) {
bosko1523 0:cd065c06ce89 35 display = counter;
bosko1523 0:cd065c06ce89 36 }
bosko1523 0:cd065c06ce89 37 }