22
User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us The Fundamental Simulations Beginner's Guide to the 8051 Online Site Map User's Guide The Microcontroller Panel The Bitfield Data and Code Memory The Assembly Code Panel Source Pane Unlocker Load and Save Copy and Paste A Few Notes on the Assembler Debugging Breakpoints The Peripherals The Logic Diagram The LED Bank, DAC and the 7segment Displays The LCD Module The Switch Bank and the ADC The Comparator and the DAC The Motor The UART The Keypad 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.

User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

  • Upload
    lybao

  • View
    218

  • Download
    0

Embed Size (px)

Citation preview

Page 1: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

User's Guide

Home Prefer theOriginal?

NewEdSim51SH

About theSimulator

User'sGuide

InstallationInstructions Examples Contact

UsThe Fundamental

SimulationsBeginner's Guideto the 8051 ­ Online Site Map

User's Guide

The Microcontroller Panel

The BitfieldData and Code Memory

The Assembly Code PanelSource Pane UnlockerLoad and SaveCopy and PasteA Few Notes on the AssemblerDebuggingBreakpoints

The PeripheralsThe Logic DiagramThe LED Bank, DAC and the 7­segment DisplaysThe LCD ModuleThe Switch Bank and the ADCThe Comparator and the DACThe MotorThe UARTThe Keypad

New Features! Get the latest EdSim51 version

The Dynamic InterfaceNow the user can switch the peripherals to otherport pins.

Get more information.

Unlock the External UARTClicking on the button marked U at the top left of the externalUART places the UART in a separate frame, as shown below.This frame has much larger text windows for transmitted andreceived text.

Simply close this frame to lock the UART back in the mainwindow.

Page 2: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

Syntax HighlightingNow, 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 theaddress 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 theprompt.

Page 3: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

Change the System Clock FrequencyOriginally, the simulator ran with a system clock frequency of 12 MHz. Now the user can enter a value for the systemclock frequency in MHz.

UART Transmitting HEX DataUp until now, the external UART only transmitted text ­ whatever the user typed in the Tx field wastransmitted 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 imageopposite.

When text is transmitted, it is terminated by 0DH. This is not the case with a list of numbers. In theexample 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, e7in the Tx field would result in 56, 3a, 23, e7 followed by 0DH being transmitted to the 8051.

LCD ModuleA simulation of the popular Hitachi HD44780 LCD module has been implemented for the EdSim51Simulator. And now CGRAM has also been implemented. Find out more.

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

Keypad ModesNow 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 InterruptUntil now the keypad could only be implemented using busy­waiting. It can still beimplemented in that manner, but it can also be used together with the 8051 external1 interrupt pin, P3.3.Note: this pin, P3.3, is also used by the display­select decoder, thereforemultiplexing of the 7­segment displays cannot be implemented together with thekeypad interrupt. To multiplex the displays and use the keypad at the same time, thekeypad must be implemented using busy waiting. More information on the keypad modes and the keypad interrupt

Page 4: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

Intel HEX Reader/Writer

You can now save your source code in Intel HEX format. Oryou can write C code for the 8051 using one of many available8051 C compilers, then import the HEX code into the EdSim51Simulator. Find out more.

Simulator Window UpdateAs with many microcontroller simulators, EdSim51 allows the user to either step through a program, executing a single instruction per step, or to run theprogram continuously. In the original EdSim51 design, when running a program, the simulator would execute one instruction, update the screen, pausefor a quarter second, then proceed with the next instruction and so on. This allowed the programmer to observe changes in the hardware and registers foreach 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) theprogrammer can choose how often the screen should be updated. The choices are: update the screen after everyinstruction 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 anumber rather than select a value from the list. For the entered number to take effect, the user must hit Enter on thecomputer keyboard.

Find out more.

The Microcontroller Panel

A screenshot of the microcontroller panel. This gives the user access to allthe 8051's registers and data memory.

Boxes that are white can be edited directly. Those that are grey cannot. Forexample, the port latch bits can be edited directly by the user, but the port pinsare controlled by the external peripherals and the port latches and cannot beedited.

When the mouse pointer is left tohover over one of the register labels,the register's address appears, asshown opposite for the PCONregister.

Page 5: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

The BitfieldIn 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) andthe 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 isdisplayed, as shown below:

The bit field for the TMOD SFR is shown. Notice bit 2 is thecounter/timer bit. Also notice the background is grey. This is becausethe TMOD register is not bit­addressable ­ the user cannot alter these bitsdirectly.

The PSW is bit­addressable, therefore the background of each bit is whiteand the user can change any of the bits directly.

The bitfield can be used to see the bit pattern of any address in RAM (0to 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 ofthe eight bits.

As with SFRs, if the location is not bit­addressable the backgrounds aregrey.

Data and Code MemoryBy 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 thenentering the desired value in the box to the right (labelled value).

Page 6: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

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 thebutton 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 startaddress 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 valuebox. 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, therate 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 shouldbe 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 assemblycode panel to the left. This program runs in a continuousloop, displaying the numbers 0 to 9 and back to 0 on thefirst 7­segment display. A snapshot of its execution isshown to the right.

When the background of the assembly code text area is white is it editable. The programmercan write code directly here, or can load a program from file using the Load button (dealtwith in the next section). When the program is ready for testing, the user can either click on the Assm button to executeinstructions 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 isdisplayed in the message box above the assembly code (with a red background) and the linewith the error is highlighted within the code in red. If the code assembles without errors, Assm is replaced by Step, the text area's backgroundchanges 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 UnlockerThe 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.

Page 7: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

Load and SaveThe 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 .aor .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 inHEX format by choosing Intel HEX Files from theFiles of Type: menu in the Save dialog box. Find out more onloading 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 nexttime 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 PasteYou 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 processingpackage. 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, clickReset). Or you can paste the selected text into some other application (such as your word processor). Similarly, you can copy text from another applicationand paste it into the assembly text area. A Few Notes on the AssemblerThe 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 mightexpect 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, thenumber cannot begin with a letter (example: F5H must be written as 0F5H). Binary values are entered by appending B after the number (as shown inthe image below).The assembler is not case­sensitive.

Debugging

Regardless of whether the code is running or being stepped, once the code assembles withouterrors, 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 greybox 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).

Page 8: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

BreakpointsA breakpoint can be set by double­clicking the instruction's address, as shown in the images below.

Setting a breakpoint: When steppingthrough the code, move the mouseover the address of the instruction anddouble­click.

When the breakpoint is set the verticalbar (|) immediately to the right of theaddress is replaced by a star (*), asshown in the image on the right.

Removing a breakpoint: Abreakpoint is indicated by a star (*).To remove the breakpoint, move themouse over the instruction's addressand double­click. The * is replaced by|.

Alternatively, you can remove allbreakpoints 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 executedwill 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 clickingon 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 imagebelow).

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 portpins. This of course may not be true in your case, if, for example, you move the motor to other pins.

Page 9: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

The Peripheral Panel

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

Page 10: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

An Instance of the Dynamic Logic Diagram

The Peripherals:

ADCComparatorFour 7­segment LED DisplaysLCD ModuleUARTKeypadLED BankBi­directional MotorSwitch BankDAC (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 byhovering the mouse over it, or by clicking on the zoom button (see below).

ZoomClick on one of the buttons marked + to display that port's connections in aseparate window. An example for port 2 is shown below.

Page 11: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

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

Page 12: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

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 areapplied 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 theprogrammer 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 inputswhen 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 outputfor 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 theexternal interrupt 1 line (P3.3) is also used by the display decoder (see logic diagram above). Therefore, keypad interrupt and multiplexing the 7­segmentdisplay cannot be used at the same time ­ the keypad AND gate should be disabled.An example of the DAC in action is shown below:

Page 13: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

Ramp Generated via DAC Appears on Scope Code for RampGeneration

LED Bank and the7­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 theaccumulator 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 thiscase, 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 forsimulation purposes). If, for example, the system clock frequency is changed to 11.059 MHz, then the scope's horizontal scale is 17.36 microseconds perdivision.

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 tothe 8051 in 4­bit mode. P1.7 through P1.4 are connected to DB7 through DB4, while P1.3is connected to the register­select pin and P1.2 is connected to the enable pin. Notice theread­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 4­bit mode. However,the lower four data bits (DB3 through DB0) are also available (on P1.3 through P1.0). If theuser wishes to write to the module in 8­bit mode, RS and E should be remapped to otherport 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. Fordetails on how to communicate with the module, see HD44780.pdf and some sampleprograms.

Reading: Instructions for reading from the module have not been implemented.

Character Blinking: Because the simulator does not run in real­time, it would be hard toknow 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 alternatesbetween blue text with red background and red text with blue background. In this way theprogrammer knows at a glance if the module is in blinking mode (when not in blinkingmode, all characters are black with grey background).

Page 14: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

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

The enable pin (E, connected to P1.2) is negative­edge triggered. On anegative­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 isinterfaced with the 8051 in 4­bit mode. In 4­bit mode, the module's linesDB3, DB2, DB1 and DB0 are not used. The 8­bit instruction or data musttherefore be sent in two 4­bit nibbles. The high nibble is sent first,followed by the low nibble. When the enable pin is taken high and thenlow, this causes the module to read the pins DB7­DB4 and store them ineither the IR (if an instruction is being sent ­ ie: RS = 0) or the DR (if datais being sent ­ ie: RS = 1). Initially, the module is in 8­bit mode and must be set to 4­bit mode by theprogrammer before any other communications with the module areattempted. This is done by sending the appropriate Function Setinstruction (see instruction set below).

Why send Function set twice? As stated, the module is initially in 8­bitmode, therefore the first instruction sent to it is read as an 8­bitinstruction (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 themodule 'knows' it is being set to 4­bit operation and it reads instructionsand data in two 4­bit nibbles from then on.Because it reads the high nibble first, the Function set high nibble must besent again, followed by the low nibble.For more information, see pages 39 and 42 of HD44780.pdf. Theexample on page 42 is for a 1­line display, but it nonetheless explainsclearly 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 becalled 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 thefont to 5 X 8 dots).

Page 15: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

Function Set Incorrectly: The programmer must set the module to 2­line,5 X 8 font. The simulation of the HD44780 is implemented for 2­line, 5 X8 font only. However, the programmer is still expected to write the codethat sets the module in this mode. If the mode is not set correctly, an errormessage stating such is displayed, as shown here. The programmer mustthen reset the simulator, modify the code and try again.

LCD Module Instruction Set

Page 16: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

CGRAMCGRAM 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, sostored 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 extractillustrates this point:

MOV A, 'W' CALL sendCharacter ; a subroutine that sends the data in A to the LCD module's DDRAM

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 theselocations 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, thecorresponding 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) andthen 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 thesesix 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 toCGRAM. You do this by calling the Set CGRAM address instruction. As with writing to DDRAM, the AC is incremented (or decremented, depending on theincrement/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 correspondwith ASCII. At location 92 you would expect to see the \ symbol. Instead there is ¥ (probably because the HD44780 was developed in Japan). At location126, 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'ssay 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 ismade 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 thebottom three bits determine which of the eight rows of this character is being written to.

CGRAM Character Address (binary) Row Address (binary) Value Written to CGRAM

010010010010010010010010

000001010011100101110111

| | | | |

| | | | |

| | | | |

| | | | |

| | | | |

| | | | |

| | | | |

| | | | |

00000B = 00H10000B = 10H01000B = 08H00100B = 04H00010B = 02H00001B = 01H00000B = 00H00000B = 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 todo 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 thecharacter'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 (inthis 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 newcharacter 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 CGRAMskip: CALL sendCharacter ; call the subroutine that sends the contents of A to the LCD

For complete instructions on how to program the LCD module, see HD44780.pdf.

Page 17: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

The Switch Bank and the ADC

When a switch is open a logic 1 appears on the port pin (viathe pull­up resistor) while closing the switch connects thepin directly to ground ­ logic 0.

The switch bank and the outputs of the ADC are applied toport 2. Therefore, it should be noted that when the ADC isbeing used the switches in the switch bank should all beopen (in the simulator, the switches are grey when they areclosed). If a switch is closed it doesn't matter what the ADCtries to put on that line, the line is held low because it isconnected 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 ADCreading 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 mustbe 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 isinitiated). This line is applied to the external 0 interrupt line, INT0. In this way, the 8051 can beinterrupted by the completion of an ADC conversion.

Note the tip that appears when the mouse is placed over the ADC button. Clicking on this buttondisables the ADC and enabled the comparator. See the Comparator for more information.

Page 18: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

Switch Bank and the ADC Panel The function of the ADC pins are summarised in the following table:

Pin FunctionRD Enables the tri­state outputs, when logic 0.

WR On a positive edge, initiates conversion.INTR Goes to logic 0 when conversion is complete and remains low until another conversion is initiated.i/p Analogue input signal applied here.CS Enables the device, when logic 0.

D0 ­ D7 Tri­state digital outputs.

Changing Switch LabelsYou can change the label of a switch in the switch bank by right­clicking onthe 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 appliedto the inverting pin of a comparator, as shown in the logic diagram extract below.

Page 19: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

Logic diagram showing the comparator and DAC connections only (notice the ADC is disabled, therefore its connections to the 8051 are notshown).

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 thecomparator is enabled, the button's label says Comparator, as can be seen in the image opposite. Hovering over thebutton 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 inthe logic diagram extract above. You can see the switch between the comparator output and P3.7 is closed while at thesame 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 whichare applied to a bi­directional DC motor. The truth table for the bridgeand its effect on the motor is: A B motor0 0 stop0 1 forward1 0 reverse1 1 stop

Logic diagram showing the motor and UART connections only.

In the image on the left, the motor's shaft is in the defaultposition (pointing at 3 o'clock). Notice the sensor (depictedby a vertical line at the top of the motor) is black.

When the motor's shaft lines up with the sensor, the sensorchanges from black to red, as shown in the image on theright.

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 sensorchanges 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, countsthe 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 therev. counting programs more interesting.

Page 20: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

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 linesare also connected to the external UART. Therefore, when exercising the motor, garbage messages may appear in the UART's receiver window. Thefunction 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 serialport 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 thiswindow 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 thisbutton 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 TxReset. 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 TxSend 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 istransmitted 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 oftext. 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 ischanged, 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 stopthis, the user can click the Motor Enabled button which has the effect of disabling the motor (the button's title then changes to Motor Disabled and the motorcan be re­enabled by clicking the button again). UART Transmitting HEX Data

Rather than text, a list of 8­bit numbers (written in HEX) can be transmitted. To do so, the userencloses the list in curly braces, each number separated by a comma, as shown in the imageopposite.

When text is transmitted, it is terminated by 0DH. This is not the case with a list of numbers. In theexample 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 inthe Tx field would result in 56, 3a, 23, e7 followed by 0DH being transmitted to the 8051.

The Keypad

Page 21: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

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 thekeypad. 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. TheAND 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 1interrupt 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 atthe 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 onlybounces if the keypad mode is set to standard). So the user knows a key is bouncing, its colour alternates betweenred (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 theswitch bounce also pauses.

Notes on interfacing to a keypad: Beginner's Guide to the 8051 ­ Peripheral Interfacing Keypad ModesNext 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 toStandard. 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 reopenedsimply 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 automaticallyreopens. 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 LabelsYou can change the label of a key by right­clicking on the key andentering a new character. Key labels can be any length. The keypadresizes automatically.

Saved Settings

Page 22: User's Guide - 2ic004mg.files.wordpress.com · User's Guide Home Prefer the Original? New EdSim51SH About the Simulator User's Guide Installation Instructions Examples Contact Us

The following settings are saved during the simulator shut down process:

Original Setting

Update Freq. 1Bitfield Address ACCData/Code Memory Data MemoryFile System Directory Operating System DependentADC/Comparator Enabled ADC EnabledExternal UART Parity No ParityExternal UART Baud Rate 4800 BaudKeypad AND Gate DisabledKeypad Type StandardKey Bounce No Key BounceKey Labels #, 0, *, 9, 8, 7, 6, 5, 4, 3, 2, 1Switch Labels 0, 1, 2, 3, 4, 5, 6, 7Motor Enabled/Disabled Enabled

These settings are saved in two files, edsim51diSettings.ser and edsim51diHardwareSettings.ser. The files are (most likely) saved in the same folderas 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 thefiles 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 notexist 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 forthe 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.

Home Prefer theOriginal?

NewEdSim51SH

About theSimulator

User'sGuide

InstallationInstructions Examples Contact

UsThe Fundamental

SimulationsBeginner's Guideto the 8051 ­ Online Site Map

Copyright (c) 2005­2013 James Rogers