Pages: 1 2 3 [4]   Go Down
Author Topic: Library for RAM chip  (Read 3223 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Intermediate Arduino user
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Intermediate Arduino user
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

#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;
}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24433
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
it keeps sending a zero

I wonder why that is:
Code:
int AM9111::read(unsigned int address)
{
  int rv = 0;
  _setAddress(address);
  return rv;
}
Logged

"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.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For that matter:

Quote
Code:
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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24433
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Pages: 1 2 3 [4]   Go Up
Jump to: