eeprom.c

Go to the documentation of this file.
00001 /*
00002  * EEPROM access routine for Sensor Control
00003  * (c) 2007 by Matthias Arndt <marndt@asmsoftware.de>
00004  * Use at your own risk!
00005  */
00007 #include "t89c51cc02.h"
00008 #include "datatypes.h"
00009 #include "eeprom.h"
00010 
00012 unsigned char xdata* eepromptr;
00013 
00023 BYTE EEPROM_read(BYTE address)
00024 {
00025         BYTE c;
00026         
00027 
00028         eepromptr=(unsigned char xdata*) address;
00029 
00030         /* wait if EEPROM is still busy */
00031         EEPROM_wait();
00032 
00033         /* activate EEPROM */
00034         EECON |= MSK_EECON_EEE;
00035 
00036         /* read from EEPROM */
00037         c=*eepromptr;
00038 
00039         /* disable EEPROM */
00040         EECON &= ~MSK_EECON_EEE;
00041         
00042         return(c);
00043 }
00044 
00054 void EEPROM_write(BYTE d,BYTE address)
00055 {
00056         eepromptr=(unsigned char xdata*) address;
00057 
00058         /* wait if EEPROM is still busy */
00059         EEPROM_wait();
00060 
00061         /* activate EEPROM */
00062         EECON |= MSK_EECON_EEE;
00063 
00064         /* write to EEPROM latch */
00065         *eepromptr=d;
00066         
00067         /* disable EEPROM */
00068         EECON &= ~MSK_EECON_EEE;
00069 }
00070 
00077 void EEPROM_flush()
00078 {
00079         bit oldEA;
00080         /* wait if EEPROM is still busy */
00081         EEPROM_wait();
00082         oldEA=EA; EA=0; /* disable interrupts if needed */
00083 
00084         /* activate EEPROM write sequence - do not add any instructions between those two lines */
00085         EECON=0x50;
00086         EECON=0xA0;
00087 
00088         EA=oldEA;       /* restore interrupt status */
00089 }

Generated on Wed Oct 24 12:57:24 2007 for SensorControl by  doxygen 1.4.6