PDA

View Full Version : 18F4550 digital input



mbw123
- 28th March 2007, 17:11
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

skimask
- 28th March 2007, 17:18
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...

mbw123
- 28th March 2007, 17:54
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

skimask
- 28th March 2007, 17:58
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...

mbw123
- 28th March 2007, 18:07
"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

skimask
- 28th March 2007, 18:12
"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.

mbw123
- 28th March 2007, 18:30
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

skimask
- 28th March 2007, 18:35
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)?

mbw123
- 28th March 2007, 18:43
"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

skimask
- 28th March 2007, 22:36
"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...

mbw123
- 29th March 2007, 02:43
OK, thanks.

-Mike