![]() |
![]() |
![]() |
|
|
|||||||
| 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 Guys I have write to eeprom but when I power up it wont starts from last saved value its starting from "0000".I cannot solve the problem please take a look.
Thanks Code:
list p=16f628a #include <P16F628A.inc> errorlevel -302 __config 0x3D18 D0 equ 21h D1 equ 22h D10 equ 23h D100 equ 24h SCcount equ 25h Eadd equ 70h ;common to all four banks Edat equ 71h ;common to all four banks org 0x00 movlw 0x07 movwf CMCON goto Main ;********************************************** ;multiplexing & increment stuff in the four SSD ;********************************************** Scan ---- ---- return Incr ---- ---- return ;********************** ;eeprom write routine ;********************** Ewrite bsf STATUS,RP1 ;B1 movf Edat,W movwf EEDATA movf Eadd,W movwf EEADR bsf EECON1,WREN movlw 55h movwf EECON2 movlw 0AAh movwf EECON2 bsf EECON1,WR btfsc EECON1,WR goto $-1 clrf STATUS ;B0 return ;********************** ;eeprom read routine ;********************** EEread bsf STATUS,RP1 ;B1 movwf EEADR bsf EECON1,RD btfsc EECON1,RD goto $-1 movf EEDATA,W clrf STATUS ;B0 return ;****************************** ;main program startd from here ;****************************** Main bsf STATUS,RP0 ;B1 movlw 01h ;make RB0 input button movwf TRISB clrf TRISA bcf OPTION_REG,NOT_RBPU bcf STATUS,RP0 ;B0 clrf Eadd clrf Edat clrf D0 clrf D1 clrf D10 clrf D100 ;************************************************************* ;read the saved value first & put into four digits in the SSD ;************************************************************* clrw call EEread movwf D0 movlw 01h call EEread movwf D1 movlw 02h call EEread movwf D10 movlw 03h call EEread movwf D100 ;**************************** ;has the save button pressed? ;**************************** Main1 movlw .100 ;100 scans movwf SCcount call Scan decfsz SCcount,f goto $-2 call Incr btfsc PORTB,0 ;check the save button goto Main1 ;**************************************** ;yes then write the four digits to EEPROM ;**************************************** clrw movwf Eadd movf D0,W movwf Edat call Ewrite movlw 01h movwf Eadd movf D1,W movwf Edat call Ewrite movlw 02h movwf Eadd movf D10,W movwf Edat call Ewrite movlw 03h movwf Eadd movf D100,W movwf Edat call Ewrite call Scan btfss PORTB,0 goto $-2 goto Main1 end |
|
|
|
|
|
|
(permalink) |
|
Hi,
Does it start at 0000? Your 7-segment displays show the numbers of D0, D1, D10 and D100 am I right? In the beginning, the value of the eeprom is not set, and you read from it. The value in the eeprom is unknown, according to the datasheet (POR reset). I've tried and it is 0xff. In my program, I first check the content of the EEPROM. If it is not 0xff, read from it. While if it is 0xff, write into it. POR is disabled in your program, so the initial value in the EEPROM is unchanged, but what is 'unchanged' if you never write anything into it in the beginning?
__________________
Superman returns..
|
|
|
|
|
|
|
(permalink) | |||
|
Hi banansiong
Quote:
Quote:
Quote:
|
||||
|
|
|
|
|
(permalink) |
|
What do you want your program to do? Save the data into the EEPROM when the button is pressed?
But in your program, I can see that the same data is written in and read from the EEPROM, no increment or any changes. Or you didn't show it here? I don't know whether there is any other method out there, maybe you can try mine. First check whether the first memory location of the EEPROM whether is 0xff or not. If it is not 0xff, read from it. Then when the button is pressed, write into it and continue counting or whatever. When the next time you turn on the PIC, the value you got will be the last saved data. Or there is any other way to do that?
__________________
Superman returns..
|
|
|
|
|
|
|
(permalink) |
|
You could write values in the source code.
Code:
org 0x2100 Data 1,2,3,4,5,6 Mike. |
|
|
|
|
|
|
(permalink) |
|
Oh I see I really missed that part it should really work.
Then those are the data. Can I put any values to that? So when I save the data through my button this data will be ovewrite.I have only four digits so I need to write only four data in the ORG 2100 location If I have more data to write I need to fill up with more values in the ORG 2100. Thanks a lot mike. Last edited by Suraj143; 20th August 2007 at 11:03 AM. |
|
|
|
|
|
|
(permalink) |
|
Hi Pommie,
How do you know that the location of EEPROM is at 0x2100? The datasheet of PIC16F628A shows only the PROGRAM MEMORY MAP AND STACK which is not more than 0x2000, never mention what is more than this location. I've tried reading PIC16F627A/628A/648A EEPROM Memory Programming Specification too, the note shows 'not implemented for the memory location after 0x2008. Or I've missed out any other application notes?
__________________
Superman returns..
|
|
|
|
|
|
|
(permalink) |
|
|
|
|
|
|
|
|
(permalink) | |
|
Quote:
Is this the same for other PIC? Thanks.
__________________
Superman returns..
|
||
|
|
|
|
|
(permalink) |
|
No, different PICs have different EEPROM addresses. The code templates included with MPLAB at;
C:\Program Files\Microchip\MPASM Suite\Template\Code usually have these values already filled in for you as an example. Or you can browse the data sheet for the device in question.
__________________
--- The days of the digital watch are numbered. --- |
|
|
|
|
|
|
(permalink) |
|
I didn't know that the EEPROM can be written in this way. Usually I do according to the datasheet. So I can straight away write into the EEPROM without using 'EEPROM write routine', i.e. 0x55 and 0xaa to EECON2? Or this is just assigning the initial value to the EEPROM?
__________________
Superman returns..
|
|
|
|
|
|
|
(permalink) |
|
It is just for the initial values for the EEPROM when the device is programmed. You still need to write the 0x55 and 0xAA bytes etc from within your code to modify eeprom.
__________________
--- The days of the digital watch are numbered. --- |
|
|
|
|
|
|
(permalink) |
|
I see some small mistakes in OP coding.Edited ones highlighted in red.Try this.
Code:
list p=16f628a #include <P16F628A.inc> errorlevel -302 __config 0x3D18 D0 equ 21h D1 equ 22h D10 equ 23h D100 equ 24h SCcount equ 25h Eadd equ 70h ;common to all four banks Edat equ 71h ;common to all four banks org 0x00 movlw 0x07 movwf CMCON goto Main ;********************************************** ;multiplexing & increment stuff in the four SSD ;********************************************** Scan ---- ---- return Incr ---- ---- return ;********************** ;eeprom write routine ;********************** Ewrite bsf STATUS,RP0 ;B1 movf Edat,W movwf EEDATA movf Eadd,W movwf EEADR bsf EECON1,WREN movlw 55h movwf EECON2 movlw 0AAh movwf EECON2 bsf EECON1,WR btfsc EECON1,WR goto $-1 clrf STATUS ;B0 return ;********************** ;eeprom read routine ;********************** EEread bsf STATUS,RP0 ;B1 movwf EEADR bsf EECON1,RD btfsc EECON1,RD goto $-1 movf EEDATA,W clrf STATUS ;B0 return ;****************************** ;main program startd from here ;****************************** Main bsf STATUS,RP0 ;B1 movlw 01h ;make RB0 input button movwf TRISB clrf TRISA bcf OPTION_REG,NOT_RBPU bcf STATUS,RP0 ;B0 clrf Eadd clrf Edat clrf D0 clrf D1 clrf D10 clrf D100 ;************************************************************* ;read the saved value first & put into four digits in the SSD ;************************************************************* clrw call EEread movwf D0 movlw 01h call EEread movwf D1 movlw 02h call EEread movwf D10 movlw 03h call EEread movwf D100 ;**************************** ;has the save button pressed? ;**************************** Main1 movlw .100 ;100 scans movwf SCcount call Scan decfsz SCcount,f goto $-2 call Incr btfsc PORTB,0 ;check the save button goto Main1 ;**************************************** ;yes then write the four digits to EEPROM ;**************************************** clrw movwf Eadd movf D0,W movwf Edat call Ewrite movlw 01h movwf Eadd movf D1,W movwf Edat call Ewrite movlw 02h movwf Eadd movf D10,W movwf Edat call Ewrite movlw 03h movwf Eadd movf D100,W movwf Edat call Ewrite call Scan btfss PORTB,0 goto $-2 goto Main1 org 2100h data .1 data .2 data .3 data .4 end |
|
|
|
|
|
|
(permalink) |
|
It really worked well.Thanks a lot Gayan. I really didn't notice that bank bits.
Thanks for your help. |
|
|
|
|
|
|
(permalink) | |
|
Quote:
I think its there to store data. When new data comes the previous values will overwrite. Earlier I tried without it but it doesn’t work. After I applied org 0x2100. & also after changing bank bits it really worked well. |
||
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| working with eeprom pages? | justDIY | Micro Controllers | 1 | 7th October 2005 09:21 AM |
| Writing Data to the EEPROM | Electrix | Micro Controllers | 2 | 31st August 2005 06:39 AM |
| faulty digital components testing,checking | walters | General Electronics Chat | 5 | 22nd August 2005 07:10 PM |
| sequential read to AT24C01A serial EEPROM | giaracam | Micro Controllers | 2 | 26th October 2004 03:19 AM |
| Ext EEPROM read delay? | brodin | Micro Controllers | 2 | 22nd February 2004 01:43 PM |