Pushbuttons on DE1-SoC Computer
Synchronization between outside I/O world and the software running must be done carefully
How does the processor know some in new input has arrived and also output has been sent?
Data register behaviour: when key i
is pressed, bit i
of the data register goes to 1
i
goes to 0
Edge capture register behaviour: pressing and releasing key i
causes bit i
to become 1
1
into bit i
0
s here means don’t change that edge capture bitThere are 4: KEY0 → KEY3
They are connected to a parallel port, which is a set of memory-mapped registers
Edge capture register goes to 1 and stays there after release
KEY
push buttons with Data RegisterWe need two loops, one to check if its been pressed down, the other to see if its been released
In Lab 4: you must first use data register to detect button push and then release
.equ KEY_BASE, 0xff200050
movia r8, KEY_BASE
; polling loop to wait for KEY1 to bepressed
poll:
ldwio r9 0(r8) ; loads the data register
andi r9, r9 , 0x2 ; bit mask to isolate out the one bit
beq r9, r0, poll
; arrive here only when key 1 is pressed -> bit is 1
KEY
push buttons with Edge Capture Register _start:
movia r8,KEY_BASE ; set r8 to base KEY port
movia r9,LEDs ; set r9 to base of LEDR port
movi r10, 1 ; first value of LEDR output is 1
poll:
ldwio r11, 0xC(r8) ; load edge capture reg
andi r11,r11,0x4 ; 'select' bit for Key2 is 0100
beq r11, r0, poll ; if 0, nothing changed -> loop
stwio r10, (r9) ; turn on/off LED
xori r10,r10, 1 ; invert r10 for next time
movi r12, 0x4 ; turn off edge capture bit
stwio r12, 0xC(r8) ; by writing 1 into bit 2
; that takes a lot of getting use to!
br poll ; go back to poll loop
Memory Mapped Address | Register | Notes |
---|---|---|
0xff202000 |
Status Register | Bit 0 = TO (Time Out) |
Bit 1 = RUN | ||
0xff202004 |
Control Register | Bit 0 = ITO |
Bit 1 = CONT | ||
Bit 2: START | ||
Bit 3: STOP | ||
0xff202008 |
Start Register | Bits 0-15: Counter start (low order) |
0xff20200c |
Bits 16 - 31: Counter start (high order) |
Status Register: contains status flags
TO
: Timer Out, which indicates whether the timer has reached the timeout value
1
when counter hits 0
0
to reset