  | 
	  | 
		 
	 
	
		| View previous topic :: View next topic   | 
	 
	
	
		| Author | 
		Message | 
	 
	
		
			David Lu Guest
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				|  16F877 internal EEPROM still can't  write / read | 
			 
			
				 Posted: Sat Mar 01, 2003 10:13 pm     | 
				     | 
			 
			
				
  | 
			 
			
				Hi,All: 
 
I am posting my roblem on Feb. 26,(I trying to use C language to write and read internal EEPROM on my 16f877, but it can not working) .  I am very thanks about some friends give me good idea. But both read and write is not working, I open EEPROM Windows , each bute is 0xff, so I am still need some help.
 
I use C2C-plus IDE, MPASM and MPLAB IDE. I think program maybe no problem, is it necessary to set CONFIG register ( address: 0x2007) CPD ( Data EE memory code protection bit), and I don't know how to set it as 1.
 
Thanks.
 
 
David
 
 
my program is: 
 
void write_eeprom ( char addr, char data ) // Write eeprom 
 
{ 
 
while ( EECON1 & WR);  // check completion of last write 
 
EEADR = addr;          // set address register 
 
EEDATA = data;           // set data register 
 
disable_interrupt( GIE );  // Enable Global Interrupts
 
clear_bit ( EECON1, EEPGD ); 
 
set_bit( EECON1, WREN ); 
 
EECON2 = 0x55; 
 
EECON2 = 0xAA; 
 
set_bit( EECON1, WR ); // write command 
 
clear_bit( EECON1, WREN ); // inhibit further writing 
 
}
 
 
 
char read_eeprom ( char addr ) // Read eeprom 
 
{ 
 
EEADR = addr;                  // set address register 
 
clear_bit (EECON1, EEPGD ); 
 
set_bit(EECON1, RD );          // read command 
 
return (EEDATA); 
 
} 
 
___________________________
 
This message was ported from CCS's old forum
 
	Original Post ID: 12267 | 
			 
		  | 
	 
	
		  | 
	 
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| Re:  16F877 internal EEPROM still can't  write / read | 
			 
			
				 Posted: Sun Mar 02, 2003 12:36 am     | 
				     | 
			 
			
				
  | 
			 
			
				:=Hi,All: 
 
:=I am posting my roblem on Feb. 26,(I trying to use C language to write and read internal EEPROM on my 16f877, but it can not working) .  I am very thanks about some friends give me good idea. But both read and write is not working, I open EEPROM Windows , each bute is 0xff, so I am still need some help.
 
:=I use C2C-plus IDE, MPASM and MPLAB IDE. I think program maybe no problem, is it necessary to set CONFIG register ( address: 0x2007) CPD ( Data EE memory code protection bit), and I don't know how to set it as 1.
 
----------------------------------------------------------
 
 
You're using the C2C compiler.  Did you know that this forum
 
is for a different compiler (CCS) ?  
 
 
I'm not trying to kick you off this forum  
 
but C2C has its own forum.  Go here, and
 
click on the link for "C Programming with C2C-plus compiler".
 
 <a href="http://www.picant.com/boards/ikonboard.cgi" TARGET="_blank">http://www.picant.com/boards/ikonboard.cgi</a>
 
 
I read that forum a little bit, and I think they're 
 
discussing your problem on Page 5 of the forum. 
 
Click on the "5" down at the bottom of that page.
 
Then read the article called: 
 
"eecon1...not working on pic16f876a"
 
 
Basically, the Admin recommends that the person
 
use the proper header file, which is supplied with C2C.
 
For example, you have obviously got your code from here:
 
 <a href="http://www.picant.com/c2c/examples/eeprom.html" TARGET="_blank">http://www.picant.com/c2c/examples/eeprom.html</a>
 
But, you have changed all the register names by removing
 
the underscore "_" symbol in front of them.  The Admin
 
on that forum says that is the problem !
 
You are supposed to use the symbol names that come
 
in their header file, which they have here:
 
 <a href="http://www.picant.com/c2c/examples/p16f877x.html" TARGET="_blank">http://www.picant.com/c2c/examples/p16f877x.html</a>
 
(Also, include that header file in your program).
 
 
You should read the C2C forum, if you are using that compiler.
 
___________________________
 
This message was ported from CCS's old forum
 
	Original Post ID: 12269 | 
			 
		  | 
	 
	
		  | 
	 
	
		
			David Lu Guest
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				| Now the problem is can't  change  EECON1.WR as 1 | 
			 
			
				 Posted: Sun Mar 02, 2003 5:47 pm     | 
				     | 
			 
			
				
  | 
			 
			
				Hi, PCM Programmer:
 
 
Thank you give me much advice. 
 
Now the problem is in MPLAB I check the EEPROM WINDOW,all unit is 0xff, and running in STEP by step, but can't change WR (Bit 1 in EECON1), when do " bsf EECON1,D'2'; set_bit_EECON1,WREN))", the EECON1 (address 0x018c) can change the value, but do "bsf EECON1,D'1';(set_bit(_EECON1,WR))" can't change regiser EECON1's value. I try to change bit 1 in EECON1 to "1" manually, but after the next command running, the bit will change to "0" automatically.
 
I think that is why I can't read and write EEPROM. But I don't 
 
know how can I do now. I try to change different bit of MPLAB, but still no way.
 
 
David 
 
___________________________
 
This message was ported from CCS's old forum
 
	Original Post ID: 12288 | 
			 
		  | 
	 
	
		  | 
	 
	
		
			David Lu Guest
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				| the problem is not can't  change  EECON1.WR as 1 | 
			 
			
				 Posted: Sun Mar 02, 2003 8:38 pm     | 
				     | 
			 
			
				
  | 
			 
			
				Hi,
 
 
I check it again, EECON1.WR will be clear by hardware, when write cycle to the EEPROM is complete, it will be '0'.
 
so, I also don't know how to solve my problem.
 
 
David
 
___________________________
 
This message was ported from CCS's old forum
 
	Original Post ID: 12296 | 
			 
		  | 
	 
	
		  | 
	 
	
		
			chris_1982 Guest
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				| Re:  16F877 internal EEPROM still can't  write / read | 
			 
			
				 Posted: Mon Mar 03, 2003 3:04 am     | 
				     | 
			 
			
				
  | 
			 
			
				:=Hi,All: 
 
:=I am posting my roblem on Feb. 26,(I trying to use C language to write and read internal EEPROM on my 16f877, but it can not working) .  I am very thanks about some friends give me good idea. But both read and write is not working, I open EEPROM Windows , each bute is 0xff, so I am still need some help.
 
:=I use C2C-plus IDE, MPASM and MPLAB IDE. I think program maybe no problem, is it necessary to set CONFIG register ( address: 0x2007) CPD ( Data EE memory code protection bit), and I don't know how to set it as 1.
 
:=Thanks.
 
:=
 
:=David
 
:=
 
:=my program is: 
 
:=void write_eeprom ( char addr, char data ) // Write eeprom 
 
:={ 
 
:=while ( EECON1 & WR);  // check completion of last write 
 
:=EEADR = addr;          // set address register 
 
:=EEDATA = data;           // set data register 
 
:=disable_interrupt( GIE );  // Enable Global Interrupts
 
:=clear_bit ( EECON1, EEPGD ); 
 
:=set_bit( EECON1, WREN ); 
 
:=EECON2 = 0x55; 
 
:=EECON2 = 0xAA; 
 
:=set_bit( EECON1, WR ); // write command 
 
:=clear_bit( EECON1, WREN ); // inhibit further writing 
 
:=}
 
:=
 
:=
 
:=char read_eeprom ( char addr ) // Read eeprom 
 
:={ 
 
:=EEADR = addr;                  // set address register 
 
:=clear_bit (EECON1, EEPGD ); 
 
:=set_bit(EECON1, RD );          // read command 
 
:=return (EEDATA); 
 
:=} 
 
:=
 
 
 
Im not sure if this will help you but i also have a PIC16F877 and could not get the internal eeprom write to work in the MPLAB simulator    BUT    it DOES work when run on the PIC.
 
___________________________
 
This message was ported from CCS's old forum
 
	Original Post ID: 12300 | 
			 
		  | 
	 
	
		  | 
	 
	
		
			chas Guest
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				| Re:  16F877 internal EEPROM still can't  write / read | 
			 
			
				 Posted: Mon Mar 03, 2003 7:36 am     | 
				     | 
			 
			
				
  | 
			 
			
				:=Hi,All: 
 
:=I am posting my roblem on Feb. 26,(I trying to use C language to write and read internal EEPROM on my 16f877, but it can not working) .  I am very thanks about some friends give me good idea. But both read and write is not working, I open EEPROM Windows , each bute is 0xff, so I am still need some help.
 
:=I use C2C-plus IDE, MPASM and MPLAB IDE. I think program maybe no problem, is it necessary to set CONFIG register ( address: 0x2007) CPD ( Data EE memory code protection bit), and I don't know how to set it as 1.
 
:=Thanks.
 
:=
 
:=David
 
:=
 
:=my program is: 
 
:=void write_eeprom ( char addr, char data ) // Write eeprom 
 
:={ 
 
:=while ( EECON1 & WR);  // check completion of last write 
 
:=EEADR = addr;          // set address register 
 
:=EEDATA = data;           // set data register 
 
:=disable_interrupt( GIE );  // Enable Global Interrupts
 
:=clear_bit ( EECON1, EEPGD ); 
 
:=set_bit( EECON1, WREN ); 
 
:=EECON2 = 0x55; 
 
:=EECON2 = 0xAA; 
 
:=set_bit( EECON1, WR ); // write command 
 
:=clear_bit( EECON1, WREN ); // inhibit further writing 
 
:=}
 
:=
 
:=
 
:=char read_eeprom ( char addr ) // Read eeprom 
 
:={ 
 
:=EEADR = addr;                  // set address register 
 
:=clear_bit (EECON1, EEPGD ); 
 
:=set_bit(EECON1, RD );          // read command 
 
:=return (EEDATA); 
 
:=} 
 
:=
 
 
There is a note in the MPLAB development mode set up window (see details) that indicates that single stepping does not work for program memory and data (EEPROM) reads and writes.
 
___________________________
 
This message was ported from CCS's old forum
 
	Original Post ID: 12305 | 
			 
		  | 
	 
	
		  | 
	 
	
		 | 
	 
 
  
	 
	    
	   | 
	
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
  | 
   
 
  
Powered by phpBB © 2001, 2005 phpBB Group
  
		 |