Advertisement
Guest User

Untitled

a guest
Jul 7th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.77 KB | None | 0 0
  1. int ROM[16] = {0x00, 0x00, 0x00, 0x00, 0xC3, 0x00, 0x00, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  2. word Address;
  3. int Prev;
  4. int Current;
  5.  
  6. void setup() {
  7.   DDRA = 0x00;                        //Pins 22-29 (lower 8b of Address Input) 22 = 0, > 29 = 7
  8.   DDRC = 0x00;                        //Pins 30-37 (upper 8b of Address Input) 37 = 0, < 30 = 7
  9.   DDRL = 0xFF;                        //Pins 42-49 (8b Data Output)            49 = 0, > 42 = 7
  10.   Prev = 0xFF;
  11.   Address = 0x0000;
  12.   Serial.begin(500000);
  13.  
  14. }
  15.  
  16. void loop() {
  17.     Address = word(PINC,PINA);        //Combines PORTC and PORTA into a single 16b Value
  18.     PORTL = ROM[Address];             //Reads from the ROM Array and puts it onto the Data Output
  19.    
  20.     Current = Address;
  21.     if(Prev != Current){              //If the Address from one cycle beofre is the same as the Current one it will not print anything on the Serial Monitor. to keep it clean
  22.       if (PORTL < 0x10 ) {
  23.         Serial.print("$0");
  24.       }
  25.       else{
  26.         Serial.print("$");
  27.       };
  28.       Serial.print(PORTL, HEX);       //Prints the Data on the current Address as HEX with leading 0.
  29.       Serial.print("    ");
  30.         if (Address < 0x0010 ) {
  31.           Serial.print("$000");
  32.           goto EOSP;
  33.         };
  34.         if (Address < 0x0100 ) {
  35.           Serial.print("$00");
  36.           goto EOSP;
  37.        };
  38.        if (Address < 0x1000 ) {
  39.          Serial.print("$0");
  40.          goto EOSP;
  41.        }
  42.        else{
  43.          Serial.print("$");
  44.        };
  45.       EOSP:
  46.       Serial.print(Address, HEX);     //Prints the Currently accessed Address as HEX with leading 0s.
  47.       Serial.println();
  48.       Prev = Current;                 //Sets the used Address as the "previous" one, so it can be compared next cycle.
  49.       };
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement