PDA

View Full Version : Trying to read PortC



BobK
- 8th November 2004, 01:27
Hello,

I am building a notification system consisting of 20 8-zone cards. I am using a 16F74. PortC has inputs 0 thru 4 as a card ID and outputs 5, 6, & 7 to address the 4051 multiplexer. What I am trying to do is read the whole port so I can send it first to a serial LCD then once this is done and working I want to send it out on an RS 485 loop to a master card that would then take the card Id and the address of the input being scanned by (5, 6, & 7).

I have set up my program with B0 as a Var Byte with B0 = PortC and the only value that displays is the card ID.

Should the whole port get read regardless of whether the pin is an input or an output?

Can any one out there lend a hand here and offer me some advise please?

Thanks,

BobK

mister_e
- 8th November 2004, 03:30
Hi BobK

TRISC=%00011111 ; set b0-b4 to inputs, B5-B7 to output

ReadFromPortC VAR BYTE
SendToPortC VAR BYTE
ValueToB5_B7 VAR BYTE

ValueToB5_B7 = 3

ReadFromPORTC = PORTC & $1F ;read from PORTC and
;isolate B0-B4 from other bits


PortC.5=ValueToB5_b7.0 ;send to PORTC
PortC.6=ValueToB5_B7.1 ;the result of ValueToB5_B7
PortC.7=ValueToB5_B7.2 ;

.....

If all the result are comming from PORTC.....

TRISC = 255
ValueFromB5_B7 VAR BYTE
ValueFromB0_b4 VAR BYTE

ReadFromPORTC=PORTC

ValueFromB5_B7=ReadFromPORTC & %11100000
ValueFromB0_B4=ReadFromPORTC & %00011111

BobK
- 9th November 2004, 00:28
Hi Steve,

Thanks for the reply. I already have the line
TRISC=%00011111 in the setup of my code. I'm a bit confused with your response. Do I have to strip off each part, meaning the input pins separately from the output pins and then send them out as separate bytes on the serial send then handle each one separately on the receive end?

What I will be doing with the data sent from each card is to have the master card then send to a serial printer the date and time along with the location information which is derived from the card ID and which input on the card that triggered the input.

I am using a 4051 1of 8 analog multiplexer that feeds the signal to a pair of comparators that tells the 16F74 whether the loop is open or shorted. These two conditions are of importance as to the manner in which there would be a response.

The main portion of the program has been working great and I've just gotten my first 2 boards built and I'm getting ready for field testing. Just working on further enhancements.

If it would help for me to send my code listing, let me know & I'll attach it.

Thanks again, Steve.

BobK.

mister_e
- 9th November 2004, 04:27
Hi BobK, fort sure if you can post,attach your code it will help. Any schematic, if possible will help too.

regards

BobK
- 9th November 2004, 09:30
Hi Steve,

Attached you should find a listing of my code. I will send the schematics separately.

Bob K.

BobK
- 9th November 2004, 09:40
Hi again Steve,

Here is the main portion of the schematic.

BobK.

BobK
- 9th November 2004, 10:16
Steve,

The concept of what I am doing is this:

I have two switches. One that is normally open and then other that is normally closed. They are connected together on the same loop with a 1K resistor that allows me to indicate an open loop and a shorted loop. The open loop indication shows a green led and the shorted loop shows a red led. The red overrides the green as the red is more important in this situation.

When the shorted condition occurs, the beeper output goes out on a bus for 1 second which is picked up by the master board that turns on a pulsing beeper until someone silences it by pressing the silence button. The green led does nothing more than indicate that the condition exists.

What I am trying to do now is create a serial output that would be picked up by the master board which would compare the message to a lookup table and then send the data to a serial printer along with the date and time of the event.

I hope this helps.

Thanks.

BobK.