8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes :: Forums :: Discuss and Learn :: PIC Microcontroller Discussion
 
<< Previous thread | Next thread >>
How to program EEPROM correctly? SAved but recall FAILED
Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
nicholastyc
Fri May 16 2008, 01:03AM
 User Offline
Registered Member #7707
Joined: Wed May 07 2008, 07:13PM

Posts: 38
Thanked 1 time in 1 posts
Hi,
Ajay, this is my last problem, i already solved the INput problems,
for pic12f629, to enable the GPIO 4,5 , you must configure the Internal Clock and other config, as below.
__CONFIG _CP_OFF & _MCLRE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _CPD_OFF &_PWRTE_OFF

This does not been told in the datasheet.

By the way, my new problem is i saved my data (0x01) into eeprom address 0x01, when i recall the data it does not recall the same data but something different from it and sometimes i can save the data and recall correctly but sometimes not.
What is the problem? is the setting or code problems? i already DOUBLExDouble check it in the DATASHEET for few hours and look for solutions on internet, i still cant recall correctly, PLEASe HELP.I write the data correctly...everytime, when i check in the EEDATA register b4 i reset the MPLAB SIM and rerun again.
Code Below, PIC12F629 ,
WRITE code from me,
CODE:
ORIGINAL_PWM EQU 0x21
TEMP EQU 0x22
WRITE:  BSF     STATUS,5; switch to bank 1
        MOVLW   0x01; go to addr 0x01
        MOVWF   EEADR;
        MOVF    ORIGINAL_PWM,w  ; (ORIGINAL_PWM = 0x01)
        MOVWF   EEDATA; write 0x01 to EEDATA
        BSF     EECON1,WREN; < follow the datasheet write process
        BCF     INTCON,GIE      ;<
        MOVLW   H'0055' ;<
        MOVWF   EECON2  ;<
        MOVLW   H'00AA'         ;<
        MOVWF   EECON2  ;<
        BSF     EECON1,WR       ;<
        BSF     INTCON,GIE      ;<
        BCF     STATUS,5; switch to bank 0
        RETURN

READ:   BSF     STATUS,5; switch to bank 1
        MOVLW   0x01; goto addr 0x01 in eeprom
        MOVWF   EEADR;
        BSF     EECON1,RD       ; read previously saved data 0x01
        MOVF    EEDATA,w        ; move 0x01 to w
        MOVWF   TEMP; (TEMP register ) move 0x01 to TEMP
        BCF     STATUS,5; switch bank 0
        RETURN



Thanks for your help....mmy last problem...



[ Edited Fri May 16 2008, 10:58PM ]
Back to top


Ajay
Fri May 16 2008, 11:06PM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3315
Thanked 611 times in 578 posts
after you set WR bit in EECON1 register you need to poll that bit till the writing is finished. Do not confuse writing in flash with writing to EEPROM.

When you write in flash, cpu stalls itself till writing is finished so no need to poll in that case, whereas in case of EEPROM, you need to poll the WR bit in EECON1 register. Try again..

use test bit instruction for checking WR bit. Please ask if you still feel any problem working on it.

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top



This post has been thanked 1 time
nicholastyc
Sun May 18 2008, 06:35PM
 User Offline
Registered Member #7707
Joined: Wed May 07 2008, 07:13PM

Posts: 38
Thanked 1 time in 1 posts
hi Ajay, wat is poll the WR bit means?
i m a newbie here...

please explain in asm or meaning of poll the WR bit..

thanks!!
Back to top


Ajay
Mon May 19 2008, 12:41AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3315
Thanked 611 times in 578 posts
polling means waiting...
it can be done something like this...

CODE:
wait:
        btfsc EECON1,WR //skip the next statement if the bit is cleared
        bra wait  //jump back and check again
        return  //return when bit is cleared.
 


www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


nicholastyc
Mon May 19 2008, 01:38AM
 User Offline
Registered Member #7707
Joined: Wed May 07 2008, 07:13PM

Posts: 38
Thanked 1 time in 1 posts
thank you very much Ajay...

i made a statement like this,

btfsc EECON1, WR;
goto $-1 ;

it looks fine... but the main problem still is the MPLAB SIM, when i simulate it in ANIMATION mode, its just keep looping...and u know wat, but i go to the RUN mode, everything just works fine and the EEPROM is saving the data n recall. Hope it will work fine in the PIC after i program it tomorrow, lets c how tomorrow. Thanks for your help.
Back to top


Ajay
Mon May 19 2008, 08:22PM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3315
Thanked 611 times in 578 posts
try using label instead of $-1

I hope it will work..

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems