I am having some difficulty understanding the results I am getting, maybe it is due to something simple but I've been trying to figure it out for the past few hours.
I am using 16F628A reading and writing to 24LC16 and displaying results on LCD.
I am also using another application called PonyProg to read/write to my same EEPROM.
So here is the story;
I write to the 2416 these values:
Code:
for i2caddr = 0 to 2048 step 16
i2cwrite d1,d2,i2cdevice,i2caddr,[$01]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$01]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$01]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$3c]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$3c]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$3c]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$3c]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$3c]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$3c]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$08]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$08]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$08]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$21]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$21]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$21]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$FF]:pause 10
next
then I read back the values and display on the LCD in this way:
Code:
i2caddr = 0
i2cread d1,d2,i2cdevice,i2caddr,[dat[0],dat[1],dat[2],dat[3],dat[4],dat[5],dat[6],dat[7],dat[8],dat[9],dat[10],dat[11],dat[12],dat[13],dat[14],dat[15]]
pause 10
errchk = 0
for i = 0 to 15
errchk = errchk + dat[i]
next
LCDOUT $FE,1
lcdout $FE,$80,dec errchk: pause 3000
Now I am expecting to get errchk = 741 but I get 716.
I cycled through each value after the addition within the loop and the last number to add up is 230 although the value I wrote was $FF = 255
Furthermore if I display on the LCD all values I see this:
1113c3c3c3c3c
3c888212121cc
but $cc = 204
Reading the content of 2416 with PonyProg shows properly:
01 01 01 3c 3c 3c 3c 3c 3c 08 08 08 21 21 21 ff
My code is not cleaned up because I was trying different ways but I always get to the same results I tried changing dat[] to word instead of byte but all the data gets messed up on the 2416.
Code:
@ __config _INTOSC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF
clear
DEFINE OSC 4
TRISB = 0 ' Make PORTB all outputs
CMCON = 7 ' Disable comparator
Dat VAR byte[15]
I var byte
D1 var PORTA.2
D2 VAR PORTA.3
I2CAddr Var byte
I2CDevice var byte
ERRchk var word
OK VAR PORTA.4
;NOTOK var PORTA.5
ERRStatus var bit
LCD_DB4 VAR PORTB.7 ' Set port for 4 bits bus
LCD_DB5 VAR PORTB.6
LCD_DB6 VAR PORTB.5
LCD_DB7 VAR PORTB.4
LCD_RS VAR PORTB.0 ' Set RS bit port
LCD_E VAR PORTB.1 ' Set Enable bit port
LCD_Lines CON 2 ' # of Lines on LCD, 1 or 2 (Note: use 2 for 4 lines)
LCD_DATAUS CON 50 ' Data delay time in us
LCD_COMMANDUS CON 2000 ' Command delay time in us
INCLUDE "LCD_AnyPin.pbp" ' Must go after LCD initialization
Pause 500: LCDOUT $FE,1: pause 250 ' clear screen and relax
Start:
i2cdevice =160
LCDOUT $FE,$80,"Start"
pause 500
for i2caddr = 0 to 2048 step 16
i2cwrite d1,d2,i2cdevice,i2caddr,[$01]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$01]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$01]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$3c]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$3c]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$3c]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$3c]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$3c]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$3c]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$08]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$08]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$08]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$21]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$21]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$21]:i2caddr = i2caddr + 1:pause 10
i2cwrite d1,d2,i2cdevice,i2caddr,[$FF]:pause 10
next
i2caddr = 0
i2cread d1,d2,i2cdevice,i2caddr,[dat[0],dat[1],dat[2],dat[3],dat[4],dat[5],dat[6],dat[7],dat[8],dat[9],dat[10],dat[11],dat[12],dat[13],dat[14],dat[15]]
pause 10
errchk = 0
for i = 0 to 15
errchk = errchk + dat[i]
next
LCDOUT $FE,1
lcdout $FE,$80,dec errchk: pause 3000
if errchk = 741 then ERRStatus = 0
i2caddr = 2032
i2cread d1,d2,i2cdevice,i2caddr,[dat[0],dat[1],dat[2],dat[3],dat[4],dat[5],dat[6],dat[7],dat[8],dat[9],dat[10],dat[11],dat[12],dat[13],dat[14],dat[15]]
pause 10
Errchk = 0
for i = 0 to 15
errchk = errchk + dat[i]
; LCDOUT $FE,1
; lcdout $FE,$80,dec ERRCHK: pause 2000
next
if errchk = 741 and errstatus = 0 then
high ok
pause 10000
low ok
else
lcdout $FE,$C0,dec ERRCHK
LCDOUT $FE,$80,hex dat[0],hex dat[1],hex dat[2],hex dat[3],hex dat[4],hex dat[5],hex dat[6],hex dat[7]
LCDOUT $FE,$C0,hex dat[8],hex dat[9],hex dat[10],hex dat[11],hex dat[12],hex dat[13],hex dat[14],hex dat[15]
endif
END
Thanks for any help.
Mike
Bookmarks