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????
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
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?
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.
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!