Digital Protoboard

The Digital Protoboard is the the set of 8 switches and 8 LEDs sitting beside the breadboard. This board can be connected to the 40-pin expansion header (either JP1 or JP2) so that the Nios II processor can access these switches and LEDs.

DeviceDigital Protoboard
Input/Outputeither
Address BaseJP1: 0x10000060
JP2: 0x10000070
Address Map
AddressR/WDescription
baseR/WData Register for reading/writing from/to the pins
Bits 7 to 0 correspond to switches, bits 15 to 8 correspond to LEDs
base+4R/WDirection Register configures each pin for input (0) or output (1)
base+8R/WInterrupt Mask Register enables interrupts for each pin (the corresponding pin should be configured as input)
base+12R/WEdge Capture Register, a bit is high if corresponding pin changed its value. Writing here clears all bits.
InitializationSet Direction Register bits of switches for input, and LEDs for output
Interrupts
TriggeredOn either edge (when any interrupt-enabled input switch is toggled)
IRQ LineJP1=11, JP2=12
EnableSet bits in Interrupt Mask Register that correspond to input pin you want to interrupt on
AcknowledgeWrite to Edge Capture Register (which clears it)
Hardware SetupConnect the 40-pin ribbon from the hexkeypad to either port JP1/2 on the DE2
Reference GPIO Ports

Notes

The 8 switches on the Digital Protoboard are connected to pins 0 to 7 on the expansion header, while the 8 LEDs are connected to pins 8 to 15. These groups of 8-bits directly control each switch/LED.

Assembly Example: Using JP1, Read switches into r3

.equ ADDR_JP1PORT, 0x10000060

  movia r2,ADDR_JP1PORT
  stwio r0,4(r2)  /* Set directions to input */

  ldwio r3,0(r2)  /* Read switch data */

Assembly Example: Turn on every other LED

.equ ADDR_JP1PORT, 0x10000060

  movia r2,ADDR_JP1PORT
  movia  r3,0x0000ff00
  stwio r3,4(r2)  /* Set directions to output */

  movui  r3,0xaa00
  stwio r3,0(r2)  /* Drive LEDs */

C Example: Using JP1, Read switches to set LEDs

#define ProtoBoard ((volatile long *) 0x10000060)

int main()
{ 
   // init protoboard interface directions
   *(ProtoBoard+1) = 0x0000ff00; //set switch bit directions to input, LEDs to output
   
   long temp;   
   while (1)
   {
      temp = *ProtoBoard;      // Read from protoboard
      *ProtoBoard = temp << 8; // Write shifted version of switch input to LEDs
   }
}