Shifting in with 74HC165N Trouble


i'm having no luck whatsoever 74hc165 entry in arduino playground.

i have wired according comments when fire says inputs low states they've changed , have gone high. sits with no updates serial window regardless of whether button pressed or not. have 8 buttons wired go high when pressed , pulled down low via 100k resistors when not pressed. sketch work? has had success it? it's been frustrating me going on month now.
code: [select]
/*
* sn74hc165n_shift_reg
*
* program shift in bit values sn74hc165n 8-bit
* parallel-in/serial-out shift register.
*
* sketch demonstrates reading in 16 digital states a
* pair of daisy-chained sn74hc165n shift registers while using
* 4 digital pins on arduino.
*
* can daisy-chain these chips connecting serial-out
* (q7 pin) on 1 shift register serial-in (ds pin) of
* other.
*
* of course can daisy chain many while still
* using 4 arduino pins (though have process
* them 4 @ time separate unsigned long variables).
*
*/

/* how many shift register chips daisy-chained.
*/
#define number_of_shift_chips   1

/* width of data (how many ext lines).
*/
#define data_width   number_of_shift_chips * 8

/* width of pulse trigger shift register read , latch.
*/
#define pulse_width_usec   5

/* optional delay between shift register reads.
*/
#define poll_delay_msec   1

/* need change "int" "long" if the
* number_of_shift_chips higher 2.
*/
#define bytes_val_t unsigned int

int ploadpin        = 8;  // connects parallel load pin 165
int clockenablepin  = 9;  // connects clock enable pin 165
int datapin         = 11; // connects q7 pin 165
int clockpin        = 12; // connects clock pin 165

bytes_val_t pinvalues;
bytes_val_t oldpinvalues;

/* function "shift-in" routine reading the
* serial data shift register chips , representing
* state of pins in unsigned integer (or long).
*/
bytes_val_t read_shift_regs()
{
   byte bitval;
   bytes_val_t bytesval = 0;

   /* trigger parallel load latch state of data lines,
   */
   digitalwrite(clockenablepin, high);
   digitalwrite(ploadpin, low);
   delaymicroseconds(pulse_width_usec);
   digitalwrite(ploadpin, high);
   digitalwrite(clockenablepin, low);

   /* loop read each bit value serial out line
    * of sn74hc165n.
   */
   for(int = 0; < data_width; i++)
   {
       bitval = digitalread(datapin);

       /* set corresponding bit in bytesval.
       */
       bytesval |= (bitval << ((data_width-1) - i));

       /* pulse clock (rising edge shifts next bit).
       */
       digitalwrite(clockpin, high);
       delaymicroseconds(pulse_width_usec);
       digitalwrite(clockpin, low);
   }

   return(bytesval);
}

/* dump list of zones along current status.
*/
void display_pin_values()
{
   serial.print("pin states:\r\n");

   for(int = 0; < data_width; i++)
   {
       serial.print("  pin-");
       serial.print(i);
       serial.print(": ");

       if((pinvalues >> i) & 1)
           serial.print("high");
       else
           serial.print("low");

       serial.print("\r\n");
   }

   serial.print("\r\n");
}

void setup()
{
   serial.begin(9600);

   /* initialize our digital pins...
   */
   pinmode(ploadpin, output);
   pinmode(clockenablepin, output);
   pinmode(clockpin, output);
   pinmode(datapin, input);

   digitalwrite(clockpin, low);
   digitalwrite(ploadpin, high);

   /* read in , display pin states @ startup.
   */
   pinvalues = read_shift_regs();
   display_pin_values();
   oldpinvalues = pinvalues;
}

void loop()
{
   /* read state of zones.
   */
   pinvalues = read_shift_regs();

   /* if there chage in state, display ones changed.
   */
   if(pinvalues != oldpinvalues)
   {
       serial.print("*pin value change detected*\r\n");
       display_pin_values();
       oldpinvalues = pinvalues;
   }

   delay(poll_delay_msec);
}


i want daisychain second 165n 16 inputs on 4 i/o lines figured it'd easier find problem working 1 shift register.

thanks in advance,

svaroh

quote
i have wired according comments


the pins in description not chip pins these right?
power , ground ok? , decoupling capacitor across supply of chip?

quote
wired go high when pressed , pulled down low via 100k resistors

clack handed way of going things should pulling ground switch , 10k. way round have it:-

too high value of resistor. make them 10k 1k pull downs.

quote
does sketch work

let's hardware right first.  ;)


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Shifting in with 74HC165N Trouble


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums