Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Writing to EEPROM

Status
Not open for further replies.

skeeterb

Member
I need help with a bit of code. I use flowcode V4 Demo version and it doesn't generate the code to Read and Write data to and from the EEPROM of a PIC. I need a little help with the little bit of code that I can replace that bit so I can read and write the EEPROM

Code:
//EEPROM0: //Macro implementations


char FCD_EEPROM0_EEPROMRead(short addr)
{
    //This licence of FlowCode does not produce code for this component
    #pragma message EEPROM0: This licence of FlowCode does not produce code for this component
    return (0);
}

void FCD_EEPROM0_WriteEEPROM(short addr, char data)
{
}
 
I believe flowcode generates BoostC code and so here are my BoostC EEPROM routines.

Mike.
Code:
unsigned char ReadEEPROM(unsigned char address){
    eecon1=0;                   //ensure CFGS=0 and EEPGD=0 
    eeadr = address;            //setup address
    eecon1.RD = 1;              //do actual read
    return(eedata);             //and return data
}

void WriteEEPROM(unsigned char address,unsigned char data){
char SaveInt;
    SaveInt=intcon;             //save interrupt status
    eecon1=0;                   //ensure CFGS=0 and EEPGD=0
    eecon1.WREN = 1;            //enable write to EEPROM
    eeadr = address;            //setup Address
    eedata = data;              //and data
    intcon.GIE=0;               //No interrupts
    eecon2 = 0x55;              //required sequence #1
    eecon2 = 0xaa;              //#2
    eecon1.WR = 1;              //#3 = actual write
    intcon=SaveInt;             //restore interrupts
    while(!pir2.EEIF);          //wait until finished
    eecon1.WREN = 0;            //disable write to EEPROM
}
 
I'm not frustrated just a little annoyed. I just needed that little bit of info so I can put information into the EEPROM memory of the chip.
 
Are my post invisible or something?

Mike.

Sorry Pommie thanks for your assistance. I noticed the newer reply before I noticed yours. I probably have to tweak the top of the code for reading and writing so it will fit in with the code generated by flowcode. I'm glad I have sourceboost IDE installed along with Flowcode.
 
Ok now i am getting frustrated. using sourceboost to attempt to build the hex file. It gave me a ton of errors like Unknown Identifier, and Unknown Operand for almost the WHOLE file. I'm attaching a copy of my source code to see if anyone else can figure out wtf is going on with my code.
 

Attachments

  • Control..c
    23.2 KB · Views: 231
The only errors I get are,

C:\Projects\BoostC\Flowcode.c(516:10): error: unknown identifier 'address'
C:\Projects\BoostC\Flowcode.c(516:10): error: invalid operand 'address'
C:\Projects\BoostC\Flowcode.c(516:8): error: failed to generate expression
C:\Projects\BoostC\Flowcode.c(528:10): error: unknown identifier 'address'
C:\Projects\BoostC\Flowcode.c(528:10): error: invalid operand 'address'
C:\Projects\BoostC\Flowcode.c(528:8): error: failed to generate expression

And these are caused by a mismatch in the routines I posted.
Code:
char FCD_EEPROM0_EEPROMRead(short [COLOR="red"]addr[/COLOR])
{
    eecon1=0;                   //ensure CFGS=0 and EEPGD=0 
    eeadr = [COLOR="red"]address[/COLOR];            //setup address
    eecon1.RD = 1;              //do actual read
    return(eedata);             //and return data
    
}

void FCD_EEPROM0_WriteEEPROM(short [COLOR="red"]addr[/COLOR], char data)
{
char SaveInt;
    SaveInt=intcon;             //save interrupt status
    eecon1=0;                   //ensure CFGS=0 and EEPGD=0
    eecon1.WREN = 1;            //enable write to EEPROM
    eeadr = [COLOR="red"]address[/COLOR];            //setup Address
    eedata = data;              //and data
    intcon.GIE=0;               //No interrupts
    eecon2 = 0x55;              //required sequence #1
    eecon2 = 0xaa;              //#2
    eecon1.WR = 1;              //#3 = actual write
    intcon=SaveInt;             //restore interrupts
    while(!pir2.EEIF);          //wait until finished
    eecon1.WREN = 0;            //disable write to EEPROM
    
}

The bits in red have to match so change them all to either addr or address.

Mike.
 
The only errors I get are,

C:\Projects\BoostC\Flowcode.c(516:10): error: unknown identifier 'address'
C:\Projects\BoostC\Flowcode.c(516:10): error: invalid operand 'address'
C:\Projects\BoostC\Flowcode.c(516:8): error: failed to generate expression
C:\Projects\BoostC\Flowcode.c(528:10): error: unknown identifier 'address'
C:\Projects\BoostC\Flowcode.c(528:10): error: invalid operand 'address'
C:\Projects\BoostC\Flowcode.c(528:8): error: failed to generate expression

And these are caused by a mismatch in the routines I posted.
Code:
char FCD_EEPROM0_EEPROMRead(short [COLOR=red]addr[/COLOR])
{
    eecon1=0;                   //ensure CFGS=0 and EEPGD=0 
    eeadr = [COLOR=red]address[/COLOR];            //setup address
    eecon1.RD = 1;              //do actual read
    return(eedata);             //and return data
    
}

void FCD_EEPROM0_WriteEEPROM(short [COLOR=red]addr[/COLOR], char data)
{
char SaveInt;
    SaveInt=intcon;             //save interrupt status
    eecon1=0;                   //ensure CFGS=0 and EEPGD=0
    eecon1.WREN = 1;            //enable write to EEPROM
    eeadr = [COLOR=red]address[/COLOR];            //setup Address
    eedata = data;              //and data
    intcon.GIE=0;               //No interrupts
    eecon2 = 0x55;              //required sequence #1
    eecon2 = 0xaa;              //#2
    eecon1.WR = 1;              //#3 = actual write
    intcon=SaveInt;             //restore interrupts
    while(!pir2.EEIF);          //wait until finished
    eecon1.WREN = 0;            //disable write to EEPROM
    
}
The bits in red have to match so change them all to either addr or address.

Mike.

I corrected that. I noticed it and fixed it before you made your post. Now I'm getting a bunch of errors like

Warning: Conversion from 'int32' to 'signed int' possible loss of data
Warning: Expression is True
Warning: Conversion from 'signed short' to 'unsigned char' possible loss of data

The first one tracks back to the internals.h file. the others track to the Source file "Control.C"
 
Well, you can probably get rid of some by changing it to,
Code:
char FCD_EEPROM0_EEPROMRead([COLOR="red"]char[/COLOR] addr)
{
    eecon1=0;                   //ensure CFGS=0 and EEPGD=0 
    eeadr = address;            //setup address
    eecon1.RD = 1;              //do actual read
    return(eedata);             //and return data
    
}

void FCD_EEPROM0_WriteEEPROM([COLOR="red"]char [/COLOR]addr, char data)
{
char SaveInt;
    SaveInt=intcon;             //save interrupt status
    eecon1=0;                   //ensure CFGS=0 and EEPGD=0
    eecon1.WREN = 1;            //enable write to EEPROM
    eeadr = address;            //setup Address
    eedata = data;              //and data
    intcon.GIE=0;               //No interrupts
    eecon2 = 0x55;              //required sequence #1
    eecon2 = 0xaa;              //#2
    eecon1.WR = 1;              //#3 = actual write
    intcon=SaveInt;             //restore interrupts
    while(!pir2.EEIF);          //wait until finished
    eecon1.WREN = 0;            //disable write to EEPROM
    
}

Mike.
 
Well, you can probably get rid of some by changing it to,
Mike.

It's not just that subroutine that gives me the errors. the first error points back to the Internals.h file that I copied from the FCD subdirectory of flowcode. I'm attaching a file I made to show all the errors that it shows in sourceboost ide.
 

Attachments

  • Errors..txt
    13.8 KB · Views: 200
OK, I loaded it up in MPLAB IDE. I found out one of the reasons it was failing. I failed to copy the definitions.h file when I copied the internal.h file to where my source code is. Now it gives me these errors

Error [196] d:\Downloads\miscellaneous\Electronic Files\Control.c; 517.11 struct/union required
Error [196] d:\Downloads\miscellaneous\Electronic Files\Control.c; 527.13 struct/union required
Error [196] d:\Downloads\miscellaneous\Electronic Files\Control.c; 530.11 struct/union required
Error [196] d:\Downloads\miscellaneous\Electronic Files\Control.c; 533.11 struct/union required
Error [196] d:\Downloads\miscellaneous\Electronic Files\Control.c; 535.17 struct/union required
Error [196] d:\Downloads\miscellaneous\Electronic Files\Control.c; 536.13 struct/union required

I tracked it down to the code that Pommie posted initially. Is there any changes I can make to the code so it will compile using MPLAB?

Here are the lines of code it points to.

Code:
Line 517
eecon1.RD = 1;              //do actual read
Line 527
eecon1.WREN = 1;            //enable write to EEPROM
Line 530
intcon.GIE=0;               //No interrupts
Line 533
eecon1.WR = 1;              //#3 = actual write
Line 535
while(!pir2.EEIF);          //wait until finished
Line 536
eecon1.WREN = 0;            //disable write to EEPROM

What do I need to change?????
 
You need to go back to the version that compiled but with the code missing and then add the code. I don't use flow code so can't advise how to get it working.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top