Jump to content
bongo

Eeprom In Sourceboost Simulator

Recommended Posts

i try to use the sourceboost simulator to check if my code for accessing internal eeprom of a 18f2525 works.

my code is a 1:1 asm2c conversion of the microchip example code.

 

result:

- my code does not work (on the simulator, didn't test on a target yet)

- the simulator shows strange behaviour

 

 

SIMULATOR PROBLEMS:

 

i first write a few bytes of data to the eeprom window of the simulator (manual entry). this looks ok, but as soon as i start simulation (first step into the program, with no access to the eeprom), each even address of the eeprom gets overwritten with the data from the next higher odd byte. this looks really strange to me.

didn't i understand the eeprom simulation model, am i completely nuts or is there really a bug in the simulator?

 

 

MY CODE:

 

i wrote an eeprom driver to read/write 8bit and 16bit values from/to the eeprom.

although this accesses the eeprom registers of the sourceboost simulator, the data i write is not written to the eeprom window (of the simulator), and when reading, the value of eedata does not get changed.

what am i doing wrong?

 

below, you find my code...

 

thank you very much for your help!!!

 

C CODE:

 

/*

internal eeprom access for pic18

 

r0.01 initial

*/

 

#include <system.h>

#include "P18INTEEAr0_01.h"

 

 

unsigned char P18IntEeWrite8 (unsigned int addr /*eeprom address*/, unsigned char data /*data to be written*/) {

//writes 8 bit data to address

//returns 0 if ok

 

clear_bit(pir2,EEIF); //clear end of eeprom write

HIBYTE(eeadrh,addr); //Upper bits of Data Memory Address to write

LOBYTE(eeadr,addr); //Lower bits of Data Memory Address to write

eedata = data; //Data Memory Value to write

clear_bit(eecon1, 7); //Point to DATA memory

clear_bit(eecon1, CFGS); //Access EEPROM

set_bit(eecon1, WREN); //Enable writes

clear_bit(intcon, GIE); //Disable Interrupts

eecon2 = 0x55; //requred Write 55h

eecon2 = 0xaa; //requred Write 0AAh

set_bit(eecon1, WR); //Set WR bit to begin write

set_bit(intcon, GIE); //Enable Interrupts

for (unsigned char i = 0; i<200; i++) {

if (test_bit(pir2,EEIF)) i = 200;

delay_ms(1);

}

clear_bit(eecon1, WREN); //Disable writes on write complete (EEIF set)

clear_bit(pir2,EEIF); //clear end of eeprom write

 

if (P18IntEeRead8(addr) == data)

return 0;

else

return 1;

}

 

unsigned char P18IntEeWrite16 (unsigned int addr /*eeprom address*/, unsigned int data /*data to be written*/) {

//writes 16 bit data to address (upper byte) and address+1 (lower byte)

//returns 0 if ok

 

unsigned char tmp, tmp2;

 

HIBYTE(tmp,data); //access upper byte

tmp2=P18IntEeWrite8(addr,tmp);

LOBYTE(tmp, data); //access lower byte

tmp2=tmp2 || P18IntEeWrite8(addr+1,tmp);

return tmp2;

}

 

 

unsigned char P18IntEeRead8 (unsigned int addr /*eeprom address*/) {

//reads 8 bit data from address

//returns data

 

unsigned char tmp;

 

eedata = ~eedata; //invert to see if value changes on read (in the simulator)

HIBYTE(eeadrh,addr); //Upper bits of Data Memory Address to read

LOBYTE(eeadr,addr); //Lower bits of Data Memory Address to read

clear_bit(eecon1, 7); //Point to DATA memory

clear_bit(eecon1, CFGS); //Access EEPROM

set_bit(eecon1, RD); //EEPROM Read

return eedata;

}

 

unsigned int P18IntEeRead16 (unsigned int addr /*eeprom address*/) {

//reads 16 bit data from address (upper byte) and address+1 (lower byte)

//returns data

 

unsigned int tmp;

 

tmp = P18IntEeRead8(addr) * 0x0100;

tmp = tmp + P18IntEeRead8(addr+1);

return tmp;

}

 

 

 

AND WHAT THE COMPILER GENERATES OUT OF IT (only the 8 bit procedures):

 

unsigned char P18IntEeWrite8 (unsigned int addr /*eeprom address*/, unsigned char data /*data to be written*/) {

 

//writes 8 bit data to address

//returns 0 if ok

 

clear_bit(pir2,EEIF); //clear end of eeprom write

1A4A 98A1 BCF gbl_pir2,4

 

HIBYTE(eeadrh,addr); //Upper bits of Data Memory Address to write

1A4C 0101 MOVLB 0x01

1A4E 5101 MOVF P18IntEeWr_00056_arg_addr+D'1', W, 1

1A50 6EAA MOVWF gbl_eeadrh

 

LOBYTE(eeadr,addr); //Lower bits of Data Memory Address to write

1A52 5100 MOVF P18IntEeWr_00056_arg_addr, W, 1

1A54 6EA9 MOVWF gbl_eeadr

 

eedata = data; //Data Memory Value to write

1A56 0100 MOVLB 0x00

1A58 51FF MOVF P18IntEeWr_00056_arg_data, W, 1

1A5A 6EA8 MOVWF gbl_eedata

 

clear_bit(eecon1, 7); //Point to DATA memory

1A5C 9EA6 BCF gbl_eecon1,7

 

clear_bit(eecon1, CFGS); //Access EEPROM

1A5E 9CA6 BCF gbl_eecon1,6

 

set_bit(eecon1, WREN); //Enable writes

1A60 84A6 BSF gbl_eecon1,2

 

clear_bit(intcon, GIE); //Disable Interrupts

1A62 9EF2 BCF gbl_intcon,7

 

eecon2 = 0x55; //requred Write 55h

1A64 0E55 MOVLW 0x55

1A66 6EA7 MOVWF gbl_eecon2

 

eecon2 = 0xaa; //requred Write 0AAh

1A68 0EAA MOVLW 0xAA

1A6A 6EA7 MOVWF gbl_eecon2

 

set_bit(eecon1, WR); //Set WR bit to begin write

1A6C 82A6 BSF gbl_eecon1,1

 

set_bit(intcon, GIE); //Enable Interrupts

1A6E 8EF2 BSF gbl_intcon,7

 

for (unsigned char i = 0; i<200; i++) {

1A70 0101 MOVLB 0x01

1A72 6B02 CLRF P18IntEeWr_00056_1_i, 1

1A74 label157

1A74 0EC8 MOVLW 0xC8

1A76 6102 CPFSLT P18IntEeWr_00056_1_i, 1

1A78 D00A BRA label159

1A8A 2B02 INCF P18IntEeWr_00056_1_i, F, 1

1A8C D7F3 BRA label157

1A8E label159

 

if (test_bit(pir2,EEIF)) i = 200;

1A7A A8A1 BTFSS gbl_pir2,4

1A7C D002 BRA label158

1A7E 0EC8 MOVLW 0xC8

1A80 6F02 MOVWF P18IntEeWr_00056_1_i, 1

1A82 label158

 

delay_ms(1);

1A82 0E01 MOVLW 0x01

1A84 6F0E MOVWF delay_ms_00000_arg_del, 1

1A86 EC10F000 CALL delay_ms_00000

 

}

clear_bit(eecon1, WREN); //Disable writes on write complete (EEIF set)

1A8E 94A6 BCF gbl_eecon1,2

 

clear_bit(pir2,EEIF); //clear end of eeprom write

1A90 98A1 BCF gbl_pir2,4

 

 

if (P18IntEeRead8(addr) == data)

1A92 5100 MOVF P18IntEeWr_00056_arg_addr, W, 1

1A94 6F0B MOVWF P18IntEeRe_00058_arg_addr, 1

1A96 5101 MOVF P18IntEeWr_00056_arg_addr+D'1', W, 1

1A98 6F0C MOVWF P18IntEeRe_00058_arg_addr+D'1', 1

1A9A EC93F004 CALL P18IntEeRe_00058

1A9E 0100 MOVLB 0x00

1AA0 51FF MOVF P18IntEeWr_00056_arg_data, W, 1

1AA2 0101 MOVLB 0x01

1AA4 630D CPFSEQ CompTempVarRet1367, 1

1AA6 D002 BRA label160

1AAC label160

 

return 0;

1AA8 6B03 CLRF CompTempVarRet1366, 1

 

else

return 1;

1AAC 0E01 MOVLW 0x01

1AAE 6F03 MOVWF CompTempVarRet1366, 1

 

}

1AAA 0012 RETURN

1AB0 0012 RETURN

 

 

 

 

unsigned char P18IntEeRead8 (unsigned int addr /*eeprom address*/) {

 

//reads 8 bit data from address

//returns data

 

unsigned char tmp;

 

eedata = ~eedata; //invert to see if value changes on read (in the simulator)

0926 1CA8 COMF gbl_eedata, W

0928 6EA8 MOVWF gbl_eedata

 

HIBYTE(eeadrh,addr); //Upper bits of Data Memory Address to read

092A 510C MOVF P18IntEeRe_00058_arg_addr+D'1', W, 1

092C 6EAA MOVWF gbl_eeadrh

 

LOBYTE(eeadr,addr); //Lower bits of Data Memory Address to read

092E 510B MOVF P18IntEeRe_00058_arg_addr, W, 1

0930 6EA9 MOVWF gbl_eeadr

 

clear_bit(eecon1, 7); //Point to DATA memory

0932 9EA6 BCF gbl_eecon1,7

 

clear_bit(eecon1, CFGS); //Access EEPROM

0934 9CA6 BCF gbl_eecon1,6

 

set_bit(eecon1, RD); //EEPROM Read

0936 80A6 BSF gbl_eecon1,0

 

return eedata;

0938 50A8 MOVF gbl_eedata, W

093A 6F0D MOVWF CompTempVarRet1367, 1

 

}

093C 0012 RETURN

Share this post


Link to post
Share on other sites

i also tried the built-in eeprom access tasks.

looks like they also do not work on the simulator.

what am i doing wrong???

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...