Use EEPROM Memory
This example illustrates write and read from built-in EEPROM memory. The program works as follows. The main loop first reads EEPROM memory location at address 5. The program then enters an endless loop in which PORTB is incremented and the state of PORTA.2 input is checked. At the moment of pressing the push button marked MEMO, a number stored in PORTB will be saved in EEPROM at address 5 and directly read from it and shown on PORTD in binary format.'Header****************************************************** program example_8 ' Program name main: ' Start of program ANSEL = 0 ' All I/O pins are configured as digital ANSELH = 0 PORTB = 0 ' PORTB initial value TRISB = 0 ' All PORTB pins are configured as outputs PORTD = 0 ' PORTB initial value TRISD = 0 ' All PORTD pins are configured as outputs TRISA = 0xFF ' All PORTA pins are configured as inputs PORTD = EEPROM_Read(5) ' Read EEPROM memory at address 5 while 1 ' Endless loop PORTB = PORTB + 1 ' Increment PORTB by 1 Delay_ms(100) ' 100mS delay while not PORTA.B2 ' Remain in this loop as long as the button is pressed if not PORTA.B2 then EEPROM_Write(5,PORTB) ' If MEMO is pressed, save PORTB PORTD = EEPROM_Read(5) ' Read written data end if wend wend end. ' End of programIn order to make this example work properly, it is necessary to check the EEPROM library in the Library Manager prior to compiling: