I'm new to PIC & this is my 1st post. I know this is an old thread but I had a similar problem with the "255" output & could not find a specific fix. Maybe this update will help out going forward.
Final summary - I changed B0 from "BYTE" to "Word". This allowed correct excecution but I don't know if it was the real cause.
My whining goes here .. after 3 days of data sheets, permutations of the code and troubleshhoting the Lab-X1. (which really did'nt need any)
Detail - The hardware is brand new flawless Lab-X1. The original code is straight from the Lab-X1 included files = i2cx.bas (below) with a 24C32 eeprom. 16f877a
Using MCS+ with ME U2 programmer & ICD:
Define LOADER_USED 1
.................................................. ........
'Define LCD registers and bits
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
SCL var PORTC.3 ' Clock pin
SDA var PORTC.4 ' Data pin
B0 var Byte ' Address <<<<I changed this to "WORD"
B1 var byte ' Data 1
B2 var byte ' Data 2
ADCON1 = 7 ' Set PORTA and PORTE to digital
Low PORTE.2 ' LCD R/W line low (W)
Pause 100 ' Wait for LCD to start up
For B0 = 0 To 15 ' Loop 16 times
B1 = B0 + 100 ' B1 is data for SEEPROM
I2CWRITE SDA,SCL,$A0,B0,[B1] ' Write each location
Pause 10 ' Delay 10ms after each write
Next B0
loop: For B0 = 0 To 15 Step 2 ' Loop 8 times
I2CREAD SDA,SCL,$A0,B0,[B1,B2] ' Read 2 locations in a row
Lcdout $fe,1,#B0,": ",#B1," ",#B2," " ' Display 2 locations
Pause 1000
Next B0
Goto loop
End
...........................
The MCS+ ICD shows that variables B1 & B2 increment properly but when the program goes from this line:
I2CREAD SDA,SCL,$A0,B0,[B1,B2] ' Read 2 locations in a row
to this line:
Lcdout $fe,1,#B0,": ",#B1," ",#B2," " ' Display 2 locations
then both B1 & B2 go to the 255 value.
The data sheet for the eeprom states that it uses a "byte" size variable.
The MELAb code defines the variable properly.
As a newbie I get to say for at least a couple more posts "I don't get it" why the change from the I2Cread line to the LCDOUT line would change the variable to 255.
My complements to MELABS MCS+ for a nice ICD combo.
Bookmarks