LAB #1 - RAM Memory

EET 211 - K. Dudeck

1)  Connect a seven segment (common cathode) display to a 74LS48 decoder/driver. Use the pin information for the display as shown on the attached drawing (page 2).

2)  Test the display by simulating a BCD input to the driver.

3)  This RAM has the capacity to store 16 4-bit binary numbers. The pulser on the counter increments the address of the RAM and displays that address on the four LEDs. The seven segment display shows the value at that memory location.

__

4)  When the negative pulser, connected to the WE (write enable), goes low, the value of the four DIP switches is written to the memory location. Try writing your 11 digit student number into the first 11 memory locations on the RAM.

5)  Try reading back your lab partner's student number.

6)  (Design)-- Using principles learned in this lab, design a memory system which will store and display (32) 8-bit numbers. Draw a block diagram of your design and explain how it operates, do not build.

LAB 2 - Using the 8051 Simulator Program

EET 211 - K. Dudeck, Penn State Hazleton

The 8051 Simulator is written by Steve Nolan and is a nice way to develop 8051 programs off line. The simulator is freeware. The Simulator will only read programs that have been assembled and converted into an Intel Hex format file. This processes begins with writing the 8051 assembly program using a text editor and saving it as an *.ASM file. The assembler produces a *.OBJ binary file. Then a utility called an Object to Hex converter “OH”is run and the result is a *.HEX file that is burned into the ROM of the 8051. This process is shown below.

prog.asm à(Assembler) à proj.obj à (OH ultility) à prog.hex

The 8051 assembler used here is called “AS31” and is a free 8051 assembler originally written by Ken Stauffer. Versions of AS31 found here include important bug fixes and

added features, such as standard intel-hex output format that can be used for the Nolan Simulator as well as for use with PAULMON2 and EPROM programmers. AS31 is a good tool for building small 8051-based projects that are written in 100% 8051 assembly language.

All the files needed to test this out are on the course webpage.

Procedure

1)  Download the file sim8051.zip from the course homepage into a directory you wish to work in. Extract all the files therein.

2)  Using Note Pad, view the assembly text file “test1.asm”

You should see a program like this:

.ORG 0H ; Assembler directive to load program at 0000H

MOV R5,#99H

MOV R7,#69H

MOV A,#10H

ADD A,R7

ADD A,#01H

HERE: SJMP HERE

.END ; Assembler directive marking program end

3) Minimize note pad, do not close it. Then go into the DOS prompt. Unfortunately,

DOS always places you into the C:\windows directory. Using the CD command,

get into the directory you placed these files into. You will see the “a31.exe” file

which is the assembler.

4) Assemble the TEST1 program by typing > a31-l test1.asm

This produces a “test1.hex” file. The simulator will run this.

The “-l” (the letter L option) produces a list file.

5)  Return to windows by typing > exit

6)  View the test1.lst file using Notepad. You will see the machine code produced by the assembler.

7)  Using Windows explorer, run the sim8051 application.

Then Load the test1.hex into the simulator. It will confirm it loaded 11 bytes from the hex file.

8)  Then hit the “view code listing” button to see the 11 bytes of machine code and the corresponding assembly program. Also hit the “View Processor registers” button. This program will adjust the contents of the registers.

9)  Run the program by hitting the “Execute Loaded File” button. This program should load a 99H into R5, a 69H into R7, and after loading a 10H into the accumulator, it adds the contents of R5 plus another 01H yielding a final result of 7A residing in the accumulator.

10) The program runs indefinitely because of the SJMP 9 command, but hit the “Stop” button. This stops and resets the processor. All the register values clear.

11) Single step through the program by hitting the “Single Step” button. You can observe what happens to the registers one instruction at a time in this manner.

12) For you to do: Modify the TEST1.asm so that it places your age into R0, your most comfortable temperature into R1 and adds 20 to your age and places that result into the accumulator.

13) Assemble and run your program on the simulator.

LAB 3 – Intro to “Paul” 8051 Microcontroller Board

EET 211 - K. Dudeck

Introduction

In this lab we will become familiar the “Paul” Stoffregen’s 8051 Microcontroller Board. This 8051 development board provides an easy and low-cost way to develop projects based on the 8051 microcontroller, without the need to purchase any other equipment, such as EPROM programmers or emulators. It accomplishes this by coming equipped with a FLASH ROM containing a boot-up program called “PAULMON2”.

PAULMON2 is a user-friendly 8051 family monitor, intended for use in a single board computer like the development board used in this course.

By placing PAULMON2 in the board's EPROM, the board will "boot-up" to a friendly menu-driven monitor which allows you to download your programs to RAM and run them, which is much faster and easier than reprogramming the EPROM.

PAULMON2 also provides several features to help you debug your programs, including a de-assembler and single-step program execution.

It is very easy to use and together with an 8051 family assembler, such as the one above, it provides a very low-cost 8051 development system. PAULMON2 is in the public domain. You may use pieces of the code in your own programs and even

incorporate the code into your own commercial products, if you wish.

For more information on the board and software details, visit:

http://www.pjrc.com/tech/8051/

The memory map for the board is shown below.

Memory Map of Paul 8051 Microcontroller Board

0000H – 1FFFH 8K ROM with PAULMON2

permanently stored.

00H – FFH Internal RAM Amtel AT89C52 Chip

Port 0 –Port 3 Internal I/O Ports (port 1 direct)

2000H – 2FFFH 8K External RAM (user programs) 6264 Chip

4000H – 4003H Port Expansion 82C55 Chip

4000H -Port A

4001H – Port B

4002H – Port C (on board LED’s)

4003H –Port Program Byte

8000H – 81FFH 8K External Flash ROM SST39F512

The procedure for running a program on the 8051 board is as follows. First the assembly program is written using a text editor, such as “notepad”. The program is stored as a text file with a *.asm file extension. Then an 8051 assembler utility, such as as31.exe, is used to generate the machine code in the Intel hex-file format. The board is capable of downloading this hex file into its memory. Normally the program is downloaded into the board’s external RAM location, 2000H. The first couple of lines of the original assembly program contains a 64 byte “header” file. Two of the lines, shown below, cause the program to be downloaded beginning at RAM location 2000H.

.equ locat, 0x2000 ;Location for this program

.org locat

To cause it to be loaded into the flash memory, set the location between 0x8000 to 0xFF00 (the last two digits must be zero for PAULMON2 to recognize the header). To program the flash memory, download your program in the same way as loading it

into RAM, and PAULMON2 will automatically handle the flash programming as it receives the data. The portion of flash memory where you're downloading must be erased, otherwise the download will not work and you'll see errors reported.

Because the RAM doesn't need to be erased before it is written, it's easier to develop your code by downloading it into the RAM, and then setting it to the flash when it's working.

If you want to make the board run your program immediately upon power up of the board, as in a dedication system application, you must have the board bypass the running of the PAULMON2 startup program. This is accomplished by editing a line in the 64 byte assembly “header” file. The appropriate line is shown below:

.db 35,255,0,0 ;id (35=prog)

To do this, change the "35" to "249" in the header. More details can be found in

the PAULMON2 manual. Once you've done this, the board will boot up and run your program, stored in Flash ROM, instead of PAULMON2.

Once this program has been downloaded into memory, the PAULMON2 program will never again to be able to be run. You would never be able to download another program to board unless there were a way to erase the Flash ROM without using the PAULMON2 software.

To manually erase the flash ROM and get back to PAULMON2, short the "ERASE FLASH" jumper and press the reset button. The board will now boot-up to PAULMON2 as before.

Procedure

There is a very good detailed description of “Using the board for the first time” on Paul Stoffregen’s web page listed below.

http://www.pjrc.com/tech/8051/board3/first_use.html

1)  Connect the serial cable from the COM1 port of the PC to the upper D connector

on the 8051 board.

2)  Run the Hyperterminal application named “8051 Board”. This session has been already been created with the proper communication settings the for the 8051 board, as described in the web site.

3)  Apply 12 - 15VDC power to the board. Hit Enter on the keyboard and the welcome message should appear.

4)  Type a “?” to see a list of functions the Monitor Program has performs.

5)  Try editing the External RAM using the “E” command. Once there, change the contents of memory locations (using control-E and control-X) 2000H to 200EH to the following:

2000: 45 45 54 20 32 31 31 20 69 73 20 66 75 6E 21 24

Notice how the corresponding ASCII are displayed. What is the text message

you just programmed?

6)  Clear the Hyperterminal screen, turn off the power supply and hit the Enter.

Notice how the RAM contents are gone.

7)  We will now download our first assembly program to the Board. This program is

called “Blink.asm” and it is an assembly text file. In order for this program to be

transferred to the board’s RAM, it must be assembled and converted into an Intel

hex file, named Blink.hex. To do this, we must run the DOS-based assembler

program, as31.exe . This assembler is available from the sim8051.zip file

downloaded from the course homepage.

8)  Go into DOS and using the CD command, change the directory to the one that

contains the unzipped files that you downloaded. Then to assemble the blink

program type:

as31 blink.asm

Notice how a file called blink.hex is generated. This is the HEX text file that will

be sent to the 8051 board at RAM location 2000H.

Return to windows by typing exit

9)  From the hyperteminal window, select Transfer –Send text file. You will need to

set the “all file type” option in notepad to list the blink.hex file. Send the

BLINK.HEX file to the board.

10) From PAULMON2 issue the “R” command. All programs written for

PAULMON2 contain a 64 byte header. In this header are the program names and

download locations. The “R” command recognizes that header and names. Run

the blink program. The LED’s will blink. To end the program, press ESC on the

keyboard.

11) Cycle the power on the board. Try to run the program again. You will notice that PAULMON2 states that there are no program headers found in memory.

12) We will next download the blink program directory into flash ROM. To do this,

edit the “blink.asm” and change the first line to read:

.equ locat, 0x8000 ;Location for this program

13) Save the changes to the assembly program and compile and download the new

version to the board by repeating steps 8 and 9. But before doing this you must

make sure that the FLASH ROM is erased. This is done by issuing the

PAULMON2 “Z” command.

14) Run the program again. Cycle the power on the board, and try to run the program

again. This time it is there.

15) There is a way to examine the assembly code of a program that is in RAM

or ROM. To view the code of this program, do the following PAULMON2

commands.

1)  Edit external RAM “E”

2)  Goto to Memory loactaion 8040 “^G 8040” (where our program begins

after the 64 (40H) byte header file).

3)  You see only the machine code. Quit this “^Q”

4)  Now notice PAULMON2 set to this location, 8040H.

5)  Issue the program list command “L”

6)  Notice the assembly and machine code.

7)  Run the program again using the “R” command.

16) We will now modify the blink program so that it will be a self starting program.

This is mentioned in the introduction. First, we MUST erase the Flash ROM

using the “Z” command.

17) Edit the “blink.asm” file and locate the line :

.db 35,255,0,0 ;id (35=prog)

Change the “35” to “249”, and re-assemble and download to the board, as

described previously.

18) Cycle the power to the board, and notice the program runs automatically. Cycle

the power again. This board will forever more run the dedicated blink program.

19) In order to get PAULMON2 to run again in order to download any future

programs, the Flash ROM must be erased by shorting the “Erase Flash” jumper

located on the board, and pressing the reset button. The board boots up as before.

20) Edit the blink.asm so that it will be downloaded into RAM again by changing

back the location to 0x2000 and the program id back to 35.

You can also make the LED’s blink faster by changing the number of times the

delay loop runs from 250 to 100 in the following portion of the program.

delay:

mov r0, a

dly2: mov r1, #250

dly3: nop