Arduino Direct Port Manipulation
a guest Apr 10th, 2012 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- //Pin Mapping
- //Arduino 9 (PORTB) -> YM Addr/Data 7
- //Arduino 8 (PORTB) -> YM Addr/Data 6
- //Arduino 7 (PORTD) -> YM Addr/Data 5
- //Arduino 6 (PORTD) -> YM Addr/Data 4
- //Arduino 5 (PORTD) -> YM Addr/Data 3
- //Arduino 4 (PORTD) -> YM Addr/Data 2
- //Arduino 3 (PORTD) -> YM Addr/Data 1
- //Arduino 2 (PORTD) -> YM Addr/Data 0
- //Pin Setup
- DDRD = DDRD | B11111100; // sets Arduino pins 2 to 7 as outputs, leaves 0 & 1 untouched.
- DDRB = DDRB | B00000011; // sets Arduino pins 8 and 9 as outputs, leaves 10-13 untouched.
- //Port Writing
- PORTD = (data << 2) & B11111100; // Shifts data 2 bits left to set up lower 6 bits of data to occupy upper 6 bits of PORTD, masked and written out.
- PORTB = (data >> 6) & B00000011; // Shifts data 6 bits right to set up upper 2 bits of data to occupy lower 2 bits of PORTB, masked and written out.
RAW Paste Data