![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
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 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. |
|
|
|
|
|
|
(permalink) |
|
Code:
MOVLW DATA_EE_ADDR ; MOVWF EEADR ;Data Memory Address to write MOVLW DATA_EE_DATA ; MOVWF EEDAT ;Data Memory Value to write Last edited by Gayan Soyza; 27th May 2008 at 04:03 AM. |
|
|
|
|
|
|
(permalink) |
|
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 Pls help.. Last edited by asp1987; 27th May 2008 at 05:25 PM. |
|
|
|
|
|
|
(permalink) |
|
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. |
|
|
|
|
|
|
(permalink) |
|
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 |
|
|
|
|
|
|
(permalink) |
|
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. |
|
|
|
|
|
|
(permalink) |
|
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/ |
|
|
|
|
|
|
(permalink) |
|
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
|
|
|
|
|
|
|
(permalink) | |
|
Quote:
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/ |
||
|
|
|
|
|
(permalink) |
|
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 Thats ok,right? |
|
|
|
|
|
|
(permalink) |
|
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 |
|
|
|
|
|
|
(permalink) | |
|
Quote:
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/ |
||
|
|
|
|
|
(permalink) |
|
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 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 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. |
|
|
|
|
|
|
(permalink) |
|
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. |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| 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 |