You are on page 1of 44

User's Guide

The Beginner Prefer About User' Installatio Sit Conta Fundament 's Guide Hom the the s n Exampl e EdSim51 ct al to the e Original Simulat Guid Instructio es Ma SH Us Simulation 8051 ? or e ns p s Online

New

User's Guide

The Microcontroller Panel


o o

The Bitfield Data and Code Memory Source Pane Unlocker Load and Save Copy and Paste A Few Notes on the Assembler Debugging Breakpoints The Logic Diagram The LED Bank, DAC and the 7-segment Displays The LCD Module The Switch Bank and the ADC The Comparator and the DAC The Motor The UART The Keypad

The Assembly Code Panel


o o o o o o

The Peripherals
o o o o o o o o

New Features!
Get the latest EdSim51 version

The Dynamic Interface


Now the user can switch the peripherals to other port pins. Get more information.

Unlock the External UART


Clicking on the button marked U at the top left of the external UART places the UART in a separate frame, as shown below. This frame has much larger text windows for transmitted and

received text. Simply close this frame to lock the UART back in the main window.

Syntax Highlighting
Now, assembly code written in EdSim51 is automatically syntax highlighted. Instructions are

coloured blue, assembler directives (such as ORG, USING, etc) are coloured purple, aliases (for example, the assembler replaces TMOD with the address of TMOD) are coloured orange and comments are coloured green. Switching off syntax highlighting: if you wish to turn off syntax highlighting, simply right-click anywhere in the assembly code window and respond to the prompt.

Change the System Clock Frequency


Originally, the simulator ran with a system clock frequency of 12 MHz. Now the user can enter a value for the system clock frequency in MHz.

UART Transmitting HEX Data


Up until now, the external UART only transmitted text - whatever the user typed in the Tx field was transmitted to the 8051. Now, a list of 8-bit numbers (written in HEX) can be transmitted. To do so, the user encloses the list in curly braces, each number separated by a comma, as shown in the image opposite. When text is transmitted, it is terminated

by 0DH. This is not the case with a list of numbers. In the example shown opposite, the four numbers 56, 3a, 23 and e7 are transmitted, nothing more. If the user wishes to send {56, 3a, 23, e7} as text rather than a list of 8-bit numbers, the text is escaped using the \ character. Therefore, \{56, 3a, 23, e7} in the Tx field would result in {56, 3a, 23, e7} followed by 0DH being transmitted to the 8051.

LCD Module
A simulation of the popular Hitachi HD44780 LCD module has been implemented for the EdSim51 Simulator. And now CGRAM has also been implemented. Find out more.

Zoom
For high resolution monitors, click on the zoom button. The zoom button is located below the red Exit button.

Keypad Modes
Now the user can select from three modes of operation: Standard - any number of keys can be closed at the same time. Pulse - once the mouse button is released the key reopens. Radio - in radio mode only one key at a time can be closed.

Keypad And External 1

Interrupt
Until now the keypad could only be implemented using busy-waiting. It can still be implemented in that manner, but it can also be used together with the 8051 external 1 interrupt pin, P3.3. Note: this pin, P3.3, is also used by the display-select decoder, therefore multiplexing of the 7-segment displays cannot be implemented together with the keypad interrupt. To multiplex the displays and use the keypad at the same time, the keypad must be implemented using busy waiting. More information on the keypad modes and the keypad interrupt

Intel HEX Reader/Writer


You can now save your source code in Intel HEX format. Or you can write C code for the 8051 using one of many available

8051 C compilers, then import the HEX code into the EdSim51 Simulator. Find out more.

Simulator Window Update


As with many microcontroller simulators, EdSim51 allows the user to either step through a program, executing a single instruction per step, or to run the program continuously. In the original EdSim51 design, when running a program, the simulator would execute one instruction, update the screen, pause for a quarter second, then proceed with the next instruction and so on. This allowed the programmer to observe changes in the hardware and registers for each executed instruction. However, while this is very useful for debugging, it meant the user would need to wait a long time for things to happen (examples: data transmitted on the serial port to appear on the UART, an LED flashing at half second intervals, etc). The best of both: now the user has the choice. Using the Update Freq. drop down menu (shown opposite) the programmer can choose how often the screen should be updated. The choices are: update the screen after every instruction execution (the default), after 100, 1000, 10,000 or 50,000 executed instructions. Type in a value: the options available from the menu may not be appropriate. Therefore, the user can now enter a number rather than select a value from the list. For the entered number to take effect, the user must hit Enter on the computer keyboard. Find out more.

The Microcontroller Panel


A screenshot of the microcontroller panel. This gives the user access to all the 8051's registers and data memory. Boxes that are white can be edited directly. Those that are grey cannot. For example, the port latch bits can be edited directly by the user, but the port pins are controlled by the external peripherals and the port latches and cannot be edited. When the mouse pointer is left to hover over one of the register labels, the register's address appears, as shown opposite for the PCON register.

The Bitfield In the above image, the individual bits for the accumulator are shown (ACC). The user can enter any address or SFR name in the blue box (replacing ACC) and the bits for that given address will then be displayed. Also, if you let the mouse pointer hover over one of the bits momentarily, the bit's description is displayed, as shown below: The bit field for the TMOD SFR is shown. Notice bit 2 is the counter/timer bit. Also notice the background is grey. This is because the TMOD register is not bit-addressable the user cannot alter these bits directly. The PSW is bit-addressable, therefore the background of each bit is white and the user can change any of the bits directly. The bitfield can be used to see the bit pattern of any address in RAM (0 to 7FH) by typing the address in the blue box. If the location is bit-addressable, the bit backgrounds are white and the user can alter any of the eight bits. As with SFRs, if the location is not bit-addressable the backgrounds are grey.

Data and Code Memory By default, data memory is displayed. Any address in RAM (00H to 7FH) can be altered by entering the address in the blue box (labelled addr) and then entering the desired value in the box to the right (labelled value).

Displaying Code Memory Code memory can also be examined and edited, as shown in the image above. To switch between data memory and code memory the user clicks on the button that is labelled Data Memory when data memory is displayed and Code Memory when code memory is displayed. The first 127 bytes of code memory are displayed. To view another area of code memory, enter the start address in the blue box. The 127 bytes from the start address onwards will then be displayed. Again, like data memory, the address specified in the blue addr box can be altered by entering a value in the value box. However, it should be noted that this will result in the machine code and the assembly program being different. In the image above, the assembly code that generated the machine code (as displayed in code memory) can be seen on the right.

Update Freq. The user can choose to either step through a program (executing a single instruction per step) or run the program continuously. When running a program, the rate at which the screen updates is determined by the setting in the Update Freq. menu.

Using the Update Freq. drop down menu the user can choose how often the screen should be updated. The choices are: update the screen after every executed instruction, after 100, 1000, 10,000 or 50,000 executed instructions.

Or, if none of these options is appropriate, the user can type in a number, then hit Enter. The update frequency may be changed while a user's program is running.

The Assembly Code Panel


A simple assembly program is shown in the assembly code panel to the left. This program runs in a continuou s loop, displaying the numbers 0 to 9 and back to 0 on the first 7segment display. A snapshot

of its execution is shown to the right. When the background of the assembly code text area is white is it editable. The programmer can write code directly here, or can load a program from file using the Load button (dealt with in the next section). When the program is ready for testing, the user can either click on the Assm button to execute instructions one at a time, or on the Run button to run the program continuously. Either way, the program will first be assembled. If an error in the code is discovered, a message is displayed in the message box above the assembly code (with a red background) and the line with the error is highlighted within the code in red. If the code assembles without errors, Assm is replaced by Step, the text area's background changes to light grey. The code cannot be edited at this point. If you want to go back to editing your code, simply click on the Reset button.

Source code window a bit small? Read about the source pane unlocker below. Source Pane Unlocker The simulator was designed so that everything is visible on the screen at the same time - the internal registers, the source code, the peripherals, etc. However, this means the code pane is quite small. But it can be expanded. Read more.

Load and Save

The user can write code directly into the text box when it is in edit mode, or an existing program can be loaded from a file using the Load button. Similarly, code in the text box can be saved to file using the Save button. There are two file types handled. The first is plain-text. Assembly programs are saved as regular plain-text files (often called text-only) and usually with .a or .asm file extension. By default, this is the format used when saving your source code in the EdSim51 Simulator. The other file type is Intel HEX. The user can select to save a file in HEX format by choosing
Intel HEX Files

from the
Files of Type:

menu in the Save dialog box. Find out more on loading and saving Intel HEX files. To make the simulator more user-friendly, the last directory accessed (either through loading a file or saving a file) will be remembered. Therefore, the next time the user opens a file dialog box by clicking on either the Load or Save buttons, the dialog box automatically opens in the last directory visited.

Copy and Paste You can select code in the assembly text area and copy it to the system clipboard using the Copy button, the same as you do in your word processing package. This can then be pasted elsewhere in the assembly text area, using the Paste button (if the text area is editable - white background if it is not, click Reset). Or you can paste the selected text into some other application (such as your word processor). Similarly, you can copy text from another application and paste it into the assembly text area.

A Few Notes on the Assembler The 2-pass assembler with the EdSim51 Simulator is not a full-blown assembler. It does not link multiple files and only some of the directives you might expect are implemented. However, I feel it is adequate for the beginner. Below is a list of its features:

All of the 8051 instructions are implemented, except for MOVX instructions, as the simulator does not handle external memory. JMP rel equates to either SJMP rel or AJMP rel. LJMP rel must be programmed explicitly. Similarly, CALL equates to ACALL. LCALL must be programmed explicitly. SET and EQU directives are implemented. ORG is implemented. USING directive (states which register bank is being used) is implemented. ARn equates to the register address, as specified by USING (if the register bank is not specified prior to ARn's use, register bank 0 is assumed). SFR names and SFR bit names equate to the appropriate address. HIGH followed by an operand in brackets equates to the high byte of the operand. LOW followed by an operand in brackets equates to the low byte of the operand. Labels are followed by a semicolon. The default for numerical values is decimal. Hex values can be entered by appending H after the number, or placing 0x before it. If H is used, the number cannot begin with a letter (example: F5H must be written as 0F5H). Binary values are entered by appending B after the number (as shown in the image below). The assembler is not case-sensitive.

Debugging

Regardless of whether the code is running or being stepped, once the code assembles without errors, the address of each instruction is displayed to the left. When stepping through the code, the instruction that was just executed is shown in the grey box at the top, together with the instruction's address (example shown: Executed 0x2A: MOV 90H, A). The next instruction to be executed, its address is highlighted. (002CH).

Breakpoints A breakpoint can be set by double-clicking the instruction's address, as shown in the images below.

Setting a breakpoint: When stepping through the code, move the mouse over the address of the instruction and double-click. When the breakpoint is set the vertical bar (|) immediately to the right of the address is replaced by a star (*), as shown in the image on the right.

Removing a breakpoint: A breakpoint is indicated by a star (*). To remove the breakpoint, move the mouse over the instruction's address and double-click. The * is replaced by |. Alternatively, you can remove all breakpoints with one click of:

When the program is running and a breakpoint is encountered execution halts just before that instruction. In other words, the next instruction to be executed will be the breakpoint instruction. The programmer can then step through the code, or run the program, from that point.

The Peripherals
Note: The logic diagrams in this section were drawn for the default peripheral interface. You may wish to alter this interface, which you can do by clicking on the DI button (see the image below). You can also view the logic diagram for the new interface by clicking on the LD button

(again, see the image below). Also, there are instances in the following section where the sharing of port pins is pointed out. For example, the motor and the UART share the same port pins. This of course may not be true in your case, if, for example, you move the motor to other pins.

The Peripheral Panel

The Dynamic Interface Panel - remap the peripherals | full size image

An Instance of the Dynamic Logic Diagram

The Peripherals: ADC Comparator Four 7-segment LED Displays LCD Module UART Keypad LED Bank Bi-directional Motor Switch Bank

DAC (output displayed on oscilloscope) These image on the left shows what is connected to each of the 32 port pins. If a pin's description is too long to fit, you can see the full description by hovering the mouse over it, or by clicking on the zoom button (see below). Zoom Click on one of the buttons marked + to display that port's connections in a separate window. An example for port 2 is shown below.

Port Pin Connections The logic diagram below gives details of the peripheral interfacing.

EdSim51 Simulator Peripheral Logic Diagram

The LED Bank, DAC and the 7-segment Displays As can be seen in the diagram below, the LED bank, the DAC inputs and the 7-segment display

data lines all share port 1. The selection of which of the four displays is enabled is done via P3.3 and P3.4. These port pins are applied to a 2-to-4 line decoder, the outputs of which are applied to the base of transistors that enable/disable the displays.

Logic diagram showing the LED bank, DAC and 7-segment display connections only. The decoder is enabled via a logic 1 on P0.7. This pin is also applied to the DAC WR input, which is active-low. Therefore, to write data to the DAC the programmer disables the displays, which also has the effect of enabling the DAC's data lines. Data can then be written to the DAC. Whatever is on the inputs when the WR line is taken low is stored in (or written to) the DAC's internal register and remains there after the WR line is taken high. The analogue output for this data will be displayed on the scope until the next time WR is taken low and a new value is placed in the internal register. The keypad can be implemented using the external interrupt 1 line (see keypad), but not while

also multiplexing the 7-segment displays. This is because the external interrupt 1 line (P3.3) is also used by the display decoder (see logic diagram above). Therefore, keypad interrupt and multiplexing the 7-segment display cannot be used at the same time - the keypad AND gate should be disabled. An example of the DAC in action is shown below:

Ramp Generated via DAC Appears on Scope

Code for Ramp Generatio n

LED Bank and the 7-segment Displays Panel

The code that generated the above ramp is also shown (above middle). The DAC's WR input is taken low permanently (CLR P0.7) while the value in the accumulator is sent to the DAC's inputs, increased by 8 and then sent to the inputs again, and so on. When the mouse is placed over the scope screen, a tooltip appears, stating the scope's vertical scale is one volt per division and the horizontal scale is, in this case, 25 microseconds per division. The scope's horizontal scale is tied in with the 8051 system clock frequency (this is unrealistic, but I feel it's adequate for simulation purposes). If, for example, the system clock frequency is changed to 11.059 MHz, then the scope's horizontal scale is 17.36 microseconds per division.

The LCD Module As can be seen in the logic diagram below, the LCD Module also shares port 1 with the LEDs and DAC.

4-bit Mode: The LCD module is a simulation of the Hitachi HD44780 and is interfaced to the 8051 in 4-bit mode. P1.7 through P1.4 are connected to DB7 through DB4, while P1.3 is connected to the register-select pin and P1.2 is connected to the enable pin. Notice the read-write pin is connected to ground - the module can only be written to. 8-bit Mode: By default, as stated above, the module is interfaced in 4bit mode. However, the lower four data bits (DB3 through DB0) are also available (on P1.3 through P1.0). If the user wishes to write to the module in 8-bit mode, RS and E should be remapped to other port pins, using the DI button at the top left of the peripheral panel. Details of the pin functions and the instructions for the LCD module are given below. For details on how to communicate with the module, see HD44780.pdf and some sample programs. Reading: Instructions for reading from the module have not been implemented.

Logic diagram showing the LED bank, DAC and LCD module connections only.

Character Blinking: Because the simulator does not run in real-time, it would be hard to know if the module was blinking. Therefore, if the programmer sets the module to blinking (see Display on/off control instruction below), the cursor position character alternates between blue text with red background and red text with blue background. In this way the programmer knows at a glance if the module is in blinking mode (when not in blinking mode, all characters are black with grey background).

The enable pin (E, connected to P1.2) is negative-edge triggered. On a negative-edge on E, the module reads the data lines DB7 - DB4. 4-bit Mode: As can be seen in the logic diagram above, the module is interfaced with the 8051 in 4bit mode. In 4bit mode, the module's lines DB3, DB2, DB1 and DB0 are not used. The 8-bit instruction or data must therefore be sent in two 4bit nibbles. The high nibble is sent first, followed by the low nibble. When the enable pin is taken high and then low, this causes the module to read the pins DB7DB4 and store them in either the IR (if an instruction is being sent - ie:

RS = 0) or the DR (if data is being sent - ie: RS = 1). Initially, the module is in 8bit mode and must be set to 4-bit mode by the programmer before any other communication s with the module are attempted. This is done by sending the appropriate Function Set instruction (see instruction set below). Why send Function set twice? As stated, the module is initially in 8-bit mode, therefore the first instruction sent to it is read as an 8-bit instruction (as if DB3 - DB0 were in use). If the correct instruction is sent (with DL on DB4 - set to zero, indicating 4-bit - see below), then the module

'knows' it is being set to 4bit operation and it reads instructions and data in two 4bit nibbles from then on. Because it reads the high nibble first, the Function set high nibble must be sent again, followed by the low nibble. For more information, see pages 39 and 42 of HD44780.pdf. The example on page 42 is for a 1-line display, but it nonetheless explains clearly how to initialise and communicate with the module in 4-bit mode. 8-bit Mode: Even if 8-bit mode is being used, Function set must first be called to ensure the module is set to 2-line with 5 X 8 font. See below.

2-line, 5 X 8 Font: The low nibble of Function set must be sent with N = 1 (setting the number of lines on the display to 2) and F = 0 (setting the font to 5 X 8 dots). Function Set Incorrectly: The programmer must set the module to 2line, 5 X 8 font. The simulation of the HD44780 is implemented for 2-line, 5 X 8 font only. However, the programmer is still expected to write the code that sets the module in this mode. If the mode is not set correctly, an error message stating such is displayed, as shown here. The programmer must then reset the simulator,

modify the code and try again.

LCD Module Instruction Set CGRAM

CGRAM stands for character generator RAM. The module's ROM contains the ASCII character set. For example, the ASCII code for the letter W is 87, so stored in location 87 in the module's RAM is the pattern for W. This makes it relatively easy to write text to the display. The following code extract illustrates this point: MOV A, 'W' CALL sendCharacter DDRAM

; a subroutine that sends the data in A to the LCD module's

When DDRAM receives a character, the corresponding pattern from ROM is displayed. Note in the ASCII set, the first seven locations are used for control characters. These characters are not applicable to the LCD module, therefore these locations are reserved for CGRAM instead. When a value in the range 0 to 7 is sent to DDRAM, instead of displaying a character from ROM, the corresponding character from CGRAM is displayed. This means the user can create eight custom characters. The characters are programmed into CGRAM by pointing to CGRAM (instead of DDRAM) and then sending data to the module the same as when sending data to DDRAM. If you look at the instruction set above you will see there is a Set CGRAM address instruction. Note the address is six bits in length - we will discuss these six bits shortly. Also notice there is only one instruction for writing to the module. To write to CGRAM, you must first ensure the AC (address counter) is pointing to CGRAM. You do this by calling the Set CGRAM address instruction. As with writing to DDRAM, the AC is incremented (or decremented, depending on the increment/decrement setting) after each write to CGRAM. It was mentioned above that ROM contains the ASCII set. This is not altogether true. There are instances where the character in ROM does not correspond with ASCII. At location 92 you would expect to see the \ symbol. Instead there is (probably because the HD44780 was developed in Japan). At location 126, instead of ~ in location 126 there is a right arrow symbol, followed by a left arrow symbol in location 127. So, if you want to display the \ symbol, for example, you will first need to create it in CGRAM. You can choose any of the eight CGRAM locations, but let's say we wish to put \ in location 2. Each character is made up of eight rows, with five dots in each row. You write the pattern for each row to CGRAM, one row at a time. The row's pattern is made up of 1s where dots are to be visible and 0s where dots are to be invisible. The six CGRAM address bits are split into two parts. The top three bits determine which of the eight CGRAM characters is being written to, while the bottom three bits determine which of the eight rows of this character is being written to. CGRAM Character Address (binary) 010 Row Address (binary) 000
| | | | |

Value Written to CGRAM 00000B = 00H

010 010 010 010 010 010 010

001 010 011 100 101 110 111

| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |

10000B = 10H 01000B = 08H 00100B = 04H 00010B = 02H 00001B = 01H 00000B = 00H 00000B = 00H

The three character bits and the three row bits make up the 6-bit CGRAM address. Note that the top row is row 0 while the bottom row is row 7 (111B). You can use the bottom row when creating a custom character, but it is not advisable to do so, especially if you intend using the cursor as well. The example above shows how to create the \ symbol in CGRAM location 2. You start by setting CGRAM address to 2, then send the pattern for the character's first row to CGRAM (in this case, 00H). The AC will automatically increment to point to the next row. You then send the pattern for that row (in this case, 10H), and so on for all eight rows. Once completed, you can then display your new character by setting the DDRAM address to some value, then send the number 2 to DDRAM and your new character in CGRAM location 2 will appear on the display. You might then write a test, as shown below, to ensure the correct symbol is displayed when writing \ to the LCD: ... ; data to be sent to LCD has been placed in A CJNE A, #'\', skip ; if A does not contain \ symbol, skip next line MOV A, #2 ; replace \ with location of \ in CGRAM CALL sendCharacter ; call the subroutine that sends the contents of A to the

skip: LCD

For complete instructions on how to program the LCD module, see HD44780.pdf. The Switch Bank and the ADC

When a switch is open a logic 1 appears on the port pin (via the pull-up resistor) while closing the switch connects the pin directly to ground - logic 0. The switch bank and the outputs of the ADC are applied to port 2. Therefor e, it should be noted that when the ADC is being used the switches in the switch bank should all be open (in the

simulator , the switches are grey when they are closed). If a switch is closed it doesn't matter what the ADC tries to put on that line, the line is held low because it is connecte d directly to ground through the closed switch. Logic diagram showing the switch bank and ADC connections only. The outputs of the ADC are tri-state: the RD line, which is connected to P3.7, must be low for the ADC reading to appear on the outputs. The WR line (connected to P3.6) is used to initiate a conversion. As it is positive edge triggered, it must be taken low and then high to start a conversion. When the conversion is complete the INTR line goes low (and remains low until another conversion is initiated). This line is applied to the external 0 interrupt line, INT0. In this way, the

8051 can be interrupted by the completion of an ADC conversion. Note the tip that appears when the mouse is placed over the ADC button. Clicking on this button disables the ADC and enabled the comparator. See the Comparator for more information. Switch Bank and the ADC Panel The function of the ADC pins are summarised in the following table:
Pin RD WR INTR i/p CS D0 D7 Function Enables the tri-state outputs, when logic 0. On a positive edge, initiates conversion. Goes to logic 0 when conversion is complete and remains low until another conversion is initiated. Analogue input signal applied here. Enables the device, when logic 0. Tri-state digital outputs.

Changing Switch Labels You can change the label of a switch in the switch bank by right-clicking on the switch and entering a new character. A switch label can only be one character in length.

The Comparator and the DAC Many lecturers like to get their students to develop their own ADC using a DAC and a comparator. To meet this need, the output of the DAC is also applied to the inverting pin of a comparator, as shown in the logic diagram extract below.

Logic diagram showing the comparator and DAC connections only (notice the ADC is disabled, therefore its connections to the 8051 are not shown). The analogue input that is applied to the ADC is also applied to the non-inverting pin of the comparator, as can be seen above (in this extract, since the ADC is disabled, the analogue voltage connection to the ADC is omitted). When the comparator is enabled, the button's label says Comparator, as can be seen in the image opposite. Hovering over the button displays a tip - click the button to disable the comparator and enable the ADC. The button corresponds to the switch at the ADC chip select and the switch between the comparator output and P3.7 in the logic diagram extract above. You can see the switch between the comparator output and P3.7 is closed while at the same time the ADC CS line is switched to +V, disabling the ADC. Comparator Panel

When the comparator is enabled it can then be used together with the DAC to implement an ADC. There are many techniques that can be used. Learn about comparators and DACs used as ADCs (An external site that is not affiliated with EdSim51.)

The Motor P3.0 and P3.1 are applied to a dual bridge driver, the outputs of which are applied to a bidirectional DC motor. The truth table for the bridge and its effect on the motor is:
A B motor 0 0 stop 0 1 forward 1 0 reverse 1 1 stop

Logic diagram showing the motor and UART connections only.

In the image on the left, the motor's shaft is in the default position (pointing at 3

o'clock). Notice the sensor (depicted by a vertical line at the top of the motor) is black. When the motor's shaft lines up with the sensor, the sensor changes from black to red, as shown in the image on the right. Motor Panel The motor sensor, which is applied to P3.5, goes low once every revolution (in the simulator, whenever the motor shaft lines up with the sensor, the sensor changes from black to red and P3.5 goes to logic 0). P3.5 is the external clock source for timer 1. Therefore, code can be written that, using timer 1, counts the motor's revolutions. The speed of the motor can be varied manually (using the slider to the right of the motor - take a look at the hardware screenshots above). This will make the rev. counting programs more interesting. Note: The motor control lines share the TXD and RXD lines for the 8051's internal serial port. As can be seen in the logic diagram extract above, these lines are also connected to the external UART. Therefore, when exercising the motor, garbage messages may appear in the UART's receiver window. The function of the external UART is explained below. The motor can be disabled by clicking on the Motor Enabled button. Why would you want to disable the motor? See The UART below.

The UART

As stated above, the motor control lines share the same port pins as the 8051 serial port RXD and TXD. An external UART is connected to P3.0 and P3.1. Data received from the 8051's serial port appears in the Rx window. The data in this window can be cleared at any time by clicking the Rx Reset button. External UART Panel Data can be transmitted to the 8051's serial port by typing text in the Tx window and clicking on the Tx Send button, which initiates transmission. When this button is clicked, the Tx window's background colour changes to grey, indicating the window is not editable. The title of the Tx Send button changes to Tx Reset. Clicking on the button at this point clears the Tx window. Its background colour changes back to white - the user can type more text and click Tx Send to restart transmission. The data transmitted by the external UART is terminated with the \r character (the ASCII code for \r is 0DH). In other words, when the text abc is transmitted by the UART, the actual data sent is abc\r (or, in ASCII - 61H 62H 63H 0DH). The UART can also transmit a list of 8-bit numbers instead of text. See HEX in Uart for more information. The UART's default Baud rate is 4800. The user can select from a drop-down list of standard Baud rates (as can be seen below). Whenever the Baud rate is changed, the external UART's receiver and transmitter are reset. The UART can be set to even parity, odd parity or no parity by clicking on the Parity button, cycling through the three options: No Parity (the default), Odd Parity and Even Parity. For more information on the 8051 serial port and on adding a parity bit, click Beginner's Guide to the 8051 - Serial Port. When communicating with the UART, the pins P3.0 and P3.1 will therefore be changing value, which will have the side effect of turning the motor. To stop this, the user can click the Motor

Enabled button which has the effect of disabling the motor (the button's title then Motor Disabled and the motor can be re-enabled by clicking the button again).

changes to

UART Transmitting HEX Data Rather than text, a list of 8-bit numbers (written in HEX) can be transmitted. To do so, the user encloses the list in curly braces, each number separated by a comma, as shown in the image opposite. When text is transmitted, it is terminated by 0DH. This is not the case with a list of numbers. In the example shown opposite, the four numbers 56, 3a, 23 and e7 are transmitted, nothing more. If the user wishes to send {56, 3a, 23, e7} as text rather than a list of 8-bit numbers, the text is escaped using the \ character. Therefore, \{56, 3a, 23, e7} in the Tx field would result in {56, 3a, 23, e7} followed by 0DH being transmitted to the 8051.

The Keypad

Logic diagram showing the keypad connections only. The 4 X 3 keypad is interfaced in a standard format, as can be seen in the logic diagram extract above. All of port 0's pins, except pin 7, are used by the keypad. External 1 Interrupt: The 3 columns are connected to the inputs of an AND gate, the output of which is connected to P3.3, the external 1 interrupt pin. The AND gate is disabled (by default) because this pin (P3.3) is also used by the display-select decoder (see Display above). To make use of the external 1 interrupt with the keypad, make sure the AND gate is enabled. But remember, you won't be able to multiplex the displays and use keypad interrupts at the same time. Instead you should use busy-waiting on the keypad. Key Bounce If Key Bounce is enabled, as shown in the image opposite, then the keys will bounce when closed (the keypad only bounces if the keypad mode is set to standard). So the user knows a key is bouncing, its colour alternates between red (switch open) and dark red (switch closed). Once the switch finishes bouncing, its colour reverts to dark grey. The length of the switch bounce is 30 ms. Note: a key will only bounce while a program is running. If the user pauses the running program, then the switch bounce also pauses. Notes on interfacing to a keypad: Beginner's Guide to the 8051 - Peripheral Interfacing Keypad Modes Next to the keypad is a menu (see image above). This gives the user a choice of three settings for the type of keypad. By default the keypad mode is set to Standard. The other two types are Pulse and Radio. Standard - in standard mode the keys are independent of each other. Any number of keys can be closed at the same time. A closed key is reopened simply by clicking on it again. Pulse - in pulse mode a key is closed while the (left) mouse button is held down. Once the mouse button is released the key reopens. Radio - in radio mode only one key at a time can be closed. For example, if key 5 is pressed (ie: closed) and then key 7 is pressed, key 5 automatically reopens. As in standard mode, a closed key is reopened simply by clicking on it again. When the user switches to another keypad mode, using the adjacent menu, all closed keys are automatically reopened.

Changing Key Labels You can change the label of a key by right-clicking on the key and entering a new character. Key labels can be any length. The keypad resizes automatically.

Saved Settings
The following settings are saved during the simulator shut down process:
Original Setting Update Freq. Bitfield Address Data/Code Memory File System Directory ADC/Comparator Enabled External UART Parity External UART Baud Rate Keypad AND Gate Keypad Type Key Bounce Key Labels Switch Labels Motor Enabled/Disabled 1 ACC Data Memory Operating System Dependent ADC Enabled No Parity 4800 Baud Disabled Standard No Key Bounce #, 0, *, 9, 8, 7, 6, 5, 4, 3, 2, 1 0, 1, 2, 3, 4, 5, 6, 7 Enabled

These settings are saved in two files, edsim51diSettings.ser and edsim51diHardwareSettings.ser. The files are (most likely) saved in the same folder as the edsim51di.jar JAR file on Windows or Mac and in the user's home folder on Linux. When the simulator is launched it tries to open these file. If the files exist then the information in them is used to restore the system settings to the values they were when the simulator was last shut down. If the files do not exist or are corrupted in some way, they are ignored and the simulator is launched with the original settings.

Note: When stepping through or running code, the length of time that passes is not only experienced by the 8051, but by all the peripherals as well. If the instruction being executed is a 1 cycle instruction then, with a system clock is 12 MHz, the length of time passed is 1 us. Therefore, 1 us has passed for the UART and for the ADC and so on. In other words, if code is not being executed, time has stopped. If you have questions about the EdSim51 simulator, please visit our Comments page.

The Beginner Prefer About User' Installatio Sit Conta Fundament 's Guide Hom the the s n Exampl e EdSim51 ct al to the e Original Simulat Guid Instructio es Ma SH Us Simulation 8051 ? or e ns p s Online

New

Copyright (c) 2005-2012 James Rogers

You might also like