Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] MikroC Reading/Writing string to EEPROM

Status
Not open for further replies.

anishpsla

Member level 2
Joined
Dec 15, 2013
Messages
44
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
402
Friends, this is my first post to the forum.


I need a help to read/write a string to EEPROM using MikroC. For example I want to write "ANISH VARGHEESE" to PIC's EEPROM and later I want to read it.
 

I just need the piece of code. Without the code, I can't start the project.
 

Or the MikroC Pro IDE Help System:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
char ii;                                 // loop variable
 
void main(){
  ANSEL =  0;                            // Configure AN pins as digital I/O
  ANSELH = 0;
  C1ON_bit = 0;                          // Disable comparators
  C2ON_bit = 0;
 
  PORTB = 0;
  PORTC = 0;
  PORTD = 0;
 
  TRISB = 0;
  TRISC = 0;
  TRISD = 0;
   
  for(ii = 0; ii < 32; ii++)             // Fill data buffer
    EEPROM_Write(0x80+ii, ii);           // Write data to address 0x80+ii
 
  EEPROM_Write(0x02,0xAA);               // Write some data at address 2
  EEPROM_Write(0x50,0x55);               // Write some data at address 0150
 
  Delay_ms(1000);                        // Blink PORTB and PORTC LEDs
  PORTB = 0xFF;                          //   to indicate reading start
  PORTC = 0xFF;
  Delay_ms(1000);
  PORTB = 0x00;
  PORTC = 0x00;
  Delay_ms(1000);
 
  PORTB = EEPROM_Read(0x02);             // Read data from address 2 and display it on PORTB
  PORTC = EEPROM_Read(0x50);             // Read data from address 0x50 and display it on PORTC
 
  Delay_ms(1000);
 
  for(ii = 0; ii < 32; ii++) {           // Read 32 bytes block from address 0x80
    PORTD = EEPROM_Read(0x80+ii);        //   and display data on PORTD
    Delay_ms(250);
    }
}




BigDog
 

I saw the example in IDE help. I want to read the data to a variable and use it for further processing.

I got plenty of examples for Writing/Reading numerical values into EEPROM.
 

I got plenty of examples for Writing/Reading numerical values into EEPROM.

The truth is, all data processed or stored by a microcontroller is numerical, binary in fact.

Only the interpretation/casting changes the way the binary number is perceived, processed, formatted, displayed, etc.

Characters are often encoded using the American Standard Code for Information Interchange (ASCII), which simply encodes the standard character set into corresponding numerical values.

'A' => 65d or 0x41
'B' => 66d or 0x42
...
...
...
'Y' => 89d or 0x59
'Z' => 90d or 0x5A

Hint: The encoding is typically sequential as are the numerical values.

BigDog
 
OK, Friends, thanks for the reply.

The data stored in EEPROM can be read as HEX digits. How can I get the word stored in an address position from the series of hex values ?

For example, I am storing "test" from address 00.

0X74 0x65 0x73 0x74 is what I will get when I read it from the address position. How can I get "test' from the sequence ?
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
EEPROM_Write(0x00, 't');
EEPROM_Write(0x01, 'e');
EEPROM_Write(0x02, 's');
EEPROM_Write(0x03, 't');
 
unsigned char myString[10];
             
myString[0] = EEPROM_Read(0x00);             
myString[1] = EEPROM_Read(0x01); 
myString[2] = EEPROM_Read(0x02); 
myString[3] = EEPROM_Read(0x03);
myString[4] = '\0';

 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top