I need help writing this HCS12 code warrior program. Bit 4 of Port B is connecte
ID: 3541094 • Letter: I
Question
I need help writing this HCS12 code warrior program.
Bit 4 of Port B is connected to a switch that normally outputs a zero. Monitor this switch to detect a change from zero to one. Immediately when it becomes one, call a function to toggle Bit 5 of Port B, which is connected to an LED. Use an exclusive-OR operation to toggle PB5 two times. After the function call, the code should branch to the line that monitors PB4.
I think that this is the general idea, but it needs to be in C;
SETB B.4
CLR C
MOV B.5, C
AGAIN: MOV C,B.4
JNC AGAIN
MOV R1,#02H
HERE: MOV A,B
XRL A,#10H
MOV B,A
DJNZ R1, HERE
SJMP AGAIN
Explanation / Answer
this is the correct order
SETB B.4
CLR C
MOV B.5, C
AGAIN: MOV C,B.4
JNC AGAIN
MOV R1,#02H
HERE: MOV A,B
XRL A,#10H
MOV B,A
DJNZ R1, HERE
SJMP AGAIN