Go Down

Topic: Library for RAM chip (Read 4 times) previous topic - next topic

farlepet

I got it to work, and i just got the Shift Registers today, so i will experiment with them and add to the library.

farlepet

I got the shift register working, but it wont work now, it keeps sending a zero
Code: [Select]


#include "AM9111_Shift.h"
#include "WProgram.h"

/////////////////////////////////////////
//
// PUBLIC
//
AM9111::AM9111(uint8_t outputDisablePin, uint8_t writeEnablePin, uint8_t clockPin, uint8_t latchPin, uint8_t dataPin)
{
 _odp = outputDisablePin;
 _wep = writeEnablePin;
 _cp = clockPin;
 _lp = latchPin;
 _dp = dataPin;
 pinMode(_lp, OUTPUT);
 pinMode(_cp, OUTPUT);
 pinMode(_dp, OUTPUT);
}

int AM9111::setIO(uint8_t IO0, uint8_t IO1, uint8_t IO2, uint8_t IO3)
{
 _IO[0] = IO0;
 _IO[1] = IO1;
 _IO[2] = IO2;
 _IO[3] = IO3;
}
 

int AM9111::read(unsigned int address)
{
 int rv = 0;
 _setAddress(address);
 return rv;
}

int AM9111::write(unsigned int address, uint8_t value)
{
 int rv = 0;
 _setAddress(address);
 rv = _write(value);
 return rv;
}

/////////////////////////////////////////
//
// PRIVATE
//
void AM9111::_setAddress(unsigned int address)
{
for(int p=0; p<8; p++)


 
 digitalWrite(_lp, LOW);
   // shift out the bits:
 shiftOut(_dp, _cp, MSBFIRST, address);  

   //take the latch pin high so the LEDs will light up:
 digitalWrite(_lp, HIGH);
   // pause before next value:
 delay(15);
}


int AM9111::_read()
{
 pinMode(_IO[0],INPUT);
 pinMode(_IO[1],INPUT);
 pinMode(_IO[2],INPUT);
 pinMode(_IO[3],INPUT);

 digitalWrite(_odp,0);
 digitalWrite(_wep,1);
 int rv = 0;
 bitWrite(rv,0,digitalRead(_IO[0]));
 bitWrite(rv,1,digitalRead(_IO[1]));
 bitWrite(rv,2,digitalRead(_IO[2]));
 bitWrite(rv,3,digitalRead(_IO[3]));
 return rv;

}


int AM9111::_write(uint8_t value)
{
 pinMode(_IO[0], OUTPUT);  
 pinMode(_IO[1], OUTPUT);
 pinMode(_IO[2], OUTPUT);
 pinMode(_IO[3], OUTPUT);

 digitalWrite(_odp,1);
 digitalWrite(_wep,0);
 int  rv = 0;
 digitalWrite(_IO[0],bitRead(0,value));
 digitalWrite(_IO[1],bitRead(1,value));
 digitalWrite(_IO[2],bitRead(2,value));
 digitalWrite(_IO[3],bitRead(3,value));
 return rv;
}


AWOL

Quote
it keeps sending a zero


I wonder why that is:
Code: [Select]
int AM9111::read(unsigned int address)
{
  int rv = 0;
  _setAddress(address);
  return rv;
}
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Nick Gammon

For that matter:

Quote
Code: [Select]
int  rv = 0;
  digitalWrite(_IO[0],bitRead(0,value));
  digitalWrite(_IO[1],bitRead(1,value));
  digitalWrite(_IO[2],bitRead(2,value));
  digitalWrite(_IO[3],bitRead(3,value));
  return rv;


What is the purpose of rv here? It is set to zero and you never change it.

I am guessing here you are just throwing in stuff to make compiler errors go away. Well that worked, now you have runtime errors.

AWOL

Quote
For that matter:


Quote
Code:
int  rv = 0;

That's in a "write" method.

Not sure why a "write" method would want to return a value anyway.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up