# input and output on the same pic pin ?

Status
Not open for further replies.

#### kutkm_ti

##### Newbie level 5
now i face a problem,
i no have any extra pin, so i need to drive a 7 segment led(commom anod) and at the same time, i need input for a push button,

tell me how to do...

any suggestion about when i push the button, it will not affect the led either on or off?

pin-->resistor-->led--> +5v

at the same pin, it will connect to a push button also.

#### A.Anand Srinivasan

use two buffers for each of the input and multiplex the input....

what circuit is that you are designing which needs this kind of inputting???....

#### kutkm_ti

##### Newbie level 5
A.Anand Srinivasan said:
use two buffers for each of the input and multiplex the input....

what circuit is that you are designing which needs this kind of inputting???....

what buffer?

the problem is : may i drive the led(commom anod) and read the pin input at the same time? reading the input pin just need take 1us only, but many configuration will make the led not working when i push the button...

any suggestion (without use any external IC) to realise that?

#### dilan2005

##### Member level 4
why u bother so much on 1us
the people can see the 1us off of the led.

any way you can't keep the led on /off ,and same time get a input.need some more circuitry

if you have some shift register you can do it easily

i just attached on of my idea

any way led will be off at 1us
the transistor will off entire 7 segment at the time of reading of push button

GOOD LUCK

#### kutkm_ti

##### Newbie level 5
my idea is similar like u, i'll try ur circuit, it may use on my project...

dilan2005 said:
why u bother so much on 1us
the people can see the 1us off of the led.

any way you can't keep the led on /off ,and same time get a input.need some more circuitry

if you have some shift register you can do it easily

i just attached on of my idea

any way led will be off at 1us
the transistor will off entire 7 segment at the time of reading of push button

GOOD LUCK

#### A.Anand Srinivasan

use analog mux.... since you need only 1µs for your switch functioning i think analog mux is the best idea.... analog mux consists of nothing but a MOSFET which acts as a switch and it is bidirectional.... you can multiplex them i.e.give a clock as input to selection line so when it is high one line say the switch gets selected and when it is in low the LED circuit will be selected.... this 1µs will not be noticed due to the storage time of the LED....

#### nguyennam

kutkm_ti said:
now i face a problem,
i no have any extra pin, so i need to drive a 7 segment led(commom anod) and at the same time, i need input for a push button,

tell me how to do...

any suggestion about when i push the button, it will not affect the led either on or off?

pin-->resistor-->led--> +5v

at the same pin, it will connect to a push button also.

So you need to "toggle" the function of input and output on the same port pin, this technique is very popular in microcontroller circuits, that you have to get familiar with as soon as possible.

Some websites that must be useful for you:
1. www.microchip.com, of course.
2. www.piclist.com, the best forum for PIC users of the world.
3. www.mikroelektronika.co.yu/english/, the free online PIC books.

For example, you may find out at Microchip website the application note AN557 (Four Channel Digital Voltmeter with Display and Keyboard) with source codes, in which there are 4 subprograms of 4 degrees, you will find out the needed subprogram with the technique for toggling input/output functions. This AN557 is very comprehensive for the PIC beginers.

nguyennam

#### Mike K8LH

##### Full Member level 2
Show us the schematic of your existing circuit, please? How many 7-segment displays?

Mike

If you're using something of a 'traditional' 7 segment display setup you should be able to implement a single-pin column driven switch matrix. This will however require an additional pin.

Since you're only ever driving 1 column driver transistor low at any given time, connect each switch through a diode for isolation to that active low PIC pin. You really should be using an interrupt service routine for driving the display and this routine should be selecting and driving a different PIC column pin each interrupt cycle. I normally use a "ring counter" variable to keep track of the column number and I use it as a mask for testing the switches (test 1 switch each interrupt).

Code:
;
comf    COLPOS,W        ; example ~Column 3 = 11110111
andwf   SWITCH,F        ; turn off switch flag bit
movf    COLPOS,W        ; example Column 3 = 00001000
btfsc   PORTA,SwInPin   ; switch pushed? no, skip, else
iorwf   SWITCH,F        ; indicate switch pressed (1)
;
;  advance column ring counter for next interrupt cycle
;
rlf     COLPOS,W        ; rlf into W to preserve C
rlf     COLPOS,F        ; (similar to 18F rlncf instruction)
;

Status
Not open for further replies.