Replacing shift register with PIC


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2006
    Posts
    92

    Default Replacing shift register with PIC

    Hi,

    I was wondering if it is possible to replace a 4021B (parallel to serial) shift register chip with a PIC using shiftin and shiftout functions?

    I am assuming that I would first need to shiftin the latch and clock data from the master, then shiftout the (serial data) bits to the master.

    The "master" in this case is a Nintendo NES video game system which uses a standard 4021B shift register in it's joystick to read 8 buttons in a parallel fashion, and then shifts the 8 bits out serially to the data input pin of the NES joystick input port.

    The NES sets the latch line low when it is ready to receive the serial data from the shift register. The shift register also receives clock data from the NES (master), but I'm not sure what to do with the clock data received.

    I want to mimic a 4021B shift register with my pic, but not sure how to handle the data received from the "master" clock and latch.

    Hope I'm not too confusing. If I am I'll try to clarify.

    Thanks for any help,
    T
    Last edited by TonyA; - 7th April 2008 at 16:18.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by TonyA View Post
    I was wondering if it is possible to replace a 4021B (parallel to serial) shift register chip with a PIC using shiftin and shiftout functions?
    I don't see why not. I think the biggest problem would be how fast the incoming data and outgoing clock signal would have to be.
    But yes, 8 data lines and a latch signal for an input, easy enough... Put the data on the lines, watch for the latch to go low (or high, whatever), grab that data and store it, wait for the latch line to go back high (or low) and start waiting again.
    Transfer that data to an output line using either shiftout or the builtin MSSP, easy enough also. If you use shiftout, the PIC would be tied up shifting that data out, if you used the MSSP, you could theoretically clock it out at about 2.5Mhz, depending on the PIC and clock speed used.

  3. #3
    Join Date
    Apr 2006
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    The pic would only be receiving clock data and latch data from the master in my case.

    And then it would only need to send serial data, and (clock data?) back out to the master.

    I'll post my code and try to clarify this a bit. Thanks for your reply.

    T

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by TonyA View Post
    The pic would only be receiving clock data and latch data from the master in my case.
    And then it would only need to send serial data, and (clock data?) back out to the master.
    T
    Just read the rest of your 1st post.
    Yes, if the NES is sending out a clock, then that would make your PIC a slave device, clocked by something else.
    Most PICs support both master and slave SPI operations.

  5. #5
    Join Date
    Apr 2006
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    Yes, right the pic would be a slave. Here is what I have.

    shiftin latchPin_in, clockPin_in, MSBFIRST, [latch_receive, clock_receive]

    ' clockPin_in is a pin on the pic that is attached to the clock line of the NES gamepad port
    ' latchPin_in is a pin on the pic that is connected to the latch line of the NES gamepad port


    if latchPin_in = 0 then 'if we receive a zero from the master's latch output data then shiftout serial data.

    shiftout serialOut_pin, clockPin_in, MSBFIRST, [serial data output] 'send a byte out to the master.

    In this case what do I do with the clock data received when shifting in? I'm not sure how to handle the clock data received.


    Does a 4021B shift register (slave) receive latch and clock data in a standard (fixed) way? Or does this rely on how the latch and clock data are being sent from the master?

    You said I would "tie up" the pic doing this. If that's true than maybe I'll skip this and just use a pic to send the parallel input into a real shift register, then out to the master.

    I was thinking about using a pot via ADCIN and then send the shifted out serial bits based on the pot reading. Would that work with shiftin and shiftout going on as well?

    Thanks again,
    T
    Last edited by TonyA; - 7th April 2008 at 17:27.

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by TonyA View Post
    Does a 4021B shift register (slave) receive latch and clock data in a standard (fixed) way? Or does this rely on how the latch and clock data are being sent from the master?
    Datasheets for the 4021 should tell you all you need to know...about the 4021.
    I guess the main thing would be to 'scope out what the NES is sending out, figure out how fast it's going, what it's logic levels are, and so on.

    You said I would "tie up" the pic doing this. If that's true than maybe I'll skip this and just use a pic to send the parallel input into a real shift register, then out to the master.
    Shiftin/Shiftout are both 'blocking' commands. You can't do anything else until the commands are done executing because it's all done in software.
    If you used the MSSP module in a PIC, you could just punch a byte to the TX register, hit a bit to send it, and go about your business. When you have another byte to send out, check the busy bit, if it's good, send another byte. The MSSP does all the clocking and shifting in hardware.

    I was thinking about using a pot via ADCIN and then send the shifted out serial bits based on the pot reading. Would that work with shiftin and shiftout going on as well?
    Depends...on the time it takes to read the pot, how fast shiftin/shiftout run, among other things...
    You could start the ADC, shiftout a byte. By the time a byte is shifted in or out, the ADC would be finished and ready for a read. Then restart the process...

  7. #7
    Join Date
    Apr 2006
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    Thanks again for your help, sincerely appreciate it.

    (Will experiment)

    Tony

Similar Threads

  1. Active low input?
    By CosMecc in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 8th August 2010, 20:31
  2. PIC16F877A pwm use for IR transmission
    By mcbeasleyjr in forum General
    Replies: 0
    Last Post: - 11th July 2009, 18:51
  3. Replies: 14
    Last Post: - 26th September 2007, 05:41
  4. Use the PIC 16f877 or 877A instead of shift registers.
    By tsanders in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th October 2006, 17:23
  5. Replies: 15
    Last Post: - 30th January 2005, 03:58

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts