PDA

View Full Version : How do you interface a 74hc165 to a pic12f629



orion1137
- 6th March 2004, 20:39
Hello all im new to the pic basic so be easy on me. I am trying to interface a standard 74hc165 parallel to serial shift register to a pic 12f629 im using GPIO.0 as CLK OUT , GPIO.2 as the DATA INPUT pin and a push button to load the parallel inputs on the 74hc165 via the Serial Shift/ Parallel Load pin, I have a 8 bit dip switch connected to the parallel port of the 74hc165 with 4.7k pullups and ground when switch contact is closed. I have looked at the SERIN and HSERIN and just havent had any luck yet.

NavMicroSystems
- 6th March 2004, 23:47
You need to use SHIFTIN.


---------------------------
CMCON=7

MyByte VAR Byte

SHIFTIN GPIO.2,GPIO.0,0,[MyByte]
---------------------------

I don't have a HC165 Datasheet available, make sure the mode matches the specs of the HC165.

See PBP Manual Section 5.72

orion1137
- 7th March 2004, 02:08
Thank you!! Works like a charm. I got most of it from the Archives. Here is a cleaned up version.

Low GPIO.0

' pin 1 of 74HC165 loads parallel port

Pause 1

High GPIO.0

' pin 1 of 74HC165 allow data to shift in

ShiftIn GPIO.2,GPIO.1,0, [VAR1\8]

'GPIO.2 to 74HC165 pin 9 and GPIO.1 to 74HC165 pin 2

Pause 1

Demon
- 5th February 2005, 04:39
"I got most of it from the Archives."

Is this on this forum?

I SEARCHed and could not find any other reference to 74HC165.

I am particularly interested in how the 74HC165 is wired.

Robert
:)

Demon
- 5th February 2005, 06:22
"See PBP Manual Section 5.72"

I get SERIN2 in my copy...? SHIFT IN is over at 5.75.

Robert
:shrug:

Demon
- 5th February 2005, 18:38
I have tried to interface a 16F628 with a 74HCT165 without success. I figured I should do a basic test to confirm that my code is working properly. I unplug the CK and PL pins and plug the Q7 pin on the PIC directly to power to test my code.

- when I plug Q7 to GND, I get all 0s, as expected.

- when I plug Q7 to +5V, I get all 0s and a 1 at the far right.

This is my code:

CMCON = 7
ASM
LIST
INCLUDE 'M16F62X.INC'
DEVICE PIC16F628, HS_OSC, WDT_ON, MCLR_OFF, PWRT_ON, LVP_OFF, PROTECT_OFF
XALL
NOLIST
ENDASM
INCLUDE "MODEDEFS.BAS"
TRISA = %10000000
TRISB = %00000001
DEFINE OSC 20
DEFINE SHIFT_PAUSEUS 3
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTA
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTA
DEFINE LCD_EBIT 1
DEFINE LCD_BITS 4
DEFINE LCD_LINES 4
DATAIN VAR BIT[16]
' ----- PORTB.0 = Q7 ----- PORTB.1 = CP ----- PORTB.2 = PL -----
PAUSE 500
LOW PORTB.2 : PAUSE 3
HIGH PORTB.2 : PAUSE 3
SHIFTIN PORTB.0,PORTB.1,MSBPRE,[DATAIN\16]
LCDOUT $FE,1,BIN16 DATAIN
END

Robert
:(

Demon
- 5th February 2005, 18:41
Note: same results no matter what shift mode I use.

I've cut out those lines of code to simplify reading on this forum, but I repeat the shift command 4 times using each mode and display 4 lines on the LCD.

Robert
:)

Another note, I am chaining two 74HCT165s, hence 16 bits.

Demon
- 5th February 2005, 18:57
Ok,

I changed the data to a BYTE, reduced 16 in the shift and LCD commands down to 8 and my test signal worked.

I don't see what it did not like about having 16 bits?

Robert
:shrug:

Demon
- 5th February 2005, 19:01
I added one step to my testing, adding a 2nd BYTE of data in the shift and LCD commands and the test signal works good too.

So it likes 2 BYTES, but not 16 BITS, I can live with that...

I think it was Ralph that said in the PIC-TO-PIC thread, "one thing at a time".

Robert
;)

Demon
- 5th February 2005, 19:07
Thank you Ralph and a HUMUNGOUS thank you to Mister E for his patience with a newb like me.

Un gros bisou mon amour! :LOL:

It works like a charm now, I can flick my bits like I want to.

Robert

mister_e
- 5th February 2005, 22:48
Hehe... sti d'fif ;)

Great to know everything is working fine now.

Demon
- 6th February 2005, 05:10
I'm going to write "74HCT166" in this thread, just so that the next guy that searches for that chip can find this thread.

I started out using the 166, but the 165 is also good for my application. Maybe including the word here can save someone else the headaches I had trying to get the 166 to work.

Robert
:)

Oh yeah, might as well include the other variants:

74HC166
74LS166