Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC Problem

Status
Not open for further replies.

Jumpingfork

New Member
Right now I'm attempting to build a circuit using 5 output pins and 5 input pins on a PIC18F2410. I need to simultaneously send 5 different signals through my outputs and have them received on a corresponding input pin. I can't just use a standard high/low signal because I need to be able to tell which signal is coming in on which pin, so I need each signal to be distinguishable from the next. I would prefer not to use analog signals because I wont be using shielded wire. Is there a way to send 5 different types of data through each pin? Any help would be much appreciated-
 
If all your inputs and outputs are on the same PIC, the easiest way is to make just one output go high at a time. When an input goes high, it must be connected to the output that has gone high.

That is how keyboards are scanned. If you look at a laptop keyboard, that has no electronics in it, there are only about 20 wires for about 100 keys.
 
Send Binary out the output
key1 you send 0001 key2 you send 0010 key3 you send 0011
key4 you send 0100 key5 0101 Make you a table for the keys then you can send it to any input and no where it came from . Also turn on more then 1 at time.
 
You do the output part
Code:
output1      equ      0x1   ;would write 0001 where you send it
output2      equ      0x2   ;would write 0010 where you send it
output3      equ      0x3   ;would write 0011 where you send it
output4      equ      0x4   ;would write 0100 where you send it
output5      equ      0x5   ;would write 0101 where you send it
you have to define where this table will start for the 18F2410
 
Last edited:
I tried writing

TRISBbits.TRISB0 = 0;
TRISBbits.TRISB1 = 0;
PORTBbits.RB0 = 0x2;
PORTBbits.RB1 = 0x3;

-but when I load that onto the PIC I've got no output from either one of those pins.
 
If I new what you where really trying to do I could help you better you say you want to send 5 outputs to 5 inputs on the same pic. What is it going to do. Most times you would like press a button that would make a output. Or send the output to a input to be read then send that back out
Lets say you have 5 leds 1 button you press the button 1 time it sends a 0001 that turns on output 1 you then press it 2 times it turns on output 2 you press it 3 times to turn on output 3 and so on till you get to 5 at 5 it starts back all over.
 
This is basically going to be a continuity checker. There aren't going to be any loads on these wires. I simply need to send 5 different signals down 5 different wires and have them received on a specific input pin. The purpose of this is to determine if any of these 5 wires have been crossed. If input pin#4 receives an output#5 signal instead of an output#4 signal need the PIC to be able determine that and display the appropriate message. This is why I cant use a simple High/Low signal, because a "High" signal from output #5 would be the same as a "High" signal from an output #4 signal. I need each input pin to know where its getting it's signal from.
 
Can you draw it out? Im trying to understand but i cant. I dont see why you cant use a high/low if each pin has its own input/output. its a 1:1 ratio. You can read the PORT and easily determin which pin is high and there for easily determin which pin set it high.

PORTA -- PORTB
OUT -- IN
----------------
RA0 -- RB0 (if RB0 is high then RA0 is high)
RA1 -- RB1 (if RB1 is high then RA1 is high)
RA2 -- RB2 (if RB2 is high then RA2 is high)
RA3 -- RB3 (if RB3 is high then RA3 is high)
RA4 -- RB4 (if RB4 is high then RA4 is high)
 
Thats a lot of chip for that you can do that easy when I get back in about 2 hours I'll try to post you some code all you need is 5 inputs. Your going to use 2 chips right 1 to send and 1 to receive or just 1 chip doing both.
 
RAO -- RBO
RA1 -- RB1
RA2 -- RB2
RA3 -- RB3
RA4 -- RB4 Display reads: All wires good

RA0 -- RB0
RA1 -- RB1
RA2 -- RB3
RA3 -- RB2
RA4 -- RB4 Display reads: 3rd and 4th wire crossed

I work on airplanes in the USAF and we have these wire bundles that always go bad, which are composed of 5 wires. We build these wire bundles ourselves, so some of the wires inside are often crossed. The only way to determine which wires have been crossed is to use a multimeter which is tedious work. Thats why I'm trying to build something that will determine where each signal is coming from. I'm not trying to activate anything with this, just simply boomerang five signal back to the microcontroller.
 
oh ok i see now. Simple then ...

Have it send out pulses. 20 Pulses for RA0 etx

RA0 = send 10 pulses
RA1 = send 20 pulses
RA2 = send 30 pulses
RA3 = send 40 pulses
RA4 = send 50 pulses

Then have it check on the other side like count every pulse
Count must start on a high and increase every other high.

RB0 = must count 10 pulses
RB1 = must count 20 pulses
RB2 = must count 30 pulses
RB3 = must count 40 pulses
RB4 = must count 50 pulses

Or you can do like "be80be" said

send out numbers. like number 4 in binary is 0100 so you can have it have a clock line so you can determine when new data is being clocked in.

So to send a 4: (0100)
---------------------------
Set Clock pin high , Data pin low(0), set clock pin low
Set Clock pin high , Data pin high(1), set clock pin low
Set Clock pin high , Data pin low(0), set clock pin low
Set Clock pin high , Data pin low(0), set clock pin low

That will send a 0100 aka 4.

On the recieve side you would have to shift in the bits 1 by 1 into a byte(nybble) on every clock high
 
Last edited:
Somewhat like:
Code:
char x;
char data = 0x04;    // data to ouput

    for(x=0;x<4;x++){   //loop through only 4

        if((data & 0x08) != 0) //if the 4th bit != 0 then
            temp = 1;          //its a 1
        else                   //else
            temp = 0;          //its a 0

    clockPin = 1;    // Set the clock high
    dataPin = temp;  // send the data pin (high or low)

    data=data<<1;    // Shift the data to get next bit

The issue here is since it is all on the same pic it will be hard to do you would have to send and check all in the same routine. The above would would if you modify it more. But as is it would work only on 2 separate pics.
 
If you what to no which pin is wired right this would be the easy way to do it hook up 5 leds to plug on one end then turn on 1 pin at a time for 1 sec then you'll no which wire is right.
 
I don't have a 18f2410 just tried some code for mplab sim to see if it worked and thats what 1 said to myself why not just press a button 1 for each output it would lite which wire is where and tale if 1 is broke but a 18f2410 is over kill for this you don't even need a pic. 5 leds and 5 resistors 5 pcb switches and 9 volts. But something to play with.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top