Storing user input string array to EEPROM – PIC – electroSome https://electrosome.com/topic/storing-input-string-array-eeprom-pic/feed/ Sat, 18 Mar 2023 04:59:57 +0000 https://bbpress.org/?v=2.6.9 en-US https://electrosome.com/topic/storing-input-string-array-eeprom-pic/#post-12904 <![CDATA[Storing user input string array to EEPROM – PIC]]> https://electrosome.com/topic/storing-input-string-array-eeprom-pic/#post-12904 Fri, 12 Aug 2016 04:55:19 +0000 mishras1132 Hello everyone,

I am trying to write a code to store user input string into an array using simple 4 push buttons and then writing it in internal EEPROM of pic16f877a micro-controller. The string is stored in an array but unable to write into EEPROM.  So can anyone please help me on this issue, below is my code:

#include "INCLUDE.h"
__CONFIG(FOSC_HS & WDTE_OFF & PWRTE_OFF & BOREN_ON & LVP_OFF & CPD_OFF & WRT_OFF & CP_ON);
__EEPROM_DATA('W','E','L','C','O','M','E',' '); // Initial string character for 1st time programming.
__EEPROM_DATA('E','E','P','R','O','M',' ',' '); // String array to store 3 digit access code
char message4[] = "WRITE COMPLETED";
char message5[] = "Reading Data";
char message7[] = "Welcome EEPROM";
char Edata[] = "0000000000000000";
unsigned short  k, NUM ;
unsigned int ADD; // Start EEPROM Location
char temp, cursor;
void main (void)
{
  TRISC   = 0x20;        //PORTC as output
  TRISD   = 0x08;        //PORTD as output
  TRISB   = 0b01000000;  //IR SENSOR INPUT ON RB6
  TRISB7  = 0;
  POWER_LED = 0;
  PORTA   = 0;
  PORTC   = 0;
  PORTD   = 0;
  InitLCD();
  InitADC();
  lcd_gotoxy(0,3);
  WriteStringToLCD("Testing");
  lcd_gotoxy(1,0);
  WriteStringToLCD("internal EEPROM");
  __delay_ms(1000);
  ClearLCDScreen();
  lcd_gotoxy(0,3);
  WriteStringToLCD("ENTER TEXT");
  do
  {
    // Read operation
    if(POWER == 1)
    {
      __delay_ms(400);
      ClearLCDScreen();
      lcd_gotoxy(0,2);
      WriteStringToLCD(message5);
      ADD = 0;
      for (k = 0; k < 16; k++)
      {
        temp = eeprom_read(ADD+k);
        Edata[k] = temp;
      }
      lcd_gotoxy(1,0);
      WriteStringToLCD(Edata);
      __delay_ms(2000);
    }
    // Cursor increment Operation
    if (ENTER == 1)
    {
      __delay_ms(400);
      k = k + 1;
      cursor = cursor + 1;
    }
    // Read & Write Operation
    if (BACK == 1)
    {
      // Write operation
      __delay_ms(400);
      ADD = 0;
      for (k = 0; k < 16; k++)
      {
        temp = message7[k];
        eeprom_write(ADD+k,temp);
      }
      ClearLCDScreen();
      lcd_gotoxy(0,1);
      WriteStringToLCD(message4);
      __delay_ms(1000);
    }
    // Increment character string
    if (UP == 1)
    {
      __delay_ms(400);
      message7[k] = message7[k]+1;
      if(message7[k] > 'Z')
        message7[k] = 'A';
      else if(message7[k] < 'A')
        message7[k] = 'Z';
      lcd_gotoxy(1,cursor);
      WriteDataToLCD(message7[k]);
      message7[ADD] = message7[k];
    }
    // Decrement character string
    if (DOWN == 1)
    {
      __delay_ms(400);
      message7[k] = message7[k]-1;
      if(message7[k] > 'Z')
        message7[k] = 'A';
      else if(message7[k] < 'A')
        message7[k] = 'Z';
      lcd_gotoxy(1,cursor);
      WriteDataToLCD(message7[k]);
      message7[ADD] = message7[k];
    }
  }while(1);
}
]]>
https://electrosome.com/topic/storing-input-string-array-eeprom-pic/#post-12908 <![CDATA[Reply To: Storing user input string array to EEPROM – PIC]]> https://electrosome.com/topic/storing-input-string-array-eeprom-pic/#post-12908 Mon, 15 Aug 2016 04:45:03 +0000 Ligo George Hi,

Logic of your program is not so clear from the above codes. I recommend following.

  1. Verify that EEPROM read write functions are working correctly by writing and reading a single character.
  2. Write  and read string by character by character. Put some small delay after each character operation.
]]>