I was trying to use serin command. Cause the chip is parallel in - serial out. Do I need to sent a special signal for CP, or PBP takes care of that ?
I was trying to use serin command. Cause the chip is parallel in - serial out. Do I need to sent a special signal for CP, or PBP takes care of that ?
Serin is for asynchronous serial communication and can't be used with that shiftregister. You need to use Shiftin which is for synchronous serial communication.
With the Shiftin command you specify two pins, one for the data and one for the clock. First you need to load/latch the data into the shiftregister by pulsing the PL pin, then the Shiftin command is used to shift data out of the '165 and into the PIC.
I understang you are mentionning two pins, one clocking and one input. Although the datasheet mentions PL and CP for input, Then Q7 for serial output. That would mean three pins, so we dont need CE pin ??.
K
Last edited by lerameur; - 13th December 2010 at 13:45.
I think I have things cleared up. Data is Q7, Clock=CP, Pulse=PL (send a signal to receive the byte with shiftin command) and CE is grounded. ?!?
Hi,
Yes, PL is parallel load - a logic low level on this input is what loads the shiftregister with the 8 databits. This way you know that all bits you shift in is from the "same moment in time". The Shiftin command does not handle this pin for you, you need to pulse it "manualy".
Correct, Q7 is the serial output of the shiftregister.
CE is chip enable or clock enable if you like, pull it low to use the CP pin as a positive clock input or tie the CP high and use the CE pin as a negative clock input.
Note that the '165 does not "send" the data out when you pulse the PL pin. It is the Shiftin command that "pulls" the data out of the shiftregsiter. Shiftin generates the clock pulses the '165 uses to shift the databits thru the shiftregister.
Also the PL (parallel load) signal needs to be High in order to clock data out of the serial data pin, but also needs to go low in order to sample the data on the parallel pins. Simplest thing to do is to invert the CE signal and use that to control the PL signal. That is how I turned the HC165 into a simple SPI-like interface (Clock, Data out, and Chip Enable).
Tim Barr
Ok, I understand pretty much how the chip works, it was the bridge between how Picbasic language treat the shiftin code that was troubling me.
Ok I have this code on a Pic16F887, I am only getting '00' as my output, I tried switcing ports ( CP and PL just to see, but no luck). My parallel input have random 0 and 5v for try out.
Code:'@ __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF OSCCON = %01110000 '8 Mhz DEFINE OSC 8 ANSELH = 0 '///////////////////////// '// LCD configuration // '///////////////////////// DEFINE LCD_DREG PORTB ' Set LCD Data port DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus RB.4, RB.5, RB.6, RB.7 DEFINE LCD_RSREG PORTB ' Set LCD Register Select port DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit DEFINE LCD_EREG PORTB ' Set LCD Enable port DEFINE LCD_EBIT 0 ' Set LCD Enable bit DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits) '4 therefore put wire at 4, 5, 6 and 7 of LCD DEFINE LCD_LINES 2 ' Set number of lines on LCD DEFINE LCD_COMMANDUS 2500 DEFINE LCD_DATAUS 250 DEFINE CHAR_PACING 2000 pause 500 TRISE = %11111100 ' Set PORTE to all input Clock var PORTE.0 'CP Load var PORTE.1 'PL Data_1 var PORTE.2 'Q7 out input1 var byte Mainloop: pulsout Load,1 shiftin Data_1,Clock,0,[input1 \8] lcdout $FE,1, "Shift in" lcdout $FE,$C0, dec2 input1 pause 300 GOTO Mainloop End
Bookmarks