IC2 pic 18f452 program problems


Closed Thread
Results 1 to 8 of 8
  1. #1
    MrSafe's Avatar
    MrSafe Guest

    Default IC2 pic 18f452 program problems

    Hi

    Hardware:

    Pic 18f452
    And I am trying to communicate and program a text to speed module.
    Heres the link to the module.

    http://www.picbasic.co.uk/forum/newt...=newthread&f=4

    The link to the tech sheet for the device:

    http://www.robot-electronics.co.uk/htm/Sp03doc.shtml

    I am using the pl1 pint section to program the unit:

    I use the SDA and SCL pins which connect to my pic.

    I am unsure how to program this unit I have tried with no success and with the unability to get any response for it. The unit has a default message which plays when you turn it on. Which is "thank you for purchasing the sp03".

    Heres my code that I am trying to use to talk with the unit:

    '************************************************* ***************
    '* Name : UNTITLED.BAS *
    '* Author : *
    '* Notice : Copyright (c) 2007 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 8/14/2007 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************
    '
    '---- Defining Modefier 4 serial in/out ----
    '
    include "modedefs.bas"
    '
    '---- Defining Oscillator ----
    '
    define OSC 4 ; Using 4MHz Oscillator
    '
    '---- Defineing Ports ----
    '
    TRISB = $00
    PORTB = $00
    TRISD = $00
    PORTB = $00
    '
    '---- Defining TX Variables ----
    '
    X var word
    Y var word
    '
    '---- Defining Variables ----
    '
    DEFINE I2C_HOLD 1
    define I2C_SLOW 1
    '
    '---- Starting Of Main Program ----
    '
    Main:
    pause 4000
    '
    Start:
    serout PORTD.0, T9600, [#80]
    pause 100
    '
    serout PORTD.0, T9600, [#00]
    pause 100
    '
    serout PORTD.0, T9600, [#04]
    pause 100
    '
    serout PORTD.0, T9600, [#02]
    pause 100
    '
    for x = 0 to 6 ; output the following
    lookup x, [$68,$65,$6C,$6C,$6F,$00],y
    serout PORTD.0, T9600, [y]
    pause 10
    next x
    '
    goto start
    '
    end

    I have also uploaded a copy of my code in a text file for anyone who needs to download it.
    All the fallowing code does is get the unit to say hello however I am unable to get it to say hello. I think first my programing code is wrong and two my hardware set up is wrong. Where do I connect the SDA pin to? and the SCL? do I simply connect the scl to a random pin on the pic? and the SDA to my data transmitting pin on the pic?
    Attached Files Attached Files

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Press F8 for MrSafe mode.

    Well, for I2C, you would use I2CWRITE, instead of SEROUT.

    The SDA and SCL can be on almost any pin. Just specify them in the I2CWRITE statement.

    P.S. Don't forget the 4.7K Pull-ups on SDA and SCL.
    <br>
    DT

  3. #3
    Join Date
    Jul 2007
    Posts
    53


    Did you find this post helpful? Yes | No

    Question Then why is there a specific SCL and SDA pins on the datasheet?

    Hi Darrel!

    Quote Originally Posted by Darrel Taylor View Post
    The SDA and SCL can be on almost any pin. Just specify them in the I2CWRITE statement.
    I know you're right, but then what's is the purpose of having specific pins listed in the datasheet for SCL and SDA? (I'm using PIC184620)

    Is there any difference between those pins and any others regarding I2C?


    J-P

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The dedicated SCL/SDA pins are for the SSP (Synchronous Serial Port).
    The SSP module can do SPI or I2C, in Master or Slave modes.

    The I2CWRITE/I2CREAD are bit bang routines that don't use the Hardware SSP, so they can use almost any pin as SDA and SCL.

    There aren't any PBP commands that use the SSP directly.
    <br>
    DT

  5. #5
    MrSafe's Avatar
    MrSafe Guest


    Did you find this post helpful? Yes | No

    Default

    thank you I have solved it.

    I have another problem I have a loop set up to where it sends messages out until the user presses a key.

    example:

    while key != 15

    gosub getkey

    serout PORTD.0, T1200, [X]

    wend
    To clarify this program sends data the first time but then waits for a user to press a key(other than 15) before sending the data again when it should send the data until the user presses a key (15).

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    If your getkey subroutine doesn't return if no keys are pressed, it'll do what you are describing.

    But it's hard to say whats wrong without seeing the getkey subroutine.
    <br>
    DT

  7. #7
    MrSafe's Avatar
    MrSafe Guest


    Did you find this post helpful? Yes | No

    Default

    Heres the subroutine for get key


    '---- Subroutine to Key from keypad ----
    '
    getkey:
    ;
    key = 0
    PortC = 0 ' all outputs pins low
    TrisC = $f0 ' bottom 4 pins out, top 4 pins in
    ;
    input PORTC
    ;
    pause 250
    ;
    PORTC = %11111110 ' row 1
    ;
    if PORTC.4 = 0 then
    key = 1
    return
    endif
    ;
    if PORTC.5 = 0 then
    key = 2
    return
    endif
    ;
    if PORTC.6 = 0 then
    key = 3
    return
    endif
    ;
    if PORTC.7 = 0 then
    key = 12
    return
    endif
    ;
    PORTC = %11111101 ' row 2
    ;
    if PORTC.4 = 0 then
    key = 4
    return
    endif
    ;
    if PORTC.5 = 0 then
    key = 5
    return
    endif
    ;
    if PORTC.6 = 0 then
    key = 6
    return
    endif
    ;
    if PORTC.7 = 0 then
    key = 13
    return
    endif
    ;
    PORTC = %11111011 ' row 3
    ;
    if PORTC.4 = 0 then
    key = 7
    return
    endif
    ;
    if PORTC.5 = 0 then
    key = 8
    return
    endif
    ;
    if PORTC.6 = 0 then
    key = 9
    return
    endif
    ;
    if PORTC.7 = 0 then
    key = 14
    return
    endif
    ;
    PORTC = %11110111 ' row 4
    ;
    if PORTC.4 = 0 then
    key = 10
    return
    endif
    ;
    if PORTC.5 = 0 then
    key = 0
    return
    endif
    ;
    if PORTC.6 = 0 then
    key = 11
    return
    endif
    ;
    if PORTC.7 = 0 then
    key = 15
    return
    endif
    ;
    goto getkey
    return
    ;
    gotkey:
    key = (col * 4) + (ncd (row ^ $f))
    '
    return
    '
    end

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Comment out the goto getkey just before GotKey:

    That will keep it from waiting for a key before proceeding.
    <br>
    DT

Similar Threads

  1. Presetting Configuration Fuses (PIC Defines) into your Program
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 82
    Last Post: - 15th December 2013, 09:54
  2. Replies: 288
    Last Post: - 25th August 2008, 16:53
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. Replies: 14
    Last Post: - 26th September 2007, 05:41
  5. Which pic has a big flash program memory?
    By amindzo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 1st November 2006, 19:35

Members who have read this thread : 1

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