Skip to content

Commit 662dd9a

Browse files
committed
exp4 and exp6
1 parent 91a8519 commit 662dd9a

6 files changed

Lines changed: 207 additions & 0 deletions

File tree

215 KB
Binary file not shown.
372 KB
Binary file not shown.

Experiment - 6/part1.asm

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; Define ports and registers
2+
PORT_DISPLAY equ 0x01 ; Address of the port connected to 7-segment displays
3+
DELAY_COUNT equ 0xFF ; Delay count for controlling the speed
4+
5+
ORG 0x0000 ; Start address of the program
6+
7+
MainLoop
8+
mov R1, #0x01 ; Initialize register R1 with 0x01
9+
10+
; Loop through the four displays
11+
LoopDisplays
12+
mov [PORT_DISPLAY], R1 ; Output the value of R1 to the display port
13+
call Delay ; Introduce a delay to control the speed
14+
mov R1, R1 << 1 ; Shift the value in R1 to the left for the next display
15+
jz ResetLoop ; If R1 becomes zero, reset the loop
16+
17+
jmp LoopDisplays ; Repeat the loop for the next display
18+
19+
ResetLoop
20+
mov R1, #0x01 ; Reset R1 to 0x01 to restart the loop
21+
22+
jmp MainLoop ; Repeat the main loop
23+
24+
Delay
25+
mov R2, #DELAY_COUNT ; Initialize register R2 with the delay count
26+
27+
DelayLoop
28+
dec R2 ; Decrement R2
29+
jnz DelayLoop ; Continue looping until R2 becomes zero
30+
ret ; Return from the delay subroutine

Experiment - 6/part2.asm

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
; Define ports and registers
2+
PORT_DISPLAY equ 0x01 ; Address of the port connected to 7-segment displays
3+
4+
ORG 0x0000 ; Start address of the program
5+
6+
Main
7+
mov R3, #0 ; Initialize register R3 to store the BCD result
8+
9+
; Binary input value (adjust this value as needed)
10+
mov R0, #97 ; Example: binary input of 97
11+
12+
; Call BCD conversion subroutine
13+
call BCDConvert
14+
15+
; Display the BCD result on 7-segment displays
16+
mov [PORT_DISPLAY], R3 ; Output the tens digit
17+
call Delay ; Introduce a delay
18+
mov [PORT_DISPLAY], R4 ; Output the ones digit
19+
20+
; Infinite loop
21+
jmp Main
22+
23+
; BCD conversion subroutine
24+
BCDConvert
25+
mov R4, R0 ; Copy the binary input to R4
26+
mov R3, #0 ; Clear R3 for the tens digit
27+
28+
; Convert tens digit
29+
BCDLoop
30+
cmp R4, #10 ; Compare R4 with 10
31+
jl BCDDone ; If R4 is less than 10, exit the loop
32+
33+
sub R4, #10 ; Subtract 10 from R4
34+
inc R3 ; Increment the tens digit
35+
jmp BCDLoop ; Repeat the loop
36+
37+
BCDDone
38+
ret ; Return from the subroutine
39+
40+
Delay
41+
; Delay subroutine goes here
42+
ret ; Placeholder return

Experiment - 6/part3.asm

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
; Define ports and registers
2+
PORT_DISPLAY equ 0x0200 ; Address of the port connected to 7-segment displays
3+
4+
; Timer A registers
5+
TA0CTL equ 0x0160 ; Timer A0 Control
6+
TA0CCR0 equ 0x0172 ; Timer A0 Capture/Compare 0
7+
TA0CCTL0 equ 0x0162 ; Timer A0 Capture/Compare Control 0
8+
9+
ORG 0x0000 ; Start address of the program
10+
11+
; Initialize the main program
12+
Main mov.w #WDTCTL, R2 ; Disable Watchdog Timer
13+
mov.w #WDTPW | WDTHOLD, R3
14+
mov.w #PORT_DISPLAY, R4 ; Address of the display port
15+
mov.w #0, R5 ; Clear register R5 for the BCD result
16+
17+
; Configure Timer A
18+
mov.w #TA0CTL, R6 ; Load the address of Timer A0 Control register
19+
mov.w #TASSEL_2 | MC_1 | ID_3, 0(R6) ; Set SMCLK as source, Up mode, and divide by 8
20+
21+
mov.w #TA0CCR0, R7 ; Load the address of Timer A0 CCR0 register
22+
mov.w #10486, 0(R7) ; Set the value for 10 ms interrupt (10486 for 1 MHz SMCLK)
23+
24+
mov.w #TA0CCTL0, R8 ; Load the address of Timer A0 CCTL0 register
25+
mov.w #CCIE, 0(R8) ; Enable Timer A0 CCR0 interrupt
26+
27+
; Enable global interrupts
28+
EINT
29+
30+
; Infinite loop
31+
MainLoop jmp MainLoop
32+
33+
; Timer A0 CCR0 interrupt service routine
34+
.sect "int09"
35+
.short TISR
36+
37+
TISR ; Interrupt service routine code goes here
38+
39+
; For demonstration purposes, toggle an output on every interrupt
40+
XOR.B #1, 0(R4) ; Toggle the least significant bit of the display port
41+
42+
RETI ; Return from interrupt

Experiment - 6/part4.asm

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
; Define ports and registers
2+
PORT_DISPLAY equ 0x0200 ; Address of the port connected to 7-segment displays
3+
PORT_BUTTONS equ 0x0210 ; Address of the port connected to buttons
4+
5+
; Timer A registers
6+
TA0CTL equ 0x0160 ; Timer A0 Control
7+
TA0CCR0 equ 0x0172 ; Timer A0 Capture/Compare 0
8+
TA0CCTL0 equ 0x0162 ; Timer A0 Capture/Compare Control 0
9+
10+
; Button registers
11+
BUTTON_STOP equ BIT0 ; Stop button (P1.0)
12+
BUTTON_START equ BIT1 ; Start button (P1.1)
13+
BUTTON_RESET equ BIT2 ; Reset button (P1.2)
14+
15+
; Variables
16+
SECONDS equ 0x0204 ; Seconds variable
17+
CENTISECONDS equ 0x0205 ; Centiseconds variable
18+
TIMER_RUNNING equ 0x0206 ; Flag to indicate if the timer is running (1 if running, 0 if stopped)
19+
20+
ORG 0x0000 ; Start address of the program
21+
22+
; Initialize the main program
23+
Main mov.w #WDTCTL, R2 ; Disable Watchdog Timer
24+
mov.w #WDTPW | WDTHOLD, R3
25+
mov.w #PORT_DISPLAY, R4 ; Address of the display port
26+
mov.w #PORT_BUTTONS, R9 ; Address of the buttons port
27+
mov.b #0, TIMER_RUNNING ; Initialize timer running flag
28+
29+
; Configure Timer A
30+
mov.w #TA0CTL, R6 ; Load the address of Timer A0 Control register
31+
mov.w #TASSEL_2 | MC_1 | ID_3, 0(R6) ; Set SMCLK as source, Up mode, and divide by 8
32+
33+
mov.w #TA0CCR0, R7 ; Load the address of Timer A0 CCR0 register
34+
mov.w #10486, 0(R7) ; Set the value for 10 ms interrupt (10486 for 1 MHz SMCLK)
35+
36+
mov.w #TA0CCTL0, R8 ; Load the address of Timer A0 CCTL0 register
37+
mov.w #CCIE, 0(R8) ; Enable Timer A0 CCR0 interrupt
38+
39+
; Configure buttons as inputs with pull-up resistors
40+
mov.w #BUTTON_STOP | BUTTON_START | BUTTON_RESET, 0(R9) ; Set pins as inputs
41+
mov.w #BUTTON_STOP | BUTTON_START | BUTTON_RESET, R10 ; Load button mask to R10
42+
43+
; Enable global interrupts
44+
EINT
45+
46+
; Infinite loop
47+
MainLoop mov.b 0(R9), R11 ; Read buttons status
48+
49+
; Check Stop button
50+
bit.b #BUTTON_STOP, R11
51+
jnz StopPressed
52+
53+
; Check Start button
54+
bit.b #BUTTON_START, R11
55+
jnz StartPressed
56+
57+
; Check Reset button
58+
bit.b #BUTTON_RESET, R11
59+
jnz ResetPressed
60+
61+
jmp MainLoop
62+
63+
StopPressed mov.b #0, TIMER_RUNNING ; Stop the timer
64+
jmp MainLoop
65+
66+
StartPressed mov.b #1, TIMER_RUNNING ; Start the timer
67+
jmp MainLoop
68+
69+
ResetPressed mov.b #0, TIMER_RUNNING ; Stop the timer
70+
clr.b SECONDS ; Clear the seconds variable
71+
clr.b CENTISECONDS ; Clear the centiseconds variable
72+
jmp MainLoop
73+
74+
; Timer A0 CCR0 interrupt service routine
75+
.sect "int09"
76+
.short TISR
77+
78+
TISR mov.b TIMER_RUNNING, R12 ; Check if the timer is running
79+
cmp.b #1, R12 ; If timer is running, proceed with counting
80+
jeq CountTime
81+
82+
RETI ; If timer is not running, return from interrupt
83+
84+
CountTime inc.b CENTISECONDS ; Increment centiseconds
85+
86+
; Check if one second has passed
87+
cmp.b #100, CENTISECONDS
88+
jne SkipSecond
89+
90+
clr.b CENTISECONDS ; Reset centiseconds
91+
inc.b SECONDS ; Increment seconds
92+
93+
SkipSecond RETI ; Return from interrupt

0 commit comments

Comments
 (0)