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

PIC18F45K80 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
Madhu_k_r



Joined: 12 Jan 2016
Posts: 26
Location: Bengaluru

View user's profile Send private message

PIC18F45K80 internal eeprom problem
PostPosted: Tue Jan 12, 2016 6:45 am     Reply with quote

hi...
how to use internal memory in pic18f45k80 in order to write and read
for that do i need to set any fuse ???


Last edited by Madhu_k_r on Sat Jan 23, 2016 12:52 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Tue Jan 12, 2016 8:10 am     Reply with quote

No.

You have to make sure that the WRT write protection bits are off. and that code protection is not enabled.

You have to think in terms of pages (64bytes on these chips).
To write a location it must first be erased. A write to the first byte of a page, erases the page. So to change a byte in the middle of a page, you have to read the entire page, change the byte, and then write the whole page back. If you want to use this in a manner like EEPROM, there is a library 'virtual_eeprom.c', which does this.

Beware that the write life of the flash is smaller than the EEPROM. Only 1000 cycles guaranteed. Given that your chip has 1KB EEPROM, why use the flash?.
Madhu_k_r



Joined: 12 Jan 2016
Posts: 26
Location: Bengaluru

View user's profile Send private message

PostPosted: Wed Jan 13, 2016 1:12 am     Reply with quote

Sorry...
it's not internal memory, i meant internal EEPROM, so how to use internal EEPROM and my code looks like:
Code:

int8 value=0,value1=0;
int8 address=10;

void main()
{
delay_ms(10);
value1=read_eeprom(address);

while(1)
  {
   if(!input(pin_b0))
     {
      delay_ms(250);
      value++;
      write_eeprom(address,value);
      delay_ms(10);
     }
  }

}
 


and i am displaying value1 on lcd
and when i try to read the stored value, i.e value1, I am getting 64.
_________________
KaalaayaTasmaiNamah:
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Wed Jan 13, 2016 2:43 am     Reply with quote

First little thing, how large is the EEPROM on this chip?. int8 is not large enough for the address. The EEPROM is 1KB.

The data EEPROM can be read, even if code protection is enabled. WRTD is the only bit that will stop write access. You need NOWRTD.
Madhu_k_r



Joined: 12 Jan 2016
Posts: 26
Location: Bengaluru

View user's profile Send private message

PostPosted: Wed Jan 13, 2016 7:26 am     Reply with quote

Ttelmah wrote:
First little thing, how large is the EEPROM on this chip?. int8 is not large enough for the address. The EEPROM is 1KB.

The data EEPROM can be read, even if code protection is enabled. WRTD is the only bit that will stop write access. You need NOWRTD.



THANKS FOR YOUR REPLY Ttelmah

i tried with even changing these stuff but still not working
these are the valid fuses what i have used
Code:

#include <18F45K80.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES VREGSLEEP             
#FUSES INTRC_HP             
//#FUSES SOSC_HIGH             
//#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES HSH                   
#FUSES NOPLLEN               
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV18               
#FUSES ZPBORM               
#FUSES WDT_NOSLEEP           
#FUSES WDT1048576           
#FUSES CANB                 
#FUSES MSSPMSK7             
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOSTVREN                 //Stack full/underflow will not cause reset
#FUSES BBSIZ2K                  //2K words Boot Block size
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES PROTECT                  //Code not protected from reading
#FUSES NOCPB                    //No Boot Block code protection
#FUSES CPD                      // EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTD                     //Data EEPROM not write protected

#device adc=12
//#device const=ROM
#use delay(clock=16000000)

and my full code is

#include <main.h>
#include "lcd4bit.c"
int8 b=0,a=0;
int8  i=0;
void main()
{

   delay_ms(200);
   lcd_init();
   lcd_display(0x80);
   printf(lcd_data,"hi");
   delay_ms(200);
   b=read_eeprom(50);
   delay_ms(10);
   
  while(1)
  {
 
  lcd_display(0xc0);
  printf(lcd_data,"%d",b);
  if(!input(pin_B0))
   {
    delay_ms(450);
    a++;
    lcd_display(0xc6);
    printf(lcd_data,"%d",a);
    write_eeprom(50,a);
    delay_ms(10);       
   }
   
  }

}

_________________
KaalaayaTasmaiNamah:
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Wed Jan 13, 2016 8:50 am     Reply with quote

Comment.
Writing to the EEPROM every half second, will kill the chip in under 5 days.
Though the EEPROM life is much better than the flash, it is still limited. It is designed for things like configuration parameters that change 'occasionally', not for counts. If you want a count like this, keep it in RAM, and only write it to the EEPROM at the moment the power fails (this is done by using an interrupt on power fail, and having sufficient capacitance to maintain the supply long enough to perform the write).

You should not be getting 64. The EEPROM on the first pass will contain 0xFF (256). The code as posted - removing the LCD stuff and just sending the output to a serial, works.
However do you really want to read protect what is in the EEPROM?. (CPD).

Currently you have lots of protection bits set, but in fact the system is not protected at all.... You have the bootloader _unprotected_ from writes, so anyone wanting to read the chip could just write their own bootloader into it, and then read everything else in memory. If you are trying to protect code using a bootloader, the first thing to protect is the bootloader. Start with the protection all off. Get the code working. Then work out what the bits do, and enable the ones that actually protect what you want.

You also have the watchdog enabled, and are never resetting it....
Madhu_k_r



Joined: 12 Jan 2016
Posts: 26
Location: Bengaluru

View user's profile Send private message

PostPosted: Sun Jan 17, 2016 11:47 pm     Reply with quote

But if i try to write to internal eprom then I am getting a warning like this
HIGH/LOW voltage detection is not modelled, writing to HLVDCON/LVDCON just stores the data in the register.
So i couldn't encounter the problem so what might be the problem..?
expecting some help Idea
_________________
KaalaayaTasmaiNamah:
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Mon Jan 18, 2016 2:18 am     Reply with quote

Look at the second sticky at the top of the forum.

This is a Proteus problem.

Their DRC for the chip is wrong.
Madhu_k_r



Joined: 12 Jan 2016
Posts: 26
Location: Bengaluru

View user's profile Send private message

PostPosted: Mon Jan 18, 2016 3:44 am     Reply with quote

Ttelmah wrote:
Look at the second sticky at the top of the forum.

This is a Proteus problem.

Their DRC for the chip is wrong.

thank you Ttelmah
yeah..but i tried with development board still it is not writing to the addressed location any idea about this ???
_________________
KaalaayaTasmaiNamah:
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Mon Jan 18, 2016 4:30 am     Reply with quote

CPD.....
Madhu_k_r



Joined: 12 Jan 2016
Posts: 26
Location: Bengaluru

View user's profile Send private message

PostPosted: Sat Jan 23, 2016 12:46 am     Reply with quote

i tried with even CPD but still no improvements Embarassed and same thing is happening even with 18f65k22 Confused
_________________
KaalaayaTasmaiNamah:
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Sat Jan 23, 2016 2:30 am     Reply with quote

Sort out your fuses first, and check the chip is actually running, and at the right speed.

You have several 'dubious' fuses. Two different master oscillators both selected, STVREN turned off (this should always be enabled, unless you are adding stack checking code to your program). NOXINST removed (this is _required_ by the compiler. Two different watchdog divisions both selected. A bootblock enabled, though there is no sign you are using a bootloader.

You have never told us your compiler version that I can see?. The read and write functions work on this chip with the current versions, but did have problems a while ago. So how old is your compiler?.
Madhu_k_r



Joined: 12 Jan 2016
Posts: 26
Location: Bengaluru

View user's profile Send private message

PostPosted: Mon Jan 25, 2016 3:35 am     Reply with quote

Ttelmah wrote:
Sort out your fuses first, and check the chip is actually running, and at the right speed.

You have several 'dubious' fuses. Two different master oscillators both selected, STVREN turned off (this should always be enabled, unless you are adding stack checking code to your program). NOXINST removed (this is _required_ by the compiler. Two different watchdog divisions both selected. A bootblock enabled, though there is no sign you are using a bootloader.

You have never told us your compiler version that I can see?. The read and write functions work on this chip with the current versions, but did have problems a while ago. So how old is your compiler?.



am using 4.114
_________________
KaalaayaTasmaiNamah:
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Mon Jan 25, 2016 4:48 am     Reply with quote

Ooh!. That is old. About December 2010. That was just about the first compiler to feature that chip (I think it was about October they added these chips). Not surprising it doesn't work. You'd have to go DIY on the access code for a compiler this old. I've posted similar routines here before for some chips with problems.
Madhu_k_r



Joined: 12 Jan 2016
Posts: 26
Location: Bengaluru

View user's profile Send private message

PostPosted: Wed Jan 27, 2016 2:51 am     Reply with quote

Thank you Ttelmah ,,
i have changed my compiler version to 5.008 and it's working now thanks for your help
_________________
KaalaayaTasmaiNamah:
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