Library for RAM chip

AWOL:

The problem with the shift register is that i don't have one, and I'm 13, so i cant just go out and buy it.

I can understand age restrictions on the purchase of weapons and alcohol, but shift registers?
Crazy.

Perhaps with a permission note from his parents?

Lefty

OK, i got it now, I didn't know that there was a way to read specific bits from a number, i will start working on it.

And by saying that I'm 13, i meant i cant drive out and get one, i don't have a credit card, and my parents don't know much about electrical things, and they don't like to buy stuff online very much, especially if they don't know what it is. But maybe they will be OK with it with that website with the 35 cent shift register.

dipmicro is very good, I have bought a lot of things from them.

Yeah, I just wish Radio Shack had things like that, and that they were less expensive.

Thanks for the help, I just have one more error:

C:\Program Files (x86)\arduino-0022\libraries\AM9111\AM9111.cpp: In member function 'int AM9111::_read()':
C:\Program Files (x86)\arduino-0022\libraries\AM9111\AM9111.cpp:74: error: lvalue required as left operand of assignment

and here is my code:

header:

#ifndef AM9111_h
#define AM9111_h


#include "WProgram.h"

class AM9111
{
  public:
    AM9111(uint8_t outputDisablePin, uint8_t writeEnablePin);  // constructor wit two pind
    int read(unsigned int address);
    int write(unsigned int address, uint8_t value);
    int setIO(uint8_t IO0, uint8_t IO1, uint8_t IO2, uint8_t IO3);

  private:
    void _setAddress(unsigned int address);
    int _read();
    int _write(uint8_t value);
    // internal pin admin
    uint8_t _odp;  
    uint8_t _wep;
    uint8_t _IO[];
    uint8_t _rbits;
};
#endif

source:

#include "AM9111.h"
#include "WProgram.h"

/////////////////////////////////////////
//
// PUBLIC
//
AM9111::AM9111(uint8_t outputDisablePin, uint8_t writeEnablePin)
{
  _odp = outputDisablePin;
  _wep = writeEnablePin;
}

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);
  rv = _read();
  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++)
{
  pinMode(p, OUTPUT);
  digitalWrite(p, bitRead(address, p));
}
}


int AM9111::_read()
{
  digitalWrite(_odp,0);
  digitalWrite(_wep,1); 
  int rv = 0;
  bitWrite(_rbits,0,digitalRead(_IO[0]));
  bitWrite(_rbits,1,digitalRead(_IO[1]));
  bitWrite(_rbits,2,digitalRead(_IO[2]));
  bitWrite(_rbits,3,digitalRead(_IO[3]));
  _read() = _rbits;
  return rv;
}


int AM9111::_write(uint8_t value)
{
  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;
}

Program:

#include <AM9111.h>

AM9111 ram(12,13);

void setup()
{
  Serial.begin(9600);
  ram.setIO(8,9,10,11);
  ram.write(0,12);
  Serial.print("Read: ");
  Serial.print(ram.read(0));
};
void loop(){};

_read() = _rbits;

What about it?

_read isn't a function returning a reference, so the assignment isn't possible.

OK, so how would I make it so you could do a statement like: Serial.print(AM9111.read()); ?

int AM9111::_read()
{
  digitalWrite(_odp,0);
  digitalWrite(_wep,1); 
  int rv = 0;
  bitWrite(_rbits,0,digitalRead(_IO[0]));
  bitWrite(_rbits,1,digitalRead(_IO[1]));
  bitWrite(_rbits,2,digitalRead(_IO[2]));
  bitWrite(_rbits,3,digitalRead(_IO[3]));
  _read() = _rbits;
  return rv;
}

Have you ever thought why this routine would always return zero? (if it were to compile)
Is that what you want?

WHat i wanted was to have _read read the outputs of the ram and have _read = the output ex: out = 1101; _read = 13;

If that's what you wanted, why does it return zero?

Your _write method also (unusually) returns a value that is always zero.

I changed, but still has an error, do i have to have it do: return _rbits; ?

Did you initialise _rbits?

how?

as in int _rbits?

No, apart from the missing semicolon, that looks more like a declaration, not an initialisation.

The clue is, you did initialise a variable, but it wasn't _rbits.

so, how should i do it?

I'd probably forget about _rbits altogether, and use (I mean really use) "rv".

ok, ill try it.

By the way, the spelling is "indeterminate", not "intermediate". :wink: