Shiftin on 16F628 changes input A.2 to output?


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2012
    Posts
    57

    Cool Shiftin on 16F628 changes input A.2 to output?

    Hello,

    I have a strange thing going on here...
    I try to decode serial information (shift register) to 2 seven-segment displays.
    This is the code:
    Code:
     DEFINE OSC 8
     CMCON = 7
     TRISA = %11111100             ' PORTA.0 and PORTA.1 = Outputs (Anodes Displays)
     TRISB = %00000000             ' PORTB = Outputs (Cathodes Displays)
    
     W  Var Word                   ' Variable for ShiftIn 
     PORTB = 255                   ' All Cathodes High, display off
     PORTA.0 = 0                   ' Anode Low, display off 
     PORTA.1 = 0                   ' Anode Low, display off
    
    ' PORTA.2 = Clock in
    ' PORTA.3 = Data in
    ' PORTA.4 = Latch in
     
     MainLoop:
       ShiftIn PORTA.3, PORTA.2, 0, [W\16]  
     WaitLoop:                     ' Wait for the Latch to go High
       If PORTA.4 = 0 then Waitloop  
       PORTB = (W & 255) XOR 255  ' PORTB = Lowest 8 Bits
       PORTA.0 = (W >> 8) & 1     ' PORTA.0 = Anode display
       PORTA.1 = (W >> 8) & 2     ' PORTA.1 = Anode display
     Goto MainLoop
    The strange thing is that PORTA.2, although configured as input, is changed to an output!
    If a comment the 'ShiftIn' out, PORTA.2 stays an input.
    I am sure I am overlooking something, but what????

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Default Re: Shiftin on 16F628 changes input A.2 to output?

    Hi,

    Might be you are somewhat mixing "Shiftin" and "Serin" commands ...
    just have a look to manual $ 5.74 to be convinced.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Feb 2012
    Posts
    57


    Did you find this post helpful? Yes | No

    Default Re: Shiftin on 16F628 changes input A.2 to output?

    I have the manual in front of me and I definitely don't want SerIn!
    I am not dealing with serial data (as with a COM-ports), but I am trying to emulate a shift register.
    But even if there was confusion, there is still no explanation why an input would change into an output!
    Should I leave the TRISA out and let ShiftIn handle the port status?

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Shiftin on 16F628 changes input A.2 to output?

    Hi,
    You are asking it to use PortA.2 as the clock output during the SHIFTIN
    Code:
    ShiftIn PORTA.3, PORTA.2, 0, [W\16]
    See, PortA.3 is the data input, PortA.2 is the clock output, so it has to change from input to output or the SHIFTIN wouldn't work.

    You can't use SHIFTIN to move data from an external device where that device provides the clock. With SHIFTIN the PIC provides the clock the external device.

    /Henrik.

  5. #5
    Join Date
    Feb 2012
    Posts
    57


    Did you find this post helpful? Yes | No

    Default Re: Shiftin on 16F628 changes input A.2 to output?

    OK, so that is the problem!
    I thought this was a way to emulate a shift register, but I didn't realise that ShiftIn was generating the clock, instead of accepting a clock!

Similar Threads

  1. Problem with switch input on 16f818
    By tasmod in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 20th December 2014, 09:26
  2. input logic threshold level for pic 16F628
    By aratti in forum General
    Replies: 4
    Last Post: - 29th December 2008, 11:35
  3. Input / output using same pin
    By leonel in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th March 2007, 21:19
  4. hserin 16f628 formatted output
    By detail in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 27th June 2005, 01:57
  5. Using 4 input to control 10 output
    By cibotsan in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th November 2004, 12:08

Members who have read this thread : 0

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