In the statement "return EEDATH*256 + EEDATL;" what's probably=20 happening is that the variable/register EEDATH is not sized properly to=20 handle being multiplied by 256. Try creating a temporary unsigned int,=20 copying EEDATH to that, then adding EEDATL to it, and then return it. Cheers, -Neil. On 4/6/2012 8:14 AM, AdiCH wrote: > Hi > > I try to read the flash ROM of my PIC16F916 to calculate a checksum. > I use the MPLAB and the PICC v9.83 Compiler. > > I tried this c function: > > unsigned int ReadFlash( unsigned int address ) { > EEADRL =3D address%256; > EEADRH =3D address/256; > EEPGD =3D 1; // program memory > RD =3D 1; // read > ; > ; > return EEDATH*256 + EEDATL; > } > > and everything in assembler: > > unsigned char low3; > unsigned char high3; > > unsigned int dataFlash; > > void main() { > > #asm > BCF _STATUS, 5 > BCF _STATUS, 6 > MOVF _low3, W > BSF _STATUS, 6 > MOVWF _EEADR > BCF _STATUS, 6 > MOVF _high3, W > BSF _STATUS, 6 > MOVWF _EEADRH > BSF _STATUS, 5 > BSF _EECON1, 7 > BSF _EECON1, 0 > NOP > NOP > BCF _STATUS, 5 > MOVF _EEDATH, W > MOVWF _dataFlash+1 > CLRF _dataFlash > MOVF _EEDATA, W > IORWF _dataFlash, F > MOVLW 0 > IORWF _dataFlash+1, F > #endasm > } > > But both are not working, if I debug it most of the time the register EED= ATA > and EEDATH have the right value. But if I copy it to the variable dataFla= sh > it is 0. > > With the mikroC compiler is a function to read the flash that works. But = I > can not use this compiler because the build hex file is much bigger and h= as > no space on the PIC. > > Any idea what is wrong or how I can read the flash ROM? > > thanks > > Adrian --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .