Physics 123: Using the RIDE 8051 assembler and...

9
Using the RIDE 8051 assembler and simulator 1 Physics 123: Using the RIDE 8051 assembler and simulator REV 0 1 : January 25, 2006 1 Installing RIDE Once you have downloaded the file kit51 735 .exe from the website, click on it, and the Winzip ’self extractor’ will ask you where you want to put the contents of this compressed .ZIP file. Make a note of the path where it lives, because you will need to specify this later, to tell RIDE where to find your register equates file. Note on screen images: these screen shots are taken from a slightly-earlier version of RIDE than the one you’re using. You’re likely to see minor differences. I don’t think they’ll throw you off. 2 Setting Up RIDE When you click on the RIDE icon, first you’ll see an image of a strange creature 2 Then you’ll get a blank gray screen, with lots of menus at the top: Figure 1: RIDE screen, before one opens a project and file 3 Create a “Project” RIDE uses a sort of folder or directory to keep together your source file and your Debug choices (these are project- specific choices rather than the ones we have spoken of above, those you make once for all projects). Make a NEW project, under the PROJECT menu. You’ll get a line that looks like c:\micro\8051\raison\lab_pgms\noname.prj (the path will depend on just where you installed RIDE). Replace “noname” with your project name. 1 Revisions: update RIDE zipped-file name; note simulator can’t be set to our DS89C420 processor (12/05). 2 A piglike monk, with shrunken head. Sometimes he seems to juggle. I wonder what Raisonance intended.

Transcript of Physics 123: Using the RIDE 8051 assembler and...

Page 1: Physics 123: Using the RIDE 8051 assembler and …sites.fas.harvard.edu/~phys123/RIDE/ride_note_dec05.pdfUsing the RIDE 8051 assembler and simulator 2 4 Compose an assembly-languagesource

Using the RIDE 8051 assembler and simulator 1

Physics 123: Using the RIDE 8051 assembler and simulator

REV 01: January 25, 2006

1 Installing RIDE

Once you have downloaded the file kit51735 .exe from the website, click on it, and the Winzip ’self extractor’ willask you where you want to put the contents of this compressed .ZIP file. Make a note of the path where it lives,because you will need to specify this later, to tell RIDE where to find your register equates file.

Note on screen images: these screen shots are taken from a slightly-earlier version of RIDE than the one you’reusing. You’re likely to see minor differences. I don’t think they’ll throw you off.

2 Setting Up RIDE

When you click on the RIDE icon, first you’ll see an image of a strange creature2 Then you’ll get a blank grayscreen, with lots of menus at the top:

Figure 1: RIDE screen, before one opens a project and file

3 Create a “Project”

RIDE uses a sort of folder or directory to keep together your source file and your Debug choices (these are project-specific choices rather than the ones we have spoken of above, those you make once for all projects).

Make a NEW project, under the PROJECT menu. You’ll get a line that looks like

c:\micro\8051\raison\lab_pgms\noname.prj

(the path will depend on just where you installed RIDE). Replace “noname” with your project name.1Revisions: update RIDE zipped-file name; note simulator can’t be set to our DS89C420 processor (12/05).2A piglike monk, with shrunken head. Sometimes he seems to juggle. I wonder what Raisonance intended.

Page 2: Physics 123: Using the RIDE 8051 assembler and …sites.fas.harvard.edu/~phys123/RIDE/ride_note_dec05.pdfUsing the RIDE 8051 assembler and simulator 2 4 Compose an assembly-languagesource

Using the RIDE 8051 assembler and simulator 2

4 Compose an assembly-languagesource file: (*.A51)

Write an assembly-language file—or, much easier—open one you’ve gotten from someone else, so that you knowthe form is OK. Incidentally if you use the FILE/OPEN menu option, you may be puzzled to get a blank window,even though you may know there are .A51 files in your RIDE directory (you may have copied them into there,earlier, or have composed them ten minutes ago). This illusion that they’ve vanished comes from RIDE’s defaultassumption that we’re interested in C files, not assembly-language. Just change the window option from “Files oftype C files” to “Files of type Assembler files.”

4.1 “INCLUDE” a file defining 80C320 registers

Here’s the start of Lab 19’s decoder-test program:

; TRYDCDR_01.A51 Lab 19: to try I/O decoder: count loops 4/13/01

$NOSYMBOLS$INCLUDE (C:\MICRO\8051\RAISON\INC\REG320.INC)$INCLUDE (C:\MICRO\8051\RAISON\INC\VECTORS320.INC)

ORG 0 ; tells assembler the address at which to place this code

SJMP STARTUP ; here code begins--with just a jump to start of; real program. ALL our programs will start thus

ORG 20h ; ...and here the program starts, at hex 20 ("...h")

STARTUP: CLR A ; This just gives a predictable, tidy start value,; to display (zero)...

The NOSYMBOLS line spares you getting a multi-page printout of DS80C320 register and bit names, each timeyou print the .LST file produced by the assembler.

Page 3: Physics 123: Using the RIDE 8051 assembler and …sites.fas.harvard.edu/~phys123/RIDE/ride_note_dec05.pdfUsing the RIDE 8051 assembler and simulator 2 4 Compose an assembly-languagesource

Using the RIDE 8051 assembler and simulator 3

The two INCLUDE lines tell the assembler to use these two EQUATES files, so as to allow you to write convenientand intelligible symbolic names, rather than addresses, in your code. For example, you can write

INC DPS

because the REG32O.INC file includes the following in its list of definitions or “equates”:

;----------------------------------------------; DALLAS DS80C320 Processor Declarations; Copyright (c) Raisonance SA, 1987-1996;----------------------------------------------; BYTE RegistersP0 DATA 080HP1 DATA 090HP2 DATA 0A0H...; DS80C320 ExtensionsDPL1 DATA 084HDPH1 DATA 085HDPS DATA 086H

That last line tells the assembler that you mean “location 086h” when you refer to DPS. Obviously, this is mucheasier for you than requiring you to go to the databook to discover just what address DPS uses.

5 Associate the .A51 file with the Project

This step RIDE calls “adding a node....” Under the PROJECT menu, choose “Add node Source/Application.” Thatwill bring up a directory listing; work your way to where your source file lives, and click on it.

6 Assemble the .A51 file

Under PROJECT click on TRANSLATE. The lower-right window will show errors, if there are any. These messagesare much easier to interpret in context, so go look at the LISTING file.

7 Viewing the .LST file, including Error Messages

Under VIEW, choose LISTING FROM COMPILER. That will display the source code alongside the address listingsand hexadecimal machine codes. Embedded in this listing will be the error messages, thus:

...0000 176 ORG 0H ; tells assembler to begin at 0, where

177 ; processor looks after a RESET178

0000 8000 F 179 SJMP STARTUP ; hop to start of program180

0010 181 ORG 10H ; ...which is here182 STARTUP: MOV DPTR, 8000H ; And here the program sets up pointer

*** ERROR #23 IN LINE 17 OF 51loop00.a51 : EXPRESSION TYPE DOES NOT MATCH INSTRUCTION183 ; to now-meaningless address...

0010 E4 184 CLR A ; clears display value, for predictable185 ; startup value...

...

Page 4: Physics 123: Using the RIDE 8051 assembler and …sites.fas.harvard.edu/~phys123/RIDE/ride_note_dec05.pdfUsing the RIDE 8051 assembler and simulator 2 4 Compose an assembly-languagesource

Using the RIDE 8051 assembler and simulator 4

Here, my error was to omit the “#” ahead of the “8000H.” This pound sign is necessary—not only in order to dowhat I intend (something the assembler isn’t smart enough to divine!), but also just to form a legal instruction.

Once you’ve assembled without producing errors, you can try your program in the simulator or “Debugger.”

8 Debugging

8.1 Debug Options

This program serves 30 variants on the 8051 design. First, we need to select our particular 8051 variant, the DallasDS80C3203.

Click on the OPTIONS menu. On some RIDE installations I have found the menu of controller-variants underTARGET; on others I have found it underDEBUG. In the steps below we’ll visit both submenus, so you’ll surelyfind a chance to select our controller.

1. OPTIONS/TARGET: the RIDE I am now using offers “80C51” and two other designs. 80C51 is the default,and you should accept it.

• Architecture: Under “Architecture Type,” To be faithful to our hardware design, you should choose “VonNeumann...” That means data and code share one memory. The choice won’t make much difference, butwill set up RIDE to warn you in the unlikely event that you place a data table and some code in the samelocation: a Harvard architecture would see no problem–since two distinct memories are assumed. VonNeumann merges the two memories, as we have done.

• Processor: Target may show a selection window, allowing you to scroll down to find the DS80C320. Ifit does, go find that design (second from the last on the list of 30).

2. OPTIONS/DEBUG: The menu looks something like this (not exactly like; this is from an earlier version):

Figure 2: Debug Options Window: choose a processor

Simulator: accept the default “Virtual Machine (Simulator).”

Device: You may see the DS80C320 already shown under “Device.” If not, scroll down to find it.

Frequency: (This may appear under a submenu, “Advanced”): Set “Frequency” to 11.059MHz (this selectionaffects only the simulator’s calculation of program execution times; but we might as well get it right).

3Probably you are using a DS89C420 processor, a later design that permits program loads from an external computer; RIDE does not yetsupport the peculiarities of this particular processor, so we pretend we’re using the simpler part (12/05).

Page 5: Physics 123: Using the RIDE 8051 assembler and …sites.fas.harvard.edu/~phys123/RIDE/ride_note_dec05.pdfUsing the RIDE 8051 assembler and simulator 2 4 Compose an assembly-languagesource

Using the RIDE 8051 assembler and simulator 5

Now the simulator is properly set up (RIDE calls it the “Debug” setup, so I guess we should call it a “debugger”,too).

Under the DEBUG menu, choose “START filename.aof”. That will bring up a display of your source file, showingthe first executable line highlighted in blue. Under the DEBUG menu you will find several options: STEP INTO(key F7) is the simplest, a plain single-step. You can do that, just to see that the program runs.

But usually you want more: you want to watch what happens to registers, and perhaps memory locations, as theprogram proceeds.

8.2 Choosing what to VIEW during Debugging

MAIN Registers

Under VIEW, you’ll probably always want to select Main Registers.

Figure 3: Ride Window showing Main registers

“@DPTR” is useful. Above, it shows a value just put out from A. Just below, we’ll see the same information in a“data dump” window.

Data Dump: External Memory Window: Memory-mapped Port Activity

If your program does memory-mapped I/O—as ours usually do (that is, using our external bus rather than the 8051’sbuilt-in ports—then you’ll probably also want to watch “external memory:” our I/O looks to the processor like “ex-ternal memory”. Under VIEW, select DATA DUMP, then XDATA VIEW. This will show you a window displayingthe content of a block of addresses.

Figure 4: Data Dump, XDATA shows port data

Page 6: Physics 123: Using the RIDE 8051 assembler and …sites.fas.harvard.edu/~phys123/RIDE/ride_note_dec05.pdfUsing the RIDE 8051 assembler and simulator 2 4 Compose an assembly-languagesource

Using the RIDE 8051 assembler and simulator 6

You can type in the address that interests you—say, 8000h, if you’re watching an I/O operation on your little com-puter. Then you can also force a particular value into any location, by clicking on the displayed value, typing in anew value, and hitting Return. Thus, you can simulate an input, from keypad, for example, or from an ADC.

Data Dump: External Memory Window: Watch a Data Table in Memory

One can watch the external RAM (true “memory”) as well as memory-mapped I/O, using Data Dump XDATA. Thewindow below was set up to check whether Lab 22’s “storage scope” was succeeding in filling the table with datafrom an ADC:

Figure 5: Data Dump, XDATA showing RAM contents, loaded from ADC

WATCH Window

This is a versatile tool that lets you make a single window to display some detail important to you. Under VIEWclick on WATCH. This opens a blank window. If you right-click on that window, you’ll get a new window askingyou to enter “expression.”

Figure 6: A Watch Window

You could use this window, for example, to keep track of the pesky detailwhich of the two Data Pointers you areusing. Just put “DPS” in the WATCH window:

Figure 7: A Watch Window used to show the pesky DPS bit, distinguishing pointers

Page 7: Physics 123: Using the RIDE 8051 assembler and …sites.fas.harvard.edu/~phys123/RIDE/ride_note_dec05.pdfUsing the RIDE 8051 assembler and simulator 2 4 Compose an assembly-languagesource

Using the RIDE 8051 assembler and simulator 7

Hardware Peripherals

This item under the VIEW menu provides a sub-menu that includes two options important to us: the “Ports,” andthe timers.

Ports: when you are using a built-in port (Port 3, in our case, since 1 and 2 are occupied by our use of the externalbus), this window allows you not only to watch output levels, bit-by-bit, but also to set input levels (High/NoConnection/Low).

Figure 8: Port 3 Window

Interrupt Simulation: In order to simulate anexternal interrupt (that is, the sort initiated by driving an 8051 pin),you will need the above PORT 3 window, also. To initiate an interrupt you will ground P3.2 (as shown justabove).

If you want more details—and particularly, if you are using more than one interrupt—you may want to displaya window dedicated to showing interrupts. Here it is:

Figure 9: Ride’s Debugger window dedicated to interrupts (image from Ride PDF file)

Page 8: Physics 123: Using the RIDE 8051 assembler and …sites.fas.harvard.edu/~phys123/RIDE/ride_note_dec05.pdfUsing the RIDE 8051 assembler and simulator 2 4 Compose an assembly-languagesource

Using the RIDE 8051 assembler and simulator 8

Timers: when you begin to use a timer, the timer window is very helpful. It shows...

• timer control register (T2CON: control);

• timer values (THL2, the 16-bit present value, for timer 2);

• “capture/reload” register (RCAP2)–for timer 2, only : this shows the value that will be reloaded, whentimer is in auto-reload mode;

• overflow flag (TF2, for timer 2);

• Run bit (TR2 for timer 2): set high to enable timer.

(The image below is reprinted from Ride’s documentation (a big .PDF file, RIDE2.PDF, which you’ll find onthe course website).

Figure 10: Timer Window (Timer 2: more versatile than 0 or 1

Page 9: Physics 123: Using the RIDE 8051 assembler and …sites.fas.harvard.edu/~phys123/RIDE/ride_note_dec05.pdfUsing the RIDE 8051 assembler and simulator 2 4 Compose an assembly-languagesource

Using the RIDE 8051 assembler and simulator 9

Serial Port: Another window is given to showing the serial port and its registers (80C320 has two serial ports; ’310has one). We’ll not attempt to explain the serial port here; we’re guessing that most of you will not use it,during this crowded term

Figure 11: Ride’s Debugger window dedicated to (a) serial port (image from Ride PDF file)

8.3 Lots more features!....

If you want to become expert in using RIDE, look at the thorough documentation provided in two PDF files postedon the course website: RIDE1.PDF and RIDE2.PDF. Have fun! I think this is a fabulous assembler/simulator (witha compiler thrown in!). The fact that it costs us nothing is a miraculous bonus.

ride note dec05.tex; January 25, 2006