Lebanese American University School of Engineering: Microprocessors Lab COE324
Lebanese American University School of Engineering: Microprocessors Lab COE324
School of Engineering
Microprocessors Lab
COE324
Ms. Safaa El Hajj
Lab 6
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.
The following is the code that contains the main code with the subroutine:
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.
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.
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.
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