Anyone know how to do this? Here\'s how it works: The following code is run on a
ID: 3551280 • Letter: A
Question
Anyone know how to do this? Here's how it works:
The following code is run on a PSoC connected to a pushbutton that produces a '1' on port1[2] when it is pushed down. The button bounces for a maximum of 34 ms after being pressed. What is the final value of [count] if the button is initially released, pushed and held for 362 ms, released for 322 ms, pushed for 257 ms, and then released? Please also show reasoning leading to your answer. Here you may assume that the time for all code except for the call to delay_50_ms is negligible.
mov [count], 0
read: tst reg[PRT1DR], %00000100 // look for port1[2] low
jz read
call delay_50_ms // assume that this delays for 50 ms
tst reg[PRT1DR], %00000100 // look for port1[2] low
jz read
inc [count]
jmp read
Explanation / Answer
lets see what program is doing
mov [count], 0
read: tst reg[PRT1DR], %00000100 // look for port1[2] low
jz read // if port 1[2] was 0 go back and read again
call delay_50_ms // wait for for 50ms to let the button debounce
tst reg[PRT1DR], %00000100 // now check again
jz read
inc [count] // increment count
jmp read
when button is pushed port1[2] will be high delay will be called and count will be incremented. hence for count to increase by 1 button needs to be pressed for 50ms.
362ms 50*7ms +12 ms
hence count increases to 7
322ms button is released . count will not increase
257ms =50*5+7
hence count increases from 7 to 7+5 =12
hence count =12
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.