PDA

View Full Version : 74HC/HCT166 shift register datasheet, error...?



Demon
- 28th January 2005, 02:22
Hi,

Wasn't sure where to ask this, figured I'd start here. NEWBIE ALERT! WOOT!

I'm trying to shift bits in and out of a PIC 16F628 using a 74HC166 as input and a 74HC164 as output with little success.

I don't understand the Function Table on p.4 of the datasheet for the 166. They mention Q0-6 registers, and yet there is only a Q7 mentionned in the Functional diagram at the top of that page, nor on the Logical diagram on the next page, nor on the Process diagram below that one. The only 0-7 pins are the D pins, not Q.

I'm trying to figure exactly how it is I am supposed to initiate SHIFT IN and SHIFT OUT commands and I'm going nowhere. I've scoured the web for schematics using these 2 shift registers as well as BASIC code to go along with them and have come up 'basically' empty-handed.

Any help would be greatly appreciated.

Thanks, and have a nice day!

Robert
:)

Demon
- 28th January 2005, 17:26
Does PIC BASIC Pro support the hardware requirements for SHIFT IN/OUT commands? Let me add a little more, does it take care of the communication protocol like MBASIC?

MBASIC can process SPI communication with any I/O pin through software. It does not necessarily have to use a pin designated for SPI, like pins RC3,4 and 5 on the PIC 16F877; labelled as SCL, SDA and SDO respectively.

I am having some serious problems trying to get a PIC 16F628 to perform SHIFT IN/OUT commands with PIC BASIC Pro and I was wondering if my problem was with my selection of chips.

Robert
:)

mister_e
- 28th January 2005, 20:45
Hi Robert, Glad to se i'm not the only one close to montreal here.



MBASIC can process SPI communication with any I/O pin through software. It does not necessarily have to use a pin designated for SPI, like pins RC3,4 and 5 on the PIC 16F877; labelled as SCL, SDA and SDO respectively.

I am having some serious problems trying to get a PIC 16F628 to perform SHIFT IN/OUT commands with PIC BASIC Pro and I was wondering if my problem was with my selection of chips.


i'm about to think you're using the PORTA. Add this line to the top of your code

CMCON=7

This one disable the internal analog comparator.

If it's not working, can you provide your code here. That way it will be more easy to see what you do.

regards

Demon
- 28th January 2005, 21:10
Bonjour Steve!

Yup, I thought of that, same with PAUSEUS. I also use a button to shift in new data after I've sent +5V DC to one of the input pins on the 74HC166. Here's all my code, I even left in the indicator LEDs I've been using to display results:


INCLUDE "MODEDEFS.BAS" ' Serial I/O modes

ASM
LIST
INCLUDE 'M16F62X.INC' ; PM header
DEVICE PIC16F628, HS_OSC, WDT_OFF, PWRT_ON, MCLR_OFF, LVP_OFF, PROTECT_OFF
XALL
NOLIST
ENDASM

DEFINE OSC 20 ' Set oscillator speed
DEFINE SHIFT_PAUSEUS 3 ' Slow down SHIFT in/out commands by 3uSECS
CMCON = 7 ' Set PORT A pins to digital

SHFTIQ7 VAR PORTB.0 ' Input data
SHFTICP VAR PORTB.1 ' Input clock pulse
SHFTICE VAR PORTB.2 ' Input clock enable
SHFTIPE VAR PORTB.3 ' Input parallel enable

BUTTONI VAR PORTA.4 ' Input user entry

LED1 VAR PORTA.2 ' Bit active indicator
LED2 VAR PORTA.3 ' Loop indicator

LOOP VAR BYTE
DATAI VAR BIT[16]
HIBIT CON %1
HIBYTE CON 1

START: DATAI = 0 ' Initialize variables
LOOP = 0

GOSUB REQBUT ' Wait for user input

LOW SHFTIPE ' Initiate parallel load of bits
LOW SHFTICE
GOSUB CYCCLK

HIGH SHFTIPE ' Initiate serial shift of bits
LOW SHFTICE
GOSUB CYCCLK

HIGH SHFTICE ' Initiate hold of shift registers

SHIFTIN SHFTIQ7,_ ' Shift in bits from registers
SHFTICP,_
LSBPRE,_
[DATAI\16]

FOR LOOP = 0 TO 15 ' Check bits for a high bit
GOSUB BITNUM
IF DATAI = HIBIT THEN
GOSUB HIFND
ENDIF
NEXT LOOP

GOTO START ' Restart processing

FINISH: END ' Terminate processing


' SUB-ROUTINES


REQBUT: GOSUB FLASH ' Process user input
IF BUTTONI <> HIBYTE THEN GOTO REQBUT
RESUME

FLASH: HIGH LED1 ' Indicate waiting for user input
HIGH LED2
PAUSE 250
LOW LED1
LOW LED2
PAUSE 250
RETURN

CYCCLK: LOW SHFTICP ' Cycle clock pulse
HIGH SHFTICP
RESUME

BITNUM: HIGH LED2 ' Indicate bit number within string
PAUSE 250
LOW LED2
PAUSE 250
RETURN

HIFND: HIGH LED1 ' Indicate bit is high
PAUSE 250
LOW LED1
PAUSE 250
RETURN

If I jst connect the input pins to the PIC to GND, all the bits are 0, if I connect to +5V DC, all the bits are 1, which is what I expect. I'm stumped.

Robert
:(

Dwayne
- 28th January 2005, 21:30
Hello Robert,

I didn't have time to go through your code all the way, but one thing that I would add to the top...For safty sake.
I can't remember but I think porta.5 is your MCLR so you are ok there.

TRISB=%00001111
TRISA=%00011111


I must go... Works a calling.

Dwayne

mister_e
- 28th January 2005, 22:13
dwayne

When you're using LOW or HIGH it make pin automatically as output. BUT i agree TRIS setting is always a safe practice.

robert



DATAI VAR BIT[16]

.
.
.
.
SHIFTIN SHFTIQ7,_ ' Shift in bits from registers
SHFTICP,_
LSBPRE,_
[DATAI\16]


what about if you change your variable DATAI as follow

DATAI VAR WORD 'it's now 16bits

and then change


FOR LOOP = 0 TO 15 ' Check bits for a high bit
GOSUB BITNUM
IF DATAI.0(LOOP) = 1 THEN
GOSUB HIFND
ENDIF
NEXT LOOP


BUT using your code without changing VAR definition (was DATAI VAR BIT[16] )


FOR LOOP = 0 TO 15 ' Check bits for a high bit
GOSUB BITNUM
IF DATAI [LOOP] = 1 THEN
GOSUB HIFND
ENDIF
NEXT LOOP

and also i see some RESUME that must be change to RETURN. RESUME are use for interrupts.

for now, it's the only thing i can see. I didn't check the Datasheet for the shift register as now. Wait for your relply on that.

A la prochaine

Demon
- 28th January 2005, 23:48
RESUME? ARGH!!! I meant RETURN.

What a bobo...?

Robert
:lol:

Demon
- 29th January 2005, 02:22
Hi guys,

I added the TRIS definitions, but no go. Also, although a pin like CP is referred to as the 'Input clock pulse', it remains an output pin since the PIC is sending this signal to the 74HC166. But no matter, that's not the problem either.

I also put the [LOOP] back in when comparing the individual bits to %1, I lost that along the way with the multitude of changes, not that either.

I've come up with an alternative method of achieving my goals. The other thread discussing QBASIC has given me an idea that could greatly improve my design, making it more flexible, less complicated and much more user-friendly. I'll explore that for a while and fall back on this if the other option doesn't pan out.

Having graduated from Champlain College in 1983 in Data Processing, some water has flowed under the bridge since the last time I've used QBASIC. I've been a mainframe programmer using COBOL since then.

Merci!

Robert
:)

mister_e
- 29th January 2005, 10:04
Qbasic..... yukkk, well it's still working with some POKE and PEEK but in 2005, i'll prefer use VB or Visual C.

Qbasic remind me those TI-99/4A, TRS80, Comodore VIC-20, Comodore 64 and 128, Zinclair Z81, Tandy 1000, CoCo 1 & 2 and how many more stone age stuff working with cassette tape to store program. Looks like we all become older ;)

BTW, tell us more about what you're going to expect with your code i.e what goes in and how, what you do at the end,

In brief what is suppose to do. As we can have many solutions here, we can help you on that... for sure.

Demon
- 29th January 2005, 13:16
Thanks Steve,

Yeah, I know I could post the basic steps of my project. But then someone with enthusiasm to burn might post the code to do it all and then I'd have to chose between accepting his code or doing it myself. I don't want to put myself in that position 'cause that would be SOOOOO tempting to speed up the process. LOL

Seriously, I'm stuck at home and I'm trying to keep my mind active. That's why I try to post specific questions to parts I can't figure out after a while. I learn best when I research the material myself, I'm a trial & error kind of guy. It may take me longer to go forward, but at least the 'thinking' is helping me fight this medication that numbs the skull (temporarily sidelined).

Thanks for that message about those LCDs, I hadn't seen any cheap 4x40s in the Montreal area. I'm holding back on the other idea now until I can go get a few at Madison. These PICs are so much more user-friendly when it comes to LCD displays.

Don't worry, I should be stuck on something else soon enough...

Robert
:)

mister_e
- 29th January 2005, 21:14
These PICs are so much more user-friendly when it comes to LCD displays.

Don't worry, I should be stuck on something else soon enough...


AND MORE, they're addictive once you get the first project run. After that we forget the old CMOS/TTL logic IC combination stuff.

That come more and more interesting to place a PIC in almost everywhere after that. What a time saving in most case.

Demon
- 29th January 2005, 22:47
Just got back from Maddison with their last 4x20. I'm searching the web now for the specs for I can start playing with it.

I also have 30 Seiko 2x40s coming within the next few weeks. I like the 4x20 more though. I'd really like to find a larger format, but I haven't been able to find anything.

Robert
:)

mister_e
- 30th January 2005, 00:51
Usually all the LCDs have the same pinout. Look in LCDOUT section of PBP manual.


I'd really like to find a larger format, but I haven't been able to find anything.


next step, use your home theater screen and display on it.

Demon
- 30th January 2005, 01:57
Euh, I'm kinda short on the home theater front...

What about monitors? Do we have the capability to output to CRTs? Or do we have to communicate to a PC to have it handle the graphic manipulation?

PIC to 14" monitor would be even better for my application. I'd like to display menus with 10-12 items, LCDs are kinda small for my needs. Of course I'll do with what I have, but a 14" area would be greatly superior.

What about the new flat screen technology, can we output to those?

(just taking a survey of what is available to me with PIC chips)

Robert
:)

mister_e
- 30th January 2005, 02:01
it's easy to do BW stuff on TV. Have a look on this link (http://www.rickard.gunee.com/projects/video/pic/howto.php)

That should be be enough to start and give food to your brain.

i never do some test with computer screen but if you look to VGA specs... i'm sure you can do something with.

Nothing is impossible.

Demon
- 30th January 2005, 03:58
"10 characters wide"

Ugh, I'm better off with the LCDs with that sort of resolution. Interesting reading though. Shoot the LCD I bought today has 4 lines by 20 characters, with backlighting, and is supported by PICs.

I've been thinking a lot about the LCDs and they are probably the most economical, easiest to implement, require the least amount of space, require little current, and give a modern look to any display.

Robert
:)