Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help writing this HCS12 code warrior program. Bit 4 of Port B is connecte

ID: 3540997 • 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

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