18F4550 digital input


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Jul 2006
    Posts
    76

    Default 18F4550 digital input

    Hello,

    This should be a really simple problem but I spent tons of time reading the datasheet and couldn't find a solution. I am trying to get a digital input on porta.0 and trigger a led to blind. Here is the code, but apparently I can't read digital inputs. I tried setting adcon1 to 1111 but it still doesn't work. Here's the code:

    ----------------

    rts var porta.0
    cts var portd.3
    led var portd.2

    input rts
    output cts
    output led

    adcon1 = 1111

    low led : low cts

    main:

    if rts = 1 then
    high led
    pause 5000
    low led
    pause 5000
    endif

    goto main

    -----------------

    Thanks for the help...

    -Mike

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mbw123 View Post
    adcon1 = 1111

    -Mike
    ADCON1 won't hold one thousand, one hundred and eleven.
    How about:
    ADCON1 = 15
    or
    ADCON1 = $0F
    or
    ADCON1 = %00001111
    or
    ADCON1 = $F

    and so on and so on and so on...

  3. #3
    Join Date
    Jul 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    Thanks,

    I put that in but I am still having problems. I think it has something to do with the serial port. I have connected the RTS line to porta.0. When I measure the voltage with a voltmeter with RTS on it says 10 volts. Is that too much for the PIC to handle? Also when RTS is off it says -10 volts. Is that a problem?

    Once again I apologize if this is very simple and I am wasting your time.

    Thanks.

    -Mike

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mbw123 View Post
    Thanks,

    I put that in but I am still having problems. I think it has something to do with the serial port. I have connected the RTS line to porta.0. When I measure the voltage with a voltmeter with RTS on it says 10 volts. Is that too much for the PIC to handle? Also when RTS is off it says -10 volts. Is that a problem?

    Once again I apologize if this is very simple and I am wasting your time.

    Thanks.

    -Mike
    Not wasting my time, but it sounds like you're wasting your PIC with those 10v.
    Let me guess...you're not using a MAX232 or at least a series resistor like the green manual says...

  5. #5
    Join Date
    Jul 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    "you're not using a MAX232 or at least a series resistor like the green manual says..."
    Uhhh...oops. I am using a 22K resistor on the transmitter line of the serial port but not on the RTS. What value of resistors should I place on the RTS line?

    Oh, and will my PIC work or is it completely trashed at this point?

    Thanks.

    -Mike

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mbw123 View Post
    "you're not using a MAX232 or at least a series resistor like the green manual says..."
    Uhhh...oops. I am using a 22K resistor on the transmitter line of the serial port but not on the RTS. What value of resistors should I place on the RTS line?

    Oh, and will my PIC work or is it completely trashed at this point?

    Thanks.

    -Mike
    22K is good...same voltages on RTS/CTS, but remember, it'll be inverted from normal RS-232 standards since it's not going thru a MAX-232.

    Pic might work, might not, easiest way to test is to write some code to make an LED on another port follow a switch put on the suspect port............then reverse the process...put an LED on the suspect port, put a switch on another port and make the LED follow that same switch.

  7. #7
    Join Date
    Jul 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    Wow, thanks Skimask, it appears to be working. I put the 22K resistor in and it is recognizing the voltage from the serial port.

    The one thing I didn't understand is

    "it'll be inverted from normal RS-232 standards since it's not going thru a MAX-232."

    What will be inverted?

    -MW

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mbw123 View Post
    Wow, thanks Skimask, it appears to be working. I put the 22K resistor in and it is recognizing the voltage from the serial port.

    The one thing I didn't understand is

    "it'll be inverted from normal RS-232 standards since it's not going thru a MAX-232."

    What will be inverted?

    -MW
    Well, the RX and TX lines are inverted from RS-232 standards right because you're not using a MAX232?
    Which serial modes are you using? Probably an N2400 or some other inverted mode...
    Aren't the RTS and CTS signals upside-down from what you'd expect (if they were true RS-232 standard signals)?

  9. #9
    Join Date
    Jul 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    "Which serial modes are you using"
    I am using the HSERIN and HSEROUT commands. I haven't actually tested it yet because I've been working on RTS and CTS. Do I need to use SERIN and SEROUT with the inverted modes like you suggested? Again I haven't tested any of this yet.

    The RTS and CTS appear to be correctly oriented, so I don't think I need to change that.

    Thanks.

    -Mike

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mbw123 View Post
    "Which serial modes are you using"
    I am using the HSERIN and HSEROUT commands. I haven't actually tested it yet because I've been working on RTS and CTS. Do I need to use SERIN and SEROUT with the inverted modes like you suggested? Again I haven't tested any of this yet.

    The RTS and CTS appear to be correctly oriented, so I don't think I need to change that.

    Thanks.

    -Mike
    It's all in the little green manual...

  11. #11
    Join Date
    Jul 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    OK, thanks.

    -Mike

Similar Threads

  1. Sony LanC Program
    By l_gaminde in forum Code Examples
    Replies: 2
    Last Post: - 25th September 2009, 18:51
  2. How do I get 18f452 pin 10 set as digital input?
    By jessey in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 26th May 2007, 18:32
  3. Really slow digital input
    By mbw123 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 30th March 2007, 04:06
  4. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 01:50
  5. Analog pins for digital input
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 9th September 2005, 00:32

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