Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help loading shift registers...

Status
Not open for further replies.

jrz126

Active Member
Hey gang, I'm trying to load 3 8 bit shift registers serially. I'm using pins C3 (for the SR enable) C4 for the SR clock, and C5 for the data.
I have the registers connected in series (the data input of SR1 is connected to the pic and the input for SR2 is connected to the output of SR1). So I need to shift 24 bits to fill all of the SR's.
Any undeclared variable in the code is defined as a global variable.

The basic algorithim:
Disable SR output.
get 1st bit from mux config and put it on pin C5.
toggle clock
get 2nd bit from mux config and put it on pin C5.
toggle clock
repeat for all 8 bits in mux, then do the same for S1 and S0.
enable SR output.

Does that code look pretty good? Is there possibly an easier way?
Code:
void load_config()
{
   int i,outbit;
   int1 clock=0;

   output_bit(PIN_C3, 1);   //disable outputs of SR's
   for(i=0;i<=7;i++)    //shift the mux config
   {
   mux_config>>i;
   outbit=mux_config & 0b00000001;
   output_bit( PIN_C5,outbit);
   output_bit( PIN_C4,0);
   delay_us(4);
   output_bit( PIN_C4,1);
   delay_us(4);
   }
   for(i=0;i<=7;i++)
   {
   s1_config>>i;
   outbit=s1_config & 0b00000001;
   output_bit( PIN_C5,outbit);
   output_bit( PIN_C4,0);
   delay_us(4);
   output_bit( PIN_C4,1);
   delay_us(4);
   }
   for(i=0;i<=7;i++)
   {
   s0_config>>i;
   outbit=s0_config & 0b00000001;
   output_bit( PIN_C5,outbit);
   output_bit( PIN_C4,0);
   delay_us(4);
   output_bit( PIN_C4,1);
   delay_us(4);
   }
   output_bit(PIN_C3,0);


}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top