CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Shift Registers

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
misperry



Joined: 03 Mar 2009
Posts: 40

View user's profile Send private message

Shift Registers
PostPosted: Sun Aug 23, 2009 2:23 pm     Reply with quote

Hello all,

It has been a while since I have posted. However, I was wondering if there is anyone knew of how to code shift registers with ccs c code using a pic 16f886?

I have a system that uses magnetic locks and all I need to do is to trigger, using 5volts, certain magnets on and off. Don't worry about the load I have already taken care of it with mosfets between the pic and the magnets. I just need a way of turning them on and off serially since I would need 13 pins for the magnets and I would like to just use shift registers to serialize it so I can use only two pins instead of 13.

So if anyone has any example code or knows of a good place to get the code would be a great help.

thanks to all!
Ttelmah
Guest







PostPosted: Sun Aug 23, 2009 3:02 pm     Reply with quote

You would really need to use three pins, rather than two.
Clock.
Serial data.
Load.

The problem is that if you just use a shift register, the solenoids will get operated, as the data is shifted in....
Hence what you need is a shift register, and a separate output latch. You simply send the data bit at a time to the register, pulsing the clock for each bit (look at any of the software SPI examples, which do exactly the same thing), and then operate one line, to load the register output, onto an output latch.

However, why not use something like the Microchip MCP23S17 I/O expander?. This, and other members of the same family, offer 16 I/O pins, directly accessible using SPI (or I2C for other versions).

Best Wishes
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Aug 23, 2009 3:53 pm     Reply with quote

TTelmah is correct, it would require three pins for a serial shift register with a latch. A 74C595/74HC595 shift register would do the trick and there's a 74595 driver in the PICC/Driver directory. You can also daisy chain these for as many bits as you need.
_________________
Google and Forum Search are some of your best tools!!!!


Last edited by dyeatman on Sun Aug 23, 2009 7:32 pm; edited 1 time in total
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sun Aug 23, 2009 6:32 pm     Reply with quote

If you REALLY only have two pins to use you could just shift real fast, faster than the magnets can respond. Maybe sit with all zeros shifted out, then quickly shift out the required pattern, then pause while the magnets respond, then shift out another batch of zeros. But that is a messy solution.
_________________
The search for better is endless. Instead simply find very good and get the job done.
misperry



Joined: 03 Mar 2009
Posts: 40

View user's profile Send private message

PostPosted: Sat Aug 29, 2009 10:53 am     Reply with quote

thanks all.

I have found that you need a latch also. Well I am using a mc74hc595a by ON Semiconductor. I was just wondering if there was a way to use the rs-232 command in in the pic library or if I was going to have to create my own clock signal and data forwarding pins with code?
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Sat Aug 29, 2009 11:45 am     Reply with quote

If you think you can do it using RS-232, I'm afraid you have a sad misconception about how serial data transmission works.

But on a chip with built-in SPI, which the 16f886 seems to have, you can indeed use the port to operate external shift registers. You just have to provide an extra pin to strobe the output latch of the '595 chip(s), when all your data has been sent.
Ttelmah
Guest







PostPosted: Sat Aug 29, 2009 1:07 pm     Reply with quote

And (of course), worth realising, that even without the hardware SPI, or on pins without this function, on the later compilers, there is the software SPI library available to do the shifting, and clocking for you, even supporting clocking word lengths other than 8bits....

Best Wishes
misperry



Joined: 03 Mar 2009
Posts: 40

View user's profile Send private message

PostPosted: Mon Aug 31, 2009 7:56 am     Reply with quote

cool! thanks you guys for all the info. You have been a great help!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group