Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

EEPROM of PIC16F887..

Status
Not open for further replies.

asp1987

New Member
Hi everyone..

In the following code for 16F887,
Code:
bcf INTCON,GIE

movfw number
call Send

BANKSEL EEADR ;
movlw DATA_EE_ADDR ;
movwf 0x00 ;Data Memory Address to write
movlw DATA_EE_DATA ;
movwf EEDAT ;Data Memory Value to write
BANKSEL EECON1 ;
bcf EECON1, EEPGD ;Point to DATA memory
bsf EECON1, WREN ;Enable writes
bcf INTCON, GIE ;Disable INTs.
btfsc INTCON, GIE ;SEE AN576
goto $-2
movlw 0x55 ;
movwf EECON2 ;Write 55h
movlw 0xAA ;
movwf EECON2 ;Write AAh
bsf EECON1, WR ;Set WR bit to begin write
bsf INTCON, GIE ;Enable INTs.
write_complete_check
btfsc EECON1,WR
goto write_complete_check
bcf EECON1, WREN ;Disable writes
;*********************
Send
 movwf	TXREG
 bsf STATUS,RP0   ; ROUTINE RESPONSIBLE FOR TRANSMISSION
Wait
 btfss TXSTA,TRMT 
 goto Wait
 bcf STATUS,RP0
 return

I replaced 'MOVLW DATA_EE_DATA' with 'movfw number'. I get a constant value for 'number' using Send routine. On reading the eeprom,the value stored is different. How is that possible?

The application uses a pic-mobile phone interface to control devices through sms. The pic first searches a specific location in the phone-book,saves the number to eeprom (PROBLEM) and then uses this number for further communication. Since the number is not known beforehand, we can't use 'movlw' instruction there..

Pls help..
 
Last edited:
Hi...
I'm sorry.. This is what I intended to post.. My friends said the code doesn't seem to have any problem. They too are perplexed with whats happening.
Code:
bcf INTCON,GIE

movfw number
call Send

BANKSEL EEADR ;
movlw 0x00 ;
movwf EEADR ;Data Memory Address to write
movlw DATA_EE_DATA ;
movwf EEDAT ;Data Memory Value to write
BANKSEL EECON1 ;
bcf EECON1, EEPGD ;Point to DATA memory
bsf EECON1, WREN ;Enable writes
bcf INTCON, GIE ;Disable INTs.
btfsc INTCON, GIE ;SEE AN576
goto $-2
movlw 0x55 ;
movwf EECON2 ;Write 55h
movlw 0xAA ;
movwf EECON2 ;Write AAh
bsf EECON1, WR ;Set WR bit to begin write
bsf INTCON, GIE ;Enable INTs.
write_complete_check
btfsc EECON1,WR
goto write_complete_check
bcf EECON1, WREN ;Disable writes
;*********************
Send
 movwf	TXREG
 bsf STATUS,RP0   ; ROUTINE RESPONSIBLE FOR TRANSMISSION
Wait
 btfss TXSTA,TRMT 
 goto Wait
 bcf STATUS,RP0
 return

Thank you.. We are doing it as a part of our 3rd year project.

Pls help..
 
Last edited:
What are you expecting the code to do? At the moment it simply writes the value of DATA_EE_DATA to location zero of the data EEPROM.

Mike.
 
Did you assign a EEPROM location in your last part in your code?
I hope this PIC also starting eeprom location from 2100h onwards but you have to confirm from the data sheet.
Ex:
Code:
	org	2100h
	data	.1
	data	.4
 
This is what happens:
1. pic sends commands to the phone to get the phone number stored at location 1 in the phone-book.
2. Phone responds and sends a mobile number in the following format.
eg, if the number is 1234567890, phone sends it as 31 32 33 34 35 36 37 38 39 30. these bytes are stored in various locations.
The pic then
1.AND all bytes with b'00001111'
2.swaps all even bytes. (swapf)..
3.Then XOR all adjacent odd n even bytes to get 21 43 65 87 09 which is the format required for this project.

Then just to know if the pic was receiving and processing the numbers properly,i inserted 'movlw number' and then called 'send' routine(uart) to display the number on the computer. It showed 89 which is what i want.(21 in the example).its saved in 'number'.
Since its correct, i need to save the number on eeprom for further use.
And thats what i want the code to do..

But,inserting 'movfw number' and then 'movwf EEDAT' produces no result. Its 0xFF all the time. To know if thr was any error in the code, i used random numbers using movlw command. like 'movlw 0x25'. Its working. So no problem with the code,I assume.. How is that possible?
Why can't we load the 'w' register with movfw command n then use it thr?

I couldn't find anything about EEPROM location in the datasheet. Apart from moving 0x00 to EEADR, i haven't specified any other location pertaining to eeprom. The pic has 4 banks with the last location ending at 0x1FFF..

The entire code is about 800 lines.
 
hi,
Post the CONFIG line for the program.
 
Code:
    __config    _config1, _lvp_off & _fcmen_on & _ieso_off & _bor_off & _cpd_off & _cp_off & _mclre_on & _pwrte_on & _wdt_off & _hs_osc
    __config    _config2, _wrt_off & _bor21v

Thank you.
 
Code:
    __config    _config1, _lvp_off & _fcmen_on & _ieso_off & _bor_off & _cpd_off & _cp_off & _mclre_on & _pwrte_on & _wdt_off & _hs_osc
    __config    _config2, _wrt_off & _bor21v

Thank you.

That looks oK, I thought you may have set the CP bit.!

The eeprom write code looks OK, can you post the eeprom read section of the program.?
 
Actually I haven't written any codes for eeprom read. After the eeprom write section, the code just loops around a nop instruction. Before reading it, we wanted to know if writing was ok.
Code:
no_operation
 nop
 goto no_operation
After programming the pic,i pulled the wire(Inchworm) from mclr pin,waited for some 15 seconds and then read the eeprom.
Thats ok,right?
 
Banking problem? Is variable "number" in the same bank as EEDAT register? Or is "number" located in the common shared 70..7F ram address range?

Mike
 
Actually I haven't written any codes for eeprom read. After the eeprom write section, the code just loops around a nop instruction. Before reading it, we wanted to know if writing was ok.
Code:
no_operation
 nop
 goto no_operation
After programming the pic,i pulled the wire(Inchworm) from mclr pin,waited for some 15 seconds and then read the eeprom.
Thats ok,right?

Then how do you know you are reading back 'FF' from the EEPROM..:confused:

Write a EEPROM read routine so that you can test the write.!
 
Well,i tried these two code sequences just now with no changes to other sections.
Code:
 BANKSEL EEADR ;
 MOVLW 0x00 ;
 MOVWF EEADR ;Data Memory Address to write
 movlw 0x02
 MOVWF EEDAT ;Data Memory Value to write
  :
write_complete_check
 btfsc EECON1,WR
 goto write_complete_check
 BCF EECON1, WREN ;Disable writes

 BANKSEL EEADR ;
 MOVLW 0x01 ;
 MOVWF EEADR ;Data Memory Address to write
 movlw 0x06
 MOVWF EEDAT ;Data Memory Value to write

 banksel EECON1
write_complete_check1
 btfsc EECON1,WR
 goto write_complete_check1
This gave 0x02 at location 0x00 and 0x06 at 0x01... Fine.

Code:
 BANKSEL EEADR ;
 MOVLW 0x00 ;
 MOVWF EEADR ;Data Memory Address to write
 movfw number
 MOVWF EEDAT ;Data Memory Value to write
 :
 banksel EECON1
write_complete_check
 btfsc EECON1,WR
 goto write_complete_check

 BANKSEL EEADR ;
 MOVLW 0x01 ;
 MOVWF EEADR ;Data Memory Address to write
 movlw 0x05
 MOVWF EEDAT ;Data Memory Value to write
 :
 banksel EECON1
write_complete_check1
 btfsc EECON1,WR
 goto write_complete_check1
This gave 0xED at 0x00 and 0x05 at 0x01..
Today morning i had got FF instead of ED... This proves that values ARE being written,right?

'number' is in bank0 while EEDAT is in bank2.. 'number' is at 0x30. I'll put banksel number and then try writing..
 
Last edited:
Hey...Thanks Mike.. banking was the problem.. Now we need to read the eeprom.. Hope that'll work fine..
Thanks to everyone..
By the way i'm really happy to know that i've become an 'experienced member' on this forum.. Hehe..:)
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top