CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

18F4620 internal eeprom problem.
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hobiadami



Joined: 17 Oct 2006
Posts: 35
Location: City of Concrete

View user's profile Send private message Visit poster's website ICQ Number

18F4620 internal eeprom problem.
PostPosted: Fri Feb 12, 2010 4:02 pm     Reply with quote

Hi all,

The Microchip datasheet says the 18F4620 has got 1024 bytes of eeprom.

But my program seems to overwrite the data from the start when the address given in write_eeprom() exceeds 0xFF. So I can only use 256 bytes of eeprom of my pic18f4620.

I've written a simple sample code for testing.

The code writes to address 0 first and checks it to verify.

Then writes to address 0x100 and again checks it to verify.

Then it reads and displays the data written at address 0 again.

and the data in address 0 is overwritten with the data that should be in 0x100.

The serial port output is like this:

EEPROM TEST 1
OK
value in address 0 is 123
EEPROM TEST 2
OK
value in address 0 is 56

What should I do to use the entire 1kbyte eeprom range of the pic 18f4620?

Thanks in advance.
Code:

#include <18F4620.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,NOLVP
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

void main() {
   
      printf("EEPROM TEST 1\r\n");             
         
      write_eeprom( 0 , 123 );
      if ( read_eeprom( 0 ) == 123  ) printf("OK\r\n");
      else printf("FAILED\r\n");
     
      printf("value in address 0 is %u\r\n", read_eeprom( 0 ));

      printf("EEPROM TEST 2\r\n");         
     
      write_eeprom( 0x100 , 56 );
      if ( read_eeprom( 0x100 ) == 56  ) printf("OK\r\n");
      else printf("FAILED\r\n");
     
      printf("value in address 0 is %u\r\n", read_eeprom( 0 ));

   while(TRUE); // wait for a reset
}

_________________
www.endtas.com
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 12, 2010 4:27 pm     Reply with quote

Post your compiler version.
hobiadami



Joined: 17 Oct 2006
Posts: 35
Location: City of Concrete

View user's profile Send private message Visit poster's website ICQ Number

PostPosted: Fri Feb 12, 2010 4:40 pm     Reply with quote

it is 4.084
_________________
www.endtas.com
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 12, 2010 5:21 pm     Reply with quote

It worked for me. I installed an 18F4620 on a PicDem2-Plus board
and I installed PCH vs. 4.084, and ran it, and I got this result:
Quote:

EEPROM TEST 1
OK
value in address 0 is 123
EEPROM TEST 2
OK
value in address 0 is 123


Are you doing this test in real hardware or are you running Proteus ?
hobiadami



Joined: 17 Oct 2006
Posts: 35
Location: City of Concrete

View user's profile Send private message Visit poster's website ICQ Number

PostPosted: Fri Feb 12, 2010 5:33 pm     Reply with quote

Sorry to take your time, I tried on a real pic and it worked. At first trial, it was on proteus.
_________________
www.endtas.com
hobiadami



Joined: 17 Oct 2006
Posts: 35
Location: City of Concrete

View user's profile Send private message Visit poster's website ICQ Number

PostPosted: Sat Feb 13, 2010 2:56 am     Reply with quote

Hello again, I've now written a small code to produce a table for saving the users of a specific device that is powered by this pic18F4620.

Every row the table consists of 5 bytes for identity card data, 10 bytes for name, and 4 bytes for password.

Sending 'u' on the serial port makes the program list saved users on the same serial port. there are 6 first users embedded in the code.

Sending 'c' makes the device add one more user to the table.

It adds users without problems until user 10.

It adds user 10 with a spoiled password then the following users with completely corrupt data.

What am I doing wrong?
Code:

#include <18F4620.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,NOLVP
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, STREAM=MODEM)

#rom int8 0xf00000={1}  // MODE
#rom int8 0xf00001={25}  // SET1
#rom int8 0xf00002={22}  // SET2
#rom int8 0xf00005={6}  // # of saved users

               //  5  byte identity card no      |          10 byte name record          |       4-6 chr password

#rom int8 0xf0003A={ 0x1C,0x00,0x40,0xD8,0xF4,    'H','a','k','k','i',' ',' ','B','e','y',         1,1,1,1 }
#rom int8 0xf0004D={ 0x1C,0x00,0x40,0xC8,0x00,    'T','e','k','n','i','s','y','e','n','2',         2,2,2,2 }
#rom int8 0xf00060={ 0x1C,0x00,0x40,0xC8,0x4B,    'T','e','k','n','i','s','y','e','n','3',         3,3,3,3 }

#rom int8 0xf00073={   14,   0,  42, 181,  64,    'Z','a','f','t','r','a',' ','t','a','n',         4,4,4,4 }
#rom int8 0xf00086={  160,   0,   3, 227, 225,    'M','u','s','t','a','f','a','B','e','y',         5,5,5,5 }
#rom int8 0xf00099={   11,   0,   3,   7,  61,    'A','l','u','v',' ','y','o','t','a','n',         6,6,6,6 }

///////////////////////////////////
void kulist(){

int sayma;

   for (sayma = 0 ; sayma < read_eeprom(5) ; sayma++ ) {
      fprintf( MODEM , "Person:%02u  Card:%03u %03u %03u %03u %03u  ",sayma,  read_eeprom( 0x3A + sayma * 19 ),read_eeprom( 0x3B + sayma * 19 ),read_eeprom( 0x3C + sayma * 19 ),read_eeprom( 0x3D + sayma * 19 ),read_eeprom( 0x3E + sayma * 19 ) );

      fprintf( MODEM , "Name:%c%c%c%c%c%c%c%c%c%c  ", read_eeprom( 0x3F + sayma * 19 ),read_eeprom( 0x40 + sayma * 19 ),read_eeprom( 0x41 + sayma * 19 ),read_eeprom( 0x42 + sayma * 19 ),read_eeprom( 0x43 + sayma * 19 ),read_eeprom( 0x44 + sayma * 19 ),read_eeprom( 0x45 + sayma * 19 ),read_eeprom( 0x46 + sayma * 19 ),read_eeprom( 0x47 + sayma * 19 ),read_eeprom( 0x48 + sayma * 19 ) );

      fprintf( MODEM , "Pass:%1u%1u%1u%1u\n\r", read_eeprom( 0x49 + sayma * 19 ),read_eeprom( 0x4A + sayma * 19 ),read_eeprom( 0x4B + sayma * 19 ),read_eeprom( 0x4C + sayma * 19 ) );
   }
}

//------------------------------------------------------
void kulyap(){

int sayma;

sayma = read_eeprom(5);
sayma++;
write_eeprom(5, sayma);
sayma--;

write_eeprom((int16) sayma*19 + 0x3A, 0);
write_eeprom((int16) sayma*19 + 0x3B, 0);
write_eeprom((int16) sayma*19 + 0x3C, 0);
write_eeprom((int16) sayma*19 + 0x3D, 0);
write_eeprom((int16) sayma*19 + 0x3E, 0);

write_eeprom((int16) sayma*19 + 0x3F, '-');
write_eeprom((int16) sayma*19 + 0x40, '-');
write_eeprom((int16) sayma*19 + 0x41, '-');
write_eeprom((int16) sayma*19 + 0x42, '-');
write_eeprom((int16) sayma*19 + 0x43, '-');
write_eeprom((int16) sayma*19 + 0x44, '-');
write_eeprom((int16) sayma*19 + 0x45, '-');
write_eeprom((int16) sayma*19 + 0x46, '-');
write_eeprom((int16) sayma*19 + 0x47, '-');
write_eeprom((int16) sayma*19 + 0x48, '-');

write_eeprom((int16) sayma*19 + 0x49, 0);
write_eeprom((int16) sayma*19 + 0x4A, 0);
write_eeprom((int16) sayma*19 + 0x4B, 0);
write_eeprom((int16) sayma*19 + 0x4C, 0);

kulist();
}

//------------------------------------------------------
void main() {

int komut;

while(TRUE){
   if( kbhit(MODEM))  {
      komut = getc(MODEM);
      fprintf( MODEM , "Command : %c\n\r" , komut );
     
      if ( komut == 'u' )  kulist();   // List users
     
      if ( komut == 'c' )  kulyap();  // Create new user
   }
}

}
hobiadami



Joined: 17 Oct 2006
Posts: 35
Location: City of Concrete

View user's profile Send private message Visit poster's website ICQ Number

PostPosted: Sat Feb 13, 2010 3:08 am     Reply with quote

I've got an ICD-U64 but I can not use it as a debugger, I only use it as an in-circuit serial programmer.

When I enable the debugger on the ide's debug menu, it connects and loads etc, and at the bottom of the debug window it says 'Ready MCU, 1Mhz.

But the pic18f4620 should be running at 8mhz. Though it runs slower than written in the #use delay(clock=8000000) line, it can not communicate with the other chips on the board, RTC, exEE, LCD screen, serial ports etc.

How can I fix this and enable the debugger run my pic with the correct oscillator freq?
_________________
www.endtas.com
hobiadami



Joined: 17 Oct 2006
Posts: 35
Location: City of Concrete

View user's profile Send private message Visit poster's website ICQ Number

ICD
PostPosted: Sun Feb 14, 2010 3:49 am     Reply with quote

After fixing the cable between the ICD unit and my circuit board, the ICD started working, thanks god.

The white plastic telephone connector on the unit is not good, it is the same for both ICD units at my hand. when I insert the connector in a normal way until I hear the click, unit doesnt work. But if I wrap a rubber o-ring around the unit which more firmly presses the connector in, then the units start working.

The MCU oscillator speed shown in the debugger is still 1mhz and the debugging is very very slow.

the lines in the code which send a stream of data to the pc for example, each character take around 5 seconds to be sent. this makes debugging very difficult and time consuming.

any suggestions?
_________________
www.endtas.com
hobiadami



Joined: 17 Oct 2006
Posts: 35
Location: City of Concrete

View user's profile Send private message Visit poster's website ICQ Number

SOLVED
PostPosted: Sun Feb 14, 2010 6:48 am     Reply with quote

Thanks guys,
It had been because of using 8 bit addresses for write_eeprom statements. Now all is working fine.
_________________
www.endtas.com
the_dalga



Joined: 27 Jun 2012
Posts: 5

View user's profile Send private message

PIC18F4620 And Proteus
PostPosted: Sun Aug 05, 2012 2:24 am     Reply with quote

It doesn't works on Proteus.
But in real pic it is okay.
İs there anybody now how to simulate it in Proteus (higher eeprom address 255 for pic18f4620) ?
dyeatman



Joined: 06 Sep 2003
Posts: 1932
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Aug 05, 2012 9:14 am     Reply with quote

Your question does not belong here. This is not a Proteus forum.
Go try your question in the Proteus forum....
_________________
Google and Forum Search are some of your best tools!!!!
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Mon Aug 06, 2012 6:34 am     Reply with quote

Quote:
It doesn't works on proteus.
But in real pic it is okay.
İs there anybody now how to smulate it in proteus (higher eeprom address 255 for pic18f4620)

You've answered your own question.

It works on real hardware.

So, why waste time working with Proteus?

Nobody here will help you with Proteus, it's so full of bugs. Throw it away.

Mmike
the_dalga



Joined: 27 Jun 2012
Posts: 5

View user's profile Send private message

PostPosted: Tue Aug 07, 2012 3:43 pm     Reply with quote

Mike Walne wrote:
Quote:
It doesn't works on proteus.
But in real pic it is okay.
İs there anybody now how to smulate it in proteus (higher eeprom address 255 for pic18f4620)

You've answered your own question.

It works on real hardware.

So, why waste time working with Proteus?

Nobody here will help you with Proteus, it's so full of bugs. Throw it away.

Mmike


Mike I have no debug card so I need for debugging. I apply your opinion. Proteus have so many bugs.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

Debugging
PostPosted: Tue Aug 07, 2012 4:40 pm     Reply with quote

At the risk of having my knuckles rapped again, you can simulate most functions with MPLAB SIM.

It has the advantage of being free, it's not perfect, but gives reasonable results.

Mike
temtronic



Joined: 01 Jul 2010
Posts: 9204
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Aug 07, 2012 6:31 pm     Reply with quote

and if all the 'simulators' still fail...
use the tried and true method, squared paper,the listing and a pencil.
'play PIC' and single step your program line by line.
Yes, it's slow..until you've done it a few times
Yes, it's NOT hitech...
Yes, it's an 'old school' approach
YES, it does work 100% of the time.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group