This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Arduino Direct Port Manipulation

By: a guest on Apr 10th, 2012  |  syntax: C  |  size: 0.83 KB  |  views: 54  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.
clone this paste RAW Paste Data