PDA

View Full Version : Problem with peek in portB



hawk72501
- 26th August 2005, 18:16
Hi guys. I have connected 8 wires with 5 volts at the 8 pins of portB .PortC is ok.It makes only a serial communication and i have tested it.

I made that program in order to understand when the wires are 0V or 5V and which of these are 0V or 5V .For example if the RB7 takes 1 (+5 volts)and the others 0 (0volts) i want to take the number 127.

INCLUDE "modedefs.bas"

TRISB=%11111111 (i make them all inputs)
TRISC=%00000010
B0 VAR BYTE



loop:
Peek PORTB,B0

SerOut2 PORTC.0,84,["I took:",DEC B0,13,10]

GoTo loop

But it doesn't work this way.fOR EXAMPLE when i had 5 volts only at RB0 (and the others had no voltage) i took number 5 and not 1 as i expected.

hAS anybody any idea how to do it? Thanks

mister_e
- 27th August 2005, 12:01
It's not revelant to your problem but ss you probably have PBP, you don't need to use PEEK or POKE. just use


MyVar var byte

MyVar=PORTB

BUT


fOR EXAMPLE when i had 5 volts only at RB0 (and the others had no voltage)


By NO VOLTAGE do you mean that those pin are left floating??? IF so pull-down resistor will help.

A PIC can't read nothing... it's 1 or 0. So you must set your pin to VDD or VSS with jumper or with resistor. Common val;ue for pull-down/pull-up 10K or less. AND, personally, when i use to set a pin to VDD or VSS i add a resistor in serie for current limiting.