Pic18f252,dacmax518 And I2c?


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    angelika's Avatar
    angelika Guest

    Default Pic18f252,dacmax518 And I2c?

    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)

  2. #2
    seinfield's Avatar
    seinfield Guest


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Another version to try
    Code:
        '   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
    Last edited by mister_e; - 27th July 2005 at 06:35.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default

    Thx for posting the i2cwrite example... it helped me get my setup workin.

Similar Threads

  1. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 22:31
  2. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  3. PIC16F877 I2C programme
    By cooqo in forum mel PIC BASIC
    Replies: 3
    Last Post: - 21st April 2008, 10:02
  4. I2C Master Slave issues.
    By cpayne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2008, 19:33
  5. Please help with i2cslave i2c slave
    By cycle_girl in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st December 2005, 13:55

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts