SHARE
TWEET

Arduino Direct Port Manipulation

a guest Apr 10th, 2012 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Pin Mapping
  2. //
  3. //Arduino 9 (PORTB) -> YM Addr/Data 7
  4. //Arduino 8 (PORTB) -> YM Addr/Data 6
  5. //Arduino 7 (PORTD) -> YM Addr/Data 5
  6. //Arduino 6 (PORTD) -> YM Addr/Data 4
  7. //Arduino 5 (PORTD) -> YM Addr/Data 3
  8. //Arduino 4 (PORTD) -> YM Addr/Data 2
  9. //Arduino 3 (PORTD) -> YM Addr/Data 1
  10. //Arduino 2 (PORTD) -> YM Addr/Data 0
  11.  
  12. //Pin Setup
  13. DDRD = DDRD | B11111100; // sets Arduino pins 2 to 7 as outputs, leaves 0 & 1 untouched.
  14.  
  15. DDRB = DDRB | B00000011; // sets Arduino pins 8 and 9 as outputs, leaves 10-13 untouched.
  16.  
  17. //Port Writing
  18. 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.
  19.  
  20. 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
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top