how to save data in internal EEPROM of PIC16F914??

Status
Not open for further replies.

kenny_zhou

Junior Member level 2
Joined
Jan 12, 2007
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
china
Activity points
1,401
hi-tech picc eeprom_write()

hello everyone!
i meet a problem,i want to save many data to the internal EEPROM of the PIC16F914.But i don't know how to write the code in C or ASM.
could you give me a hand!

thanks a lot !
 

ccs eeprom macro

Have a look at the datasheet - there are code examples there.
 

pic16f914 code examples

If you are using a C compiler, most of them have eeprom read and write routines in their libraries.
If you are using Hi-Tech, look in "Pic.h" and you will fine both macro definitions and function prototypes for reading and writing flash and eeprom memory.

Extract from Hi-Tech pic.h

Code:
/***********************************************************************/
/****** EEPROM memory read/write macros and function definitions *******/
/***********************************************************************/
/* NOTE WELL:

   The macro EEPROM_READ() is NOT safe to use immediately after any
   write to EEPROM, as it does NOT wait for WR to clear.  This is by
   design, to allow minimal code size if a sequence of reads is
   desired.  To guarantee uncorrupted writes, use the function
   eeprom_read() or insert
	while(WR)continue;
   before calling EEPROM_READ().
*/
#if	EEPROM_SIZE > 0
#ifdef	__FLASHTYPE
	// macro versions of EEPROM write and read
#define	EEPROM_WRITE(addr, value) \
do{ \
	while(WR)continue;EEADR=(addr);EEDATA=(value); \
	EECON1&=0x7F;CARRY=0;if(GIE)CARRY=1;GIE=0; \
	WREN=1;EECON2=0x55;EECON2=0xAA;WR=1;WREN=0; \
	if(CARRY)GIE=1; \
}while(0)
#define	EEPROM_READ(addr) ((EEADR=(addr)),(EECON1&=0x7F),(RD=1),EEDATA)
#else	// else doesn't write flash
#define	EEPROM_WRITE(addr, value) \
do{ \
	while(WR)continue;EEADR=(addr);EEDATA=(value); \
	CARRY=0;if(GIE)CARRY=1;GIE=0; \
	WREN=1;EECON2=0x55;EECON2=0xAA;WR=1;WREN=0; \
	if(CARRY)GIE=1; \
}while(0)
#define	EEPROM_READ(addr) ((EEADR=(addr)),(RD=1),EEDATA)
#endif

/* library function versions */
extern void eeprom_write(unsigned char addr, unsigned char value);
extern unsigned char eeprom_read(unsigned char addr);
#endif	// end EEPROM routines
 

hi tech macro eeprom

I use CCS.
Code:
#include <18F8722.h> 
#device *=16 
#device adc=8 

#FUSES NOWDT, WDT128, EC_IO, NOPROTECT, IESO, BROWNOUT, BORV25, PUT, NOCPD 
#FUSES STVREN, NODEBUG, NOLVP, NOWRT, NOCPB, NOEBTRB, NOEBTR, NOWRTD, NOWRTC 
#FUSES NOWRTB, FCMEN, LPT1OSC, MCLR, NOXINST, MCU 

#use delay(clock=40000000) 

#use rs232( stream = PC, baud=115200, parity=N, xmit=PIN_G1, rcv=PIN_G2, errors ) 

#define RLED             PIN_F7 
#define YLED             PIN_H5 

#rom int8 0xF0000 = { 1, 2, 3, 4 } 

void main() 
{ 
   setup_adc_ports(NO_ANALOGS|VSS_VDD); 
   setup_adc(ADC_OFF|ADC_TAD_MUL_0); 
   setup_psp(PSP_DISABLED); 
   setup_spi(FALSE); 
   setup_wdt(WDT_OFF); 
   setup_timer_0(RTCC_INTERNAL); 
   setup_timer_1(T1_DISABLED); 
   setup_timer_2(T2_DISABLED,0,1); 
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1); 
   setup_timer_4(T4_DISABLED,0,1); 
   setup_comparator(NC_NC_NC_NC); 
   setup_vref(VREF_LOW|-2); 
   setup_low_volt_detect(FALSE); 
   setup_oscillator(False); 

   output_low( RLED ) ; 
   output_high( YLED ) ; 
   delay_ms( 350 ) ; 

   output_high( RLED ) ; 
   output_low( YLED ) ; 
   delay_ms( 350 ) ; 

   output_low( RLED ) ; 

   while( 1 ) 
   { 
      if( read_eeprom( 0x0000 ) == 1 ) 
         output_high( YLED ) ; 
      else 
         output_high( RLED ) ; 

      delay_ms( 100 ) ; 

      output_low( YLED ) ; 
      output_low( RLED ) ; 
      delay_ms( 100 ) ; 
   } 

}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…