di2688.txt ;************************************************************************************************ ; LISTING 1 - VIRTUAL EEPROM C CODE ; ; "Microcontroller eliminates offboard EEPROM with "virtual-EEPROM" routines," EDN, May 10, 2001, pg 123 ; ; http://www.ednmag.com/ednmag/reg/2001/051001/designideas.htm#11di1 ;************************************************************************************************ // Virtual E2 demonstration files #include "8cbr.h"; // COP8CBR Include Files #include "flash_OP.h"; // Flash Operation Files void veeprom_write(unsigned int data); // Prototype header for the virtual E2 write void veeprom_read(void); // Prototype header for the virtual E2 read unsigned int write_counter; // The counter to hold how many write to allow unsigned int write_pointer; // The pointer to where the current write is unsigned int total_write; // Counter to tell how many write has already passed unsigned int scratch_RAM[128]; // Create a 128 byte virtual E2 // Begining of Main void main(){ // Set the total written to equal = 5 total_write=0x05; write_counter=total_write; // Store a 0x1E in the first byte of the virtual E2 veeprom_write(0x1E); // Zero the write counter total_write=0; // Do an entire read of the Virtual E2 veeprom_read(); } // Subroutine to write data to the Virtual E2 void veeprom_write(unsigned int data){ unsigned int i; // A counter variable scratch_RAM[total_write]=data; // Write the data to the scratch RAM if (total_write==0){ // Flush immediately page_erase (0x3000); // Erase the 0x3000 page for (i=0; i