Software e Hardware para uC PIC
Moderadores: andre_luis, 51, guest2003, Renie
por tcpipchip » 20 Nov 2009 07:49
- Código: Selecionar todos
'CRISTAL 20MHZ
DEFINE OSC 20
' Define LCD registers and bits
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTA
DEFINE LCD_RSBIT 4
DEFINE LCD_EREG PORTA
DEFINE LCD_EBIT 5
DEFINE I2C_HOLD 1
SCL VAR PORTC.3 ' Clock pin
SDA VAR PORTC.4 ' Data pin
ACK VAR BYTE ' VERIFICA SE DISPOSITIVO RESPONDEU
ADCON1 = 7 ' Set PORTA and PORTE to digital
Pause 1000 ' Wait for LCD to start up
LCDOut $fe, 1, "I2CX" ' Display
Pause 1000
I2CWrite SDA,SCL,$02,["D",$FE,$01,$00], bogus ' Write offset to slave
pause 100
I2CWrite SDA,SCL,$02,["D","TELIT :)",$00], bogus
pause 100
while 1
I2CWrite SDA,SCL,$02,["K",$00], bogus ' Write offset to slave
Pause 100
I2CRead SDA,SCL,$02,[ack], bogus ' Read string from slave
LCDOut $fe, 1, DEC ACK ' Mostra se LCD respondeu
WEND
Pause 1000
loop:
I2CRead SDA,SCL,$02,[ack], bogus ' Read string from slave
'LCDOut $fe, 1, DEC ACK ' Mostra se LCD respondeu
' string received from slave.
Pause 1000
GOTO LOOP
I2CWrite SDA,SCL,$02,["L",$FE,$01,$00], bogus ' Write offset to slave
Pause 10
I2CRead SDA,SCL,$02,[ack], bogus ' Read string from slave
'LCDOut $fe, 1, DEC ACK ' Mostra se LCD respondeu
' string received from slave.
Pause 10
I2CWrite SDA,SCL,$02,["L","SALEEX",$00], bogus ' Write offset to slave
Pause 10
I2CRead SDA,SCL,$02,[ack], bogus ' Read string from slave
'LCDOut $fe, 1, DEC ACK ' Mostra se LCD respondeu
' string received from slave.
Pause 10
I2CWrite SDA,SCL,$02,["S",100,5,$00], bogus ' Write offset to slave
Pause 10
I2CRead SDA,SCL,$02,[ack], bogus ' Read string from slave
'LCDOut $fe, 1, DEC ACK ' Mostra se LCD respondeu
' string received from slave.
Pause 10
I2CWrite SDA,SCL,$02,["K",$00], bogus ' Write offset to slave
Pause 10
I2CRead SDA,SCL,$02,[ack], bogus ' Read string from slave
LCDOut $fe, 1, DEC ACK ' Mostra se LCD respondeu
' string received from slave.
Pause 10
GoTo loop ' Do it forever
bogus:
LCDOut $fe,1, "timed out" ' I2C command timed out
Pause 1000
GoTo loop
End
-

tcpipchip
- Dword
-
- Mensagens: 6560
- Registrado em: 11 Out 2006 22:32
- Localização: TCPIPCHIPizinho!
por Alesandro F Zagui » 16 Dez 2009 23:59
Não querendo dar uma de coveiro, mas só hoje voltei a esse projeto.
Resolvido, o problema estava no resistor de pull-up e no endereço do slave.
Coloquei um Pullup Digital como sugerido e configurei o endereço do slave multiplicando por 2.
Obrigado a todos pela ajuda.
Feliz Natal e Prospero Ano Novo.
Alesandro Freire Zagui
-
Alesandro F Zagui
- Byte
-
- Mensagens: 154
- Registrado em: 12 Mai 2009 11:03
- Localização: Campo Mourao, Pr
por tcpipchip » 17 Dez 2009 06:01
x2 ?
-

tcpipchip
- Dword
-
- Mensagens: 6560
- Registrado em: 11 Out 2006 22:32
- Localização: TCPIPCHIPizinho!
por Alesandro F Zagui » 17 Dez 2009 07:30
Digo isso porque os bits de endereço são os 7 mais significativos. Então o Slave de numero 0x01, na verdade é 0b0000001x, ou seja, o endereço slaves devem ser multiplos de 2.
Ou não é por ai?
Alesandro Freire Zagui
-
Alesandro F Zagui
- Byte
-
- Mensagens: 154
- Registrado em: 12 Mai 2009 11:03
- Localização: Campo Mourao, Pr
por aguivone » 17 Dez 2009 16:41
no compilador do ccs
para ler via i2c
disable_interrupts(GLOBAL);
i2c_start();
i2c_write(endereco);// endereco do dispositivo
i2c_write(escreva aqui );
lido = i2c_read(0);//ler sem ack =0 , ler com ack = 1
i2c_stop();
enable_interrupts(GLOBAL);
para escrever
disable_interrupts(GLOBAL);
i2c_start(); //inicializa a comunicaçao i2c
i2c_write(endereco do escravo);
i2c_write(dados);
i2c_stop(); //finaliza comunicação
enable_interrupts(GLOBAL);
-
aguivone
- Bit
-
- Mensagens: 35
- Registrado em: 08 Dez 2009 13:12
Voltar para PIC
Quem está online
Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante