Created
February 22, 2022 16:34
-
-
Save podstawek/af9c8c00992b9fccfbdf68b43a444501 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define Arduino pin constants to correspond with MOS6522 pins | |
const byte CS1 = 24; // Chip Select 1 | |
const byte CS2 = 23; // Chip Select 2 | |
const byte RS0 = 38; // Register Select 0 | |
const byte RS1 = 37; // Register Select 1 | |
const byte RS2 = 36; // Register Select 2 | |
const byte RS3 = 35; // Register Select 3 | |
const byte RW = 22; // Read-Write Line | |
const byte D0 = 33; // Data Bus 0 | |
const byte D1 = 32; // Data Bus 1 | |
const byte D2 = 31; // Data Bus 2 | |
const byte D3 = 30; // Data Bus 3 | |
const byte D4 = 29; // Data Bus 4 | |
const byte D5 = 28; // Data Bus 5 | |
const byte D6 = 27; // Data Bus 6 | |
const byte D7 = 26; // Data Bus 7 | |
const byte CLOCKOUT = 11; // Mega 2560 clock goes to | |
void setup() { | |
// set all digital ports to output mode | |
int inMin = 11; // Lowest input pin | |
int inMax = 38; // Highest input pin | |
for (int i = inMin; i <= inMax; i++) | |
{ | |
pinMode(i, OUTPUT); | |
} | |
{ | |
// set up 1 MHz timer on CLOCKOUT (OC1A) | |
pinMode (CLOCKOUT, OUTPUT); | |
// set up Timer 1 | |
TCCR1A = bit (COM1A0); // toggle OC1A on Compare Match | |
TCCR1B = bit (WGM12) | bit (CS10); // CTC, no prescaling | |
OCR1A = 7; // output every cycle | |
} // end of setup | |
// per 6522 datasheet: | |
// "selected MCS6522 register will be accessed when CS1 is high and CS2 is low" | |
digitalWrite(CS1, HIGH); | |
digitalWrite(CS2, LOW); | |
// RW switch | |
delay(1); | |
digitalWrite(RW, LOW); | |
// first set Register Select to select ACR (1011): | |
delay(1); | |
digitalWrite(RS3, HIGH); | |
digitalWrite(RS2, LOW); | |
digitalWrite(RS1, HIGH); | |
digitalWrite(RS0, HIGH); | |
// then set the ACR to enable Shift Out | |
// Start by zeroing the 3 relevant ACR bits (000): | |
delay(1); | |
digitalWrite(D7, LOW); | |
digitalWrite(D6, LOW); | |
digitalWrite(D5, LOW); | |
digitalWrite(D4, LOW); | |
digitalWrite(D3, LOW); | |
digitalWrite(D2, LOW); | |
digitalWrite(D1, LOW); | |
digitalWrite(D0, LOW); | |
// then set to Shift Out, free-running mode shift rate controlled by T2 (100): | |
delay(1); | |
digitalWrite(D7, LOW); | |
digitalWrite(D6, LOW); | |
digitalWrite(D5, LOW); | |
digitalWrite(D4, HIGH); | |
digitalWrite(D3, LOW); | |
digitalWrite(D2, LOW); | |
digitalWrite(D2, LOW); | |
digitalWrite(D1, LOW); | |
digitalWrite(D0, LOW); | |
// now set Register Select to select T2C-L timer (1000): | |
delay(1); | |
digitalWrite(RS3, HIGH); | |
digitalWrite(RS2, LOW); | |
digitalWrite(RS1, LOW); | |
digitalWrite(RS0, LOW); | |
// set T2C-L timer to a value, say A0 (00100000) | |
digitalWrite(D7, LOW); | |
digitalWrite(D6, LOW); | |
digitalWrite(D5, HIGH); | |
digitalWrite(D4, LOW); | |
digitalWrite(D3, LOW); | |
digitalWrite(D2, LOW); | |
digitalWrite(D1, LOW); | |
digitalWrite(D0, LOW); | |
// now set Register Select to select Shift Register (1010): | |
digitalWrite(RS3, HIGH); | |
digitalWrite(RS2, LOW); | |
digitalWrite(RS1, HIGH); | |
digitalWrite(RS0, LOW); | |
// send a pattern to Shift Register (e.g. 00011000) | |
digitalWrite(D7, HIGH); | |
digitalWrite(D6, LOW); | |
digitalWrite(D5, HIGH); | |
digitalWrite(D4, HIGH); | |
digitalWrite(D3, HIGH); | |
digitalWrite(D2, LOW); | |
digitalWrite(D1, HIGH); | |
digitalWrite(D0, LOW); | |
digitalWrite(CS1, HIGH); | |
digitalWrite(CS2, HIGH); | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment