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
Ok. I did the adjustments as u suggested.. Seems there is no syntax error.. However I can't seem to build it.. Alot of errors while building it.. Heres the Eeprom.c
#include <AT898252.H> #ifndef BYTE #define BYTE unsigned char #endif typedef volatile BYTE xdata Eeprom; #define EepromEnable 0x08 #define EepromWriteEn 0x10 #define EepromEnableRead WMCON |= EepromEnable #define EepromEnableWrite WMCON |= (EepromEnable | EepromWriteEn) #define EepromDisable WMCON &= ~(EepromEnable | EepromWriteEn) BYTE ReadEEPROM(Eeprom* addr); void WriteEEPROM(Eeprom* addr, BYTE eeData); void msdelay(unsigned x); BYTE ReadEEPROM(Eeprom* addr) { BYTE eeData; EepromEnableRead; eeData = *addr; EepromDisable; return eeData; } void WriteEEPROM(Eeprom* addr, BYTE eeData) { EepromEnableWrite; *addr = eeData; msdelay(15); EepromDisable; } void msdelay(unsigned int x) { BYTE delval; while(x--) { delval = 123; /* Modify thisvalue to tune delay for 1mS */ while(delval--) ; } }
#include <AT898252.H> #include "eeprom.c" void main() { Eeprom* addr=0; BYTE b=0,eeData=0x3F; for(b=0;b<9;b++) { WriteEEPROM(*(addr+b),eeData); } }