Question: Description In digital logic and computing, a counter is a device which stores (and sometimes displays) the number of times a particular event or process

Description

In digital logic and computing, a counter is a device which stores (and sometimes displays) the number of times a particular event or process has occurred, often in relationship to a clock signal. Counting in binary is similar to counting in any other number system. Beginning with a single digit, counting proceeds through each symbol, in increasing order. Decimal counting uses the symbols 0 through 9, while binary only uses the symbols 0 and 1.

Work Task

Fully complete both steps (steps 1 and 2) below and then demo them to me. Do the steps as separate CW projects.

Step 1

For this step, you will create a binary counter using the Output Compare (OC) subsystem. The output of the counter (variable OUT) must be displayed on the LEDs. Every OC interrupt, increment the OUT variable and then display its contents on the LEDs. For example, if OUT=$01 then only the rightmost LED will illuminate. If OUT=$FF, then all the LEDs will illuminate. If OUT=$00, then all the LEDs will be off.

Some of the code is provided in the template available on TITANium (lab_7_template.asm). You are only required to do the following:

Enable the LEDs appropriately in the INIT subroutine. We will use all 8 LEDs for this program.

Create an OC initialization subroutine called OC_INIT to initialize the OC subsystem by doing the following:

Your initialization subroutine for the OC subsystem must initially disable maskable interrupts and re-enable them at the end of the subroutine (see instructions SEI and CLI).

Set the correct register such that OC channel 1 (OC1) is used.

Divide the clock by 128 (see pre-scalar bits PR2-0 in TSCR2).

Arm interrupts for OC1.

Set the OM and OL bits such that, when an interrupt occurs, the associated OC channel is toggled.

Set the appropriate timer channel such that an OC interrupt on channel 1 occurs in 100ms.

Create an OC interrupt subroutine called OC1_ISR that does the following:

Acknowledges the interrupt.

Increments the variable OUT.

Set the timer counter such that the next interrupt occurs in 100ms.

Return from the interrupt using the RTI instruction

After the RTI instruction, set the OC1_ISR to the appropriate interrupt vector location (see pg. 37 of the Dragon12 Light User Manual on the course website).

NOTES

You will not call the OC1_ISR in the main program. It is called automatically by the MCU when an interrupt occurs. For this lab, if initialized appropriately, an interrupt will occur when TC1=TCNT (when the timer channel 1 equals the free-running timer counter).

Also, the main loop portion of your code should remain the same as the template. Do not remove/add code to the main loop. This holds true for step 2 as well.

Step 2

For this step, copy the code you created in step 1 into a new project and use this as a basis. Now, you will use the pushbuttons to increase and decrease the counting speed. You will use PB1 to decrease the speed and PB2 to increase the speed by 10ms each push. However, if the user holds the pushbutton, the change should only occur once. In other words, the user must continuously press the pushbutton to change (increase or decrease) the counting speed.

Also, you should set lower and upper limits for the speed to prevent wrapping. For example, the LEDs shouldnt slow down and then suddenly speed-up (and vice-versa).

You will have to configure port H to accept interrupts from PB1 and PB2 (see Figure 1). In the initialization subroutine for the pushbuttons, only set the appropriate port pins such that only PB1 and PB2 are configured. Points will be deducted if all the pins of port H are set to inputs.

Figure 1: The PBs used for this step.

What to Turn In (Please read this carefully)

You are to put your code as text into the lab_7_template.docx in the designated area. Also, answer the questions asked in the template. This will be the file that you upload to TITANium as your submission. Provide your code as text, not an image. Points will be deducted if it is an image. You must also demo your functioning code for both steps.

here is the presented assumbly laungage

;****************************************************************

;*

;* Lab 7 Template

;*

;****************************************************************

;----------------------------------------------------

; Export Symbols

; KEEP THIS!!

;----------------------------------------------------

XDEF Entry ; export 'Entry' symbol

ABSENTRY Entry ; for absolute assembly: mark this as application entry point

;----------------------------------------------------

; Derivative-Specific Definitions

; KEEP THIS!!

;----------------------------------------------------

INCLUDE 'derivative.inc'

;----------------------------------------------------

; Constants Section

; KEEP THIS!!

;----------------------------------------------------

ROM EQU $0400

DATA EQU $1000

PROG EQU $2000

;----------------------------------------------------

; Variable/Data Section

; KEEP THIS!!

;----------------------------------------------------

ORG DATA

OUT FCB 0

;----------------------------------------------------

; Code Section

; KEEP THIS!!

;----------------------------------------------------

ORG PROG

; Insert your code following the label "Entry"

Entry: ; KEEP THIS LABEL!!

LDS #PROG

BSR INIT

BSR OC_INIT

MAIN:

LDAA OUT

STAA PORTB

BRA MAIN

;----------------------------------------------------

; Init Subroutine

;----------------------------------------------------

INIT:

;******************************************

; Enable Discrete LEDs here

;******************************************

;******************************************

; Disable 7-Segment Display

BSET DDRP,#$0F ; Set Port P pins 0-3 to output

RTS

;----------------------------------------------------

; OC Init Subroutine

;----------------------------------------------------

OC_INIT:

;******************************************

; Enter OC Init here

;******************************************

;******************************************

RTS

;----------------------------------------------------

; OC ISR

;----------------------------------------------------

OC1_ISR:

;******************************************

; Enter ISR code here

;******************************************

;******************************************

RTI

;----------------------------------------------------

; Interrupt Vector

;----------------------------------------------------

;******************************************

; Enter Interrupt Vector code here

;******************************************

;******************************************

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!