View Full Version : Pic18f252,dacmax518 And I2c?
angelika
- 13th June 2005, 07:12
Hello! Please, You help me.
I have PIC18F252 and DAC MAX518(2 wire serial 8- bit dac with rail to rail outputs)
I use the portc.3(SCL) and the portC.4(SDA) and I2C protocol. I try to programme,
but it doesn't work.I don't know what to do. I want to give me an example(with simple way, please)
seinfield
- 27th July 2005, 04:55
i have this code for the max519, i hope this helps you:
DEFINE NO_CLRWDT 1
DEFINE OSC 20
DEFINE LCD_DREG PORTB ' Se establece el puerto de datos
DEFINE LCD_DBIT 4 ' Se establece el bit de inicio de los datos
DEFINE LCD_RSREG PORTB ' Se establece el puerto de R/S
DEFINE LCD_RSBIT 1 ' Se establece el bit R/S
DEFINE LCD_EREG PORTB ' Se establece el puerto de E
DEFINE LCD_EBIT 0 ' Se establece el bit E
ADCON1=7
PAUSEUS 1
SDA VAR PORTA.2
SCL VAR PORTA.3
I2C_READ CON 1
I2C_WRITE CON 0
I2C_OUT VAR BYTE
I2C_IN VAR BYTE[2]
I2C_ACK VAR BIT
a var word
a=0
top:
GOSUB CONFIG_REGISTER
GOSUB START_CONVERT
IF PORTA.1=1 THEN GOTO SALIDA
a=a+1
GOTO TOP
CONFIG_REGISTER:
GOSUB I2C_START
I2C_OUT=%10010000
GOSUB I2C_TX
I2C_OUT=$AC
GOSUB I2C_TX
I2C_OUT=$00
GOSUB I2C_TX
GOSUB I2C_STOP
RETURN
START_CONVERT:
GOSUB I2C_START
I2C_OUT=%01000000
GOSUB I2C_TX
I2C_OUT=%00000000
GOSUB I2C_TX
I2C_OUT=a
gosub i2c_tx
GOSUB I2C_STOP
RETURN
I2C_START:
HIGH SDA
HIGH SCL
LOW SDA
LOW SCL
RETURN
I2C_STOP:
LOW SDA
HIGH SCL
HIGH SDA
PAUSE 1
RETURN
I2C_TX:
SHIFTOUT SDA,SCL,1,[I2C_OUT]
SHIFTIN SDA,SCL,0,[I2C_ACK\1]
RETURN
SALIDA:
LCDOUT $FE,1,DEC A
END
mister_e
- 27th July 2005, 06:31
Another version to try ;)
' Hardware setting
' ================
'
'
SDA var PORTC.4
SCL var PORTC.3
' Variable definition
' ===================
'
'
Loop VAR Byte
' Constant definition
' ===================
'
'
DACAddressByte con %01011000 ' DAC Address byte
DACCommandByte con 0 ' DAC command byte
' Main Loop
' =========
' this loop will generate simple ramp-up and
' ramp-down on the DAC output
'
'
start:
For Loop = 0 To 255
I2CWRITE sda,scl,DACAddressByte,DACCommandByte,[Loop]
Pause 10
Next
For Loop = 255 To 0 Step -1
I2CWRITE sda, scl,DACAddressByte,DACCommandByte,[Loop]
pause 10
Next
GoTo start
RYTECH
- 13th September 2006, 22:52
Thx for posting the i2cwrite example... it helped me get my setup workin.
Powered by vBulletin® Version 4.1.7 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.