0% found this document useful (0 votes)
67 views

Lebanese American University School of Engineering: Microprocessors Lab COE324

This document describes two tasks completed in a microprocessors lab. Task 1 involves printing a 2-digit decimal number on an LCD screen by converting each digit to ASCII. Task 2 implements a continuous countdown from 10 to 0 using an interrupt triggered by a switch. Variables, registers, and subroutines are defined to divide the number, get each digit, convert to ASCII, and print on the LCD. An interrupt vector and subroutine are used to reset the counter when the switch is pressed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

Lebanese American University School of Engineering: Microprocessors Lab COE324

This document describes two tasks completed in a microprocessors lab. Task 1 involves printing a 2-digit decimal number on an LCD screen by converting each digit to ASCII. Task 2 implements a continuous countdown from 10 to 0 using an interrupt triggered by a switch. Variables, registers, and subroutines are defined to divide the number, get each digit, convert to ASCII, and print on the LCD. An interrupt vector and subroutine are used to reset the counter when the switch is pressed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Lebanese American University

School of Engineering

Microprocessors Lab
COE324
Ms. Safaa El Hajj
Lab 6

Farah ElAkoum 201701833

Ragheed Habli 201702464

Monday, November 4, 2019


Table of Contents
Introduction.................................................................................................................................................4
Task 1: Print a 2-digit decimal number on the LCD screen..........................................................................5
Task 2: Continuously count down from 10 to 0...........................................................................................7
Table of Figures
Figure 1: Variable Definitions......................................................................................................................5
Figure 2: Main Code....................................................................................................................................5
Figure 3: Flowchart of Task1 Logic...............................................................................................................6
Figure 4: Variable Definition........................................................................................................................7
Figure 5: Switches' Connection....................................................................................................................7
Figure 6: Interrupt Origin.............................................................................................................................8
Figure 7: Interrupt Vector............................................................................................................................8
Figure 8: Interrupt Subroutine.....................................................................................................................8
Figure 9: Countdown Subroutine.................................................................................................................9
Introduction
In this lab, we will use our knowledge in previous labs like issuing interrupts and printing on LCD screen
to perform several tasks. We will first display a 2-digit decimal number on the LCD screen after
converting its digits to the ASCII representation. Second, we will perform a continuous countdown with
interrupt issued when a switch is pushed. Finally, we will display the number 0 on LCD with switch
buttons pushed to perform different operations.
Task 1: Print a 2-digit decimal number on the LCD screen
In order to complete this task several things are taken into consideration

 The decimal number to print is saved in memory (DECIMAL), and a place in memory is held for
the quotient (QUOTIENT) and data (DATA) to store the quotient and remainder of the division
operation after each iteration.

Figure 1: Variable Definitions

 Register X will hold the address of the decimal number to be displayed.


 We push registers X and D onto the stack then pull them at the end of the subroutine so that
their contents are not ruined.
 We will use “IDIV” instruction :
This is a 16 by 16 unsigned integer division where the content of register D is divided by
the content in register X. The remainder is stored in D and the quotient is stored in
register X.
 The SEND_DATA, SEND_INST, LCD_INIT, SEND_SPI, initializing SPI and DELAY subroutines are
pieces of reused code from previous labs; we will not repeat them again and put them in this
lab.

The following is the code that contains the main code with the subroutine:

Figure 2: Main Code


The following is the logic of our subroutine which takes the decimal number, gets each digit, converts it
to the ASCII representation and prints it to the LCD :

Figure 3: Flowchart of Task1 Logic


Task 2: Continuously count down from 10 to 0
In this task, our code is an infinite loop that continuously counts down from 10 to 0. In addition, if switch
2 (SW2) is pressed, the timer is reset. This can be done by issuing an interrupt. We will go through
several steps to write this code:

 The SEND_DATA, SEND_INST, LCD_INIT, SEND_SPI, initializing SPI and DELAY subroutines are
pieces of reused code from previous labs; we will not repeat them again and put them in this
lab.

 First, our data should be initialized by defining COUNTD variable in memory with the value 10.

Figure 4: Variable Definition

 Second, we need to determine to which port SW2 is connected and configure its registers.
From the figure below, SW2 is connected to the second bit (bit1) of portP and thus five
registers , DDRP | RDRP | PERP | PPSP | PIEP are configured.

Figure 5: Switches' Connection


1. DDRP : PORT P Data direction register which determines whether the associated pin to
portP acts as an input or output. If we set a bit to “0” we configure it as input, and we set it
to “1” we configure it to act as output. We want to configure SW2 as an input, so we push
$FC into the register(inputs SW1 and SW2)

2. RDRP: Reduced Driver Register which determines the drive strength of the associated
output pin as either full (“0”) or reduced(“1”). We require the driver strength to be
maximum, so we push $00 into this register.

3. PERP: Pull Device Enable Register which is responsible for whether the pull up or pull-down
devices are enabled. This bit controls whether a pull device on the associated port input pin
is active. Configuring the input pin as “1” means pull device is enabled and “0” means
disabled; so, we load it with $03 (enable last 2 bits corresponding to switches 1 and 2).

4. PPSP: This is Port P Polarity Select Register. Setting its bit to “1” means a pull-down device
selected; rising edge selected and setting it to “0” means a pull-up device selected; falling
edge selected. We want the latter, since SW2 is grounded so by default it gives a “0” when
not pressed so we load the register with $00 to make it “1”.

5. PIEP: This is an Interrupt Enable Register enables or disables on the edge sensitive pin
interrupt on the associated pin. Setting its bits to “1” enables interrupt and setting it to “0”
disables interrupt. We want it to be enabled so we load $03 into this register (enable last 2
bits corresponding to switches 1 and 2).

 Third we need to set the interrupt vector along with the interrupt subroutine.
Our interrupt is a portP interrupt so from interrupt vector location table we find the origin of our
interrupt to be $FF8E.

Figure 6: Interrupt Origin

Figure 7: Interrupt Vector


We call our interrupt subroutine RESET and thus our interrupt vector is defined as follows
In the interrupt subroutine, a register should be configured before returning from it and that is
Port P Interrupt Flag Register (PIFP) . The flag bit is set after an active edge was applied to the
associated input pin, so to clear this flag we write “1” to the corresponding bit field. Therefore,
this register is loaded with $FF.

Figure 8: Interrupt Subroutine

 Finally, we need to write our main code which performs the continuous countdown from 10 to
0. Note that we will reuse the subroutine “ASCII” from task 1 to add the #48 to each digit and
send it to the LCD for printing, with the variables COUNTD containing the decimal number, DATA
and QUOTIENT having the same functionality as the ones in task1. The code is the following:
Figure 9: Countdown Subroutine

You might also like