Starting from:

$25

ELEC291- Laboratory 1 Solved

 The AT89LP51RC2 Microcontroller 

System

Introduction
                  This laboratory module shows how to build a simple microcontroller system using the

Atmel AT89LP51RC2 microcontroller.  The AT89LP51RC2 is a modern derivative of the Industry Standard 8051 microcontroller developed by Intel in the early 1980’s.  As part of this module, students will compile, download, and run programs into the microcontroller system.  Finally in this laboratory module, students will be attaching an LCD to the microcontroller system and display their names and student number on it.  Note: the AT89LP51RC2 Microcontroller System (and LCD) will be used for the first three laboratory assignments as well as project 1 of ELEC291/292.

Pre-laboratory
Find the datasheet for the following components used in this laboratory module. Keep them for reference.Atmel’s AT89LP51RC2 microcontroller.
Hitachi’s HD44780 LCD controller.
Find the 8051 microcontroller assembly instruction set. Describe the major differences between the 8051 microcontroller assembly and the processor assembly you learned in CPEN211 (ARM, 68K, NIOS II, etc.)
Laboratory
The laboratory component of this module consists of three activities:

Assembling a Microcontroller System.
Attaching the LCD to the Microcontroller System.
Display your name and student number using the Microcontroller/LCD System.
1)  Assembling the Microcontroller System
 Figure 1 shows the circuit schematic of the microcontroller system used in this laboratory assignment.  It can be assembled using a bread board.  Table 1 lists the components needed to assemble the circuit.

Quantity 
Description 
2
0.1uF capacitors
1
330Ω resistor
1
LED 5MM GREEN
1
22.1184MHZ Crystal
1
BO230XS USB adapter
1
AT89LP51RC2 IC 80C51 MCU 32K FLASH 40-DIP
2
Push button switch
Table 1. Parts required to assemble the microcontroller system. 

 The components are included in the ELEC291/ELEC292 microcontroller parts kit.  Figure 2 below displays all the parts needed.  Also shown in figure 2, are several precut and stripped wires.  These wires are used to assemble the circuit as shown in figure 3.

0.1µF 

5V

Figure 1.  Circuit schematic of the microcontroller system.

Figure 2.  Parts needed to assemble the microcontroller system.

Figure 3.  Bread boarded microcontroller system. 

Writing, Compiling, and Downloading Code to the Microcontroller System. 

Download and install CrossIDE from the course webpage.
Run CrossIDE, and create a new ‘Asm’ file. Add the code listed below.   Tip1:  copy and paste from this document!  Tip2: Sometimes this code is available from the course web page.
; Blinky.asm: toggles an LED attached to pin 17 (P3.7) 

$MODLP51  org 0000H     ljmp myprogram 

; When using a 22.1184MHz crystal in fast mode 

; one cycle takes 1.0/22.1184MHz = 45.21123 ns 

WaitHalfSec:     mov R2, #89 L3: mov R1, #250 

L2: mov R0, #166

L1: djnz R0, L1 ; 3 cycles->3*45.21123ns*166=22.51519us     djnz R1, L2 ; 22.51519us*250=5.629ms     djnz R2, L3 ; 5.629ms*89=0.5s (approximately)     ret                

myprogram: 

    mov SP, #7FH

M0: 

    cpl P3.7     lcall WaitHalfSec     sjmp M0 

END

Attach a red LED in series with a 330 Ohm resistor to P3.7 (pin 17) of the AT89LP51RC2 microcontroller. The LED circuit is shown below.   
Compile and link the program using A51. In CrossIDE click “Build”, then “Compile/Link with A51”,  a pop-up like this one is displayed:
Make sure the complete path of a51.exe is correct and then click ok.  a51.exe is located in the same folder where Crosside is installed, in a sub-folder called “call51\bin”. If everything went well and the program has no errors, the compiler creates the file ‘blinky.hex’:

------- CrossIde - Assembling -------

D:\Courses\ELEC291\Jan_2018\Module1\Source\blinky.asm:1: Assembling...

No errors found

The HEX file contains the binary program that is downloaded to the microcontroller system.  If the program has errors, they will be reported directly into CrossIDE.  The errors need to be fixed and the compilation process should be repeated again.

To download the code to the microcontroller system use CrossIDE’s built-in flash loader.  Before proceeding with this step, attach an USB cable to the BO230XS adapter and the computer.  

On CrossIDE click “fLash” followed by “Atmel AT89LP Using SPI”. A pop-up window like this one is displayed:

Select the HEX file created by the compiler, and click “Flash”.   Wait for the process to complete.    The LED should start blinking.  If the LED is not blinking at the right rate, unconnected the system from the USB port and reconnect it again.  This is because the AT89LP51RC2 comes in “slow mode” from factory and needs to be power cycled before it switches to full speed.

2)  Attaching the LCD to the Microcontroller System
                      Included in the Microcontroller parts kit is the LCM-S01602DTR/M Liquid Crystal

Display Module (LCD).  This LCD module uses the industry standard HD44780 controller.  The LCD can be configured either in 4-bit or 8-bit mode.  For this laboratory experiment examples, the LCD will be configured in 4-bit mode in order to minimize the number of I/O pins and wires used.  The figure below shows the connections between the microcontroller system and the LCD.  The pin assignments in the microcontroller are arbitrary.  The pins can be changed, but the example source code provided should be modified to match the wiring.

 One way of wiring the LCD to the bread boarded microcontroller system is shown in the picture below.

 In order to verify the functionality of the microcontroller/LCD system, a test program called ‘LCD_test_4bit.asm’ is provided in the course web page.  Compile and load the program into the microcontroller system.  After reset, the LCD should display letter ‘A’ in the first column of row one and letter ‘B’ in the third column of row two.

3)  Display your name and student name using the Microcontroller/LCD System
 Write a program to display your name and student number using the LCD.  The first row should display your name, while the second row should display your student number.   You can use the test program as a reference and/or starting point for your program.  Don’t forget to add extra functionality and/or features for bonus marks.  You must submit a picture (or a movie/gif showing any LCD animations) of your microcontroller system as well as your assembly code to Canvas where it will be marked by the TAs.

A few tips: 

The LCD can be configured to scroll left/right.
You can create and use up to 8 custom characters.
Instead of writing one character at a time, you can write a subroutine that displays a string stored in the constant (or code) memory space. To access the constant string use the MOVC instruction.
 

More products