PDA

View Full Version : A help with Write/Read a I2C memory



Eugeniu
- 27th March 2008, 16:23
Hello !

My name is Eugen , from Romania - Bucharest . I am a new in use PBP . Please help me to know where I wrong . I have a Pic16F877 , and I wish to write a one or two texts as connstant , and variables as hours , minutes , seconds (these are not writes in my example), on a I2C memory type 24FC512 ,Read memory and display on a LCD with 2X16 lines:
*****************************
define LOADER_USED 1
define OSC 4
INCLUDE "Modedefs.bas"

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 3
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 2

SDA VAR PORTC.4
SCL VAR PORTC.3

J var word
i var word

c var byte

I=0
J=0

ADCON1 = 7
TRISB = 0

start:


DISABLE INTERRUPT

FOR i = 0 TO 20
I2cwrite SDA, SCL,$A0,I,["TEXT1",VARIABILA1,"TEXT2",VARIABILA2]
pause 30
NEXT i

for J = 0 to 20
i2cread SDA, SCL,$A0,J,[C]
pause 30

lcdout $FE,1
LCDOUT $FE,$80,"INCERCARI"
LCDOUT $FE,$C0+j ,c

pause 400
next J
pause 400
Enable
goto start
*****************************
Thenk you very much !

JD123
- 27th March 2008, 17:39
Instead of "TEXT1", use [#T,#E,#X,#T,#1...etc]

Don't overwrite your buffer.

Eugeniu
- 27th March 2008, 18:58
Instead of "TEXT1", use [#T,#E,#X,#T,#1...etc]

Don't overwrite your buffer.

Do not work .

"I2cwrite SDA, SCL,$A0,I,[#T,#E,#X,#T,# ]" = "bad expression "

Thanks !

JD123
- 27th March 2008, 19:16
Oops, my bad... that's for serial stuff.

Try:

text var byte[5]
test[4] = "T"
test[3] = "E"
test[2] = "X"
test[1] = "T"
test[0] = "1"

I2cwrite SDA, SCL,$A0,I,[char test\5, {your other data to send} ]

I don't know if the array is sent out lowest ([0]) or highest ([4]) first. Reverse array asignments if it comes out backwards.

skimask
- 27th March 2008, 19:48
I2cwrite SDA, SCL,$A0,I,[ "T" , "E" , "X" , "T" , "1" ].....
should also work. (not 100% sure, haven't tried myself, but it should work)

What you originally had was an embedded string, which PBP doesn't natively handle. ( "TEXT1" ). A byte array of characters as noted in the post preceeding can be used as a string, but is not really a 'string' as far as PBP is concerned.

Eugeniu
- 27th March 2008, 20:38
I2cwrite SDA, SCL,$A0,I,[ "T" , "E" , "X" , "T" , "1" ].....
should also work. (not 100% sure, haven't tried myself, but it should work)

What you originally had was an embedded string, which PBP doesn't natively handle. ( "TEXT1" ). A byte array of characters as noted in the post preceeding can be used as a string, but is not really a 'string' as far as PBP is concerned.

I have tried again , and in other kinds , and do not work .

Eugeniu
- 27th March 2008, 20:45
[QUOTE=skimask;53213]I2cwrite SDA, SCL,$A0,I,[ "T" , "E" , "X" , "T" , "1" ].....
should also work. (not 100% sure, haven't tried myself, but it should work)

What you originally had was an embedded string, which PBP doesn't natively handle. ( "TEXT1" ). A byte array of characters as noted in the post preceeding can be used as a string, but is not really a 'string' as far as PBP is concerned.[/QUOTE

I used this and not work .Read and display step by step only " T " ,first karakter .

........................................
test var byte[5]
test[4] = "T"
test[3] = "E"
test[2] = "X"
test[1] = "T"
test[0] = "1"

ADCON1 = 7
TRISB = 0
TRISC = 0

start:


DISABLE INTERRUPT
scriere:

FOR i = 1 TO 20
I2cwrite SDA, SCL,$A0,I,["T","E","S","T","1"]
pause 30
NEXT i
........................................

skimask
- 27th March 2008, 20:48
I have tried again , and in other kinds , and do not work .
Well, that code isn't going to work in a loop like that. Why would it?
Get rid of the loop on the write.

mister_e
- 27th March 2008, 21:00
Hi, something like the following will work.


EEP1 con %10100000 ' First EEPROM A<2:0>=Gnd

Addr var word
ByteA var byte
ByteB var byte

PAUSE 50

addr=0
BYTEA="A"
byteb="B"
I2CWRITE SDA,SCL,EEP1,ADDR,[bYTEA," TEXT1",BYTEB," TEXT2"]
PAUSE 10

FOR ADDR=0 TO 13
I2Cread SDA,SCL,EEP1,ADDR,[bYTEA]
hserout [BYTEA]
next

@ GOTO $

mister_e
- 27th March 2008, 21:04
in your first example, try to change to..


<font color="#000000"> @ __CONFIG _XT_OSC &amp; _WDT_ON &amp; _PWRTE_ON &amp; _BODEN_ON &amp; _LVP_OFF
<font color="#000080">DEFINE </font>OSC 4
<font color="#000080">INCLUDE </font>&quot;Modedefs.bas&quot;

<font color="#000080">DEFINE </font>LCD_DREG PORTB
<font color="#000080">DEFINE </font>LCD_DBIT 4
<font color="#000080">DEFINE </font>LCD_RSREG PORTB
<font color="#000080">DEFINE </font>LCD_RSBIT 3
<font color="#000080">DEFINE </font>LCD_EREG PORTB
<font color="#000080">DEFINE </font>LCD_EBIT 2

SDA <font color="#000080">VAR </font>PORTC.4
SCL <font color="#000080">VAR </font>PORTC.3

J <font color="#000080">VAR WORD
</font>i <font color="#000080">VAR WORD

</font>c <font color="#000080">VAR BYTE
</font>variabila1 <font color="#000080">VAR BYTE
</font>variabila2 <font color="#000080">VAR BYTE
</font>variabila1=&quot;A&quot;
variabila2=&quot;B&quot;

i=0
J=0

ADCON1 = 7
TRISB = 0

start:

<font color="#000080">I2CWRITE </font>SDA, SCL,$A0,i,[&quot;TEXT1&quot;,variabila1,&quot; TEXT2&quot;,variabila2]
<font color="#000080">LCDOUT </font>$FE,1
<font color="#000080">LCDOUT </font>$FE,$80,&quot;INCERCARI&quot;
<font color="#000080">LCDOUT </font>$FE,$C0

<font color="#000080">FOR </font>J = 0 <font color="#000080">TO </font>12
<font color="#000080">I2CREAD </font>SDA, SCL,$A0,J,[c]
<font color="#000080">LCDOUT </font>c
<font color="#000080">NEXT </font>J

@ <font color="#000080">GOTO </font>$

Eugeniu
- 27th March 2008, 21:09
Well, that code isn't going to work in a loop like that. Why would it?
Get rid of the loop on the write.

Write code lines please , what have you in your mind .

Corect my lines .

Thank you !

Eugeniu
- 27th March 2008, 21:18
in your first example, try to change to..


lcdout $FE,1
LCDOUT $FE,$80,"INCERCARI"
LCDOUT $FE,$C0

for J = 0 to 20
i2cread SDA, SCL,$A0,J,[C]
LCDOUT c
next


In this situation the fist karakter is write in the same place , first possition .

mister_e
- 27th March 2008, 21:31
no it works here, look at post #10

Eugeniu
- 27th March 2008, 21:32
Hi, something like the following will work.


EEP1 con %10100000 ' First EEPROM A<2:0>=Gnd
.................................................. ..............

@ GOTO $

I have write your code ..and display " ATEXT1 BTEXT2 " BUT NOT ALL TOGETHER -alternately . If will be remain all karakters on the display -ALL WILL BE OK !

Addr var word
ByteA var byte
ByteB var byte

PAUSE 50

addr=0
BYTEA="A"
byteb="B"
I2CWRITE SDA,SCL,$A0,ADDR,[bYTEA," TEXT1",BYTEB," TEXT2"]
PAUSE 10
reading:
FOR ADDR=0 TO 13
I2Cread SDA,SCL,$A0,ADDR,[bYTEA]



lcdout $FE,1
LCDOUT $FE,$80,"INCERCARI"
LCDOUT $FE,$C0+addr ,ByteA ' HERE I WRITE " +ADDR " BECOSE HE WRITE IN THE SAME PLACE

pause 300
next
pause 400
Enable
goto scriere

mister_e
- 27th March 2008, 21:36
POST #10, not #9

anyways, look what your actual code do...


FOR ADDR=0 TO 13
I2Cread SDA,SCL,$A0,ADDR,

lcdout $FE,1 ' it always clear your LCD and return to home
LCDOUT $FE,$80,"INCERCARI" ' it always draw this line
LCDOUT $FE,$C0+addr ,ByteA ' and finally here, it will only draw a single character, because you ALWAYS clear the WHOLE lcd with [B]$FE,1

pause 300
next


hence why i've move most LCDOUT BEFORE the FOR/NEXT loop.... twice.

Eugeniu
- 27th March 2008, 21:56
POST #10, not #9

anyways, look what your actual code do...


FOR ADDR=0 TO 13
I2Cread SDA,SCL,$A0,ADDR,

I understand that : in this line " byTEA is a new variable where PBP put what read at "ADDR" I have change with "C" and is the same .

lcdout $FE,1 ' it always clear your LCD and return to home

Aha , I will delete this line !! .....and WORK !!

LCDOUT $FE,$80,"INCERCARI" ' it always draw this line

yes , I wish this .

LCDOUT $FE,$C0+addr ,ByteA ' and finally here, it will only draw a single character, because you ALWAYS clear the WHOLE lcd with [B]$FE,1

pause 300
next


hence why i've move most LCDOUT BEFORE the FOR/NEXT loop.... twice.

I understand , I have make changes in programs and now it work !

Thank you very much for all help ! Have you only a happy days !

mister_e
- 27th March 2008, 21:58
Grreeeeeeeeeeeeeat! Enjoy!

JD123
- 27th March 2008, 22:04
"Have you only a happy days !"

Quote of the day.

mister_e
- 27th March 2008, 22:07
ah come on... read first post


My name is Eugen , from Romania - Bucharest .

Chances are that our friend is not English, and try to do it's best... as i do each days since i'm here.... and yes i do tons of mistakes here and there, in each and every of my over 4,800 posts.

Time to raise Melanie's post once again
http://www.picbasic.co.uk/forum/showthread.php?t=4583

JD123
- 27th March 2008, 22:28
mister-e, tong-in-cheek, you know that. I would have stuck with helping him but my job called me away. Thanks for jumping in. It's best anyway, as I'm working on alot of I2C code right now and this kind of evolved into an LCD issue, which is not in the front of my mind.

mister_e
- 27th March 2008, 22:37
You just provided one example for me and probably tons of other users + spelling mistake ;). Tongue-in-cheek... for me, French Quebecer, it doesn't mean anything... but thanks Wikipedia...

Tongue-in-cheek is a term that refers to a style of humour in which things are said only half seriously, or in a subtly mocking way. It is related to satire and irony.

I learn something new everyday ;) Thanks!

JD123
- 27th March 2008, 22:54
LOL!!! "tong", I just noticed that!

mister_e
- 27th March 2008, 23:00
sounded more chinese to me :D

ni hao!

Eugeniu
- 28th March 2008, 07:19
Apologize for my english, please ! Do not be angry .

Eugeniu

mister_e
- 28th March 2008, 12:03
Don't worry Eugeniu, there's a lot of people here, including me, who aren't english. We do our best and that's it. Your question was clear enough for me.

Don't be afraid and don't give up!

Eugeniu
- 28th March 2008, 13:53
Don't worry Eugeniu, there's a lot of people here, including me, who aren't english. We do our best and that's it. Your question was clear enough for me.

Don't be afraid and don't give up!


Thank you , again ! My misyakes was very simple , for others , that "COLUMB EGG " but , I have lost a day , and my mind and eyes do not want to see they .