Using Assembly Language Programming You have to write a loop that will wait for
ID: 2085832 • Letter: U
Question
Using Assembly Language Programming
You have to write a loop that will wait for a bit in PORTB to be cleared. It is on pin 5 (just like the push button on your VIVA board when the shorting block is set correctly) and is usually held high by a pull-up resistor to Vcc until a button is pushed that shorts the pin to ground. When this pin goes low, you should then drop through to label "Phase2" to continue the application with some unknown other code. I suggest you use one of the bit test instructions. Don't forget the BANKSEL where needed.Explanation / Answer
Answer:- We just need to check PORTB pin 5 continuously and if this pin is made low, we need to jump to a label named as "Phase2", the loop code with some pre-configuration is written below-
Start1: ; label name Start1
MOVLW 0x20 ; load literal 0x20 to W register i.e 0b0010_0000
BANKSEL TRISB ; select the bank of memory in which TRISB register is present
MOVWF TRISB ; making pin 5 as input port, rest input sice zero is assigned
Loop1:
BTFSS PORTB, 5 ; check pin5 of portb if set, skip next instruction written(reading portb pin 5)
GOTO Phase2 ; goto label name "Phase2" if portb pin 5 is clear
GOTO Loop1 ; goto "Loop1" label if portb pin 5 is set
........
.......
Phase2: ; label name "Phase2" starts here onwards
........
........
Note:- This code is for PIC microcontroller only.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.