http://www.smspower.org/forums/viewtopic.php?t=2450 (bottom post) and
http://www.smspower.org/maxim/Documents ... estprogram
this runs on my arduino uno
Code: Select all
//ym2612
#define wr_pin 10
#define a0_pin 11
#define a1_pin 12
#define d7 9
#define clock_pin A0
#define cs_pin A1
#define led_pin 13
unsigned char clock;
ISR(TIMER1_COMPA_vect)
{
digitalWrite(clock_pin,clock);
clock=clock^HIGH;
}
void writetTo(unsigned char address,unsigned char data)
{
digitalWrite(led_pin,HIGH);
//first send address to d0-d7
DDRD = DDRD | B11111100; //0-7
DDRB = DDRB | B00111111; //8-13
digitalWrite(a0_pin,LOW);
digitalWrite(a1_pin,LOW);
delay(2);
PORTD |= (address<<2);
PORTB |= (address>>6);
digitalWrite(a0_pin,HIGH);
digitalWrite(a1_pin,LOW);
PORTD |= (data<<2);
PORTB |= (data>>6);
delay(2);
digitalWrite(wr_pin,LOW);
delay(5);
digitalWrite(wr_pin,HIGH);
digitalWrite(led_pin,LOW);
}
void setup()
{
clock=LOW;
//DDRC = 0xFF;
pinMode(wr_pin, OUTPUT);
pinMode(cs_pin, OUTPUT);
pinMode(a0_pin, OUTPUT);
pinMode(a1_pin, OUTPUT);
pinMode(led_pin, OUTPUT);
pinMode(clock_pin, OUTPUT);
digitalWrite(cs_pin,LOW);
// Set up Timer 1 to send a sample every interrupt.
cli();
// Set CTC mode (Clear Timer on Compare Match) (p.133)
// Have to set OCR1A *after*, otherwise it gets reset to 0!
TCCR1B = (TCCR1B & ~_BV(WGM13)) | _BV(WGM12);
TCCR1A = TCCR1A & ~(_BV(WGM11) | _BV(WGM10));
// No prescaler (p.134)
TCCR1B = (TCCR1B & ~(_BV(CS12) | _BV(CS11))) | _BV(CS10);
// Set the compare register (OCR1A).
// OCR1A is a 16-bit register, so we have to do this with
// interrupts disabled to be safe.
OCR1A = F_CPU / 8000000; // 16e6 / 8000 = 2000
// Enable interrupt when TCNT1 == OCR1A (p.136)
TIMSK1 |= _BV(OCIE1A);
sei();
}
void loop()
{
// digitalWrite(led_pin,LOW);
writetTo(0x22,0);
writetTo(0x27,0);
writetTo(0x28,0);
writetTo(0x2B,0);
writetTo(0x30,0x71);
writetTo(0x34,0x0D);
writetTo(0x38,0x33);
writetTo(0x3C,0x01);
writetTo(0x40,0x23);
writetTo(0x44,0x2D);
writetTo(0x48,0x26);
writetTo(0x4C,0x00);
writetTo(0x50,0x5F);
writetTo(0x54,0x99);
writetTo(0x58,0x5F);
writetTo(0x5C,0x94);
writetTo(0x60,0x05);
writetTo(0x64,0x05);
writetTo(0x68,0x05);
writetTo(0x6C,0x07);
writetTo(0x70,0x02);
writetTo(0x74,0x02);
writetTo(0x78,0x02);
writetTo(0x7C,0x02);
writetTo(0x80,0x11);
writetTo(0x84,0x11);
writetTo(0x88,0x11);
writetTo(0x8c,0xa6);
writetTo(0x90,0x00);
writetTo(0x94,0x00);
writetTo(0x98,0x00);
writetTo(0x9c,0x00);
writetTo(0xB0,0x32);
writetTo(0xB4,0xC0);
writetTo(0x28,0x00);
writetTo(0xA4,0x22);
writetTo(0xA0,0x69);
writetTo(0x28,0xF0);
// digitalWrite(led_pin,HIGH);
delay(100);
writetTo(0x28,0x00);
}