/*********************************************************** Chris Foster and Jeff Puchalski ECE 476 Spring 2003 Project - 84256A 32K SRAM Chip Test ***********************************************************/ #include #include #define RESET 0 #define WRITE 1 #define READ 2 #define DONE 3 unsigned char state; void main(void) { unsigned char c; DDRA=0xff; // PORT A is memory address lines A0-A7 PORTA=0x00; DDRB=0xff; // PORT B is memory address lines A8-A12,CE,OE,WE // note that you only have room for 13 address lines // using two ports, which limits you to 8K of memory // CE := chip enable (but doesn't seem to do anything?) // OE := output enable (a.k.a. read) // WE := write enable PORTB=0b11100000; DDRC=0xff; // PORT C is the LEDs DDRD=0xff; // PORT D is the data bus likes D0-D7 state = RESET; c = 0; while (1) { switch (state) { case RESET : state = WRITE; PORTC=0x00; // turn on all the LEDs delay_ms(1000); break; case WRITE : PORTA=0b00101010; // set the address.. PORTB=0b11100000; // ..and make sure r/w are disabled PORTB=0b01100000; // flip WE low (on) PORTD=0b01001110; // write the data PORTB=0b11100000; // flip WE high (off) state = READ; PORTC = 0xff; // turn off all the LEDs delay_ms(2000); break; case READ : DDRD=0x00; PORTA=0b00101010; // set the address.. PORTB=0b11100000; // ..and make sure r/w are disabled PORTB=0b10100000; // flip OE low (on) c=PIND; // read the data PORTB=0b11100000; // flip OE high (off) PORTC=~c; // display the data read back to the LEDs state = DONE; break; case DONE : while (1); // stay here forever!! (or till reset) break; } } }