Upgrade 32kbyte RAM for arduino mega with ic UT62256CSCL-70LL

Upgrade 32kbyte RAM for arduino mega with ic UT62256CSCL-70LL
Çeşme:

http://arduino.vn/tutorial/1869-nang-cap-32kbyte-ram-cho-arduino-mega-voi-ic-ut62256cscl-70ll
void SRAM_SET_PORT () { // This function to install the battery for arduino DDRA = DDRA | B11111111; // from pin 0 -> pin 6 is output DDRC = DDRC | B11111111; // all DDRB = DDRB | B00000111; // 3 PORT FIRST PORTB = PORTB | B00000111; // stand_byte: about lock status DDRL = 0; // = B00000000: set the output I / O to in put PORTA = 0; // = PORTA & B00000000 // RESET DOWN 0 PORTC = 0; // = PORTC & B000000; delayMicroseconds (10); } void SRAM_WRITE_1_BYTE (uint16_t adress, uint8_t value_1_byte) { // write to Sram 1 byte of memory at "adress" address // B1: prepare the previous address DDRL = 255; // = B11111111: set the I / O output to out put // OPEN IC CE CE PORTB = PORTB & B11111011; // read: CE low uint8_t bit_8_cao = (uint8_t) ((adress >> 8) & 0xFF); uint8_t bit_8_thap = (uint8_t) (adress & 0xFF); PORTA = PORTA | bit_8_cao; PORTC = PORTC | bit_8_thap; // B2: Open the write port // delayMicroseconds (10); PORTB = PORTB & B11111110; // read: WE down low // WE: high don't care // delayMicroseconds (10); // b3: shift out: PORTL = value_1_byte; PORTL = value_1_byte; // this part if ic is slow, you need to wait 1 time before closing the ic // b4: close the ic PORTB = PORTB | B00000111; // stand_byte: about lock status DDRL = 0; // = B00000000: set the output I / O to in put PORTA = 0; // PORTA & B00000000 // RESET DOWN 0 PORTC = 0; // PORTC & B00000000; } uint8_t SRAM_READ_1_BYTE (uint16_t adress) { // B1: prepare the previous address DDRL = 0; // = B00000000: set the output I / O to in put // OPEN IC CE CE PORTB = PORTB & B11111011; // read: CE low // delayMicroseconds (10); uint8_t bit_8_cao = (uint8_t) ((adress >> 8) & 0xFF); uint8_t bit_8_thap = (uint8_t) (adress & 0xFF); PORTA = PORTA | bit_8_cao; PORTC = PORTC | bit_8_thap; // B2: OPEN READING PORT PORTB = PORTB | B00000001; // WE: high PORTB = PORTB & B11111001; // read: CE low, OE low // delayMicroseconds (10); // B3: SHIFT IN uint8_t Read_port = PINL; Read_port = PINL; // B4: LOCK PORTB = PORTB | B00000111; // stand_byte: about lock status DDRL = 0; // = B00000000: set the output I / O to in put PORTA = 0; // = PORTA & B00000000 // RESET DOWN 0 PORTC = 0; // = PORTC & B000000; return (uint8_t) Read_port; } void setup () { SRAM_SET_PORT (); Serial.begin (9600); int i; int v = 0; for (i = 1000, v = 0; i <= 1005; i++) { SRAM_WRITE_1_BYTE (i, v); // write value 123 in memory 1000 v++; } for (i = 1000; i <= 1005; i++) { byte gia_tri = SRAM_READ_1_BYTE (i); // output the value in cell 1000 Serial.println (gia_tri); } /* SRAM_WRITE_1_BYTE (1000, 123); // write value 123 in memory 1000 byte gia_tri = SRAM_READ_1_BYTE (1000); // output the value in cell 1000 Serial.println (gia_tri); */ } void loop () { }