|
| 1 | +; Define constants for buttons and LEDs |
| 2 | +incXButtonMask equ 00000001b ; Bit mask for P1.0 (Increase X) |
| 3 | +incYButtonMask equ 00000010b ; Bit mask for P1.1 (Increase Y) |
| 4 | +resetButtonMask equ 00000100b ; Bit mask for P1.2 (Reset) |
| 5 | +ledXMask equ 00001000b ; Bit mask for P1.3 (LED for X) |
| 6 | +ledYMask equ 00010000b ; Bit mask for P1.4 (LED for Y) |
| 7 | + |
| 8 | +; Define variables |
| 9 | +countX equ 0 ; Variable X |
| 10 | +countY equ 0 ; Variable Y |
| 11 | + |
| 12 | +; Initialize ports and variables |
| 13 | +SetupP1: |
| 14 | + mov.b #11111111b, &P1DIR ; Set all P1 pins as inputs (except P1.3 and P1.4) |
| 15 | + mov.b #11110011b, &P1OUT ; Enable pull-up resistors for P1.0, P1.1, and P1.2 |
| 16 | + mov.b #00000000b, &P1OUT ; Initialize LEDs (P1.3 and P1.4) to LOW |
| 17 | + mov.b #0d, R8 ; Initialize R8 as a loop counter |
| 18 | + |
| 19 | +main: |
| 20 | + ; Check if the Increase X button is pressed |
| 21 | + bit.b #incXButtonMask, &P1IN |
| 22 | + jz incYButtonPressed ; If the Increase X button is not pressed, check the Increase Y button |
| 23 | + |
| 24 | + ; Debounce the button (wait for a short time) |
| 25 | + mov.w #1000, R9 ; Adjust the delay as needed |
| 26 | +debounceLoopX: |
| 27 | + dec.w R9 |
| 28 | + jnz debounceLoopX |
| 29 | + |
| 30 | + ; Check the button state again |
| 31 | + bit.b #incXButtonMask, &P1IN |
| 32 | + jz incYButtonPressed ; If the Increase X button is still not pressed, check the Increase Y button |
| 33 | + |
| 34 | + ; Increase X |
| 35 | + inc.w countX ; Increment X |
| 36 | + ; Display X on the LED (P1.3) |
| 37 | + mov.b countX, &P1OUT ; Output X to P1.3 LED |
| 38 | + jmp main |
| 39 | + |
| 40 | +incYButtonPressed: |
| 41 | + ; Check if the Increase Y button is pressed |
| 42 | + bit.b #incYButtonMask, &P1IN |
| 43 | + jz resetButtonPressed ; If the Increase Y button is not pressed, check the Reset button |
| 44 | + |
| 45 | + ; Debounce the button (wait for a short time) |
| 46 | + mov.w #1000, R9 ; Adjust the delay as needed |
| 47 | +debounceLoopY: |
| 48 | + dec.w R9 |
| 49 | + jnz debounceLoopY |
| 50 | + |
| 51 | + ; Check the button state again |
| 52 | + bit.b #incYButtonMask, &P1IN |
| 53 | + jz resetButtonPressed ; If the Increase Y button is still not pressed, check the Reset button |
| 54 | + |
| 55 | + ; Increase Y |
| 56 | + inc.w countY ; Increment Y |
| 57 | + ; Display Y on the LED (P1.4) |
| 58 | + mov.b countY, &P1OUT ; Output Y to P1.4 LED |
| 59 | + jmp main |
| 60 | + |
| 61 | +resetButtonPressed: |
| 62 | + ; Check if the Reset button is pressed |
| 63 | + bit.b #resetButtonMask, &P1IN |
| 64 | + jz debounceLoopX ; If the Reset button is not pressed, go back to checking the Increase X button |
| 65 | + |
| 66 | + ; Debounce the button (wait for a short time) |
| 67 | + mov.w #1000, R9 ; Adjust the delay as needed |
| 68 | +debounceLoopReset: |
| 69 | + dec.w R9 |
| 70 | + jnz debounceLoopReset |
| 71 | + |
| 72 | + ; Check the button state again |
| 73 | + bit.b #resetButtonMask, &P1IN |
| 74 | + jz debounceLoopX ; If the Reset button is still not pressed, go back to checking the Increase X button |
| 75 | + |
| 76 | + ; Reset X and Y |
| 77 | + clr.w countX ; Clear X |
| 78 | + clr.w countY ; Clear Y |
| 79 | + ; Turn off LEDs (P1.3 and P1.4) |
| 80 | + mov.b #00000000b, &P1OUT ; Turn off LEDs |
| 81 | + jmp main |
0 commit comments