I got a code, and modified it to run.. But i can't seem to get the code correct. it has to do with XDATA but i can't seem to get it right.
#include <AT898252.H> #include "lcd.c" BYTE ReadEEPROM(int addr) { char EEdata; WMCON |= 0x08; // Enable EEPROM memory space EEdata = addr; // --> how do u write here? WMCON &= 0xF7; // Disable EEPROM memory space return(EEdata); } // To write a single byte to a location in EEPROM. void WriteEEPROM(int addr, char EEdata) { WMCON |= 0x08; // Enable EEPROM memory space WMCON |= 0x10; // Enable EEPROM memory write addr = EEdata; --> how do u write here? msdelay(15); WMCON &= 0xEF; // Disable EEPROM memory write WMCON &= 0xF7; // Disable EEPROM memory space }
WMCON DATA 96h ; watchdog and memory control register EEMEN EQU 00001000b ; EEPROM access enable bit EEMWE EQU 00010000b ; EEPROM write enable bit WDTRST EQU 00000010b ; EEPROM RDY/BSY bit ADDRESS EQU 10H DATAS EQU 0AAH ; EEPROM read example. ;orl WMCON, #EEMEN ; enable EEPROM accesses ;mov dptr, #ADDRESS ; address to read ;movx a, @dptr ; read EEPROM ;xrl WMCON, #EEMEN ; disable EEPROM accesses ; EEPROM write example, utilizing fixed delay for write cycle. ; Delay is worst case (10 ms). Code for delay is not shown. ; Write is followed by verify (read and compare), but code to handle ; verification failure is not shown. orl WMCON, #EEMEN ; enable EEPROM accesses orl WMCON, #EEMWE ; enable EEPROM writes mov dptr, #ADDRESS ; address to write mov a, #DATAS ; data to write movx @dptr, a ; write EEPROM xrl WMCON, #EEMWE ; disable EEPROM writes xrl WMCON, #EEMEN ; disable EEPROM accesses
// --> how do u write here? You have an address in xdata space at which you wish to read and write. A C pointer is an address. I'd use a pointer rather than an int. To turn a pointer into the thing at which it points, you "dereference" the pointer with the "*" operator: char* p; *p = myChar;
typedef volatile BYTE xdata Eeprom; BYTE ReadEEPROM(Eeprom* addr) { char EEdata; WMCON |= 0x08; // Enable EEPROM memory space EEdata = *addr; // Note the '*' WMCON &= 0xF7; // Disable EEPROM memory space return(EEdata); }
typedef volatile BYTE xdata Eeprom; #define EepromEnable 0x08 #define EepromWriteEn 0x10 // Address copied from asm example BYTE ReadEEPROM(Eeprom* addr) { BYTE eeData; WMCON |= EepromEnable; // Enable EEPROM memory space EEdata = *addr; // Note the '*' WMCON &= ~EepromEnable; // Disable EEPROM memory space return eeData; } void WriteEEPROM(Eeprom* addr, BYTE eeData) { WMCON |= (EepromEnable | EepromWriteEn); *addr = eeData; // Note the '*' msdelay(15); WMCON &= ~(EepromEnable | EepromWriteEn); }
#define EepromEnableRead WMCON |= EepromEnable #define EepromEnableWrite WMCON |= (EepromEnable | EepromWriteEn) #define EepromDisable WMCON &= ~(EepromEnable | EepromWriteEn) BYTE ReadEEPROM(Eeprom* addr) { BYTE eeData; EepromEnableRead; EEdata = *addr; // Note the '*' EepromDisable; return eeData; } void WriteEEPROM(Eeprom* addr, BYTE eeData) { EepromEnableWrite; *addr = eeData; // Note the '*' msdelay(15); EepromDisable; }