nicholastyc
May 16 2008, 1:03 AM
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,
Thanks for your help....mmy last problem...
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
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...
Ajay
May 16 2008, 11:06 PM
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.
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.
nicholastyc
May 18 2008, 6:35 PM
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!!
i m a newbie here...
please explain in asm or meaning of poll the WR bit..
thanks!!
Ajay
May 19 2008, 12:41 AM
polling means waiting...
it can be done something like this...
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.
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.
nicholastyc
May 19 2008, 1:38 AM
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.
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.
Ajay
May 19 2008, 8:22 PM
try using label instead of $-1
I hope it will work..
I hope it will work..