uas_arduino

SRAM Debug

Feb 15th, 2013
54
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int dataPins[] = {2,3,4,5};
  2. int NUMBER_OF_DATA_PINS = 4;
  3. int addrPins[] = {7,8,9,10};
  4. int NUMBER_OF_ADDR_PINS = 4;
  5. int oe = 11;
  6. int we = 12;
  7.  
  8. void setup(){
  9. Serial.begin(115200);
  10. for(int a = 0; a < NUMBER_OF_ADDR_PINS; a++){
  11. pinMode(addrPins[a], OUTPUT);
  12. }
  13.  
  14. pinMode(oe,OUTPUT);
  15. pinMode(we,OUTPUT);
  16. }
  17.  
  18. void setAddr(byte addr){
  19. for(int a = 0; a < NUMBER_OF_ADDR_PINS; a++){
  20. if((addr >> a) & 0x01){
  21. digitalWrite(addrPins[a],HIGH);
  22. }else{
  23. digitalWrite(addrPins[a],LOW);
  24. }
  25. }
  26. }
  27.  
  28. void setData(byte data){
  29. for(int a = 0; a < NUMBER_OF_DATA_PINS; a++){
  30. pinMode(dataPins[a],OUTPUT);
  31. Serial.print("Setting data to: ");
  32. if((data >> a) & 0x01){
  33. Serial.print("1");
  34. digitalWrite(dataPins[a],HIGH);
  35. }else{
  36. Serial.print("0");
  37. digitalWrite(dataPins[a],LOW);
  38. }
  39. Serial.println();
  40. }
  41. }
  42.  
  43. void writeData(byte addr, byte data){
  44. Serial.print("Setting address to ");
  45. Serial.println(addr,DEC);
  46. setAddr(addr);
  47. digitalWrite(we,LOW);
  48. setData(data);
  49. digitalWrite(we,HIGH);
  50. }
  51.  
  52. byte readData(byte addr){
  53. byte data = 0x00;
  54. setAddr(addr);
  55.  
  56. digitalWrite(oe,LOW);
  57. for(byte a = 0; a < NUMBER_OF_DATA_PINS; a++){
  58. pinMode(dataPins[a],INPUT);
  59. if(digitalRead(dataPins[a])){
  60. data |= (0x01 << a);
  61. }
  62. }
  63. digitalWrite(oe,HIGH);
  64. return data;
  65. }
  66.  
  67. void loop(){
  68. for(int a = 0; a < 16; a++){
  69. writeData(a,a);
  70. }
  71.  
  72. for(int a = 0; a < 16; a++){
  73. Serial.print("Looking at address: ");
  74. Serial.print(a,DEC);
  75. Serial.print(" Got back: ");
  76. Serial.println(readData(a),DEC);
  77. delay(1000);
  78. }
  79. }
RAW Paste Data