Trying to read PortC


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352

    Default Trying to read PortC

    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

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Default

    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.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Hi BobK, fort sure if you can post,attach your code it will help. Any schematic, if possible will help too.

    regards
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Default

    Hi Steve,

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

    Bob K.
    Attached Files Attached Files

  6. #6
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Default

    Hi again Steve,

    Here is the main portion of the schematic.

    BobK.
    Attached Images Attached Images  

  7. #7
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Default

    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.

Similar Threads

  1. Cleaning up code
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2009, 07:14
  2. SEROUT WORD variable problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th April 2009, 11:20
  3. Q: using MCLR for Input on 12F683
    By picster in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 31st January 2009, 15:25
  4. MY FIRST scrolling 8X8 LED
    By earltyso in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th August 2008, 16:23
  5. How do I configure the PIC16F737?
    By LinkMTech in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 18th November 2007, 23:05

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts