Would someone with experience of shift registers and particularly the 74ls299 please take a look at my sketch and let me know what I am missing?
the first code is a sketch for the hct4021 and it works fine.
/* set up CD4021 with
pin1 - i/p 1 pin16 - vcc
pin2 - n/c pin15 - i/p 2
pin3 - data in pin14 - i/p 3
pin4 - i/p 5 pin13 - i/p 4
pin5 - i/p 6 pin12 - n/c
pin6 - i/p 7 pin11 - n/c
pin7 - i/p 8 pin10 - clock
pin8 - 0v pin9 - ser/par switch (latch)
bias inputs with resistors to ov and put a switch on each input to vcc
*/
const int latchPinin = 5; //4021 pin 9
const int dataPinin = 6; //4021 pin 3
const int clockPinin = 7; //4021 pin 10
int myinput;
int a;
void setup() {
Serial.begin(9600);
pinMode(latchPinin, OUTPUT);
pinMode(clockPinin, OUTPUT);
pinMode(dataPinin, INPUT);
}
void loop() {
delayMicroseconds (20);
digitalWrite (clockPinin,HIGH);/*puts the clockpin high so the first
bit is read before the register is clocked on*/
digitalWrite (latchPinin,HIGH);//set it to 1 to collect parallel data
delayMicroseconds (20); //pause to let digitalWrite finish
digitalWrite (latchPinin,LOW); //set it to 0 to transmit data serially
delayMicroseconds (20); //pause to let latch go low
myinput = shiftIn (dataPinin, clockPinin, MSBFIRST);//read register
delayMicroseconds (20); //pause to let shiftin read register
for (a=0;a<8;a++) /*bit read the contents of myinput so that
it maintains leading '0's for the screen*/
{
Serial.print (bitRead (myinput,(7-a)));
}
Serial.print (" "); //space the outputs on the screen
Serial.print (myinput); //print myinput in decimal
Serial.println(); //add a line feed
delay (1000); //delay to read output on screen
}
I am trying to understand how a 74ls299 works and trying to get it to do something similar.
I have done the same thing with a 74ls595 and converted it to work with the 74ls299, my ultimate goal is to integrate both programs and use the 74ls299 to send and receive 4 inputs and 4 outputs at the same time.
If I use the sketch below into the arduino, with I/O 7 high (switch on) I get all 1’s with it low I get all 0’s. I think it is not clocking through the bits and I am just getting what is on the first gate, I think all the connection information is contained in the sketch.
/* set up 74ls299 with
pin1 - S0 pin20 - vcc
pin2 - OE1 pin19 - S1
pin3 - OE2 pin18 - DS 7
pin4 - I/O 6 pin17 - Q 7
pin5 - I/O 4 pin16 - I/O 7
pin6 - I/O 2 pin15 - I/O 5
pin7 - I/O 0 pin14 - I/O 3
pin8 - Q 0 pin13 - I/O 1
pin9 - MR pin12 - CP
pin10 - 0V pin11 - DS0
put PINS 5, 15, 4, 16 to 0v bias (with resistors to 0v) side of switches connected to 5v.
MR is held high as are S0 and S1*/
const int latchPinin = 9; //299 pins 2 & 3 (OE1 & OE2)
const int dataPinin = 6; //299 pin 17 (Q7)
const int clockPinin = 10; //299 pin 12 (CP)
int myinput;
int a;
void setup(){
Serial.begin(9600);
pinMode(latchPinin, OUTPUT);
pinMode(clockPinin, OUTPUT);
pinMode(dataPinin, INPUT);
}
void loop() {
// digitalWrite (clockPinin,HIGH);/*puts the clockpin high so the first
// bit is read before the register is clocked on*/
digitalWrite (latchPinin,HIGH);//set it to 1 to collect parallel data
delayMicroseconds (20); //pause to let digitalWrite finish
digitalWrite (latchPinin,LOW); //set it to 0 to transmit data serially
delayMicroseconds (20); //pause to let latch go low
myinput = shiftIn (dataPinin, clockPinin, LSBFIRST);//read register
delayMicroseconds (20); //pause to let shiftin read register
for (a=0;a<8;a++) /*bit read the contents of myinput so that
it maintains leading '0's for the screen*/
{
Serial.print (bitRead (myinput,(7-a)));
}
Serial.print (" "); //space the outputs on the screen
Serial.print (myinput); //print myinput in decimal
Serial.println(); //add a line feed
delay (1000); //delay to read output on screen
}
I have tried many changes of connection but I am now stumped. I would appreciate someones help.
Thanks.