Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define MEM_E 12 // E or chip select or crystal select
- #define MEM_D 19 // input data to memory
- #define MEM_W 4 // write
- #define MEM_Q 5 // output data from memory
- #define MEM_A0 11
- #define MEM_A1 10
- #define MEM_A2 9
- #define MEM_A3 8
- #define MEM_A4 13
- #define MEM_A5 14
- #define MEM_A6 15
- #define MEM_A9 16
- #define MEM_A8 17
- #define MEM_A7 18
- #define MEM_A11 6
- #define MEM_A10 7
- /*
- User functions
- */
- void setAddress(const unsigned offset) {
- bool result;
- result = (offset & 0b00000000000000000000000000000001) != 0;
- digitalWrite(MEM_A0, result);
- result = (offset & 0b00000000000000000000000000000010) != 0;
- digitalWrite(MEM_A1, result);
- result = (offset & 0b00000000000000000000000000000100) != 0;
- digitalWrite(MEM_A2, result);
- result = (offset & 0b00000000000000000000000000001000) != 0;
- digitalWrite(MEM_A3, result);
- result = (offset & 0b00000000000000000000000000010000) != 0;
- digitalWrite(MEM_A4, result);
- result = (offset & 0b00000000000000000000000000100000) != 0;
- digitalWrite(MEM_A5, result);
- result = (offset & 0b00000000000000000000000001000000) != 0;
- digitalWrite(MEM_A6, result);
- result = (offset & 0b00000000000000000000000010000000) != 0;
- digitalWrite(MEM_A7, result);
- result = (offset & 0b00000000000000000000000100000000) != 0;
- digitalWrite(MEM_A8, result);
- result = (offset & 0b00000000000000000000001000000000) != 0;
- digitalWrite(MEM_A9, result);
- result = (offset & 0b00000000000000000000010000000000) != 0;
- digitalWrite(MEM_A10, result);
- result = (offset & 0b00000000000000000000100000000000) != 0;
- digitalWrite(MEM_A11, result);
- }
- void writeCycle(const bool value, const int diapasonStart, const int diapasonEnd) {
- int dataOffset = diapasonStart;
- digitalWrite(MEM_W, 1);
- while (dataOffset <= diapasonEnd) {
- digitalWrite(MEM_E, 1);
- setAddress(dataOffset);
- digitalWrite(MEM_E, 0);
- digitalWrite(MEM_D, value);
- digitalWrite(MEM_W, 0);
- digitalWrite(MEM_W, 1);
- dataOffset++;
- }
- }
- void earlyWriteCycle(const bool value, const unsigned diapasonStart, const unsigned diapasonEnd) {
- unsigned dataOffset = diapasonStart;
- digitalWrite(MEM_W, 0);
- while (dataOffset <= diapasonEnd) {
- digitalWrite(MEM_E, 1);
- setAddress(dataOffset);
- digitalWrite(MEM_D, value);
- digitalWrite(MEM_E, 0);
- dataOffset++;
- }
- }
- void checkCycle(const bool value, const unsigned diapasonStart, const unsigned diapasonEnd) {
- unsigned dataOffset = diapasonStart;
- unsigned errorCounter = 0;
- digitalWrite(MEM_W, 1);
- while (dataOffset <= diapasonEnd) {
- setAddress(dataOffset);
- digitalWrite(MEM_E, 0);
- if (digitalRead(MEM_Q) == value) {
- } else {
- errorCounter++;
- }
- digitalWrite(MEM_E, 1);
- dataOffset++;
- }
- Serial.print("Total number of errors - ");
- Serial.println(errorCounter); //вывод количества ошибок
- }
- /*
- Tests
- */
- void Test_MATS_PLUS() {
- //первый шаг теста, пишем 0 во все ячейки
- writeCycle(0, 0, 4095);
- //второй шаг теста, в каждой ячейке проверям на 0 и затем пишем 1
- unsigned errorCounter = 0;
- for (int i = 0; i < 4096; i++) {
- //проверка на 0
- digitalWrite(MEM_W, 1);
- digitalWrite(MEM_E, 1);
- setAddress(i);
- digitalWrite(MEM_E, 0);
- if (digitalRead(MEM_Q) == 0) {
- //если в ячейке памяти 0, то ничего не делаем
- } else { //если в ячейке 1, то это ошибка
- errorCounter++; //увеличиваем количество ошибок на 1
- }
- digitalWrite(MEM_E, 1);
- //запись 1
- //закомментирован late write cycle
- // digitalWrite(MEM_W, 1);
- // digitalWrite(MEM_E, 1);
- // setMemPorts(i);
- // digitalWrite(MEM_E, 0);
- // digitalWrite(MEM_D, 1);
- // digitalWrite(MEM_W, 0);
- // digitalWrite(MEM_W, 1);
- //используется early write cycle
- digitalWrite(MEM_W, 0);
- digitalWrite(MEM_E, 1);
- setAddress(i);
- digitalWrite(MEM_D, 1);//из-за этого конфликт
- digitalWrite(MEM_E, 0);
- }
- Serial.print("Total number of errors after (r0+w1) - ");
- Serial.println(errorCounter); //вывод количества ошибок
- }
- /*
- Program entry point
- */
- void setup() {
- Serial.begin(9600);
- pinMode(MEM_A0, OUTPUT);
- pinMode(MEM_A1, OUTPUT);
- pinMode(MEM_A2, OUTPUT);
- pinMode(MEM_A3, OUTPUT);
- pinMode(MEM_A4, OUTPUT);
- pinMode(MEM_A5, OUTPUT);
- pinMode(MEM_A6, OUTPUT);
- pinMode(MEM_A7, OUTPUT);
- pinMode(MEM_A8, OUTPUT);
- pinMode(MEM_A9, OUTPUT);
- pinMode(MEM_A10, OUTPUT);
- pinMode(MEM_A11, OUTPUT);
- pinMode(MEM_E, OUTPUT);
- pinMode(MEM_D, OUTPUT);
- pinMode(MEM_W, OUTPUT);
- pinMode(MEM_Q, INPUT); //input port
- pinMode(LED_BUILTIN, OUTPUT); //led activation
- //запуск теста
- Test_MATS_PLUS();
- }
- void loop() {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement