2. Write a program to turn LED4 and LED1 ON. LED2 and LED3 must be OFF. A. Cut and paste the source code. B. Single step the code. After executing the line that sends the pattern to PTT, cut and paste the Memory Window showing the value of PTT. The Memory Address of PTT is $270. Right-click on Memory Window and select address. Type 270 in the address field. 3. Write a program to continuously turn all four green LEDs ON and OFF (toggle). There should be a one-second delay between each toggle. A. Cut and paste the source code. B. Show the delay calculation. 4. Write a program that displays values from 0 to 15 sequentially, with a 0.75-second delay in between each display. After the count value reaches 15 (i.e. all LEDs are ON), the program should stop. A. Cut and paste the code. B. Show the delay calculation. 5. Use BSET and BCLR instructions to Turn LED2 ON and OFF continuously with a 0.5-second delay between each change. A. Cut and paste the source code. B. Show the delay calculation. Change the delay to 1ms and run the program.

1. Introduction

In this assignment, we will be writing and analyzing code for controlling LEDs on a microcontroller. The goal is to write programs that can turn on/off specific LEDs, toggle all LEDs, sequentially display values, and use specific instructions for controlling LEDs with delay calculations. We will be providing the source code for each program and demonstrating how to single-step through the code for better understanding and analysis.

2. Program to turn LED4 and LED1 ON

Let’s start by writing a program to turn on LED4 and LED1 while keeping LED2 and LED3 off. Below is the source code for this program:

“`
MOV PTT, #$09
“`

Explanation:
– The `MOV` instruction is used to move a value into a specific register or memory location.
– `PTT` is a register that controls the output pins for the LEDs on the microcontroller.
– `#$09` is a hexadecimal value that represents the desired pattern for the LEDs. In this case, LED4 and LED1 are turned on, while LED2 and LED3 are turned off.

To single-step through the code and see the value of `PTT` in the memory window, follow these steps:
1. Execute the line that sends the pattern to `PTT` (MOV PTT, #$09).
2. Cut and paste the memory window showing the value of `PTT`. The memory address of `PTT` is $270.
3. Right-click on the memory window and select “address”.
4. Type 270 in the address field.

By following these steps, you will be able to observe the value of `PTT` in the memory window, which should be #$09, indicating that LED4 and LED1 are turned on.

3. Program to toggle all four green LEDs with a one-second delay

Next, we will write a program to continuously toggle all four green LEDs on and off with a one-second delay between each toggle. Below is the source code for this program:

“`
TOGGLE_LOOP:
MOV PTT, #$0F
JSR DELAY_1_SECOND
MOV PTT, #$00
JSR DELAY_1_SECOND
JMP TOGGLE_LOOP

DELAY_1_SECOND: ; Delay subroutine
; Delay calculation goes here
RTS
“`

Explanation:
– The program uses a loop (`TOGGLE_LOOP`) to continuously toggle the LEDs on and off.
– The `MOV` instruction is used to set `PTT` to #$0F, turning on all four LEDs, followed by a one-second delay subroutine (`JSR DELAY_1_SECOND`).
– Then, the `MOV` instruction is used to set `PTT` to #$00, turning off all four LEDs, followed by another one-second delay subroutine.
– The program then jumps back to the `TOGGLE_LOOP` label to repeat the process indefinitely.

To analyze the delay calculation and determine the length of the delay, please provide the delay calculation code for further examination.

4. Program to sequentially display values from 0 to 15

Next, we will write a program that displays values from 0 to 15 sequentially, with a 0.75-second delay between each display. Once the count value reaches 15, indicating that all LEDs are turned on, the program should stop. Below is the source code for this program:

“`
SEQUENTIAL_LOOP:
MOV PTT, COUNT
JSR DELAY_0_75_SECOND
INC COUNT
CMP COUNT, #$10
BNE SEQUENTIAL_LOOP

DELAY_0_75_SECOND: ; Delay subroutine
; Delay calculation goes here
RTS
“`

Explanation:
– The program uses a loop (`SEQUENTIAL_LOOP`) to display values from 0 to 15 sequentially.
– The value to be displayed is stored in a register called `COUNT`, which is moved into `PTT` using the `MOV` instruction.
– After each display, the program performs a 0.75-second delay (`JSR DELAY_0_75_SECOND`).
– The `INC` instruction increments the value of `COUNT` by 1.
– The `CMP` instruction compares the value of `COUNT` with 16 (hexadecimal #$10) to check if it has reached 15.
– If the values are not equal (`BNE`), the program jumps back to the `SEQUENTIAL_LOOP` label to continue the sequence.

To analyze the delay calculation and determine the length of the delay, please provide the delay calculation code for further examination.

5. Using BSET and BCLR instructions to turn LED2 on and off with a 0.5-second delay

Lastly, we will write a program that continuously turns LED2 on and off using the BSET and BCLR instructions, with a 0.5-second delay between each change. Below is the source code for this program:

“`
DELAY_LOOP:
BSET PTT, #$02
JSR DELAY_0_5_SECOND
BCLR PTT, #$02
JSR DELAY_0_5_SECOND
JMP DELAY_LOOP

DELAY_0_5_SECOND: ; Delay subroutine
; Delay calculation goes here
RTS
“`

Explanation:
– The program uses a loop (`DELAY_LOOP`) to continuously turn LED2 on and off.
– The `BSET` instruction sets bit 2 of `PTT` to 1, turning LED2 on.
– After a 0.5-second delay (`JSR DELAY_0_5_SECOND`), the `BCLR` instruction clears bit 2 of `PTT`, turning LED2 off.
– Another 0.5-second delay is performed before jumping back to the `DELAY_LOOP` label to repeat the process indefinitely.

To analyze the delay calculation and determine the length of the delay, please provide the delay calculation code for further examination. Additionally, if you would like to change the delay to 1ms and run the program, please specify the desired changes and provide the updated code.

In the next sections, we will discuss the delay calculation code and provide recommendations for modifying the delay to 1ms.

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Click Here to Make an Order Click Here to Hire a Writer