Skip to content

Commit f3d2809

Browse files
committed
first commit
1 parent 2cfebb3 commit f3d2809

File tree

3 files changed

+182
-0
lines changed

3 files changed

+182
-0
lines changed

Experiment - 2/part1.asm

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
; Define constants for button and LED
2+
buttonMask equ 00000100b ; Bit mask for P1.2
3+
ledMask equ 00010000b ; Bit mask for P1.4
4+
5+
; Define variables
6+
count equ 0 ; Counter for button presses
7+
8+
; Initialize ports and variables
9+
SetupP1:
10+
mov.b #11111111b, &P1DIR ; Set all P1 pins as inputs (except P1.4)
11+
mov.b #11110111b, &P1OUT ; Enable pull-up resistor for P1.2 (P1.4 is initially low)
12+
mov.b #0d, R8 ; Initialize R8 as a loop counter
13+
14+
main:
15+
; Check if the button is pressed
16+
bit.b #buttonMask, &P1IN ; Read the state of the button
17+
jz buttonNotPressed ; If the button is not pressed, continue
18+
; Debounce the button (wait for a short time)
19+
mov.w #1000, R9 ; Adjust the delay as needed
20+
debounceLoop:
21+
dec.w R9
22+
jnz debounceLoop
23+
; Check the button state again
24+
bit.b #buttonMask, &P1IN
25+
jz buttonNotPressed ; If the button is still not pressed, continue
26+
; Button is pressed
27+
inc.w count ; Increment the count
28+
; Toggle the LED
29+
bit.b #ledMask, &P1OUT ; Toggle the LED state
30+
buttonNotPressed:
31+
; Your code continues here
32+
; For example, you can display the count on the LEDs or perform other actions
33+
34+
; Delay for a short time (optional)
35+
mov.w #10000, R10 ; Adjust the delay as needed
36+
delayLoop:
37+
dec.w R10
38+
jnz delayLoop
39+
40+
jmp main ; Repeat the main loop

Experiment - 2/part2.asm

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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

Experiment - 2/part3.asm

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
calculateZButtonMask equ 00001000b ; Bit mask for P1.3 (Calculate Z)
6+
ledXMask equ 00010000b ; Bit mask for P1.4 (LED for X)
7+
ledYMask equ 00100000b ; Bit mask for P1.5 (LED for Y)
8+
ledZMask equ 01000000b ; Bit mask for P1.6 (LED for Z)
9+
10+
; Define variables
11+
countX equ 0 ; Variable X
12+
countY equ 0 ; Variable Y
13+
countZ equ 0 ; Variable Z
14+
15+
; Initialize ports and variables
16+
SetupP1:
17+
mov.b #11111111b, &P1DIR ; Set all P1 pins as inputs (except P1.4, P1.5, and P1.6)
18+
mov.b #11110011b, &P1OUT ; Enable pull-up resistors for P1.0, P1.1, and P1.2
19+
mov.b #00000000b, &P1OUT ; Initialize LEDs (P1.4, P1.5, and P1.6) to LOW
20+
mov.b #0d, R8 ; Initialize R8 as a loop counter
21+
22+
main:
23+
; Check if the Increase X button is pressed
24+
bit.b #incXButtonMask, &P1IN
25+
jz incYButtonPressed ; If the Increase X button is not pressed, check the Increase Y button
26+
27+
; ... (Increment X code)
28+
29+
incYButtonPressed:
30+
; Check if the Increase Y button is pressed
31+
bit.b #incYButtonMask, &P1IN
32+
jz resetButtonPressed ; If the Increase Y button is not pressed, check the Reset button
33+
34+
; ... (Increment Y code)
35+
36+
resetButtonPressed:
37+
; Check if the Reset button is pressed
38+
bit.b #resetButtonMask, &P1IN
39+
jz calculateZButtonPressed ; If the Reset button is not pressed, check the Calculate Z button
40+
41+
; ... (Reset code)
42+
43+
calculateZButtonPressed:
44+
; Check if the Calculate Z button is pressed
45+
bit.b #calculateZButtonMask, &P1IN
46+
jz debounceLoopX ; If the Calculate Z button is not pressed, go back to checking the Increase X button
47+
48+
; ... (Debounce Calculate Z button)
49+
50+
calculateZ:
51+
; Calculate Z as X * Y using a loop
52+
clr.w countZ ; Clear Z
53+
54+
calculateZLoop:
55+
add.w countX, countZ ; Add X to Z
56+
dec.w countY
57+
jnz calculateZLoop
58+
59+
; Display Z on the LED (P1.6)
60+
mov.b countZ, &P1OUT ; Output Z to P1.6 LED
61+
jmp main

0 commit comments

Comments
 (0)