PDA

View Full Version : please friends help a beginner with i2chello people I'm in big trouble i2c, I'm using



Fernandocsouza
- 3rd May 2014, 22:35
hello people I'm in big trouble i2c, I'm using a pic 16F628A a 24c32a and eeprom proteus simulator
I am using this code

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


SCL var PORTA.0 'Clock pin
SDA var PORTA.1 'Data pin

E0 var byte 'Address <<<< I changed this to "WORD"

B1 var byte 'Data 1
B2 var byte 'Data 2
B3 var byte 'Data 3

ADCON1 = 7 'Set PORTA and PORTE to digital
Lcdout $ fe, 1, "1 EEPROM"
pause 1000
Lcdout $ fe, 1, "writing"
pause 100
Lcdout $ FE, 1
PAUSE 100
Pause 100 'Wait for LCD to start up
b1 = e0 + $ 80 'B1 is the EEPROM data
b2 = e0 + $ B0
pause 100
I2CWRITE SDA, SCL, $ A0, E0, [B1, "pic basic pro"] 'WRITTEN
pause 100

the phrase "pic basic pro" is a stored eeprom, which do happen to read this sentence and appears on lcd

you guys could help me with this
thank you
fernandocsouza

EarlyBird2
- 4th May 2014, 10:17
What is not working?

Demon
- 5th May 2014, 03:33
...
PORTB DEFINE LCD_DREG
DEFINE LCD_DBIT 4
PORTB DEFINE LCD_RSREG
DEFINE LCD_RSBIT 1
PORTB DEFINE LCD_EREG
DEFINE LCD_EBIT 2
...

This is an example from the manual:


' Set LCD Data port
DEFINE LCD_DREG PORTA
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 0
' Set LCD Register Select port
DEFINE LCD_RSREG PORTA
' Set LCD Register Select bit
DEFINE LCD_RSBIT 4
' Set LCD Enable port
DEFINE LCD_EREG PORTB
' Set LCD Enable bit
DEFINE LCD_EBIT 3
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
' Set command delay time in us
DEFINE LCD_COMMANDUS 1500
' Set data delay time in us
DEFINE LCD_DATAUS 44

Your syntax varies slightly.

Robert

Fernandocsouza
- 5th May 2014, 15:12
Good morning guys thanks for replying, well what is not working:
the data are already saved in eeprom 24c32a I was wondering how do I make reading through these data through the 24c32a eeprom PIC16F628A
(example when I write I2CWRITE SDA, SCL, $ A0, e0, [B1, "pic basic pro"]
it is recorded in the external EEPROM, and now comes the hardest as I do for the the reading of this phrase "pi pro basic" appears on the LCD
already used all the commands and the phrase nothing appears
I2CREAD SDA, SCL, $ A0, E0, b1, b2, b3
I2CREAD SDA, SCL, $ A0, E0, b1, b2
I2CREAD SDA, SCL, $ A0, E0, b1
what I'm already one week trying to solve this and nothing, please help me staff
thank you

fernandocsouza

Demon
- 5th May 2014, 15:29
Lcdout $ fe, 1, "1 EEPROM"

I'm not sure you can have a SPACE after $.

Post all your updated code. It will be easier to spot an error than using our crystal ball.

Do you get any compile errors?

Robert

Fernandocsouza
- 5th May 2014, 16:23
hello robert thanks for replying, oh oo this code
hello robert thanks for replying, oh oo this code

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


SCL var PORTA.0 'Clock pin
SDA var PORTA.1 'Data pin

E0 var byte 'Address <<<< I changed this to "WORD"

B1 var byte 'Data 1


ADCON1 = 7 'Set PORTA and PORTE to digital

Pause 100 'Wait for LCD to start up
b1 = e0 + $ 80 'B1 is the EEPROM data

pause 100
I2CWRITE SDA, SCL, $ A0, E0, [B1, "pic basic pro"] 'WRITTEN
pause 100
I2CREAD SDA, SCL, $ A0, E0, b1
PAUSE 100
lcdout $ FE, 1, B1
end

I want the pic 16F628A EEPROM read and write q 24c32a this recorded in the external EEPROM and appears on the LCD, the case would be the phrase "pic basic pro"

sorry my english, I'm Brazilian, sao paulo

thank you
fernandocsouza

nomad
- 5th May 2014, 17:31
The lcd defines are not correct format.

The 16f628a does not use adcon1, but you need to turn off comparators that are on porta.

'ADCON1 = 7 'Set PORTA and PORTE to digital
CMCON = 7 'turn off comparators

address E0 is not set anywhere.

remove the spaces after "$"

that i2cread will only read one byte, you'll need to set an array and use str\x or a loop to read the whole string.

You may want to send something to the lcd first to make sure it's working before solving the i2cread issues.
the following compiles and should display the "Display working" at least


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

SCL var PORTA.0 'Clock pin
SDA var PORTA.1 'Data pin

E0 var WORD 'Address <<<< I changed this to "WORD"
B1 var byte 'Data 1

CMCON = 7 'turn off comparators

Pause 100 'Wait for LCD to start up

E0 = $0000 'didn't see i2c address anywhere, need to set.
b1 = e0 + $80 'B1 is the EEPROM data

pause 100
LCDOUT $FE,1,"Display working!" ' see if lcd setup correctly.
I2CWRITE SDA, SCL, $A0, E0, [B1, "pic basic pro"] 'WRITTEN
pause 100
I2CREAD SDA, SCL, $A0, E0, b1
PAUSE 100
lcdout $FE, 1, B1
end

nomad
- 5th May 2014, 17:39
also need to add "TRISB = 0" somewhere before using lcdout. (default is input, need to set to output)
Also, make sure Low voltage programming is disabled, it uses portb.4.

Fernandocsouza
- 5th May 2014, 18:11
HELLO personal thanks for replying,
I pulled the ADCON1 and put the CMCON = 7 and appeared error symbol

Nor did the case of states i2c address you explain to me or write code to perform this address
because the lcd was already running and the data were recorded in eeprom 24c32a
the difficult that even this reading is made of the data in the EEPROM and show lcd

thanks for helping me
fernandocsouza

Fernandocsouza
- 5th May 2014, 21:03
(double post)

nomad
- 6th May 2014, 01:24
sorry, i'm lost as how to help. your code should not compile at all.
(I tried in microcode studio, fixed all the errors, and posted the result.)
Are you sure you've selected 16f628a? it has comparators and uses cmcon.
I've used them before and checked against my old projects and the data sheet.
what I posted compiles fine here with no errors. (Although I did not correct the i2cread section to get the full string for display)

If nothing at all is displaying, there's bigger issues.

make sure 16f628a is the chip youre using, and it is selected in your program!

Fernandocsouza
- 6th May 2014, 01:46
thank you for answering me NOMAD installed microcode studio again and the LCD worked just right and I could write the phrase "pic basic pro" in eeprom 24c32a, and now a friend as I do for reading the data and display on lcd
please help me
fernandocsouza

Fernandocsouza
- 6th May 2014, 02:28
Friend nomad thanks for helping me
got the pic 16F628A read the eeprom 24c32a this error in declarations
I2CREAD SDA, SCL, $ A1, e0 + $ 20 [b1 str \ 9] 'limit
pause 100

lcdout str b1 \ 9
pause 100
had to put the var data with the line of the EEPROM memory in the case E0 + $ 20
but anyway thanks
fernandocsouza