Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 26th May 2008, 08:10 PM   (permalink)
Default EEPROM of PIC16F887..

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 by asp1987; 26th May 2008 at 08:16 PM.
asp1987 is offline   Reply With Quote
Old 27th May 2008, 04:00 AM   (permalink)
Default

Code:
	MOVLW DATA_EE_ADDR 	;
	MOVWF EEADR 		;Data Memory Address to write
	MOVLW DATA_EE_DATA 	;
	MOVWF EEDAT 		;Data Memory Value to write
By the way its an interesting project.
__________________
Gayan

My Website
http://gsmicro.blogspot.com/

Last edited by Gayan Soyza; 27th May 2008 at 04:03 AM.
Gayan Soyza is offline   Reply With Quote
Old 27th May 2008, 05:22 PM   (permalink)
Default

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 by asp1987; 27th May 2008 at 05:25 PM.
asp1987 is offline   Reply With Quote
Old 28th May 2008, 03:40 AM   (permalink)
Default

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.
Pommie is online now   Reply With Quote
Old 28th May 2008, 03:43 AM   (permalink)
Default

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
__________________
Gayan

My Website
http://gsmicro.blogspot.com/
Gayan Soyza is offline   Reply With Quote
Old 28th May 2008, 06:06 PM   (permalink)
Default

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.
asp1987 is offline   Reply With Quote
Old 28th May 2008, 06:16 PM   (permalink)
Default

hi,
Post the CONFIG line for the program.
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/
ericgibbs is online now   Reply With Quote
Old 28th May 2008, 06:22 PM   (permalink)
Default

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.
asp1987 is offline   Reply With Quote
Old 28th May 2008, 06:32 PM   (permalink)
Default

Quote:
Originally Posted by asp1987 View Post
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.?
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/
ericgibbs is online now   Reply With Quote
Old 28th May 2008, 06:46 PM   (permalink)
Default

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?
asp1987 is offline   Reply With Quote
Old 28th May 2008, 07:02 PM   (permalink)
Default

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
Mike, K8LH is offline   Reply With Quote
Old 28th May 2008, 07:03 PM   (permalink)
Default

Quote:
Originally Posted by asp1987 View Post
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..

Write a EEPROM read routine so that you can test the write.!
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/
ericgibbs is online now   Reply With Quote
Old 28th May 2008, 07:44 PM   (permalink)
Default

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 by asp1987; 28th May 2008 at 07:48 PM.
asp1987 is offline   Reply With Quote
Old 28th May 2008, 08:21 PM   (permalink)
Smile

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 by asp1987; 28th May 2008 at 08:29 PM.
asp1987 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Pic16f887 speakerguy79 Micro Controllers 6 8th August 2008 01:32 PM
pic16f887 analogue reference spuffock Micro Controllers 5 15th October 2007 04:19 PM
EEPROM to TX flemmard Micro Controllers 6 26th September 2007 12:58 AM
Recommend PIC16F887 falleafd Micro Controllers 4 24th June 2007 09:57 AM
8 bit EEPROM with 16 bit uP... udi_hakim Micro Controllers 13 17th March 2004 02:57 PM



All times are GMT. The time now is 01:01 PM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.