Discussion in "PIC Microcontroller Discussion" started by    dspicmicro    Dec 21, 2013.
Sat Dec 21 2013, 04:43 pm
#1
I want to read n write internal flash ROM of PIC18F4520. Here is code for that...
void ROM_WRTT(void);
void ROM_READD(void);
void SerTx(unsigned char);
void main()
 {
  unsigned char RomString[11]="PIC18F4520";
  unsigned char x,ch;
 TRISD = 0;
 LCD_Init(&PORTD);
 LCD_Cmd(LCD_CLEAR);
 LCD_Cmd(LCD_CURSOR_OFF);
 LCD_Cmd(LCD_RETURN_HOME);
 LCD_Out(1,1,"hi");
 Delay_ms(100);
 LCD_Cmd(LCD_CLEAR);
  TXSTA=0x20;
  SPBRG=0x12;
  TXSTA.TXEN=1;
  RCSTA.SPEN=1;
  TBLPTR=0x50;
  for(x=0;x<11;x++)
   {
    TABLAT=RomString[x];
    ROM_WRTT();
    //SerTx(TABLAT);
    TBLPTR=TBLPTR+1;
    }
  EECON1.WREN=0;
  TBLPTR=0x50;
  for(x=0;x<11;x++)
  {
    ch= TABLAT;
    ROM_READD();
    SerTx(ch);
    Lcd_chr_cp(ch++);
    Delay_ms(100);
    TBLPTR=TBLPTR+1;
  }
  while(1);
}

void ROM_WRTT()
{
    EECON1.EEPGD=1;
    EECON1.CFGS=0;
    EECON1.WREN=1;
    INTCON.GIE=0;
    EECON2=0x55;
    EECON2=0xAA;
    EECON1.WR=1;
    Delay_ms(5);
    INTCON.GIE=1;
}
void ROM_READD()
{
    EECON1.EEPGD=1;
    EECON1.CFGS=0;
    EECON1.RD=1;
    INTCON.GIE=0;
    EECON2=0x55;
    EECON2=0xAA;
   Delay_ms(5);
    INTCON.GIE=1;
 }
void SerTx(unsigned char c)
{
    while(PIR1.TXIF==0);
    TXREG=c;
}


[ Edited Sat Dec 21 2013, 04:57 pm ]
Sat Dec 21 2013, 04:54 pm
#2
My problem is that i m ABLE to write inside flash ,but unable to read the data n send it on hyper-terminal.
Mon Dec 23 2013, 03:51 am
#3


My problem is that i m ABLE to write inside flash ,but unable to read the data n send it on hyper-terminal.

dspicmicro


just to avoid confusion.
Do you want to access the internal eeprom ?
Flash ROM is different.

How do you know you are able to write, if you can't read it back ?
Which compiler are you using, does it have built in eeprom access commands ?


[ Edited Mon Dec 23 2013, 03:58 am ]
Mon Dec 23 2013, 04:21 pm
#4
Thanks;
Actually sir i m accessing FLASH ROME not internal EEPROM. i had seen the discussion in chappter 14 in PIC microcontroller by Mazidi.where i seen the topic accessing the flash memory . and i was trying to accessing the internal flash memory throug c-programming.
I m using PIC18F4520 microcontroller .and compiler is mikro-c.

i am able to write data in side the flash ->
bcs through this programming
for(x=0;x<11;x++)
{
TABLAT=RomString[x];
ROM_WRTT();
SerTx(TABLAT); /******** i m sending data of TABLAT on serial port and i can see the masg there**************/
TBLPTR=TBLPTR+1;
}
is the data in TABLAT is not going to write on my define address?(is my consideration is wrong).
please describe me sir.


[ Edited Mon Dec 23 2013, 04:26 pm ]
Wed Dec 25 2013, 01:30 am
#5
I think C18 compiler from microchip provides routines for writing into Flash Memory. The things that you need to take care while writing to Flash is.. You can only write in bunch. as write buffer is of 64 bytes I think so you first need to fill up the buffer and then give assert write operation. Moreover ever write cycle should be preceded by a flash erase cycle coz its a Flash memory not EEPROM.

Open C18 installation folder and look for the code inside. You can directly call those routines from your source including "Flash.h" header file. Also look at C18 manual for more help on this.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am