writeEepromByte(0x01, result>>8); this line is ; writeEepromByte(0x01, test1>>8); I mistyped. On Fri, Oct 28, 2011 at 7:01 PM, Yigit Turgut wrote: > test1 =3D 512; > > if ( PORTBbits.RB2 =3D=3D 0 ){ > Delay10KTCYx( 50 ); > writeEepromByte(0x00, test1&0xFF); > Delay10TCYx(200); > writeEepromByte(0x01, result>>8); > Delay10TCYx(200); > test2 =3D readEepromByte(0x00 + (readEepromByte(0x01)<<8)); > Delay10TCYx(100); > } > > if( if test1 !=3D test2 ){ > LATBbits.LATB7 =3D 1; > } > > RB7 is always on now where it shouldn't be. > > On Fri, Oct 28, 2011 at 6:40 PM, Kerry Wentworth > wrote: >> You are reading the high byte twice, and adding them together. =A0Elimin= ate: >> test2 =3D test2 + (readEepromByte(0x01)<<8); >> Delay10TCYx(100); >> >> Kerry >> >> >> >> Yigit Turgut wrote: >>> I modified a bit your code to guarantee the operation ; >>> >>> test1 =3D 512; >>> >>> writeEepromByte(0x00, test1t&0xFF); >>> Delay10TCYx(200); >>> writeEepromByte(0x01, test1>>8); >>> Delay10TCYx(200); >>> test2 =3D readEepromByte(0x00+ (readEepromByte(0x01)<<8)); >>> Delay10TCYx(100); >>> test2 =3D test2 + (readEepromByte(0x01)<<8); >>> Delay10TCYx(100); >>> >>> f( test1=3D=3Dtest2) { >>> =A0PORTBbits.RB7 =3D1; } >>> >>> Now RB7 is low always, it's not changing into high state. >>> >>> On Fri, Oct 28, 2011 at 5:26 PM, Kerry Wentworth >>> wrote: >>> >>>> You can write/read a 16 bit integer (512 requires a 16 bit integer) by= : >>>> >>>> // Write >>>> test1 =3D 512; >>>> writeEepromByte(0x00, test1&0xFF); >>>> writeEepromByte(0x01, test1>>8); >>>> >>>> // Read >>>> test2 =3D readEepromByte(0x00)+(readEepromByte(0x01)<<8); >>>> >>>> // Check >>>> if( test1=3D=3Dtest2) { >>>> PORTBbits.RB7 =3D1; } >>>> >>>> Kerry >>>> >>>> >>>> Yigit Turgut wrote: >>>> >>>>> Hi all, >>>>> >>>>> I am trying to write an 8bit integer to internal eeprom of a 18f2550 >>>>> by the following functions ; >>>>> >>>>> #define byte unsigned char >>>>> #define BYTE_ADDR 0 >>>>> int test1, test2; >>>>> >>>>> void writeEepromByte(byte addr, byte data) { >>>>> INTCONbits.GIE =3D 0; >>>>> EECON1bits.EEPGD =3D 0; >>>>> EECON1bits.CFGS =3D 0; >>>>> EECON1bits.WREN =3D 1; >>>>> EEADR =3D addr; >>>>> EEDATA =3D data; >>>>> EECON2 =3D 0x55; >>>>> EECON2 =3D 0xaa; >>>>> EECON1bits.WR =3D 1; >>>>> while (!PIR2bits.EEIF) ; >>>>> PIR2bits.EEIF =3D 0; >>>>> INTCONbits.GIE =3D 1; >>>>> } >>>>> >>>>> byte readEepromByte(unsigned char addr) { >>>>> EECON1bits.EEPGD =3D 0; >>>>> EECON1bits.CFGS =3D 0; >>>>> EEADR =3D addr; >>>>> EECON1bits.RD =3D 1; >>>>> return EEDATA; >>>>> } >>>>> >>>>> And to test it I use ; >>>>> >>>>> if ( PORTBbits.RB2 =3D=3D 0 ){ >>>>> Delay10KTCYx( 50 ); >>>>> test1 =3D 512; >>>>> writeEepromByte(0x00, test1); >>>>> Delay10TCYx(200); >>>>> test2 =3D readEepromByte(0x00); >>>>> Delay10TCYx(100); >>>>> } >>>>> >>>>> if( test1=3D=3Dtest2<<8) { >>>>> PORTBbits.RB7 =3D1; } >>>>> >>>>> All ports are configured correctly and board is functioning well. Wit= h >>>>> a push of the button at RB2, value 512 should be stored in eeprom. >>>>> Actually least significant 8bits of test1 will be written because it'= s >>>>> a one-bye space that it's writing to. Even if so, =A0test1=3D=3Dtest2= <<8 >>>>> this expression should be valid and RB7 is should be set high. None o= f >>>>> this happens, nothing happens at all. Is this a problem because only >>>>> bytes can be written to eeprom ? It should be pretty straightforward >>>>> to write/read 8 bit integer to/from internal eeprom/ >>>>> >>>>> >>>> -- >>>> http://www.piclist.com PIC/SX FAQ & list archive >>>> View/change your membership options at >>>> http://mailman.mit.edu/mailman/listinfo/piclist >>>> >>>> >>> >>> >> >> -- >> http://www.piclist.com PIC/SX FAQ & list archive >> View/change your membership options at >> http://mailman.mit.edu/mailman/listinfo/piclist >> > --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .