78
MDA-WinEMS51 MANUAL User's Manual Midas Engineering co., ltd. ACE Techno-Tower Ⅴ#906 197-22 Kuro-Dong Kuro-Gu, Seoul, Korea. Tel. 82-2-2109-5964~7 Fax. 82-2-2109-5968 www.midaseng.com E_mail. [email protected]

WinEMS51

Embed Size (px)

DESCRIPTION

fgggffg

Citation preview

Page 1: WinEMS51

MDA-WinEMS51

MANUAL

Users Manual

Midas Engineering co ltdACE Techno-Tower Ⅴ906 197-22

Kuro-Dong Kuro-Gu Seoul Korea

Tel 82-2-2109-5964~7 Fax 82-2-2109-5968

wwwmidasengcom

E_mail infomidasengcom

Notice

Copyright 2005 Midas engineering

The Midas engineering will not repair an MDA-WinEMS51 kit that has been modified and when circuity has been added to user design area may request that circuit be disconnected prior to submitting the kit to the Midas engineering for repair

Service amp Information

If following assembly you cannot get your kit to operate satisfactory the Midas engineering is available for assistance This service is provided during the hours of 9AM to 6PM(Korea time) Monday trough Friday

Tel 82-2-2109-5964~7 Fax 82-2-2109-5968

httpwwwmidasengcomE_mail infomidasengcom

PART MDA-WinEMS51 USERS MANUAL

TABLE OF CONTENTS 1 Introduction middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 7

1-1 Specifications of the MDA-WinEMS51 kit middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 81-2 MDA-WinEMS51 Kit Address map middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 11

2 Install WinIDE Studio-51(EMS) middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 12

3 View WinIDE Studio-51(EMS) middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 19

3-1 Structure of WinIDE Stuio-51(EMS) Program Screens middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 193-2 Explanation of the WinIDE Studio-51(EMS) Screens by Studio middotmiddotmiddotmiddotmiddotmiddot 203-3 Functions of Each Studio middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 213-4 The Main Menu of WinIDE Studio-51(EMS) middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 263-5 The Shortcut Button of WinIDE Studio-51(EMS) middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 303-6 Compiling the source middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 32

4 Keyboard Monitor middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 34

4-1 Introduction middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 344-2 Using the Keyboard monitor middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 344-3 Keyboard middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 354-4 LCD Display middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 374-5 Basic operation middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 37

5 Experiment middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 43

The Schematic of the MDA-WinEMS51 kit middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 69

MDA-WinEMS51 MANUAL - 7 -

1 Introduction The MDA-WinEMS51 kit is shown in Figure 1-1 contains all the

basic components necessary to understand 8051 microcomputer

Figure 1-1 MDA-WinEMS51 Kit(main)

1 Introduction

- 8 - MDA-WinEMS51 MANUAL

The MDA-WinEMS51 Kit has a CPU Memory (Monitor ROM and RAM) keyboard a LCD display RS- 232C Dot matrix LED ROM writer etc

A few major features of the MDA-WinEMS51 Kit include Run the assembler or compiler you have chosen Edit the source files Save the selected files Select a new file to edit assemble or compile Interfacing and board configuration information for connecting peripheral devices to the MDA-WinEMS51 Kit Writing the 89C51 Excising the 8051 microcomputer Excising the DOT matrix DC motor Stepping motor Excising the DA AD converter

1‐1 Specifications of the MDA‐WinEMS51 kitEach function of the MDA-WinEMS51 kit components is described below

CPU(Central processing unit) The CPU is located to the center of the MDA-WinEMS51 kit(marking the CPU amp MEMORY) The CPU use the 805180318751 with the clock 110592[ ]

ROM(Read Only Memory) The ROM is located to the center of the MDA-WinEMS51 kit(marking the CPU amp MEMORY) It contains the basic program to allow user to control the MDA-WinEMS51 kit with the keyboard LCD display data communication

SRAM(Static Random Access Memory) The RAM is located to the center of the MDA-WinEMS51 kit(marking the CPU amp MEMORY) Information (instructions and data) can be inserted (written) into RAM

1-1 Specifications of the MDA-WinEMS51

MDA-WinEMS51 MANUAL - 9 -

The information can be also be read from memory or altered by user

DISPLAY The display is comprised of LCD display providing visual display of the data or control information It has the 16(Character)times2(Line)

KEYBOARD It is a switch consisting of sixteen labeled hexadecimal eight function keys The keyboard is interfaced to system bus by the priority encoder

Control information and data is entered into system by the key

SPEAKER The SPEAKER is located to the right-center part of the MDA-WinEMS51 kit(marking the SPEAKER)

The speaker can test the sound and the synthesizer

RS-232C The RS-232C is located to the right-top part of the MDA-WinEMS51 kit(marking the RS-232C)

It use the IBM compatible PC to communicate the data

8751AT89C51 WRITER The WRITER is located to the center-bottom of the MDA-WinEMS51 kit (marking the 89C51 WRITER)

The writer can write the users program to the microcomputerAT89C51

DOT MATRIX LED The DOT MATRIX LED is located to the center-top part of the MDA-WinEMS51 kit(marking the DOT MATRIX 8 X 8) It use the dot matrix LED to understand the dot matrix structure and the principle of display it is interfaced to system bus by the 8255A(PPI)

AD CONVERTER The AD converter is located to the

1 Introduction

- 10 - MDA-WinEMS51 MANUAL

left-center part of the MDA-WinEMS51 kit(marking the AD CONVERTER)

The A(Analog)D(Digital) Convert used the ADC0804 to convert the analog singial to digital singial with the ADC0804

DA CONVERTER The DA converter is located to the left-center part of the MDA-WinEMS51 kit(marking the DA CONVERTER) It used the DAC0800(8 bit DA converter) to convert the digital signal to the analog signal and to control the DC motor

STEPPING MOTOR DRIVER The stepping motor driver is located to the left-upper part of the MDA-WinEMS51 kit(marking the STEPPING MOTOR) It use the stepping motor driver to control the stepping motor

DC MOTOR The DC motor is located to the left-bottom of the MDA-WinEMS51 kit(marking the DC MOTOR) It use the DA converter to control the speed of DC motor It use the photo interrupter to measure the speed of DC motor

CONNECTOR The connector is located to the left amp bottom of the MDA-WinEMS51 kit(marking the PORT-IO EXT-IO CON3)It use to interface the peripheral device

POWER The POWER is located to the right-top of the MDA-WinEMS51 kit(marking the AC POWER)

The power spec is the +5V(3A) +12V(1A) -12V(05A)

1-2 MDA-WinEMS51 Kit Address map

MDA-WinEMS51 MANUAL - 11 -

1‐2 MDA‐WinEMS51 Kit Address map The Table 1-1 show the address map of the MDA-WinEMS51 kit

Address MemoryIO Comment0000H 6FFFH RAM ProgramData memory

7000H 7FFFH ROM WRITER

8000H BFFFH ROM Monitor ROM

C000H C003H KEY_FLAG Keyboard buffer clear

C004H C007H KEY_PORT Keyboard buffer read

C008H C00BH 8255A(PPI)

C008H A PORT 89C51 WRITER DATA BUS

C009H B PORT LCD DATA BUSC00AH C PORT Control the

LCD and the 89C51 writerC00BH Control Register

C00CH C00FH 89C51 WRITER C00CH Control the 89C51 writer

C010H C013H SPEAKERC010H Control the speaker

C014H C017H8255A( Control the dot matrix)

C014H A PORTC015H B PORTC016H C PORTC017H Control Register

C018H C01BHADCONVERTER

C018H Control the AD converter

C01CH C01FH CON10 Control the peripheral device

C020H FFFFH USERS Region

Table 1-1

2 Install WinIDE Studio-51(EMS)

- 12 - MDA-WinEMS51 MANUAL

2 Install WinIDE Studio-51(EMS)

MDA-WinEMS51 has to be connected to the users PC after WinIDE Studio-51(EMS) the dedicated program for MDA-WinEMS51 provided by MIDAS ENGINEERING is installed in the users PC in advance

However If there is a WinIDE Studio-51(EMS) program in the users PC the following procedures may be omitted

What is WinIDE Studio-51(EMS)WinIDE Studio-51(EMS) can execute the assemblecompile in

one screen of Windows by making a source file (assembly language or C language) is further linked to the MDA-WinEMS51 kit to have all of the internal RAM register bank and SFR(Special Function Register) of the MDA-WinEMS51 kit displayed on one screen and can process the program execution and single steps of the downloaded file with the MDA-WinEMS51 kit

WinIDE Studio-51(EMS) is to simply process all the jobs by simply pressing the corresponding function keys in Windows 95982002XP

The WinIDE Studio-51(EMS) CD-ROM provided by MIDAS ENGINEERING is the CD-ROM only to use the MDA-WinEMS51 kit and the minimum conditions and installation procedures are as follows

MDA-WinEMS51 MANUAL - 13 -

User System Requirements

Processor PC based on the Pentium processor (166 or higher)

Operating Systems Microsoft Windows 95982000XP

RAM 16MB RAM (64MB recommended)

Hard Disk The 100 MB or higher blank space of a hard disk

2 Install WinIDE Studio-51(EMS)

- 14 - MDA-WinEMS51 MANUAL

Double-click My Computer after inserting the WinIDE Studio-51(EMS) CD into the users CD-ROM (AUTO RUN was not executed with the CD inserted into the CD-ROM)

Double-click Setupexe by reading the contents of the users CD-ROM drive

MDA-WinEMS51 MANUAL - 15 -

Read the license agreement and click Next if you agree with the agreement

Type in the name of the user (PC) and the company name if you are not a personal user and click Next

2 Install WinIDE Studio-51(EMS)

- 16 - MDA-WinEMS51 MANUAL

The path to the MIDAS ENG folder created is shown in the Windows program folder Confirm this and click ldquoNext

The installation path of WinIDE Studio-51(EMS) is shown Confirm this and click ldquoNext

MDA-WinEMS51 MANUAL - 17 -

The installation progress status of WinIDE Studio-51(EMS) is displayed

If the installation is successful the execution file of WinIDE Studio-51(EMS) is created in the MIDAS ENG folder and the installation has been successfully done

2 Install WinIDE Studio-51(EMS)

- 18 - MDA-WinEMS51 MANUAL

If WinIDE Studio-51(EMS) is executed the WinIDE Studio-51(EMS) logo appears

In case of the users PC connected correctly the WinIDE Studio-51(EMS) screen shows up Otherwise the next screen is displayed (If a user doesnt want the connection of MDA-WinEMS51 to the PC

with RS-232C DEMO is to be executed)

3-1 Structure of WinIDE Studio-51(EMS) Program Screens

MDA-WinEMS51 MANUAL - 19 -

3 View WinIDE Studio-51(EMS)

A user has to fully know about the structure and operating instructions of the WinIDE Studio-51(EMS) program to correctly develop the desired system with MDA-WinEMS51 so that they need to be perfectly understood

3‐1 Structure of WinIDE Studio‐51(EMS) Program Screens

The above screen is the main screen of WinIDE Studio-51(EMS) (Windows Integrated Development Environment Studio-51(EMS)) that is the integrated development environment of MDA-WinEMS51 and here in each studio and menu are to be explained for the first-time user

3 View WinIDE Studio-51(EMS)

- 20 - MDA-WinEMS51 MANUAL

3‐2 Explanation of the WinIDE Studio‐51(EMS) Program Screens by Studio

Menu There are submenus for a main menu and shortcut buttons are made to execute the main menus and the submenus at a time If the cursor is placed on this shortcut button the balloon help shows up and lets the function of the shortcut button known

File Studio Functions such as edit file save file assemble amp link compile amp link download etc are available

SFR Studio The values of the SFR (Special Function Register) of MDA-WinEMS51 are displayed and the values of the SFRs can be modified with the mouse and the keyboard of a personal computer

Internal RAM Studio The contents of the internal data RAM (20H-7FH) of MDA-WinEMS51 are displayed and the contents of the internal data RAM can be modified with the mouse and the keyboard of a personal computer

Register Bank Studio The contents of the general purpose registers (R0 R7) of MDA-WinEMS51 are displayed and the contents of the registers can be modified with the mouse and the keyboard of a personal computer

3-3 Functions of Each Studio

MDA-WinEMS51 MANUAL - 21 -

3‐3 Functions of Each Studio

File Studio Functions such as make and save assemble link or download a source file are executed in this studio Making and assembling a source file and downloading it to MDA-WinEMS51 are to be explained in the different chapter And the source file in the present file studio is displayed in the file recently worked out so a user doesnt have to worry about this source file

(1) If a user makes and assembles the source file and downloads it to MDA-WinEMS51 the command pointer window pointing to

the location of instructions as in the figure below appears in the file studio

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 2: WinEMS51

Notice

Copyright 2005 Midas engineering

The Midas engineering will not repair an MDA-WinEMS51 kit that has been modified and when circuity has been added to user design area may request that circuit be disconnected prior to submitting the kit to the Midas engineering for repair

Service amp Information

If following assembly you cannot get your kit to operate satisfactory the Midas engineering is available for assistance This service is provided during the hours of 9AM to 6PM(Korea time) Monday trough Friday

Tel 82-2-2109-5964~7 Fax 82-2-2109-5968

httpwwwmidasengcomE_mail infomidasengcom

PART MDA-WinEMS51 USERS MANUAL

TABLE OF CONTENTS 1 Introduction middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 7

1-1 Specifications of the MDA-WinEMS51 kit middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 81-2 MDA-WinEMS51 Kit Address map middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 11

2 Install WinIDE Studio-51(EMS) middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 12

3 View WinIDE Studio-51(EMS) middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 19

3-1 Structure of WinIDE Stuio-51(EMS) Program Screens middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 193-2 Explanation of the WinIDE Studio-51(EMS) Screens by Studio middotmiddotmiddotmiddotmiddotmiddot 203-3 Functions of Each Studio middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 213-4 The Main Menu of WinIDE Studio-51(EMS) middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 263-5 The Shortcut Button of WinIDE Studio-51(EMS) middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 303-6 Compiling the source middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 32

4 Keyboard Monitor middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 34

4-1 Introduction middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 344-2 Using the Keyboard monitor middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 344-3 Keyboard middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 354-4 LCD Display middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 374-5 Basic operation middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 37

5 Experiment middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 43

The Schematic of the MDA-WinEMS51 kit middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 69

MDA-WinEMS51 MANUAL - 7 -

1 Introduction The MDA-WinEMS51 kit is shown in Figure 1-1 contains all the

basic components necessary to understand 8051 microcomputer

Figure 1-1 MDA-WinEMS51 Kit(main)

1 Introduction

- 8 - MDA-WinEMS51 MANUAL

The MDA-WinEMS51 Kit has a CPU Memory (Monitor ROM and RAM) keyboard a LCD display RS- 232C Dot matrix LED ROM writer etc

A few major features of the MDA-WinEMS51 Kit include Run the assembler or compiler you have chosen Edit the source files Save the selected files Select a new file to edit assemble or compile Interfacing and board configuration information for connecting peripheral devices to the MDA-WinEMS51 Kit Writing the 89C51 Excising the 8051 microcomputer Excising the DOT matrix DC motor Stepping motor Excising the DA AD converter

1‐1 Specifications of the MDA‐WinEMS51 kitEach function of the MDA-WinEMS51 kit components is described below

CPU(Central processing unit) The CPU is located to the center of the MDA-WinEMS51 kit(marking the CPU amp MEMORY) The CPU use the 805180318751 with the clock 110592[ ]

ROM(Read Only Memory) The ROM is located to the center of the MDA-WinEMS51 kit(marking the CPU amp MEMORY) It contains the basic program to allow user to control the MDA-WinEMS51 kit with the keyboard LCD display data communication

SRAM(Static Random Access Memory) The RAM is located to the center of the MDA-WinEMS51 kit(marking the CPU amp MEMORY) Information (instructions and data) can be inserted (written) into RAM

1-1 Specifications of the MDA-WinEMS51

MDA-WinEMS51 MANUAL - 9 -

The information can be also be read from memory or altered by user

DISPLAY The display is comprised of LCD display providing visual display of the data or control information It has the 16(Character)times2(Line)

KEYBOARD It is a switch consisting of sixteen labeled hexadecimal eight function keys The keyboard is interfaced to system bus by the priority encoder

Control information and data is entered into system by the key

SPEAKER The SPEAKER is located to the right-center part of the MDA-WinEMS51 kit(marking the SPEAKER)

The speaker can test the sound and the synthesizer

RS-232C The RS-232C is located to the right-top part of the MDA-WinEMS51 kit(marking the RS-232C)

It use the IBM compatible PC to communicate the data

8751AT89C51 WRITER The WRITER is located to the center-bottom of the MDA-WinEMS51 kit (marking the 89C51 WRITER)

The writer can write the users program to the microcomputerAT89C51

DOT MATRIX LED The DOT MATRIX LED is located to the center-top part of the MDA-WinEMS51 kit(marking the DOT MATRIX 8 X 8) It use the dot matrix LED to understand the dot matrix structure and the principle of display it is interfaced to system bus by the 8255A(PPI)

AD CONVERTER The AD converter is located to the

1 Introduction

- 10 - MDA-WinEMS51 MANUAL

left-center part of the MDA-WinEMS51 kit(marking the AD CONVERTER)

The A(Analog)D(Digital) Convert used the ADC0804 to convert the analog singial to digital singial with the ADC0804

DA CONVERTER The DA converter is located to the left-center part of the MDA-WinEMS51 kit(marking the DA CONVERTER) It used the DAC0800(8 bit DA converter) to convert the digital signal to the analog signal and to control the DC motor

STEPPING MOTOR DRIVER The stepping motor driver is located to the left-upper part of the MDA-WinEMS51 kit(marking the STEPPING MOTOR) It use the stepping motor driver to control the stepping motor

DC MOTOR The DC motor is located to the left-bottom of the MDA-WinEMS51 kit(marking the DC MOTOR) It use the DA converter to control the speed of DC motor It use the photo interrupter to measure the speed of DC motor

CONNECTOR The connector is located to the left amp bottom of the MDA-WinEMS51 kit(marking the PORT-IO EXT-IO CON3)It use to interface the peripheral device

POWER The POWER is located to the right-top of the MDA-WinEMS51 kit(marking the AC POWER)

The power spec is the +5V(3A) +12V(1A) -12V(05A)

1-2 MDA-WinEMS51 Kit Address map

MDA-WinEMS51 MANUAL - 11 -

1‐2 MDA‐WinEMS51 Kit Address map The Table 1-1 show the address map of the MDA-WinEMS51 kit

Address MemoryIO Comment0000H 6FFFH RAM ProgramData memory

7000H 7FFFH ROM WRITER

8000H BFFFH ROM Monitor ROM

C000H C003H KEY_FLAG Keyboard buffer clear

C004H C007H KEY_PORT Keyboard buffer read

C008H C00BH 8255A(PPI)

C008H A PORT 89C51 WRITER DATA BUS

C009H B PORT LCD DATA BUSC00AH C PORT Control the

LCD and the 89C51 writerC00BH Control Register

C00CH C00FH 89C51 WRITER C00CH Control the 89C51 writer

C010H C013H SPEAKERC010H Control the speaker

C014H C017H8255A( Control the dot matrix)

C014H A PORTC015H B PORTC016H C PORTC017H Control Register

C018H C01BHADCONVERTER

C018H Control the AD converter

C01CH C01FH CON10 Control the peripheral device

C020H FFFFH USERS Region

Table 1-1

2 Install WinIDE Studio-51(EMS)

- 12 - MDA-WinEMS51 MANUAL

2 Install WinIDE Studio-51(EMS)

MDA-WinEMS51 has to be connected to the users PC after WinIDE Studio-51(EMS) the dedicated program for MDA-WinEMS51 provided by MIDAS ENGINEERING is installed in the users PC in advance

However If there is a WinIDE Studio-51(EMS) program in the users PC the following procedures may be omitted

What is WinIDE Studio-51(EMS)WinIDE Studio-51(EMS) can execute the assemblecompile in

one screen of Windows by making a source file (assembly language or C language) is further linked to the MDA-WinEMS51 kit to have all of the internal RAM register bank and SFR(Special Function Register) of the MDA-WinEMS51 kit displayed on one screen and can process the program execution and single steps of the downloaded file with the MDA-WinEMS51 kit

WinIDE Studio-51(EMS) is to simply process all the jobs by simply pressing the corresponding function keys in Windows 95982002XP

The WinIDE Studio-51(EMS) CD-ROM provided by MIDAS ENGINEERING is the CD-ROM only to use the MDA-WinEMS51 kit and the minimum conditions and installation procedures are as follows

MDA-WinEMS51 MANUAL - 13 -

User System Requirements

Processor PC based on the Pentium processor (166 or higher)

Operating Systems Microsoft Windows 95982000XP

RAM 16MB RAM (64MB recommended)

Hard Disk The 100 MB or higher blank space of a hard disk

2 Install WinIDE Studio-51(EMS)

- 14 - MDA-WinEMS51 MANUAL

Double-click My Computer after inserting the WinIDE Studio-51(EMS) CD into the users CD-ROM (AUTO RUN was not executed with the CD inserted into the CD-ROM)

Double-click Setupexe by reading the contents of the users CD-ROM drive

MDA-WinEMS51 MANUAL - 15 -

Read the license agreement and click Next if you agree with the agreement

Type in the name of the user (PC) and the company name if you are not a personal user and click Next

2 Install WinIDE Studio-51(EMS)

- 16 - MDA-WinEMS51 MANUAL

The path to the MIDAS ENG folder created is shown in the Windows program folder Confirm this and click ldquoNext

The installation path of WinIDE Studio-51(EMS) is shown Confirm this and click ldquoNext

MDA-WinEMS51 MANUAL - 17 -

The installation progress status of WinIDE Studio-51(EMS) is displayed

If the installation is successful the execution file of WinIDE Studio-51(EMS) is created in the MIDAS ENG folder and the installation has been successfully done

2 Install WinIDE Studio-51(EMS)

- 18 - MDA-WinEMS51 MANUAL

If WinIDE Studio-51(EMS) is executed the WinIDE Studio-51(EMS) logo appears

In case of the users PC connected correctly the WinIDE Studio-51(EMS) screen shows up Otherwise the next screen is displayed (If a user doesnt want the connection of MDA-WinEMS51 to the PC

with RS-232C DEMO is to be executed)

3-1 Structure of WinIDE Studio-51(EMS) Program Screens

MDA-WinEMS51 MANUAL - 19 -

3 View WinIDE Studio-51(EMS)

A user has to fully know about the structure and operating instructions of the WinIDE Studio-51(EMS) program to correctly develop the desired system with MDA-WinEMS51 so that they need to be perfectly understood

3‐1 Structure of WinIDE Studio‐51(EMS) Program Screens

The above screen is the main screen of WinIDE Studio-51(EMS) (Windows Integrated Development Environment Studio-51(EMS)) that is the integrated development environment of MDA-WinEMS51 and here in each studio and menu are to be explained for the first-time user

3 View WinIDE Studio-51(EMS)

- 20 - MDA-WinEMS51 MANUAL

3‐2 Explanation of the WinIDE Studio‐51(EMS) Program Screens by Studio

Menu There are submenus for a main menu and shortcut buttons are made to execute the main menus and the submenus at a time If the cursor is placed on this shortcut button the balloon help shows up and lets the function of the shortcut button known

File Studio Functions such as edit file save file assemble amp link compile amp link download etc are available

SFR Studio The values of the SFR (Special Function Register) of MDA-WinEMS51 are displayed and the values of the SFRs can be modified with the mouse and the keyboard of a personal computer

Internal RAM Studio The contents of the internal data RAM (20H-7FH) of MDA-WinEMS51 are displayed and the contents of the internal data RAM can be modified with the mouse and the keyboard of a personal computer

Register Bank Studio The contents of the general purpose registers (R0 R7) of MDA-WinEMS51 are displayed and the contents of the registers can be modified with the mouse and the keyboard of a personal computer

3-3 Functions of Each Studio

MDA-WinEMS51 MANUAL - 21 -

3‐3 Functions of Each Studio

File Studio Functions such as make and save assemble link or download a source file are executed in this studio Making and assembling a source file and downloading it to MDA-WinEMS51 are to be explained in the different chapter And the source file in the present file studio is displayed in the file recently worked out so a user doesnt have to worry about this source file

(1) If a user makes and assembles the source file and downloads it to MDA-WinEMS51 the command pointer window pointing to

the location of instructions as in the figure below appears in the file studio

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 3: WinEMS51

PART MDA-WinEMS51 USERS MANUAL

TABLE OF CONTENTS 1 Introduction middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 7

1-1 Specifications of the MDA-WinEMS51 kit middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 81-2 MDA-WinEMS51 Kit Address map middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 11

2 Install WinIDE Studio-51(EMS) middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 12

3 View WinIDE Studio-51(EMS) middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 19

3-1 Structure of WinIDE Stuio-51(EMS) Program Screens middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 193-2 Explanation of the WinIDE Studio-51(EMS) Screens by Studio middotmiddotmiddotmiddotmiddotmiddot 203-3 Functions of Each Studio middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 213-4 The Main Menu of WinIDE Studio-51(EMS) middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 263-5 The Shortcut Button of WinIDE Studio-51(EMS) middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 303-6 Compiling the source middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 32

4 Keyboard Monitor middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 34

4-1 Introduction middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 344-2 Using the Keyboard monitor middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 344-3 Keyboard middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 354-4 LCD Display middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 374-5 Basic operation middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 37

5 Experiment middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 43

The Schematic of the MDA-WinEMS51 kit middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 69

MDA-WinEMS51 MANUAL - 7 -

1 Introduction The MDA-WinEMS51 kit is shown in Figure 1-1 contains all the

basic components necessary to understand 8051 microcomputer

Figure 1-1 MDA-WinEMS51 Kit(main)

1 Introduction

- 8 - MDA-WinEMS51 MANUAL

The MDA-WinEMS51 Kit has a CPU Memory (Monitor ROM and RAM) keyboard a LCD display RS- 232C Dot matrix LED ROM writer etc

A few major features of the MDA-WinEMS51 Kit include Run the assembler or compiler you have chosen Edit the source files Save the selected files Select a new file to edit assemble or compile Interfacing and board configuration information for connecting peripheral devices to the MDA-WinEMS51 Kit Writing the 89C51 Excising the 8051 microcomputer Excising the DOT matrix DC motor Stepping motor Excising the DA AD converter

1‐1 Specifications of the MDA‐WinEMS51 kitEach function of the MDA-WinEMS51 kit components is described below

CPU(Central processing unit) The CPU is located to the center of the MDA-WinEMS51 kit(marking the CPU amp MEMORY) The CPU use the 805180318751 with the clock 110592[ ]

ROM(Read Only Memory) The ROM is located to the center of the MDA-WinEMS51 kit(marking the CPU amp MEMORY) It contains the basic program to allow user to control the MDA-WinEMS51 kit with the keyboard LCD display data communication

SRAM(Static Random Access Memory) The RAM is located to the center of the MDA-WinEMS51 kit(marking the CPU amp MEMORY) Information (instructions and data) can be inserted (written) into RAM

1-1 Specifications of the MDA-WinEMS51

MDA-WinEMS51 MANUAL - 9 -

The information can be also be read from memory or altered by user

DISPLAY The display is comprised of LCD display providing visual display of the data or control information It has the 16(Character)times2(Line)

KEYBOARD It is a switch consisting of sixteen labeled hexadecimal eight function keys The keyboard is interfaced to system bus by the priority encoder

Control information and data is entered into system by the key

SPEAKER The SPEAKER is located to the right-center part of the MDA-WinEMS51 kit(marking the SPEAKER)

The speaker can test the sound and the synthesizer

RS-232C The RS-232C is located to the right-top part of the MDA-WinEMS51 kit(marking the RS-232C)

It use the IBM compatible PC to communicate the data

8751AT89C51 WRITER The WRITER is located to the center-bottom of the MDA-WinEMS51 kit (marking the 89C51 WRITER)

The writer can write the users program to the microcomputerAT89C51

DOT MATRIX LED The DOT MATRIX LED is located to the center-top part of the MDA-WinEMS51 kit(marking the DOT MATRIX 8 X 8) It use the dot matrix LED to understand the dot matrix structure and the principle of display it is interfaced to system bus by the 8255A(PPI)

AD CONVERTER The AD converter is located to the

1 Introduction

- 10 - MDA-WinEMS51 MANUAL

left-center part of the MDA-WinEMS51 kit(marking the AD CONVERTER)

The A(Analog)D(Digital) Convert used the ADC0804 to convert the analog singial to digital singial with the ADC0804

DA CONVERTER The DA converter is located to the left-center part of the MDA-WinEMS51 kit(marking the DA CONVERTER) It used the DAC0800(8 bit DA converter) to convert the digital signal to the analog signal and to control the DC motor

STEPPING MOTOR DRIVER The stepping motor driver is located to the left-upper part of the MDA-WinEMS51 kit(marking the STEPPING MOTOR) It use the stepping motor driver to control the stepping motor

DC MOTOR The DC motor is located to the left-bottom of the MDA-WinEMS51 kit(marking the DC MOTOR) It use the DA converter to control the speed of DC motor It use the photo interrupter to measure the speed of DC motor

CONNECTOR The connector is located to the left amp bottom of the MDA-WinEMS51 kit(marking the PORT-IO EXT-IO CON3)It use to interface the peripheral device

POWER The POWER is located to the right-top of the MDA-WinEMS51 kit(marking the AC POWER)

The power spec is the +5V(3A) +12V(1A) -12V(05A)

1-2 MDA-WinEMS51 Kit Address map

MDA-WinEMS51 MANUAL - 11 -

1‐2 MDA‐WinEMS51 Kit Address map The Table 1-1 show the address map of the MDA-WinEMS51 kit

Address MemoryIO Comment0000H 6FFFH RAM ProgramData memory

7000H 7FFFH ROM WRITER

8000H BFFFH ROM Monitor ROM

C000H C003H KEY_FLAG Keyboard buffer clear

C004H C007H KEY_PORT Keyboard buffer read

C008H C00BH 8255A(PPI)

C008H A PORT 89C51 WRITER DATA BUS

C009H B PORT LCD DATA BUSC00AH C PORT Control the

LCD and the 89C51 writerC00BH Control Register

C00CH C00FH 89C51 WRITER C00CH Control the 89C51 writer

C010H C013H SPEAKERC010H Control the speaker

C014H C017H8255A( Control the dot matrix)

C014H A PORTC015H B PORTC016H C PORTC017H Control Register

C018H C01BHADCONVERTER

C018H Control the AD converter

C01CH C01FH CON10 Control the peripheral device

C020H FFFFH USERS Region

Table 1-1

2 Install WinIDE Studio-51(EMS)

- 12 - MDA-WinEMS51 MANUAL

2 Install WinIDE Studio-51(EMS)

MDA-WinEMS51 has to be connected to the users PC after WinIDE Studio-51(EMS) the dedicated program for MDA-WinEMS51 provided by MIDAS ENGINEERING is installed in the users PC in advance

However If there is a WinIDE Studio-51(EMS) program in the users PC the following procedures may be omitted

What is WinIDE Studio-51(EMS)WinIDE Studio-51(EMS) can execute the assemblecompile in

one screen of Windows by making a source file (assembly language or C language) is further linked to the MDA-WinEMS51 kit to have all of the internal RAM register bank and SFR(Special Function Register) of the MDA-WinEMS51 kit displayed on one screen and can process the program execution and single steps of the downloaded file with the MDA-WinEMS51 kit

WinIDE Studio-51(EMS) is to simply process all the jobs by simply pressing the corresponding function keys in Windows 95982002XP

The WinIDE Studio-51(EMS) CD-ROM provided by MIDAS ENGINEERING is the CD-ROM only to use the MDA-WinEMS51 kit and the minimum conditions and installation procedures are as follows

MDA-WinEMS51 MANUAL - 13 -

User System Requirements

Processor PC based on the Pentium processor (166 or higher)

Operating Systems Microsoft Windows 95982000XP

RAM 16MB RAM (64MB recommended)

Hard Disk The 100 MB or higher blank space of a hard disk

2 Install WinIDE Studio-51(EMS)

- 14 - MDA-WinEMS51 MANUAL

Double-click My Computer after inserting the WinIDE Studio-51(EMS) CD into the users CD-ROM (AUTO RUN was not executed with the CD inserted into the CD-ROM)

Double-click Setupexe by reading the contents of the users CD-ROM drive

MDA-WinEMS51 MANUAL - 15 -

Read the license agreement and click Next if you agree with the agreement

Type in the name of the user (PC) and the company name if you are not a personal user and click Next

2 Install WinIDE Studio-51(EMS)

- 16 - MDA-WinEMS51 MANUAL

The path to the MIDAS ENG folder created is shown in the Windows program folder Confirm this and click ldquoNext

The installation path of WinIDE Studio-51(EMS) is shown Confirm this and click ldquoNext

MDA-WinEMS51 MANUAL - 17 -

The installation progress status of WinIDE Studio-51(EMS) is displayed

If the installation is successful the execution file of WinIDE Studio-51(EMS) is created in the MIDAS ENG folder and the installation has been successfully done

2 Install WinIDE Studio-51(EMS)

- 18 - MDA-WinEMS51 MANUAL

If WinIDE Studio-51(EMS) is executed the WinIDE Studio-51(EMS) logo appears

In case of the users PC connected correctly the WinIDE Studio-51(EMS) screen shows up Otherwise the next screen is displayed (If a user doesnt want the connection of MDA-WinEMS51 to the PC

with RS-232C DEMO is to be executed)

3-1 Structure of WinIDE Studio-51(EMS) Program Screens

MDA-WinEMS51 MANUAL - 19 -

3 View WinIDE Studio-51(EMS)

A user has to fully know about the structure and operating instructions of the WinIDE Studio-51(EMS) program to correctly develop the desired system with MDA-WinEMS51 so that they need to be perfectly understood

3‐1 Structure of WinIDE Studio‐51(EMS) Program Screens

The above screen is the main screen of WinIDE Studio-51(EMS) (Windows Integrated Development Environment Studio-51(EMS)) that is the integrated development environment of MDA-WinEMS51 and here in each studio and menu are to be explained for the first-time user

3 View WinIDE Studio-51(EMS)

- 20 - MDA-WinEMS51 MANUAL

3‐2 Explanation of the WinIDE Studio‐51(EMS) Program Screens by Studio

Menu There are submenus for a main menu and shortcut buttons are made to execute the main menus and the submenus at a time If the cursor is placed on this shortcut button the balloon help shows up and lets the function of the shortcut button known

File Studio Functions such as edit file save file assemble amp link compile amp link download etc are available

SFR Studio The values of the SFR (Special Function Register) of MDA-WinEMS51 are displayed and the values of the SFRs can be modified with the mouse and the keyboard of a personal computer

Internal RAM Studio The contents of the internal data RAM (20H-7FH) of MDA-WinEMS51 are displayed and the contents of the internal data RAM can be modified with the mouse and the keyboard of a personal computer

Register Bank Studio The contents of the general purpose registers (R0 R7) of MDA-WinEMS51 are displayed and the contents of the registers can be modified with the mouse and the keyboard of a personal computer

3-3 Functions of Each Studio

MDA-WinEMS51 MANUAL - 21 -

3‐3 Functions of Each Studio

File Studio Functions such as make and save assemble link or download a source file are executed in this studio Making and assembling a source file and downloading it to MDA-WinEMS51 are to be explained in the different chapter And the source file in the present file studio is displayed in the file recently worked out so a user doesnt have to worry about this source file

(1) If a user makes and assembles the source file and downloads it to MDA-WinEMS51 the command pointer window pointing to

the location of instructions as in the figure below appears in the file studio

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 4: WinEMS51

The Schematic of the MDA-WinEMS51 kit middotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddotmiddot 69

MDA-WinEMS51 MANUAL - 7 -

1 Introduction The MDA-WinEMS51 kit is shown in Figure 1-1 contains all the

basic components necessary to understand 8051 microcomputer

Figure 1-1 MDA-WinEMS51 Kit(main)

1 Introduction

- 8 - MDA-WinEMS51 MANUAL

The MDA-WinEMS51 Kit has a CPU Memory (Monitor ROM and RAM) keyboard a LCD display RS- 232C Dot matrix LED ROM writer etc

A few major features of the MDA-WinEMS51 Kit include Run the assembler or compiler you have chosen Edit the source files Save the selected files Select a new file to edit assemble or compile Interfacing and board configuration information for connecting peripheral devices to the MDA-WinEMS51 Kit Writing the 89C51 Excising the 8051 microcomputer Excising the DOT matrix DC motor Stepping motor Excising the DA AD converter

1‐1 Specifications of the MDA‐WinEMS51 kitEach function of the MDA-WinEMS51 kit components is described below

CPU(Central processing unit) The CPU is located to the center of the MDA-WinEMS51 kit(marking the CPU amp MEMORY) The CPU use the 805180318751 with the clock 110592[ ]

ROM(Read Only Memory) The ROM is located to the center of the MDA-WinEMS51 kit(marking the CPU amp MEMORY) It contains the basic program to allow user to control the MDA-WinEMS51 kit with the keyboard LCD display data communication

SRAM(Static Random Access Memory) The RAM is located to the center of the MDA-WinEMS51 kit(marking the CPU amp MEMORY) Information (instructions and data) can be inserted (written) into RAM

1-1 Specifications of the MDA-WinEMS51

MDA-WinEMS51 MANUAL - 9 -

The information can be also be read from memory or altered by user

DISPLAY The display is comprised of LCD display providing visual display of the data or control information It has the 16(Character)times2(Line)

KEYBOARD It is a switch consisting of sixteen labeled hexadecimal eight function keys The keyboard is interfaced to system bus by the priority encoder

Control information and data is entered into system by the key

SPEAKER The SPEAKER is located to the right-center part of the MDA-WinEMS51 kit(marking the SPEAKER)

The speaker can test the sound and the synthesizer

RS-232C The RS-232C is located to the right-top part of the MDA-WinEMS51 kit(marking the RS-232C)

It use the IBM compatible PC to communicate the data

8751AT89C51 WRITER The WRITER is located to the center-bottom of the MDA-WinEMS51 kit (marking the 89C51 WRITER)

The writer can write the users program to the microcomputerAT89C51

DOT MATRIX LED The DOT MATRIX LED is located to the center-top part of the MDA-WinEMS51 kit(marking the DOT MATRIX 8 X 8) It use the dot matrix LED to understand the dot matrix structure and the principle of display it is interfaced to system bus by the 8255A(PPI)

AD CONVERTER The AD converter is located to the

1 Introduction

- 10 - MDA-WinEMS51 MANUAL

left-center part of the MDA-WinEMS51 kit(marking the AD CONVERTER)

The A(Analog)D(Digital) Convert used the ADC0804 to convert the analog singial to digital singial with the ADC0804

DA CONVERTER The DA converter is located to the left-center part of the MDA-WinEMS51 kit(marking the DA CONVERTER) It used the DAC0800(8 bit DA converter) to convert the digital signal to the analog signal and to control the DC motor

STEPPING MOTOR DRIVER The stepping motor driver is located to the left-upper part of the MDA-WinEMS51 kit(marking the STEPPING MOTOR) It use the stepping motor driver to control the stepping motor

DC MOTOR The DC motor is located to the left-bottom of the MDA-WinEMS51 kit(marking the DC MOTOR) It use the DA converter to control the speed of DC motor It use the photo interrupter to measure the speed of DC motor

CONNECTOR The connector is located to the left amp bottom of the MDA-WinEMS51 kit(marking the PORT-IO EXT-IO CON3)It use to interface the peripheral device

POWER The POWER is located to the right-top of the MDA-WinEMS51 kit(marking the AC POWER)

The power spec is the +5V(3A) +12V(1A) -12V(05A)

1-2 MDA-WinEMS51 Kit Address map

MDA-WinEMS51 MANUAL - 11 -

1‐2 MDA‐WinEMS51 Kit Address map The Table 1-1 show the address map of the MDA-WinEMS51 kit

Address MemoryIO Comment0000H 6FFFH RAM ProgramData memory

7000H 7FFFH ROM WRITER

8000H BFFFH ROM Monitor ROM

C000H C003H KEY_FLAG Keyboard buffer clear

C004H C007H KEY_PORT Keyboard buffer read

C008H C00BH 8255A(PPI)

C008H A PORT 89C51 WRITER DATA BUS

C009H B PORT LCD DATA BUSC00AH C PORT Control the

LCD and the 89C51 writerC00BH Control Register

C00CH C00FH 89C51 WRITER C00CH Control the 89C51 writer

C010H C013H SPEAKERC010H Control the speaker

C014H C017H8255A( Control the dot matrix)

C014H A PORTC015H B PORTC016H C PORTC017H Control Register

C018H C01BHADCONVERTER

C018H Control the AD converter

C01CH C01FH CON10 Control the peripheral device

C020H FFFFH USERS Region

Table 1-1

2 Install WinIDE Studio-51(EMS)

- 12 - MDA-WinEMS51 MANUAL

2 Install WinIDE Studio-51(EMS)

MDA-WinEMS51 has to be connected to the users PC after WinIDE Studio-51(EMS) the dedicated program for MDA-WinEMS51 provided by MIDAS ENGINEERING is installed in the users PC in advance

However If there is a WinIDE Studio-51(EMS) program in the users PC the following procedures may be omitted

What is WinIDE Studio-51(EMS)WinIDE Studio-51(EMS) can execute the assemblecompile in

one screen of Windows by making a source file (assembly language or C language) is further linked to the MDA-WinEMS51 kit to have all of the internal RAM register bank and SFR(Special Function Register) of the MDA-WinEMS51 kit displayed on one screen and can process the program execution and single steps of the downloaded file with the MDA-WinEMS51 kit

WinIDE Studio-51(EMS) is to simply process all the jobs by simply pressing the corresponding function keys in Windows 95982002XP

The WinIDE Studio-51(EMS) CD-ROM provided by MIDAS ENGINEERING is the CD-ROM only to use the MDA-WinEMS51 kit and the minimum conditions and installation procedures are as follows

MDA-WinEMS51 MANUAL - 13 -

User System Requirements

Processor PC based on the Pentium processor (166 or higher)

Operating Systems Microsoft Windows 95982000XP

RAM 16MB RAM (64MB recommended)

Hard Disk The 100 MB or higher blank space of a hard disk

2 Install WinIDE Studio-51(EMS)

- 14 - MDA-WinEMS51 MANUAL

Double-click My Computer after inserting the WinIDE Studio-51(EMS) CD into the users CD-ROM (AUTO RUN was not executed with the CD inserted into the CD-ROM)

Double-click Setupexe by reading the contents of the users CD-ROM drive

MDA-WinEMS51 MANUAL - 15 -

Read the license agreement and click Next if you agree with the agreement

Type in the name of the user (PC) and the company name if you are not a personal user and click Next

2 Install WinIDE Studio-51(EMS)

- 16 - MDA-WinEMS51 MANUAL

The path to the MIDAS ENG folder created is shown in the Windows program folder Confirm this and click ldquoNext

The installation path of WinIDE Studio-51(EMS) is shown Confirm this and click ldquoNext

MDA-WinEMS51 MANUAL - 17 -

The installation progress status of WinIDE Studio-51(EMS) is displayed

If the installation is successful the execution file of WinIDE Studio-51(EMS) is created in the MIDAS ENG folder and the installation has been successfully done

2 Install WinIDE Studio-51(EMS)

- 18 - MDA-WinEMS51 MANUAL

If WinIDE Studio-51(EMS) is executed the WinIDE Studio-51(EMS) logo appears

In case of the users PC connected correctly the WinIDE Studio-51(EMS) screen shows up Otherwise the next screen is displayed (If a user doesnt want the connection of MDA-WinEMS51 to the PC

with RS-232C DEMO is to be executed)

3-1 Structure of WinIDE Studio-51(EMS) Program Screens

MDA-WinEMS51 MANUAL - 19 -

3 View WinIDE Studio-51(EMS)

A user has to fully know about the structure and operating instructions of the WinIDE Studio-51(EMS) program to correctly develop the desired system with MDA-WinEMS51 so that they need to be perfectly understood

3‐1 Structure of WinIDE Studio‐51(EMS) Program Screens

The above screen is the main screen of WinIDE Studio-51(EMS) (Windows Integrated Development Environment Studio-51(EMS)) that is the integrated development environment of MDA-WinEMS51 and here in each studio and menu are to be explained for the first-time user

3 View WinIDE Studio-51(EMS)

- 20 - MDA-WinEMS51 MANUAL

3‐2 Explanation of the WinIDE Studio‐51(EMS) Program Screens by Studio

Menu There are submenus for a main menu and shortcut buttons are made to execute the main menus and the submenus at a time If the cursor is placed on this shortcut button the balloon help shows up and lets the function of the shortcut button known

File Studio Functions such as edit file save file assemble amp link compile amp link download etc are available

SFR Studio The values of the SFR (Special Function Register) of MDA-WinEMS51 are displayed and the values of the SFRs can be modified with the mouse and the keyboard of a personal computer

Internal RAM Studio The contents of the internal data RAM (20H-7FH) of MDA-WinEMS51 are displayed and the contents of the internal data RAM can be modified with the mouse and the keyboard of a personal computer

Register Bank Studio The contents of the general purpose registers (R0 R7) of MDA-WinEMS51 are displayed and the contents of the registers can be modified with the mouse and the keyboard of a personal computer

3-3 Functions of Each Studio

MDA-WinEMS51 MANUAL - 21 -

3‐3 Functions of Each Studio

File Studio Functions such as make and save assemble link or download a source file are executed in this studio Making and assembling a source file and downloading it to MDA-WinEMS51 are to be explained in the different chapter And the source file in the present file studio is displayed in the file recently worked out so a user doesnt have to worry about this source file

(1) If a user makes and assembles the source file and downloads it to MDA-WinEMS51 the command pointer window pointing to

the location of instructions as in the figure below appears in the file studio

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 5: WinEMS51

MDA-WinEMS51 MANUAL - 7 -

1 Introduction The MDA-WinEMS51 kit is shown in Figure 1-1 contains all the

basic components necessary to understand 8051 microcomputer

Figure 1-1 MDA-WinEMS51 Kit(main)

1 Introduction

- 8 - MDA-WinEMS51 MANUAL

The MDA-WinEMS51 Kit has a CPU Memory (Monitor ROM and RAM) keyboard a LCD display RS- 232C Dot matrix LED ROM writer etc

A few major features of the MDA-WinEMS51 Kit include Run the assembler or compiler you have chosen Edit the source files Save the selected files Select a new file to edit assemble or compile Interfacing and board configuration information for connecting peripheral devices to the MDA-WinEMS51 Kit Writing the 89C51 Excising the 8051 microcomputer Excising the DOT matrix DC motor Stepping motor Excising the DA AD converter

1‐1 Specifications of the MDA‐WinEMS51 kitEach function of the MDA-WinEMS51 kit components is described below

CPU(Central processing unit) The CPU is located to the center of the MDA-WinEMS51 kit(marking the CPU amp MEMORY) The CPU use the 805180318751 with the clock 110592[ ]

ROM(Read Only Memory) The ROM is located to the center of the MDA-WinEMS51 kit(marking the CPU amp MEMORY) It contains the basic program to allow user to control the MDA-WinEMS51 kit with the keyboard LCD display data communication

SRAM(Static Random Access Memory) The RAM is located to the center of the MDA-WinEMS51 kit(marking the CPU amp MEMORY) Information (instructions and data) can be inserted (written) into RAM

1-1 Specifications of the MDA-WinEMS51

MDA-WinEMS51 MANUAL - 9 -

The information can be also be read from memory or altered by user

DISPLAY The display is comprised of LCD display providing visual display of the data or control information It has the 16(Character)times2(Line)

KEYBOARD It is a switch consisting of sixteen labeled hexadecimal eight function keys The keyboard is interfaced to system bus by the priority encoder

Control information and data is entered into system by the key

SPEAKER The SPEAKER is located to the right-center part of the MDA-WinEMS51 kit(marking the SPEAKER)

The speaker can test the sound and the synthesizer

RS-232C The RS-232C is located to the right-top part of the MDA-WinEMS51 kit(marking the RS-232C)

It use the IBM compatible PC to communicate the data

8751AT89C51 WRITER The WRITER is located to the center-bottom of the MDA-WinEMS51 kit (marking the 89C51 WRITER)

The writer can write the users program to the microcomputerAT89C51

DOT MATRIX LED The DOT MATRIX LED is located to the center-top part of the MDA-WinEMS51 kit(marking the DOT MATRIX 8 X 8) It use the dot matrix LED to understand the dot matrix structure and the principle of display it is interfaced to system bus by the 8255A(PPI)

AD CONVERTER The AD converter is located to the

1 Introduction

- 10 - MDA-WinEMS51 MANUAL

left-center part of the MDA-WinEMS51 kit(marking the AD CONVERTER)

The A(Analog)D(Digital) Convert used the ADC0804 to convert the analog singial to digital singial with the ADC0804

DA CONVERTER The DA converter is located to the left-center part of the MDA-WinEMS51 kit(marking the DA CONVERTER) It used the DAC0800(8 bit DA converter) to convert the digital signal to the analog signal and to control the DC motor

STEPPING MOTOR DRIVER The stepping motor driver is located to the left-upper part of the MDA-WinEMS51 kit(marking the STEPPING MOTOR) It use the stepping motor driver to control the stepping motor

DC MOTOR The DC motor is located to the left-bottom of the MDA-WinEMS51 kit(marking the DC MOTOR) It use the DA converter to control the speed of DC motor It use the photo interrupter to measure the speed of DC motor

CONNECTOR The connector is located to the left amp bottom of the MDA-WinEMS51 kit(marking the PORT-IO EXT-IO CON3)It use to interface the peripheral device

POWER The POWER is located to the right-top of the MDA-WinEMS51 kit(marking the AC POWER)

The power spec is the +5V(3A) +12V(1A) -12V(05A)

1-2 MDA-WinEMS51 Kit Address map

MDA-WinEMS51 MANUAL - 11 -

1‐2 MDA‐WinEMS51 Kit Address map The Table 1-1 show the address map of the MDA-WinEMS51 kit

Address MemoryIO Comment0000H 6FFFH RAM ProgramData memory

7000H 7FFFH ROM WRITER

8000H BFFFH ROM Monitor ROM

C000H C003H KEY_FLAG Keyboard buffer clear

C004H C007H KEY_PORT Keyboard buffer read

C008H C00BH 8255A(PPI)

C008H A PORT 89C51 WRITER DATA BUS

C009H B PORT LCD DATA BUSC00AH C PORT Control the

LCD and the 89C51 writerC00BH Control Register

C00CH C00FH 89C51 WRITER C00CH Control the 89C51 writer

C010H C013H SPEAKERC010H Control the speaker

C014H C017H8255A( Control the dot matrix)

C014H A PORTC015H B PORTC016H C PORTC017H Control Register

C018H C01BHADCONVERTER

C018H Control the AD converter

C01CH C01FH CON10 Control the peripheral device

C020H FFFFH USERS Region

Table 1-1

2 Install WinIDE Studio-51(EMS)

- 12 - MDA-WinEMS51 MANUAL

2 Install WinIDE Studio-51(EMS)

MDA-WinEMS51 has to be connected to the users PC after WinIDE Studio-51(EMS) the dedicated program for MDA-WinEMS51 provided by MIDAS ENGINEERING is installed in the users PC in advance

However If there is a WinIDE Studio-51(EMS) program in the users PC the following procedures may be omitted

What is WinIDE Studio-51(EMS)WinIDE Studio-51(EMS) can execute the assemblecompile in

one screen of Windows by making a source file (assembly language or C language) is further linked to the MDA-WinEMS51 kit to have all of the internal RAM register bank and SFR(Special Function Register) of the MDA-WinEMS51 kit displayed on one screen and can process the program execution and single steps of the downloaded file with the MDA-WinEMS51 kit

WinIDE Studio-51(EMS) is to simply process all the jobs by simply pressing the corresponding function keys in Windows 95982002XP

The WinIDE Studio-51(EMS) CD-ROM provided by MIDAS ENGINEERING is the CD-ROM only to use the MDA-WinEMS51 kit and the minimum conditions and installation procedures are as follows

MDA-WinEMS51 MANUAL - 13 -

User System Requirements

Processor PC based on the Pentium processor (166 or higher)

Operating Systems Microsoft Windows 95982000XP

RAM 16MB RAM (64MB recommended)

Hard Disk The 100 MB or higher blank space of a hard disk

2 Install WinIDE Studio-51(EMS)

- 14 - MDA-WinEMS51 MANUAL

Double-click My Computer after inserting the WinIDE Studio-51(EMS) CD into the users CD-ROM (AUTO RUN was not executed with the CD inserted into the CD-ROM)

Double-click Setupexe by reading the contents of the users CD-ROM drive

MDA-WinEMS51 MANUAL - 15 -

Read the license agreement and click Next if you agree with the agreement

Type in the name of the user (PC) and the company name if you are not a personal user and click Next

2 Install WinIDE Studio-51(EMS)

- 16 - MDA-WinEMS51 MANUAL

The path to the MIDAS ENG folder created is shown in the Windows program folder Confirm this and click ldquoNext

The installation path of WinIDE Studio-51(EMS) is shown Confirm this and click ldquoNext

MDA-WinEMS51 MANUAL - 17 -

The installation progress status of WinIDE Studio-51(EMS) is displayed

If the installation is successful the execution file of WinIDE Studio-51(EMS) is created in the MIDAS ENG folder and the installation has been successfully done

2 Install WinIDE Studio-51(EMS)

- 18 - MDA-WinEMS51 MANUAL

If WinIDE Studio-51(EMS) is executed the WinIDE Studio-51(EMS) logo appears

In case of the users PC connected correctly the WinIDE Studio-51(EMS) screen shows up Otherwise the next screen is displayed (If a user doesnt want the connection of MDA-WinEMS51 to the PC

with RS-232C DEMO is to be executed)

3-1 Structure of WinIDE Studio-51(EMS) Program Screens

MDA-WinEMS51 MANUAL - 19 -

3 View WinIDE Studio-51(EMS)

A user has to fully know about the structure and operating instructions of the WinIDE Studio-51(EMS) program to correctly develop the desired system with MDA-WinEMS51 so that they need to be perfectly understood

3‐1 Structure of WinIDE Studio‐51(EMS) Program Screens

The above screen is the main screen of WinIDE Studio-51(EMS) (Windows Integrated Development Environment Studio-51(EMS)) that is the integrated development environment of MDA-WinEMS51 and here in each studio and menu are to be explained for the first-time user

3 View WinIDE Studio-51(EMS)

- 20 - MDA-WinEMS51 MANUAL

3‐2 Explanation of the WinIDE Studio‐51(EMS) Program Screens by Studio

Menu There are submenus for a main menu and shortcut buttons are made to execute the main menus and the submenus at a time If the cursor is placed on this shortcut button the balloon help shows up and lets the function of the shortcut button known

File Studio Functions such as edit file save file assemble amp link compile amp link download etc are available

SFR Studio The values of the SFR (Special Function Register) of MDA-WinEMS51 are displayed and the values of the SFRs can be modified with the mouse and the keyboard of a personal computer

Internal RAM Studio The contents of the internal data RAM (20H-7FH) of MDA-WinEMS51 are displayed and the contents of the internal data RAM can be modified with the mouse and the keyboard of a personal computer

Register Bank Studio The contents of the general purpose registers (R0 R7) of MDA-WinEMS51 are displayed and the contents of the registers can be modified with the mouse and the keyboard of a personal computer

3-3 Functions of Each Studio

MDA-WinEMS51 MANUAL - 21 -

3‐3 Functions of Each Studio

File Studio Functions such as make and save assemble link or download a source file are executed in this studio Making and assembling a source file and downloading it to MDA-WinEMS51 are to be explained in the different chapter And the source file in the present file studio is displayed in the file recently worked out so a user doesnt have to worry about this source file

(1) If a user makes and assembles the source file and downloads it to MDA-WinEMS51 the command pointer window pointing to

the location of instructions as in the figure below appears in the file studio

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 6: WinEMS51

1 Introduction

- 8 - MDA-WinEMS51 MANUAL

The MDA-WinEMS51 Kit has a CPU Memory (Monitor ROM and RAM) keyboard a LCD display RS- 232C Dot matrix LED ROM writer etc

A few major features of the MDA-WinEMS51 Kit include Run the assembler or compiler you have chosen Edit the source files Save the selected files Select a new file to edit assemble or compile Interfacing and board configuration information for connecting peripheral devices to the MDA-WinEMS51 Kit Writing the 89C51 Excising the 8051 microcomputer Excising the DOT matrix DC motor Stepping motor Excising the DA AD converter

1‐1 Specifications of the MDA‐WinEMS51 kitEach function of the MDA-WinEMS51 kit components is described below

CPU(Central processing unit) The CPU is located to the center of the MDA-WinEMS51 kit(marking the CPU amp MEMORY) The CPU use the 805180318751 with the clock 110592[ ]

ROM(Read Only Memory) The ROM is located to the center of the MDA-WinEMS51 kit(marking the CPU amp MEMORY) It contains the basic program to allow user to control the MDA-WinEMS51 kit with the keyboard LCD display data communication

SRAM(Static Random Access Memory) The RAM is located to the center of the MDA-WinEMS51 kit(marking the CPU amp MEMORY) Information (instructions and data) can be inserted (written) into RAM

1-1 Specifications of the MDA-WinEMS51

MDA-WinEMS51 MANUAL - 9 -

The information can be also be read from memory or altered by user

DISPLAY The display is comprised of LCD display providing visual display of the data or control information It has the 16(Character)times2(Line)

KEYBOARD It is a switch consisting of sixteen labeled hexadecimal eight function keys The keyboard is interfaced to system bus by the priority encoder

Control information and data is entered into system by the key

SPEAKER The SPEAKER is located to the right-center part of the MDA-WinEMS51 kit(marking the SPEAKER)

The speaker can test the sound and the synthesizer

RS-232C The RS-232C is located to the right-top part of the MDA-WinEMS51 kit(marking the RS-232C)

It use the IBM compatible PC to communicate the data

8751AT89C51 WRITER The WRITER is located to the center-bottom of the MDA-WinEMS51 kit (marking the 89C51 WRITER)

The writer can write the users program to the microcomputerAT89C51

DOT MATRIX LED The DOT MATRIX LED is located to the center-top part of the MDA-WinEMS51 kit(marking the DOT MATRIX 8 X 8) It use the dot matrix LED to understand the dot matrix structure and the principle of display it is interfaced to system bus by the 8255A(PPI)

AD CONVERTER The AD converter is located to the

1 Introduction

- 10 - MDA-WinEMS51 MANUAL

left-center part of the MDA-WinEMS51 kit(marking the AD CONVERTER)

The A(Analog)D(Digital) Convert used the ADC0804 to convert the analog singial to digital singial with the ADC0804

DA CONVERTER The DA converter is located to the left-center part of the MDA-WinEMS51 kit(marking the DA CONVERTER) It used the DAC0800(8 bit DA converter) to convert the digital signal to the analog signal and to control the DC motor

STEPPING MOTOR DRIVER The stepping motor driver is located to the left-upper part of the MDA-WinEMS51 kit(marking the STEPPING MOTOR) It use the stepping motor driver to control the stepping motor

DC MOTOR The DC motor is located to the left-bottom of the MDA-WinEMS51 kit(marking the DC MOTOR) It use the DA converter to control the speed of DC motor It use the photo interrupter to measure the speed of DC motor

CONNECTOR The connector is located to the left amp bottom of the MDA-WinEMS51 kit(marking the PORT-IO EXT-IO CON3)It use to interface the peripheral device

POWER The POWER is located to the right-top of the MDA-WinEMS51 kit(marking the AC POWER)

The power spec is the +5V(3A) +12V(1A) -12V(05A)

1-2 MDA-WinEMS51 Kit Address map

MDA-WinEMS51 MANUAL - 11 -

1‐2 MDA‐WinEMS51 Kit Address map The Table 1-1 show the address map of the MDA-WinEMS51 kit

Address MemoryIO Comment0000H 6FFFH RAM ProgramData memory

7000H 7FFFH ROM WRITER

8000H BFFFH ROM Monitor ROM

C000H C003H KEY_FLAG Keyboard buffer clear

C004H C007H KEY_PORT Keyboard buffer read

C008H C00BH 8255A(PPI)

C008H A PORT 89C51 WRITER DATA BUS

C009H B PORT LCD DATA BUSC00AH C PORT Control the

LCD and the 89C51 writerC00BH Control Register

C00CH C00FH 89C51 WRITER C00CH Control the 89C51 writer

C010H C013H SPEAKERC010H Control the speaker

C014H C017H8255A( Control the dot matrix)

C014H A PORTC015H B PORTC016H C PORTC017H Control Register

C018H C01BHADCONVERTER

C018H Control the AD converter

C01CH C01FH CON10 Control the peripheral device

C020H FFFFH USERS Region

Table 1-1

2 Install WinIDE Studio-51(EMS)

- 12 - MDA-WinEMS51 MANUAL

2 Install WinIDE Studio-51(EMS)

MDA-WinEMS51 has to be connected to the users PC after WinIDE Studio-51(EMS) the dedicated program for MDA-WinEMS51 provided by MIDAS ENGINEERING is installed in the users PC in advance

However If there is a WinIDE Studio-51(EMS) program in the users PC the following procedures may be omitted

What is WinIDE Studio-51(EMS)WinIDE Studio-51(EMS) can execute the assemblecompile in

one screen of Windows by making a source file (assembly language or C language) is further linked to the MDA-WinEMS51 kit to have all of the internal RAM register bank and SFR(Special Function Register) of the MDA-WinEMS51 kit displayed on one screen and can process the program execution and single steps of the downloaded file with the MDA-WinEMS51 kit

WinIDE Studio-51(EMS) is to simply process all the jobs by simply pressing the corresponding function keys in Windows 95982002XP

The WinIDE Studio-51(EMS) CD-ROM provided by MIDAS ENGINEERING is the CD-ROM only to use the MDA-WinEMS51 kit and the minimum conditions and installation procedures are as follows

MDA-WinEMS51 MANUAL - 13 -

User System Requirements

Processor PC based on the Pentium processor (166 or higher)

Operating Systems Microsoft Windows 95982000XP

RAM 16MB RAM (64MB recommended)

Hard Disk The 100 MB or higher blank space of a hard disk

2 Install WinIDE Studio-51(EMS)

- 14 - MDA-WinEMS51 MANUAL

Double-click My Computer after inserting the WinIDE Studio-51(EMS) CD into the users CD-ROM (AUTO RUN was not executed with the CD inserted into the CD-ROM)

Double-click Setupexe by reading the contents of the users CD-ROM drive

MDA-WinEMS51 MANUAL - 15 -

Read the license agreement and click Next if you agree with the agreement

Type in the name of the user (PC) and the company name if you are not a personal user and click Next

2 Install WinIDE Studio-51(EMS)

- 16 - MDA-WinEMS51 MANUAL

The path to the MIDAS ENG folder created is shown in the Windows program folder Confirm this and click ldquoNext

The installation path of WinIDE Studio-51(EMS) is shown Confirm this and click ldquoNext

MDA-WinEMS51 MANUAL - 17 -

The installation progress status of WinIDE Studio-51(EMS) is displayed

If the installation is successful the execution file of WinIDE Studio-51(EMS) is created in the MIDAS ENG folder and the installation has been successfully done

2 Install WinIDE Studio-51(EMS)

- 18 - MDA-WinEMS51 MANUAL

If WinIDE Studio-51(EMS) is executed the WinIDE Studio-51(EMS) logo appears

In case of the users PC connected correctly the WinIDE Studio-51(EMS) screen shows up Otherwise the next screen is displayed (If a user doesnt want the connection of MDA-WinEMS51 to the PC

with RS-232C DEMO is to be executed)

3-1 Structure of WinIDE Studio-51(EMS) Program Screens

MDA-WinEMS51 MANUAL - 19 -

3 View WinIDE Studio-51(EMS)

A user has to fully know about the structure and operating instructions of the WinIDE Studio-51(EMS) program to correctly develop the desired system with MDA-WinEMS51 so that they need to be perfectly understood

3‐1 Structure of WinIDE Studio‐51(EMS) Program Screens

The above screen is the main screen of WinIDE Studio-51(EMS) (Windows Integrated Development Environment Studio-51(EMS)) that is the integrated development environment of MDA-WinEMS51 and here in each studio and menu are to be explained for the first-time user

3 View WinIDE Studio-51(EMS)

- 20 - MDA-WinEMS51 MANUAL

3‐2 Explanation of the WinIDE Studio‐51(EMS) Program Screens by Studio

Menu There are submenus for a main menu and shortcut buttons are made to execute the main menus and the submenus at a time If the cursor is placed on this shortcut button the balloon help shows up and lets the function of the shortcut button known

File Studio Functions such as edit file save file assemble amp link compile amp link download etc are available

SFR Studio The values of the SFR (Special Function Register) of MDA-WinEMS51 are displayed and the values of the SFRs can be modified with the mouse and the keyboard of a personal computer

Internal RAM Studio The contents of the internal data RAM (20H-7FH) of MDA-WinEMS51 are displayed and the contents of the internal data RAM can be modified with the mouse and the keyboard of a personal computer

Register Bank Studio The contents of the general purpose registers (R0 R7) of MDA-WinEMS51 are displayed and the contents of the registers can be modified with the mouse and the keyboard of a personal computer

3-3 Functions of Each Studio

MDA-WinEMS51 MANUAL - 21 -

3‐3 Functions of Each Studio

File Studio Functions such as make and save assemble link or download a source file are executed in this studio Making and assembling a source file and downloading it to MDA-WinEMS51 are to be explained in the different chapter And the source file in the present file studio is displayed in the file recently worked out so a user doesnt have to worry about this source file

(1) If a user makes and assembles the source file and downloads it to MDA-WinEMS51 the command pointer window pointing to

the location of instructions as in the figure below appears in the file studio

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 7: WinEMS51

1-1 Specifications of the MDA-WinEMS51

MDA-WinEMS51 MANUAL - 9 -

The information can be also be read from memory or altered by user

DISPLAY The display is comprised of LCD display providing visual display of the data or control information It has the 16(Character)times2(Line)

KEYBOARD It is a switch consisting of sixteen labeled hexadecimal eight function keys The keyboard is interfaced to system bus by the priority encoder

Control information and data is entered into system by the key

SPEAKER The SPEAKER is located to the right-center part of the MDA-WinEMS51 kit(marking the SPEAKER)

The speaker can test the sound and the synthesizer

RS-232C The RS-232C is located to the right-top part of the MDA-WinEMS51 kit(marking the RS-232C)

It use the IBM compatible PC to communicate the data

8751AT89C51 WRITER The WRITER is located to the center-bottom of the MDA-WinEMS51 kit (marking the 89C51 WRITER)

The writer can write the users program to the microcomputerAT89C51

DOT MATRIX LED The DOT MATRIX LED is located to the center-top part of the MDA-WinEMS51 kit(marking the DOT MATRIX 8 X 8) It use the dot matrix LED to understand the dot matrix structure and the principle of display it is interfaced to system bus by the 8255A(PPI)

AD CONVERTER The AD converter is located to the

1 Introduction

- 10 - MDA-WinEMS51 MANUAL

left-center part of the MDA-WinEMS51 kit(marking the AD CONVERTER)

The A(Analog)D(Digital) Convert used the ADC0804 to convert the analog singial to digital singial with the ADC0804

DA CONVERTER The DA converter is located to the left-center part of the MDA-WinEMS51 kit(marking the DA CONVERTER) It used the DAC0800(8 bit DA converter) to convert the digital signal to the analog signal and to control the DC motor

STEPPING MOTOR DRIVER The stepping motor driver is located to the left-upper part of the MDA-WinEMS51 kit(marking the STEPPING MOTOR) It use the stepping motor driver to control the stepping motor

DC MOTOR The DC motor is located to the left-bottom of the MDA-WinEMS51 kit(marking the DC MOTOR) It use the DA converter to control the speed of DC motor It use the photo interrupter to measure the speed of DC motor

CONNECTOR The connector is located to the left amp bottom of the MDA-WinEMS51 kit(marking the PORT-IO EXT-IO CON3)It use to interface the peripheral device

POWER The POWER is located to the right-top of the MDA-WinEMS51 kit(marking the AC POWER)

The power spec is the +5V(3A) +12V(1A) -12V(05A)

1-2 MDA-WinEMS51 Kit Address map

MDA-WinEMS51 MANUAL - 11 -

1‐2 MDA‐WinEMS51 Kit Address map The Table 1-1 show the address map of the MDA-WinEMS51 kit

Address MemoryIO Comment0000H 6FFFH RAM ProgramData memory

7000H 7FFFH ROM WRITER

8000H BFFFH ROM Monitor ROM

C000H C003H KEY_FLAG Keyboard buffer clear

C004H C007H KEY_PORT Keyboard buffer read

C008H C00BH 8255A(PPI)

C008H A PORT 89C51 WRITER DATA BUS

C009H B PORT LCD DATA BUSC00AH C PORT Control the

LCD and the 89C51 writerC00BH Control Register

C00CH C00FH 89C51 WRITER C00CH Control the 89C51 writer

C010H C013H SPEAKERC010H Control the speaker

C014H C017H8255A( Control the dot matrix)

C014H A PORTC015H B PORTC016H C PORTC017H Control Register

C018H C01BHADCONVERTER

C018H Control the AD converter

C01CH C01FH CON10 Control the peripheral device

C020H FFFFH USERS Region

Table 1-1

2 Install WinIDE Studio-51(EMS)

- 12 - MDA-WinEMS51 MANUAL

2 Install WinIDE Studio-51(EMS)

MDA-WinEMS51 has to be connected to the users PC after WinIDE Studio-51(EMS) the dedicated program for MDA-WinEMS51 provided by MIDAS ENGINEERING is installed in the users PC in advance

However If there is a WinIDE Studio-51(EMS) program in the users PC the following procedures may be omitted

What is WinIDE Studio-51(EMS)WinIDE Studio-51(EMS) can execute the assemblecompile in

one screen of Windows by making a source file (assembly language or C language) is further linked to the MDA-WinEMS51 kit to have all of the internal RAM register bank and SFR(Special Function Register) of the MDA-WinEMS51 kit displayed on one screen and can process the program execution and single steps of the downloaded file with the MDA-WinEMS51 kit

WinIDE Studio-51(EMS) is to simply process all the jobs by simply pressing the corresponding function keys in Windows 95982002XP

The WinIDE Studio-51(EMS) CD-ROM provided by MIDAS ENGINEERING is the CD-ROM only to use the MDA-WinEMS51 kit and the minimum conditions and installation procedures are as follows

MDA-WinEMS51 MANUAL - 13 -

User System Requirements

Processor PC based on the Pentium processor (166 or higher)

Operating Systems Microsoft Windows 95982000XP

RAM 16MB RAM (64MB recommended)

Hard Disk The 100 MB or higher blank space of a hard disk

2 Install WinIDE Studio-51(EMS)

- 14 - MDA-WinEMS51 MANUAL

Double-click My Computer after inserting the WinIDE Studio-51(EMS) CD into the users CD-ROM (AUTO RUN was not executed with the CD inserted into the CD-ROM)

Double-click Setupexe by reading the contents of the users CD-ROM drive

MDA-WinEMS51 MANUAL - 15 -

Read the license agreement and click Next if you agree with the agreement

Type in the name of the user (PC) and the company name if you are not a personal user and click Next

2 Install WinIDE Studio-51(EMS)

- 16 - MDA-WinEMS51 MANUAL

The path to the MIDAS ENG folder created is shown in the Windows program folder Confirm this and click ldquoNext

The installation path of WinIDE Studio-51(EMS) is shown Confirm this and click ldquoNext

MDA-WinEMS51 MANUAL - 17 -

The installation progress status of WinIDE Studio-51(EMS) is displayed

If the installation is successful the execution file of WinIDE Studio-51(EMS) is created in the MIDAS ENG folder and the installation has been successfully done

2 Install WinIDE Studio-51(EMS)

- 18 - MDA-WinEMS51 MANUAL

If WinIDE Studio-51(EMS) is executed the WinIDE Studio-51(EMS) logo appears

In case of the users PC connected correctly the WinIDE Studio-51(EMS) screen shows up Otherwise the next screen is displayed (If a user doesnt want the connection of MDA-WinEMS51 to the PC

with RS-232C DEMO is to be executed)

3-1 Structure of WinIDE Studio-51(EMS) Program Screens

MDA-WinEMS51 MANUAL - 19 -

3 View WinIDE Studio-51(EMS)

A user has to fully know about the structure and operating instructions of the WinIDE Studio-51(EMS) program to correctly develop the desired system with MDA-WinEMS51 so that they need to be perfectly understood

3‐1 Structure of WinIDE Studio‐51(EMS) Program Screens

The above screen is the main screen of WinIDE Studio-51(EMS) (Windows Integrated Development Environment Studio-51(EMS)) that is the integrated development environment of MDA-WinEMS51 and here in each studio and menu are to be explained for the first-time user

3 View WinIDE Studio-51(EMS)

- 20 - MDA-WinEMS51 MANUAL

3‐2 Explanation of the WinIDE Studio‐51(EMS) Program Screens by Studio

Menu There are submenus for a main menu and shortcut buttons are made to execute the main menus and the submenus at a time If the cursor is placed on this shortcut button the balloon help shows up and lets the function of the shortcut button known

File Studio Functions such as edit file save file assemble amp link compile amp link download etc are available

SFR Studio The values of the SFR (Special Function Register) of MDA-WinEMS51 are displayed and the values of the SFRs can be modified with the mouse and the keyboard of a personal computer

Internal RAM Studio The contents of the internal data RAM (20H-7FH) of MDA-WinEMS51 are displayed and the contents of the internal data RAM can be modified with the mouse and the keyboard of a personal computer

Register Bank Studio The contents of the general purpose registers (R0 R7) of MDA-WinEMS51 are displayed and the contents of the registers can be modified with the mouse and the keyboard of a personal computer

3-3 Functions of Each Studio

MDA-WinEMS51 MANUAL - 21 -

3‐3 Functions of Each Studio

File Studio Functions such as make and save assemble link or download a source file are executed in this studio Making and assembling a source file and downloading it to MDA-WinEMS51 are to be explained in the different chapter And the source file in the present file studio is displayed in the file recently worked out so a user doesnt have to worry about this source file

(1) If a user makes and assembles the source file and downloads it to MDA-WinEMS51 the command pointer window pointing to

the location of instructions as in the figure below appears in the file studio

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 8: WinEMS51

1 Introduction

- 10 - MDA-WinEMS51 MANUAL

left-center part of the MDA-WinEMS51 kit(marking the AD CONVERTER)

The A(Analog)D(Digital) Convert used the ADC0804 to convert the analog singial to digital singial with the ADC0804

DA CONVERTER The DA converter is located to the left-center part of the MDA-WinEMS51 kit(marking the DA CONVERTER) It used the DAC0800(8 bit DA converter) to convert the digital signal to the analog signal and to control the DC motor

STEPPING MOTOR DRIVER The stepping motor driver is located to the left-upper part of the MDA-WinEMS51 kit(marking the STEPPING MOTOR) It use the stepping motor driver to control the stepping motor

DC MOTOR The DC motor is located to the left-bottom of the MDA-WinEMS51 kit(marking the DC MOTOR) It use the DA converter to control the speed of DC motor It use the photo interrupter to measure the speed of DC motor

CONNECTOR The connector is located to the left amp bottom of the MDA-WinEMS51 kit(marking the PORT-IO EXT-IO CON3)It use to interface the peripheral device

POWER The POWER is located to the right-top of the MDA-WinEMS51 kit(marking the AC POWER)

The power spec is the +5V(3A) +12V(1A) -12V(05A)

1-2 MDA-WinEMS51 Kit Address map

MDA-WinEMS51 MANUAL - 11 -

1‐2 MDA‐WinEMS51 Kit Address map The Table 1-1 show the address map of the MDA-WinEMS51 kit

Address MemoryIO Comment0000H 6FFFH RAM ProgramData memory

7000H 7FFFH ROM WRITER

8000H BFFFH ROM Monitor ROM

C000H C003H KEY_FLAG Keyboard buffer clear

C004H C007H KEY_PORT Keyboard buffer read

C008H C00BH 8255A(PPI)

C008H A PORT 89C51 WRITER DATA BUS

C009H B PORT LCD DATA BUSC00AH C PORT Control the

LCD and the 89C51 writerC00BH Control Register

C00CH C00FH 89C51 WRITER C00CH Control the 89C51 writer

C010H C013H SPEAKERC010H Control the speaker

C014H C017H8255A( Control the dot matrix)

C014H A PORTC015H B PORTC016H C PORTC017H Control Register

C018H C01BHADCONVERTER

C018H Control the AD converter

C01CH C01FH CON10 Control the peripheral device

C020H FFFFH USERS Region

Table 1-1

2 Install WinIDE Studio-51(EMS)

- 12 - MDA-WinEMS51 MANUAL

2 Install WinIDE Studio-51(EMS)

MDA-WinEMS51 has to be connected to the users PC after WinIDE Studio-51(EMS) the dedicated program for MDA-WinEMS51 provided by MIDAS ENGINEERING is installed in the users PC in advance

However If there is a WinIDE Studio-51(EMS) program in the users PC the following procedures may be omitted

What is WinIDE Studio-51(EMS)WinIDE Studio-51(EMS) can execute the assemblecompile in

one screen of Windows by making a source file (assembly language or C language) is further linked to the MDA-WinEMS51 kit to have all of the internal RAM register bank and SFR(Special Function Register) of the MDA-WinEMS51 kit displayed on one screen and can process the program execution and single steps of the downloaded file with the MDA-WinEMS51 kit

WinIDE Studio-51(EMS) is to simply process all the jobs by simply pressing the corresponding function keys in Windows 95982002XP

The WinIDE Studio-51(EMS) CD-ROM provided by MIDAS ENGINEERING is the CD-ROM only to use the MDA-WinEMS51 kit and the minimum conditions and installation procedures are as follows

MDA-WinEMS51 MANUAL - 13 -

User System Requirements

Processor PC based on the Pentium processor (166 or higher)

Operating Systems Microsoft Windows 95982000XP

RAM 16MB RAM (64MB recommended)

Hard Disk The 100 MB or higher blank space of a hard disk

2 Install WinIDE Studio-51(EMS)

- 14 - MDA-WinEMS51 MANUAL

Double-click My Computer after inserting the WinIDE Studio-51(EMS) CD into the users CD-ROM (AUTO RUN was not executed with the CD inserted into the CD-ROM)

Double-click Setupexe by reading the contents of the users CD-ROM drive

MDA-WinEMS51 MANUAL - 15 -

Read the license agreement and click Next if you agree with the agreement

Type in the name of the user (PC) and the company name if you are not a personal user and click Next

2 Install WinIDE Studio-51(EMS)

- 16 - MDA-WinEMS51 MANUAL

The path to the MIDAS ENG folder created is shown in the Windows program folder Confirm this and click ldquoNext

The installation path of WinIDE Studio-51(EMS) is shown Confirm this and click ldquoNext

MDA-WinEMS51 MANUAL - 17 -

The installation progress status of WinIDE Studio-51(EMS) is displayed

If the installation is successful the execution file of WinIDE Studio-51(EMS) is created in the MIDAS ENG folder and the installation has been successfully done

2 Install WinIDE Studio-51(EMS)

- 18 - MDA-WinEMS51 MANUAL

If WinIDE Studio-51(EMS) is executed the WinIDE Studio-51(EMS) logo appears

In case of the users PC connected correctly the WinIDE Studio-51(EMS) screen shows up Otherwise the next screen is displayed (If a user doesnt want the connection of MDA-WinEMS51 to the PC

with RS-232C DEMO is to be executed)

3-1 Structure of WinIDE Studio-51(EMS) Program Screens

MDA-WinEMS51 MANUAL - 19 -

3 View WinIDE Studio-51(EMS)

A user has to fully know about the structure and operating instructions of the WinIDE Studio-51(EMS) program to correctly develop the desired system with MDA-WinEMS51 so that they need to be perfectly understood

3‐1 Structure of WinIDE Studio‐51(EMS) Program Screens

The above screen is the main screen of WinIDE Studio-51(EMS) (Windows Integrated Development Environment Studio-51(EMS)) that is the integrated development environment of MDA-WinEMS51 and here in each studio and menu are to be explained for the first-time user

3 View WinIDE Studio-51(EMS)

- 20 - MDA-WinEMS51 MANUAL

3‐2 Explanation of the WinIDE Studio‐51(EMS) Program Screens by Studio

Menu There are submenus for a main menu and shortcut buttons are made to execute the main menus and the submenus at a time If the cursor is placed on this shortcut button the balloon help shows up and lets the function of the shortcut button known

File Studio Functions such as edit file save file assemble amp link compile amp link download etc are available

SFR Studio The values of the SFR (Special Function Register) of MDA-WinEMS51 are displayed and the values of the SFRs can be modified with the mouse and the keyboard of a personal computer

Internal RAM Studio The contents of the internal data RAM (20H-7FH) of MDA-WinEMS51 are displayed and the contents of the internal data RAM can be modified with the mouse and the keyboard of a personal computer

Register Bank Studio The contents of the general purpose registers (R0 R7) of MDA-WinEMS51 are displayed and the contents of the registers can be modified with the mouse and the keyboard of a personal computer

3-3 Functions of Each Studio

MDA-WinEMS51 MANUAL - 21 -

3‐3 Functions of Each Studio

File Studio Functions such as make and save assemble link or download a source file are executed in this studio Making and assembling a source file and downloading it to MDA-WinEMS51 are to be explained in the different chapter And the source file in the present file studio is displayed in the file recently worked out so a user doesnt have to worry about this source file

(1) If a user makes and assembles the source file and downloads it to MDA-WinEMS51 the command pointer window pointing to

the location of instructions as in the figure below appears in the file studio

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 9: WinEMS51

1-2 MDA-WinEMS51 Kit Address map

MDA-WinEMS51 MANUAL - 11 -

1‐2 MDA‐WinEMS51 Kit Address map The Table 1-1 show the address map of the MDA-WinEMS51 kit

Address MemoryIO Comment0000H 6FFFH RAM ProgramData memory

7000H 7FFFH ROM WRITER

8000H BFFFH ROM Monitor ROM

C000H C003H KEY_FLAG Keyboard buffer clear

C004H C007H KEY_PORT Keyboard buffer read

C008H C00BH 8255A(PPI)

C008H A PORT 89C51 WRITER DATA BUS

C009H B PORT LCD DATA BUSC00AH C PORT Control the

LCD and the 89C51 writerC00BH Control Register

C00CH C00FH 89C51 WRITER C00CH Control the 89C51 writer

C010H C013H SPEAKERC010H Control the speaker

C014H C017H8255A( Control the dot matrix)

C014H A PORTC015H B PORTC016H C PORTC017H Control Register

C018H C01BHADCONVERTER

C018H Control the AD converter

C01CH C01FH CON10 Control the peripheral device

C020H FFFFH USERS Region

Table 1-1

2 Install WinIDE Studio-51(EMS)

- 12 - MDA-WinEMS51 MANUAL

2 Install WinIDE Studio-51(EMS)

MDA-WinEMS51 has to be connected to the users PC after WinIDE Studio-51(EMS) the dedicated program for MDA-WinEMS51 provided by MIDAS ENGINEERING is installed in the users PC in advance

However If there is a WinIDE Studio-51(EMS) program in the users PC the following procedures may be omitted

What is WinIDE Studio-51(EMS)WinIDE Studio-51(EMS) can execute the assemblecompile in

one screen of Windows by making a source file (assembly language or C language) is further linked to the MDA-WinEMS51 kit to have all of the internal RAM register bank and SFR(Special Function Register) of the MDA-WinEMS51 kit displayed on one screen and can process the program execution and single steps of the downloaded file with the MDA-WinEMS51 kit

WinIDE Studio-51(EMS) is to simply process all the jobs by simply pressing the corresponding function keys in Windows 95982002XP

The WinIDE Studio-51(EMS) CD-ROM provided by MIDAS ENGINEERING is the CD-ROM only to use the MDA-WinEMS51 kit and the minimum conditions and installation procedures are as follows

MDA-WinEMS51 MANUAL - 13 -

User System Requirements

Processor PC based on the Pentium processor (166 or higher)

Operating Systems Microsoft Windows 95982000XP

RAM 16MB RAM (64MB recommended)

Hard Disk The 100 MB or higher blank space of a hard disk

2 Install WinIDE Studio-51(EMS)

- 14 - MDA-WinEMS51 MANUAL

Double-click My Computer after inserting the WinIDE Studio-51(EMS) CD into the users CD-ROM (AUTO RUN was not executed with the CD inserted into the CD-ROM)

Double-click Setupexe by reading the contents of the users CD-ROM drive

MDA-WinEMS51 MANUAL - 15 -

Read the license agreement and click Next if you agree with the agreement

Type in the name of the user (PC) and the company name if you are not a personal user and click Next

2 Install WinIDE Studio-51(EMS)

- 16 - MDA-WinEMS51 MANUAL

The path to the MIDAS ENG folder created is shown in the Windows program folder Confirm this and click ldquoNext

The installation path of WinIDE Studio-51(EMS) is shown Confirm this and click ldquoNext

MDA-WinEMS51 MANUAL - 17 -

The installation progress status of WinIDE Studio-51(EMS) is displayed

If the installation is successful the execution file of WinIDE Studio-51(EMS) is created in the MIDAS ENG folder and the installation has been successfully done

2 Install WinIDE Studio-51(EMS)

- 18 - MDA-WinEMS51 MANUAL

If WinIDE Studio-51(EMS) is executed the WinIDE Studio-51(EMS) logo appears

In case of the users PC connected correctly the WinIDE Studio-51(EMS) screen shows up Otherwise the next screen is displayed (If a user doesnt want the connection of MDA-WinEMS51 to the PC

with RS-232C DEMO is to be executed)

3-1 Structure of WinIDE Studio-51(EMS) Program Screens

MDA-WinEMS51 MANUAL - 19 -

3 View WinIDE Studio-51(EMS)

A user has to fully know about the structure and operating instructions of the WinIDE Studio-51(EMS) program to correctly develop the desired system with MDA-WinEMS51 so that they need to be perfectly understood

3‐1 Structure of WinIDE Studio‐51(EMS) Program Screens

The above screen is the main screen of WinIDE Studio-51(EMS) (Windows Integrated Development Environment Studio-51(EMS)) that is the integrated development environment of MDA-WinEMS51 and here in each studio and menu are to be explained for the first-time user

3 View WinIDE Studio-51(EMS)

- 20 - MDA-WinEMS51 MANUAL

3‐2 Explanation of the WinIDE Studio‐51(EMS) Program Screens by Studio

Menu There are submenus for a main menu and shortcut buttons are made to execute the main menus and the submenus at a time If the cursor is placed on this shortcut button the balloon help shows up and lets the function of the shortcut button known

File Studio Functions such as edit file save file assemble amp link compile amp link download etc are available

SFR Studio The values of the SFR (Special Function Register) of MDA-WinEMS51 are displayed and the values of the SFRs can be modified with the mouse and the keyboard of a personal computer

Internal RAM Studio The contents of the internal data RAM (20H-7FH) of MDA-WinEMS51 are displayed and the contents of the internal data RAM can be modified with the mouse and the keyboard of a personal computer

Register Bank Studio The contents of the general purpose registers (R0 R7) of MDA-WinEMS51 are displayed and the contents of the registers can be modified with the mouse and the keyboard of a personal computer

3-3 Functions of Each Studio

MDA-WinEMS51 MANUAL - 21 -

3‐3 Functions of Each Studio

File Studio Functions such as make and save assemble link or download a source file are executed in this studio Making and assembling a source file and downloading it to MDA-WinEMS51 are to be explained in the different chapter And the source file in the present file studio is displayed in the file recently worked out so a user doesnt have to worry about this source file

(1) If a user makes and assembles the source file and downloads it to MDA-WinEMS51 the command pointer window pointing to

the location of instructions as in the figure below appears in the file studio

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 10: WinEMS51

2 Install WinIDE Studio-51(EMS)

- 12 - MDA-WinEMS51 MANUAL

2 Install WinIDE Studio-51(EMS)

MDA-WinEMS51 has to be connected to the users PC after WinIDE Studio-51(EMS) the dedicated program for MDA-WinEMS51 provided by MIDAS ENGINEERING is installed in the users PC in advance

However If there is a WinIDE Studio-51(EMS) program in the users PC the following procedures may be omitted

What is WinIDE Studio-51(EMS)WinIDE Studio-51(EMS) can execute the assemblecompile in

one screen of Windows by making a source file (assembly language or C language) is further linked to the MDA-WinEMS51 kit to have all of the internal RAM register bank and SFR(Special Function Register) of the MDA-WinEMS51 kit displayed on one screen and can process the program execution and single steps of the downloaded file with the MDA-WinEMS51 kit

WinIDE Studio-51(EMS) is to simply process all the jobs by simply pressing the corresponding function keys in Windows 95982002XP

The WinIDE Studio-51(EMS) CD-ROM provided by MIDAS ENGINEERING is the CD-ROM only to use the MDA-WinEMS51 kit and the minimum conditions and installation procedures are as follows

MDA-WinEMS51 MANUAL - 13 -

User System Requirements

Processor PC based on the Pentium processor (166 or higher)

Operating Systems Microsoft Windows 95982000XP

RAM 16MB RAM (64MB recommended)

Hard Disk The 100 MB or higher blank space of a hard disk

2 Install WinIDE Studio-51(EMS)

- 14 - MDA-WinEMS51 MANUAL

Double-click My Computer after inserting the WinIDE Studio-51(EMS) CD into the users CD-ROM (AUTO RUN was not executed with the CD inserted into the CD-ROM)

Double-click Setupexe by reading the contents of the users CD-ROM drive

MDA-WinEMS51 MANUAL - 15 -

Read the license agreement and click Next if you agree with the agreement

Type in the name of the user (PC) and the company name if you are not a personal user and click Next

2 Install WinIDE Studio-51(EMS)

- 16 - MDA-WinEMS51 MANUAL

The path to the MIDAS ENG folder created is shown in the Windows program folder Confirm this and click ldquoNext

The installation path of WinIDE Studio-51(EMS) is shown Confirm this and click ldquoNext

MDA-WinEMS51 MANUAL - 17 -

The installation progress status of WinIDE Studio-51(EMS) is displayed

If the installation is successful the execution file of WinIDE Studio-51(EMS) is created in the MIDAS ENG folder and the installation has been successfully done

2 Install WinIDE Studio-51(EMS)

- 18 - MDA-WinEMS51 MANUAL

If WinIDE Studio-51(EMS) is executed the WinIDE Studio-51(EMS) logo appears

In case of the users PC connected correctly the WinIDE Studio-51(EMS) screen shows up Otherwise the next screen is displayed (If a user doesnt want the connection of MDA-WinEMS51 to the PC

with RS-232C DEMO is to be executed)

3-1 Structure of WinIDE Studio-51(EMS) Program Screens

MDA-WinEMS51 MANUAL - 19 -

3 View WinIDE Studio-51(EMS)

A user has to fully know about the structure and operating instructions of the WinIDE Studio-51(EMS) program to correctly develop the desired system with MDA-WinEMS51 so that they need to be perfectly understood

3‐1 Structure of WinIDE Studio‐51(EMS) Program Screens

The above screen is the main screen of WinIDE Studio-51(EMS) (Windows Integrated Development Environment Studio-51(EMS)) that is the integrated development environment of MDA-WinEMS51 and here in each studio and menu are to be explained for the first-time user

3 View WinIDE Studio-51(EMS)

- 20 - MDA-WinEMS51 MANUAL

3‐2 Explanation of the WinIDE Studio‐51(EMS) Program Screens by Studio

Menu There are submenus for a main menu and shortcut buttons are made to execute the main menus and the submenus at a time If the cursor is placed on this shortcut button the balloon help shows up and lets the function of the shortcut button known

File Studio Functions such as edit file save file assemble amp link compile amp link download etc are available

SFR Studio The values of the SFR (Special Function Register) of MDA-WinEMS51 are displayed and the values of the SFRs can be modified with the mouse and the keyboard of a personal computer

Internal RAM Studio The contents of the internal data RAM (20H-7FH) of MDA-WinEMS51 are displayed and the contents of the internal data RAM can be modified with the mouse and the keyboard of a personal computer

Register Bank Studio The contents of the general purpose registers (R0 R7) of MDA-WinEMS51 are displayed and the contents of the registers can be modified with the mouse and the keyboard of a personal computer

3-3 Functions of Each Studio

MDA-WinEMS51 MANUAL - 21 -

3‐3 Functions of Each Studio

File Studio Functions such as make and save assemble link or download a source file are executed in this studio Making and assembling a source file and downloading it to MDA-WinEMS51 are to be explained in the different chapter And the source file in the present file studio is displayed in the file recently worked out so a user doesnt have to worry about this source file

(1) If a user makes and assembles the source file and downloads it to MDA-WinEMS51 the command pointer window pointing to

the location of instructions as in the figure below appears in the file studio

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 11: WinEMS51

MDA-WinEMS51 MANUAL - 13 -

User System Requirements

Processor PC based on the Pentium processor (166 or higher)

Operating Systems Microsoft Windows 95982000XP

RAM 16MB RAM (64MB recommended)

Hard Disk The 100 MB or higher blank space of a hard disk

2 Install WinIDE Studio-51(EMS)

- 14 - MDA-WinEMS51 MANUAL

Double-click My Computer after inserting the WinIDE Studio-51(EMS) CD into the users CD-ROM (AUTO RUN was not executed with the CD inserted into the CD-ROM)

Double-click Setupexe by reading the contents of the users CD-ROM drive

MDA-WinEMS51 MANUAL - 15 -

Read the license agreement and click Next if you agree with the agreement

Type in the name of the user (PC) and the company name if you are not a personal user and click Next

2 Install WinIDE Studio-51(EMS)

- 16 - MDA-WinEMS51 MANUAL

The path to the MIDAS ENG folder created is shown in the Windows program folder Confirm this and click ldquoNext

The installation path of WinIDE Studio-51(EMS) is shown Confirm this and click ldquoNext

MDA-WinEMS51 MANUAL - 17 -

The installation progress status of WinIDE Studio-51(EMS) is displayed

If the installation is successful the execution file of WinIDE Studio-51(EMS) is created in the MIDAS ENG folder and the installation has been successfully done

2 Install WinIDE Studio-51(EMS)

- 18 - MDA-WinEMS51 MANUAL

If WinIDE Studio-51(EMS) is executed the WinIDE Studio-51(EMS) logo appears

In case of the users PC connected correctly the WinIDE Studio-51(EMS) screen shows up Otherwise the next screen is displayed (If a user doesnt want the connection of MDA-WinEMS51 to the PC

with RS-232C DEMO is to be executed)

3-1 Structure of WinIDE Studio-51(EMS) Program Screens

MDA-WinEMS51 MANUAL - 19 -

3 View WinIDE Studio-51(EMS)

A user has to fully know about the structure and operating instructions of the WinIDE Studio-51(EMS) program to correctly develop the desired system with MDA-WinEMS51 so that they need to be perfectly understood

3‐1 Structure of WinIDE Studio‐51(EMS) Program Screens

The above screen is the main screen of WinIDE Studio-51(EMS) (Windows Integrated Development Environment Studio-51(EMS)) that is the integrated development environment of MDA-WinEMS51 and here in each studio and menu are to be explained for the first-time user

3 View WinIDE Studio-51(EMS)

- 20 - MDA-WinEMS51 MANUAL

3‐2 Explanation of the WinIDE Studio‐51(EMS) Program Screens by Studio

Menu There are submenus for a main menu and shortcut buttons are made to execute the main menus and the submenus at a time If the cursor is placed on this shortcut button the balloon help shows up and lets the function of the shortcut button known

File Studio Functions such as edit file save file assemble amp link compile amp link download etc are available

SFR Studio The values of the SFR (Special Function Register) of MDA-WinEMS51 are displayed and the values of the SFRs can be modified with the mouse and the keyboard of a personal computer

Internal RAM Studio The contents of the internal data RAM (20H-7FH) of MDA-WinEMS51 are displayed and the contents of the internal data RAM can be modified with the mouse and the keyboard of a personal computer

Register Bank Studio The contents of the general purpose registers (R0 R7) of MDA-WinEMS51 are displayed and the contents of the registers can be modified with the mouse and the keyboard of a personal computer

3-3 Functions of Each Studio

MDA-WinEMS51 MANUAL - 21 -

3‐3 Functions of Each Studio

File Studio Functions such as make and save assemble link or download a source file are executed in this studio Making and assembling a source file and downloading it to MDA-WinEMS51 are to be explained in the different chapter And the source file in the present file studio is displayed in the file recently worked out so a user doesnt have to worry about this source file

(1) If a user makes and assembles the source file and downloads it to MDA-WinEMS51 the command pointer window pointing to

the location of instructions as in the figure below appears in the file studio

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 12: WinEMS51

2 Install WinIDE Studio-51(EMS)

- 14 - MDA-WinEMS51 MANUAL

Double-click My Computer after inserting the WinIDE Studio-51(EMS) CD into the users CD-ROM (AUTO RUN was not executed with the CD inserted into the CD-ROM)

Double-click Setupexe by reading the contents of the users CD-ROM drive

MDA-WinEMS51 MANUAL - 15 -

Read the license agreement and click Next if you agree with the agreement

Type in the name of the user (PC) and the company name if you are not a personal user and click Next

2 Install WinIDE Studio-51(EMS)

- 16 - MDA-WinEMS51 MANUAL

The path to the MIDAS ENG folder created is shown in the Windows program folder Confirm this and click ldquoNext

The installation path of WinIDE Studio-51(EMS) is shown Confirm this and click ldquoNext

MDA-WinEMS51 MANUAL - 17 -

The installation progress status of WinIDE Studio-51(EMS) is displayed

If the installation is successful the execution file of WinIDE Studio-51(EMS) is created in the MIDAS ENG folder and the installation has been successfully done

2 Install WinIDE Studio-51(EMS)

- 18 - MDA-WinEMS51 MANUAL

If WinIDE Studio-51(EMS) is executed the WinIDE Studio-51(EMS) logo appears

In case of the users PC connected correctly the WinIDE Studio-51(EMS) screen shows up Otherwise the next screen is displayed (If a user doesnt want the connection of MDA-WinEMS51 to the PC

with RS-232C DEMO is to be executed)

3-1 Structure of WinIDE Studio-51(EMS) Program Screens

MDA-WinEMS51 MANUAL - 19 -

3 View WinIDE Studio-51(EMS)

A user has to fully know about the structure and operating instructions of the WinIDE Studio-51(EMS) program to correctly develop the desired system with MDA-WinEMS51 so that they need to be perfectly understood

3‐1 Structure of WinIDE Studio‐51(EMS) Program Screens

The above screen is the main screen of WinIDE Studio-51(EMS) (Windows Integrated Development Environment Studio-51(EMS)) that is the integrated development environment of MDA-WinEMS51 and here in each studio and menu are to be explained for the first-time user

3 View WinIDE Studio-51(EMS)

- 20 - MDA-WinEMS51 MANUAL

3‐2 Explanation of the WinIDE Studio‐51(EMS) Program Screens by Studio

Menu There are submenus for a main menu and shortcut buttons are made to execute the main menus and the submenus at a time If the cursor is placed on this shortcut button the balloon help shows up and lets the function of the shortcut button known

File Studio Functions such as edit file save file assemble amp link compile amp link download etc are available

SFR Studio The values of the SFR (Special Function Register) of MDA-WinEMS51 are displayed and the values of the SFRs can be modified with the mouse and the keyboard of a personal computer

Internal RAM Studio The contents of the internal data RAM (20H-7FH) of MDA-WinEMS51 are displayed and the contents of the internal data RAM can be modified with the mouse and the keyboard of a personal computer

Register Bank Studio The contents of the general purpose registers (R0 R7) of MDA-WinEMS51 are displayed and the contents of the registers can be modified with the mouse and the keyboard of a personal computer

3-3 Functions of Each Studio

MDA-WinEMS51 MANUAL - 21 -

3‐3 Functions of Each Studio

File Studio Functions such as make and save assemble link or download a source file are executed in this studio Making and assembling a source file and downloading it to MDA-WinEMS51 are to be explained in the different chapter And the source file in the present file studio is displayed in the file recently worked out so a user doesnt have to worry about this source file

(1) If a user makes and assembles the source file and downloads it to MDA-WinEMS51 the command pointer window pointing to

the location of instructions as in the figure below appears in the file studio

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 13: WinEMS51

MDA-WinEMS51 MANUAL - 15 -

Read the license agreement and click Next if you agree with the agreement

Type in the name of the user (PC) and the company name if you are not a personal user and click Next

2 Install WinIDE Studio-51(EMS)

- 16 - MDA-WinEMS51 MANUAL

The path to the MIDAS ENG folder created is shown in the Windows program folder Confirm this and click ldquoNext

The installation path of WinIDE Studio-51(EMS) is shown Confirm this and click ldquoNext

MDA-WinEMS51 MANUAL - 17 -

The installation progress status of WinIDE Studio-51(EMS) is displayed

If the installation is successful the execution file of WinIDE Studio-51(EMS) is created in the MIDAS ENG folder and the installation has been successfully done

2 Install WinIDE Studio-51(EMS)

- 18 - MDA-WinEMS51 MANUAL

If WinIDE Studio-51(EMS) is executed the WinIDE Studio-51(EMS) logo appears

In case of the users PC connected correctly the WinIDE Studio-51(EMS) screen shows up Otherwise the next screen is displayed (If a user doesnt want the connection of MDA-WinEMS51 to the PC

with RS-232C DEMO is to be executed)

3-1 Structure of WinIDE Studio-51(EMS) Program Screens

MDA-WinEMS51 MANUAL - 19 -

3 View WinIDE Studio-51(EMS)

A user has to fully know about the structure and operating instructions of the WinIDE Studio-51(EMS) program to correctly develop the desired system with MDA-WinEMS51 so that they need to be perfectly understood

3‐1 Structure of WinIDE Studio‐51(EMS) Program Screens

The above screen is the main screen of WinIDE Studio-51(EMS) (Windows Integrated Development Environment Studio-51(EMS)) that is the integrated development environment of MDA-WinEMS51 and here in each studio and menu are to be explained for the first-time user

3 View WinIDE Studio-51(EMS)

- 20 - MDA-WinEMS51 MANUAL

3‐2 Explanation of the WinIDE Studio‐51(EMS) Program Screens by Studio

Menu There are submenus for a main menu and shortcut buttons are made to execute the main menus and the submenus at a time If the cursor is placed on this shortcut button the balloon help shows up and lets the function of the shortcut button known

File Studio Functions such as edit file save file assemble amp link compile amp link download etc are available

SFR Studio The values of the SFR (Special Function Register) of MDA-WinEMS51 are displayed and the values of the SFRs can be modified with the mouse and the keyboard of a personal computer

Internal RAM Studio The contents of the internal data RAM (20H-7FH) of MDA-WinEMS51 are displayed and the contents of the internal data RAM can be modified with the mouse and the keyboard of a personal computer

Register Bank Studio The contents of the general purpose registers (R0 R7) of MDA-WinEMS51 are displayed and the contents of the registers can be modified with the mouse and the keyboard of a personal computer

3-3 Functions of Each Studio

MDA-WinEMS51 MANUAL - 21 -

3‐3 Functions of Each Studio

File Studio Functions such as make and save assemble link or download a source file are executed in this studio Making and assembling a source file and downloading it to MDA-WinEMS51 are to be explained in the different chapter And the source file in the present file studio is displayed in the file recently worked out so a user doesnt have to worry about this source file

(1) If a user makes and assembles the source file and downloads it to MDA-WinEMS51 the command pointer window pointing to

the location of instructions as in the figure below appears in the file studio

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 14: WinEMS51

2 Install WinIDE Studio-51(EMS)

- 16 - MDA-WinEMS51 MANUAL

The path to the MIDAS ENG folder created is shown in the Windows program folder Confirm this and click ldquoNext

The installation path of WinIDE Studio-51(EMS) is shown Confirm this and click ldquoNext

MDA-WinEMS51 MANUAL - 17 -

The installation progress status of WinIDE Studio-51(EMS) is displayed

If the installation is successful the execution file of WinIDE Studio-51(EMS) is created in the MIDAS ENG folder and the installation has been successfully done

2 Install WinIDE Studio-51(EMS)

- 18 - MDA-WinEMS51 MANUAL

If WinIDE Studio-51(EMS) is executed the WinIDE Studio-51(EMS) logo appears

In case of the users PC connected correctly the WinIDE Studio-51(EMS) screen shows up Otherwise the next screen is displayed (If a user doesnt want the connection of MDA-WinEMS51 to the PC

with RS-232C DEMO is to be executed)

3-1 Structure of WinIDE Studio-51(EMS) Program Screens

MDA-WinEMS51 MANUAL - 19 -

3 View WinIDE Studio-51(EMS)

A user has to fully know about the structure and operating instructions of the WinIDE Studio-51(EMS) program to correctly develop the desired system with MDA-WinEMS51 so that they need to be perfectly understood

3‐1 Structure of WinIDE Studio‐51(EMS) Program Screens

The above screen is the main screen of WinIDE Studio-51(EMS) (Windows Integrated Development Environment Studio-51(EMS)) that is the integrated development environment of MDA-WinEMS51 and here in each studio and menu are to be explained for the first-time user

3 View WinIDE Studio-51(EMS)

- 20 - MDA-WinEMS51 MANUAL

3‐2 Explanation of the WinIDE Studio‐51(EMS) Program Screens by Studio

Menu There are submenus for a main menu and shortcut buttons are made to execute the main menus and the submenus at a time If the cursor is placed on this shortcut button the balloon help shows up and lets the function of the shortcut button known

File Studio Functions such as edit file save file assemble amp link compile amp link download etc are available

SFR Studio The values of the SFR (Special Function Register) of MDA-WinEMS51 are displayed and the values of the SFRs can be modified with the mouse and the keyboard of a personal computer

Internal RAM Studio The contents of the internal data RAM (20H-7FH) of MDA-WinEMS51 are displayed and the contents of the internal data RAM can be modified with the mouse and the keyboard of a personal computer

Register Bank Studio The contents of the general purpose registers (R0 R7) of MDA-WinEMS51 are displayed and the contents of the registers can be modified with the mouse and the keyboard of a personal computer

3-3 Functions of Each Studio

MDA-WinEMS51 MANUAL - 21 -

3‐3 Functions of Each Studio

File Studio Functions such as make and save assemble link or download a source file are executed in this studio Making and assembling a source file and downloading it to MDA-WinEMS51 are to be explained in the different chapter And the source file in the present file studio is displayed in the file recently worked out so a user doesnt have to worry about this source file

(1) If a user makes and assembles the source file and downloads it to MDA-WinEMS51 the command pointer window pointing to

the location of instructions as in the figure below appears in the file studio

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 15: WinEMS51

MDA-WinEMS51 MANUAL - 17 -

The installation progress status of WinIDE Studio-51(EMS) is displayed

If the installation is successful the execution file of WinIDE Studio-51(EMS) is created in the MIDAS ENG folder and the installation has been successfully done

2 Install WinIDE Studio-51(EMS)

- 18 - MDA-WinEMS51 MANUAL

If WinIDE Studio-51(EMS) is executed the WinIDE Studio-51(EMS) logo appears

In case of the users PC connected correctly the WinIDE Studio-51(EMS) screen shows up Otherwise the next screen is displayed (If a user doesnt want the connection of MDA-WinEMS51 to the PC

with RS-232C DEMO is to be executed)

3-1 Structure of WinIDE Studio-51(EMS) Program Screens

MDA-WinEMS51 MANUAL - 19 -

3 View WinIDE Studio-51(EMS)

A user has to fully know about the structure and operating instructions of the WinIDE Studio-51(EMS) program to correctly develop the desired system with MDA-WinEMS51 so that they need to be perfectly understood

3‐1 Structure of WinIDE Studio‐51(EMS) Program Screens

The above screen is the main screen of WinIDE Studio-51(EMS) (Windows Integrated Development Environment Studio-51(EMS)) that is the integrated development environment of MDA-WinEMS51 and here in each studio and menu are to be explained for the first-time user

3 View WinIDE Studio-51(EMS)

- 20 - MDA-WinEMS51 MANUAL

3‐2 Explanation of the WinIDE Studio‐51(EMS) Program Screens by Studio

Menu There are submenus for a main menu and shortcut buttons are made to execute the main menus and the submenus at a time If the cursor is placed on this shortcut button the balloon help shows up and lets the function of the shortcut button known

File Studio Functions such as edit file save file assemble amp link compile amp link download etc are available

SFR Studio The values of the SFR (Special Function Register) of MDA-WinEMS51 are displayed and the values of the SFRs can be modified with the mouse and the keyboard of a personal computer

Internal RAM Studio The contents of the internal data RAM (20H-7FH) of MDA-WinEMS51 are displayed and the contents of the internal data RAM can be modified with the mouse and the keyboard of a personal computer

Register Bank Studio The contents of the general purpose registers (R0 R7) of MDA-WinEMS51 are displayed and the contents of the registers can be modified with the mouse and the keyboard of a personal computer

3-3 Functions of Each Studio

MDA-WinEMS51 MANUAL - 21 -

3‐3 Functions of Each Studio

File Studio Functions such as make and save assemble link or download a source file are executed in this studio Making and assembling a source file and downloading it to MDA-WinEMS51 are to be explained in the different chapter And the source file in the present file studio is displayed in the file recently worked out so a user doesnt have to worry about this source file

(1) If a user makes and assembles the source file and downloads it to MDA-WinEMS51 the command pointer window pointing to

the location of instructions as in the figure below appears in the file studio

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 16: WinEMS51

2 Install WinIDE Studio-51(EMS)

- 18 - MDA-WinEMS51 MANUAL

If WinIDE Studio-51(EMS) is executed the WinIDE Studio-51(EMS) logo appears

In case of the users PC connected correctly the WinIDE Studio-51(EMS) screen shows up Otherwise the next screen is displayed (If a user doesnt want the connection of MDA-WinEMS51 to the PC

with RS-232C DEMO is to be executed)

3-1 Structure of WinIDE Studio-51(EMS) Program Screens

MDA-WinEMS51 MANUAL - 19 -

3 View WinIDE Studio-51(EMS)

A user has to fully know about the structure and operating instructions of the WinIDE Studio-51(EMS) program to correctly develop the desired system with MDA-WinEMS51 so that they need to be perfectly understood

3‐1 Structure of WinIDE Studio‐51(EMS) Program Screens

The above screen is the main screen of WinIDE Studio-51(EMS) (Windows Integrated Development Environment Studio-51(EMS)) that is the integrated development environment of MDA-WinEMS51 and here in each studio and menu are to be explained for the first-time user

3 View WinIDE Studio-51(EMS)

- 20 - MDA-WinEMS51 MANUAL

3‐2 Explanation of the WinIDE Studio‐51(EMS) Program Screens by Studio

Menu There are submenus for a main menu and shortcut buttons are made to execute the main menus and the submenus at a time If the cursor is placed on this shortcut button the balloon help shows up and lets the function of the shortcut button known

File Studio Functions such as edit file save file assemble amp link compile amp link download etc are available

SFR Studio The values of the SFR (Special Function Register) of MDA-WinEMS51 are displayed and the values of the SFRs can be modified with the mouse and the keyboard of a personal computer

Internal RAM Studio The contents of the internal data RAM (20H-7FH) of MDA-WinEMS51 are displayed and the contents of the internal data RAM can be modified with the mouse and the keyboard of a personal computer

Register Bank Studio The contents of the general purpose registers (R0 R7) of MDA-WinEMS51 are displayed and the contents of the registers can be modified with the mouse and the keyboard of a personal computer

3-3 Functions of Each Studio

MDA-WinEMS51 MANUAL - 21 -

3‐3 Functions of Each Studio

File Studio Functions such as make and save assemble link or download a source file are executed in this studio Making and assembling a source file and downloading it to MDA-WinEMS51 are to be explained in the different chapter And the source file in the present file studio is displayed in the file recently worked out so a user doesnt have to worry about this source file

(1) If a user makes and assembles the source file and downloads it to MDA-WinEMS51 the command pointer window pointing to

the location of instructions as in the figure below appears in the file studio

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 17: WinEMS51

3-1 Structure of WinIDE Studio-51(EMS) Program Screens

MDA-WinEMS51 MANUAL - 19 -

3 View WinIDE Studio-51(EMS)

A user has to fully know about the structure and operating instructions of the WinIDE Studio-51(EMS) program to correctly develop the desired system with MDA-WinEMS51 so that they need to be perfectly understood

3‐1 Structure of WinIDE Studio‐51(EMS) Program Screens

The above screen is the main screen of WinIDE Studio-51(EMS) (Windows Integrated Development Environment Studio-51(EMS)) that is the integrated development environment of MDA-WinEMS51 and here in each studio and menu are to be explained for the first-time user

3 View WinIDE Studio-51(EMS)

- 20 - MDA-WinEMS51 MANUAL

3‐2 Explanation of the WinIDE Studio‐51(EMS) Program Screens by Studio

Menu There are submenus for a main menu and shortcut buttons are made to execute the main menus and the submenus at a time If the cursor is placed on this shortcut button the balloon help shows up and lets the function of the shortcut button known

File Studio Functions such as edit file save file assemble amp link compile amp link download etc are available

SFR Studio The values of the SFR (Special Function Register) of MDA-WinEMS51 are displayed and the values of the SFRs can be modified with the mouse and the keyboard of a personal computer

Internal RAM Studio The contents of the internal data RAM (20H-7FH) of MDA-WinEMS51 are displayed and the contents of the internal data RAM can be modified with the mouse and the keyboard of a personal computer

Register Bank Studio The contents of the general purpose registers (R0 R7) of MDA-WinEMS51 are displayed and the contents of the registers can be modified with the mouse and the keyboard of a personal computer

3-3 Functions of Each Studio

MDA-WinEMS51 MANUAL - 21 -

3‐3 Functions of Each Studio

File Studio Functions such as make and save assemble link or download a source file are executed in this studio Making and assembling a source file and downloading it to MDA-WinEMS51 are to be explained in the different chapter And the source file in the present file studio is displayed in the file recently worked out so a user doesnt have to worry about this source file

(1) If a user makes and assembles the source file and downloads it to MDA-WinEMS51 the command pointer window pointing to

the location of instructions as in the figure below appears in the file studio

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 18: WinEMS51

3 View WinIDE Studio-51(EMS)

- 20 - MDA-WinEMS51 MANUAL

3‐2 Explanation of the WinIDE Studio‐51(EMS) Program Screens by Studio

Menu There are submenus for a main menu and shortcut buttons are made to execute the main menus and the submenus at a time If the cursor is placed on this shortcut button the balloon help shows up and lets the function of the shortcut button known

File Studio Functions such as edit file save file assemble amp link compile amp link download etc are available

SFR Studio The values of the SFR (Special Function Register) of MDA-WinEMS51 are displayed and the values of the SFRs can be modified with the mouse and the keyboard of a personal computer

Internal RAM Studio The contents of the internal data RAM (20H-7FH) of MDA-WinEMS51 are displayed and the contents of the internal data RAM can be modified with the mouse and the keyboard of a personal computer

Register Bank Studio The contents of the general purpose registers (R0 R7) of MDA-WinEMS51 are displayed and the contents of the registers can be modified with the mouse and the keyboard of a personal computer

3-3 Functions of Each Studio

MDA-WinEMS51 MANUAL - 21 -

3‐3 Functions of Each Studio

File Studio Functions such as make and save assemble link or download a source file are executed in this studio Making and assembling a source file and downloading it to MDA-WinEMS51 are to be explained in the different chapter And the source file in the present file studio is displayed in the file recently worked out so a user doesnt have to worry about this source file

(1) If a user makes and assembles the source file and downloads it to MDA-WinEMS51 the command pointer window pointing to

the location of instructions as in the figure below appears in the file studio

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 19: WinEMS51

3-3 Functions of Each Studio

MDA-WinEMS51 MANUAL - 21 -

3‐3 Functions of Each Studio

File Studio Functions such as make and save assemble link or download a source file are executed in this studio Making and assembling a source file and downloading it to MDA-WinEMS51 are to be explained in the different chapter And the source file in the present file studio is displayed in the file recently worked out so a user doesnt have to worry about this source file

(1) If a user makes and assembles the source file and downloads it to MDA-WinEMS51 the command pointer window pointing to

the location of instructions as in the figure below appears in the file studio

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 20: WinEMS51

3 View WinIDE Studio-51(EMS)

- 22 - MDA-WinEMS51 MANUAL

(2) If in the same state as the figure above the mouse cursor is placed on the arbitrary location of the file studio and the right button of the mouse is pressed the pop-up menu of the file studio is displayed as in the figure below

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 21: WinEMS51

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 23 -

(3) Clicking the mouse cursor on the Assembler Show displays the Assembler window corresponding to the instructions as the figure below

(4) Functions from (1) to (4) are feasible only if the source file of MDA-WinEMS51 is loaded

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 22: WinEMS51

3 View WinIDE Studio-51(EMS)

- 24 - MDA-WinEMS51 MANUAL

SFR Studio The contents of the SFRs (Special Function Registers) of MDA-WinEMS51 were displayed

(1) The SFR names of WinIDE Studio-51(EMS) are represented with the red color the bit names within the SFR are represented

with the black color and each SFR contents are displayed in the unit of words bytes or bits

(2) Each movement to SFR is attained by using 983918 key of a personal computer or clicking the mouse cursor placed on the SFR to be selected

(3) As for the SFR selected or the contents of SFR selected a box is represented with the dotted lines

(4) If the contents of the selected SFR are represented with bits the bit location is moved with 983996 and 983997 keys of a personal computer

(5) In order to change the contents of the selected SFR type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

(6) Double-clicking the bit area of the SFR with the mouse or pressing 983966 changes 1 to 0 or 0 to 1

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 23: WinEMS51

3-3 Funtions of Each Studio

MDA-WinEMS51 MANUAL - 25 -

Register Bank Studio The bank 0 to 3 of MDA-WinEMS51 is displayed

(1) In order to move to the register of each bank use either 983996 983998 983999 and 983997 keys of a personal computer or the mouse

(2) In order to change the contents of the selected register type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

Internal RAM Studio The contents of the internal data RAM 20H7FH of MDA-WinEMS51 are displayed

(1) In order to move to the internal data memory use 983996 983998 983999 and 983997 keys of a personal computer or use the mouse

(2) In order to change the contents of the selected internal memory type them in with the hexadecimal number by using 983929 983928 and 983933 983938 keys of a personal computer

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 24: WinEMS51

3 View WinIDE Studio-51(EMS)

- 26 - MDA-WinEMS51 MANUAL

3‐4 The Main Menu of WinIDE Studio‐51(EMS)There are several main menus in WinIDE Studio-51(EMS) and there are

submenus in each main menu

Place the mouse cursor on the menu to select and click itPress the alphabet character in the menu parentheses of the

main menu with 983915 key of a personal computer pressed

The functions of the main menu are as follows

File(F) Executing the File menu has the submenu displayed as follows and executing the submenu has the screen corresponding to the submenu displayed

(1) Ctrl+N Ctrl+P etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 25: WinEMS51

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 27 -

(3) The + representation means that another key is pressed with 983917 key pressed

Edit(E) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The operating instructions of this menu is the same as the operating instructions of the editor used in the general Windows

(1) Ctrl+A Ctrl+X etc besides the submenu means the hot keys (2) Pressing the alphabet character with 983915 key of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The + representation means that another key is pressed with 983917 key pressed

Work(W) Executing the Edit menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 26: WinEMS51

3 View WinIDE Studio-51(EMS)

- 28 - MDA-WinEMS51 MANUAL

(1) F3 F4 F5 etc besides the submenu means the hotkeys (2) Pressing F3 F4 F5 of a personal computer keyboard pressed means that the corresponding submenu is executed(3) The submenus of ldquoAssemble And Linkrdquo and ldquoCompile And Linkrdquo dont become active at the same time and are automatically set up by the source file in the file studio

Run(R) Executing the Run menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu isnt operated unless a program is not downloaded in MDA-WinEMS51

(1) F6 F7 F9 etc besides the submenu means the hot keys and the operating instructions are the same as Run menu

(2) The submenu of ldquoStop Programrdquo can be used after a program is run

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 27: WinEMS51

3-4 The Main Menu of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 29 -

Dump(D) Executing the Dump menu has the submenu displayed as follows and executing the submenu has the function corresponding to the submenu executed The submenu of this menu is to view the program and data memory of MDA-WinEMS51

(1) F2 Ctrl+U etc besides the submenu means the hot keys and the operating instructions are the same as Run menu(2) The submenu of ldquoView C Language Variablesrdquo is operated only if the source file in the file studio is a C language program

Window(I) If Window is executed the Window has to be selected is displayed

Micom Write(M) It is to be explained in ldquo4 Use of the One-Chip Test Unitrdquo

Help(H) The Help menu provides the information needed for the user to use MDA-WinEMS51 and WinIDE Studio-51(EMS) such as the internal structure of 8051 Refer to Help if there is a part you cannot understand when using WinIDE Studio-51(EMS)

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 28: WinEMS51

3 View WinIDE Studio-51(EMS)

- 30 - MDA-WinEMS51 MANUAL

3‐5 The Shortcut Button of WinIDE Studio‐51(EMS)

WinIDE Studio-51(EMS) has made a shortcut button to alleviate the annoyance that a user selects and executes the main menu and the submenu

The functions of the shortcut button are summarized as in the following

table and if a user places the mouse cursor on the shortcut button the name of the shortcut button is displayed under the shortcut button with the balloon help If a user wants to use WinIDE Studio-51(EMS) fast the user had better be accustomed to this shortcut button

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 29: WinEMS51

3-5 The Shortcut Button of WinIDE Studio-51(EMS)

MDA-WinEMS51 MANUAL - 31 -

SHORTCUTBUTTON

SHORTCUT BUTTON NAME

MAIN MENU SUBMENU

New File File(F) New File

File Open File(F) File Open

View File File(F) View File

Save File(F) Save

Printer File(F) Printer

Cancel Run Edit(E) Cancel Edit

Find Edit(E) Find

Assemble amp Link Work(W) Assemble amp Link

Compile amp Link Work(W) Compile amp Link

Transmit Program Work(W) Transmit Program

Data Memory Dump Dump(D) Data Memory

Program Memory Dump Dump(D) Program Memory View C Language

VariablesDump(D)

View c LanguageVariables

Run Program Run(R) Run Program

Single Step Run(R) Execute 1 Step

Program Stop Run(R) Program Stop

983689983705Micom Write Micom Write(M)

983689983706 Software Reset Run(R)

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 30: WinEMS51

3 View WinIDE Studio-51(EMS)

- 32 - MDA-WinEMS51 MANUAL

3‐6 Compiling the source

Selecting the company The compiler provided by Midas Engineering is the demonstration software of Keil and IARThe compiler selection screen shows up to ask a question when you click the Setup Compiler menu

Choose the compiler company

Setting compiler If you select assembler from the assembler selection screen add the path to the executable file to the Compiler

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 31: WinEMS51

3-6 Compiling the source

MDA-WinEMS51 MANUAL - 33 -

Define the environment variables INCLUDE and LIBRARY specifying the paths to the INC and LIB directoriesIf you define the executable file LIB and INC path will be automatically defined

Company Execution file pathIAR CMDAWinEMS51CIARicc8051exe

KEIL CMDAWinEMS51CKEILc51exe

Compile and Link Compile and Link shows the messages generated when building a

source file

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 32: WinEMS51

4 Keyboard Monitor

- 34 - MDA-WinEMS51 MANUAL

4 Keyboard Monitor

4‐1 Introduction This chapter describes your interaction or how you communicate

with your MDA-WinEMS51 kit through the key pad monitor The monitor program resides in 8K byte ROM The program is initialize or ready whenever power is turned on or

your any time the RESET switch is pressed and allow to perform the following operations using the Keyboard and LCD display

Examine and modify internal memory and external memory within the 8051 microcomputer Examine and modify memory locations Enter and initiate execution of your own programs Evaluate execution(debug) of your program through the monitors

single-step

4‐2 Using the Keyboard monitor The MDA-WinEMS51 kit power on The LCD display the following

message

MDA-WinEMS51 8051 KIT ver30

If the LCD does not display this message follow the steps below Move the JP1 switch to the G marking The JP1 is

located to the right-center part of the MDA-WinEMS51 kit (marking the JP1 SELECT MODE)

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 33: WinEMS51

4-3 Keyboard

MDA-WinEMS51 MANUAL - 35 -

G +5

KIT PC JP1

SELECTMODE

Figure 4-1 JP1

Push the RESET switch The RESET switch is located to the upper part of the MDA-WinEMS51 kit keyboard (yellow push button switch)

4‐3 Keyboard With the Keyboard monitor program you enter both commands and

data by pressing individual keys of key pad(The monitor communicates with you through the LCD display) As shown in Figure 4-2 the Keyboard is divided into two logical groups the 16 hexadecimal keys on the right-hand side and the 6 function keys on the left hand side

FUNCTION983046 983047

HEXADECIMAL983046 983047 RES

INT STP C D E F

T0 GO 8 9 A B

+ DA 4 5 6 7

- AD 0 1 2 3

Figure 4-2 Keyboard arrangement

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 34: WinEMS51

4 Keyboard Monitor

- 36 - MDA-WinEMS51 MANUAL

The individual operation of the 6 function and 2 experiment keys id defined below

RES The RESET key allows to terminate any present activity and to return your MDA-WinEMS51 kit to an initialized state MDA-WinEMS51 kit INPUT gt message appears in the LCD display and monitor is ready for command entry

AD The AD key is used to enter the internal memory or external memory address

DA The DA key allows you to enter the data in the internal memory or external memory

+ The + key is used to increase internal memory or external memory

- The - key is used to decrease internal memory or external memory

GO The GO key is used to execute the yours program

STP The STP key is used to execute a line on time of the yours program

INT The INT key is used to generate an external interrupt to the 8051 microcomputer

T0 The T0 key is used to generate an pulse to the 8051 microcomputer timercounter

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 35: WinEMS51

4-5 Basic operation

MDA-WinEMS51 MANUAL - 37 -

4‐4 LCD Display Your MDA-WinEMS51 Kit uses the LCD display(16 x 2 lines) to

communicate with you Depending on the current state of the monitor the information the Current contents of a register or PC PSW etc An echo of a hexadecimal key entry A monitor prompt sign Current contents of memory location

4‐5 Basic operation When using the keyboard monitor you will prompted through the LCD

display as to the input required Whenever the monitor is expecting a command entry a following

message appears in the LCD display

8051gt input _

4-5-1 Writing the internal and external memory

Example 1 Examination the internal data memory 0000H~0003H

KEY LCD

RES 8051 gt input _

AD The contents of external data memory 2000h(It may be different)

Addr Data2000_ FF

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 36: WinEMS51

4 Keyboard Monitor

- 38 - MDA-WinEMS51 MANUAL

0 The contents of internal data memory 0000h(It may be different)

Addr Data0000_ 00

+ Address increment and cursor is moved

Addr Data0001 00_

+ Addr Data0002 00_

-Address decrement

Addr Data0001 00_

Example 2Examination and modifying the internal data memory

0030H~0031H

KEY LCD

AD Addr Data0001_ 00

0 0 3 0 Addr Data0030_ 00

DACursor is moved

Addr Data0030 00_

A B Addr Data0030 AB_

+ Addr Data0031 00_

C D Addr Data0031 CD_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 37: WinEMS51

4-5 Basic operation

MDA-WinEMS51 MANUAL - 39 -

Example 3Examination and modifying the external data

memory 2000H

KEY LCD

AD Addr Data0031_ CD

2 0 0 0 Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

3 5 Addr Data2000 35_

4-5-2 Executing the users program

The method of entering the users program executing is described through the following example program

The example program

Address Machine code Mnemonic2000 74 F7 MOV A0F7H2002 F5 90 MOV P1A2004 02 80 28 JMP 8028H monitor return

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 38: WinEMS51

4 Keyboard Monitor

- 40 - MDA-WinEMS51 MANUAL

Entering The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

DACursor is moved

Addr Data2000 FF_

7 4 Addr Data2000 74_

+ F 7 Addr Data2001 F7_

+ F 5 Addr Data2002 F5_

+ 9 0 Addr Data2003 90_

+ 0 2 Addr Data2004 02_

+ 8 0 Addr Data2005 80_

+ 2 8 Addr Data2006 28_

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 39: WinEMS51

4-5 Basic operation

MDA-WinEMS51 MANUAL - 41 -

Executing The example program

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ FF

GO A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted The update register values will be displayed

Using The Single step key

TO use the single step key STP you must insert the instruction JNB IE1$ at the first line of the program

Address Machine code Mnemonic2000 30 8B FD JNB IE1$2003 74 F7 MOV A0F7H2005 F5 90 MOV P1A 2007 02 80 28 JMP 8028H monitor return

Enter the changed program

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 40: WinEMS51

4 Keyboard Monitor

- 42 - MDA-WinEMS51 MANUAL

Execute the following method

KEY LCD

RES 8051 gt input _

AD Addr Data2000_ 30

GO STP After a few momentthe PC value is displayed

next PC=2000_

The update registervalue is displayed

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2003_

A=00 B=00 PSW=00SP=50 DPTR=0000

STP next PC=2005_

A=F7 B=00 PSW=01SP=50 DPTR=0000

STP next PC=2007_

A=F7 B=00 PSW=01SP=50 DPTR=0000

The LED which connect to port1 will be lighted

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 41: WinEMS51

Experiment1 P_1C

MDA-WinEMS51 MANUAL - 43 -

5 ExperimentExperiment1 P_1C

IO PORT Experiment 1

include ltio51hgt

void delay(int i)

while(i--)

void main(void)

data unsigned char led

led = 0xfe

do P1 = ledled = (ledltlt1) |1if((led amp 0x10) == 0)

led = 0xfedelay( 10000 )

while(1)

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 42: WinEMS51

5 Experiment

- 44 - MDA-WinEMS51 MANUAL

Experiment2 P_2C

IO PORT Experiment 2-- Traffic signal

include ltio51hgt

bit led1 = P10bit led2 = P11bit led3 = P12

void delay( int i )

while( i -- )

void main( void )

int i

do led1 = 0 Green LED on delay( 50000 )led1 = 1

Green LED 4time flicker for( i = 0 i lt 4 i ++ )

delay( 10000 )led1 = 0delay( 10000 )led1 = 1

Amber LED on led2 = 0

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 43: WinEMS51

Experiment3 DOT1C

MDA-WinEMS51 MANUAL - 45 -

delay( 30000 )led2 = 1

Red LED on led3 = 0delay( 30000 )led3 = 1

while( 1 )

Experiment3 DOT1C

DOT Experiment 1-- Row Display

include ltio51hgt

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 44: WinEMS51

5 Experiment

- 46 - MDA-WinEMS51 MANUAL

define PPI_A ((unsigned char )0x1c014)define PPI_B ((unsigned char )0x1c015)define PPI_C ((unsigned char )0x1c016)define PPI_CR ((unsigned char )0x1c017)

void delay( unsigned int del )

while( del-- )

font Display void font_write( unsigned char fontunsigned char font1 )

int i

for(i=0ilt8i++)

PPI_A = fontPPI_B = font1

PPI_C = 0x00 col on delay ( 10000 )

font = ( font ltlt 1 ) red font1 =( font1 ltlt1 ) green PPI_C = 0xff off

delay ( 10000 )

void main( void )

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 45: WinEMS51

Experiment4 Ch6_1C

MDA-WinEMS51 MANUAL - 47 -

PPI_CR = 0x80

do font_write( 0x010x00 )font_write( 0x000x01 )font_write( 0x010x01 )

while( 1 )

Experiment4 Ch6_1C

External Interrupt0 Experiment include ltio51hgt

data unsigned char tbl[4] = 0xfe 0xfd 0xfb 0xf7 data unsigned char led

interrupt [0x03] void X0_int(void)

EA=0led++if( led == 4 ) led = 0P1 = tbl[led]EA = 1return

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 46: WinEMS51

5 Experiment

- 48 - MDA-WinEMS51 MANUAL

void main( void )

led = 0

PX0 = 1IT0 = 1EX0 = 1EA = 1 Interrupt enable

P1 = tbl[led]while(1)

Experiment5 LCD_1C

LCD Experiment 1 include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define DISP_OFF 0x08define DISP_ON 0x0c

void delay( unsigned int del )

while( del-- )

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 47: WinEMS51

Experiment5 LCD_1C

MDA-WinEMS51 MANUAL - 49 -

Busy flag check void check_bf(void)

data unsigned char d

PPI_CR = 0x92 B Port Input Mode PPI_C = 0x73

do PPI_C = 0x76 E = 1 d = PPI_BPPI_C = 0x72 E = 0

while( d amp 0x80 )

PPI_CR = 0x90 B Port Output Mode PPI_C =0x73

lcd Instruction void cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 1 PPI_C = 0x73

1 Character Display void char_out( char ch )

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 48: WinEMS51

5 Experiment

- 50 - MDA-WinEMS51 MANUAL

check_bf()PPI_C = 0x75PPI_B = ch

PPI_C = 0x70PPI_C = 0x73

String Display void string_out( char str )

while( str ) char_out( str )str ++delay( 20000 )

void main( void )

do cmd_write( ALL_CLR )

string_out( Serial Monitor )cmd_write( LN21 )

string_out( ET8051 KIT )

cmd_write( DISP_OFF )delay( 40000 )cmd_write( DISP_ON )

while( 1 )

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 49: WinEMS51

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 51 -

Experiment6 STEPC

================================================= Stepping motor Experiment

include ltio51hgt

define KEY_IN ((unsigned char )0x1c004)define CLR_KEY ((unsigned char )0x1c000)

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

bit direction_flagunsigned char pl_counterunsigned char pl_ptr

const unsigned char pl[4] = 0xcc 0x99 0x33 0x66

union unsigned int iunsigned char b[2]

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 50: WinEMS51

5 Experiment

- 52 - MDA-WinEMS51 MANUAL

speed

LCD Busy flag Check void check_bf( void )

data unsigned char d

PPI_CR = 0x92PPI_C = 0x73

do PPI_C = 0x76d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

PPI_C = 0x70 E = 0 PPI_C = 0x73

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 51: WinEMS51

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 53 -

1 Character Display void lcd_char_out( unsigned char ch )

check_bf()

PPI_C = 0x75PPI_B = ch

PPI_C = 0x71PPI_C = 0x73

String Display void lcd_string_out( char str )

while( str )

lcd_char_out( str )str ++

void BinToHex( char buf int v )

buf[0] = ((v gtgt 12) amp 0x000f)buf[0] += (buf[0] gt= 0x0a) 0x37 0x30buf[1] = ((v gtgt 8) amp 0x000f)buf[1] += (buf[1] gt= 0x0a) 0x37 0x30buf[2] = ((v gtgt 4) amp 0x000f)buf[2] += (buf[2] gt= 0x0a) 0x37 0x30buf[3] = (v amp 0x000f)

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 52: WinEMS51

5 Experiment

- 54 - MDA-WinEMS51 MANUAL

buf[3] += (buf[3] gt= 0x0a) 0x37 0x30buf[4] = 0

void dsp_speed( void )

char str[17]

lcd_cmd_write( LN11 )lcd_string_out( Speed )

BinToHex( str speedi)lcd_string_out( str )

void dsp_msg( char str )

lcd_cmd_write( LN21 )

lcd_string_out( str )

void init_timer( void )

TR0 = 0

TH0 = speedb[0]TL0 = speedb[1]

TR0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 53: WinEMS51

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 55 -

Timer0 interrupt Routine interrupt [0x0b] void timer0( void )

TR0 = 0EA = 0

TH0 = speedb[0]TL0 = speedb[1]

if( pl_counter ) Stop Check EA = 1return

if( pl_counter = 0xff ) pl_counter --

if( direction_flag ) P1 = pl[pl_ptr]

pl_ptr ++if( pl_ptr gt= 4 ) pl_ptr = 0

else

P1 = pl[pl_ptr]

pl_ptr --if( pl_ptr == 0xff ) pl_ptr = 3

TR0 = 1EA = 1

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 54: WinEMS51

5 Experiment

- 56 - MDA-WinEMS51 MANUAL

Key Input char scan( void )

data unsigned char key

do key = KEY_IN

while( key amp 0x80 )

CLR_KEY = 0

return( key amp 0x1f )

Main program void main( void )

char in_key

lcd_cmd_write( ALL_CLR )

speedi = 0xc000dsp_speed()

pl_ptr = 0pl_counter = 0

TMOD = 0x11init_timer()

ET0 = 1PT0 = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 55: WinEMS51

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 57 -

EA = 1

do in_key = scan()switch( in_key )

case 1 right 45 EA = 0

pl_counter = 25direction_flag = 0dsp_msg( Right 45 )

EA = 1TR0 = 1

break

case 3 right 90 EA = 0

pl_counter = 50direction_flag = 0dsp_msg( Right 90 )

EA = 1TR0 = 1

break

case 5 right 180 EA = 0

pl_counter = 100direction_flag = 0dsp_msg( Right 180 )

EA = 1TR0 = 1

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 56: WinEMS51

5 Experiment

- 58 - MDA-WinEMS51 MANUAL

break

case 7 right EA = 0

pl_counter = 0xffdirection_flag = 0dsp_msg( Right Revolution )

EA = 1TR0 = 1

break

case 0 left 45 EA = 0

pl_counter = 25direction_flag = 1dsp_msg( left 45 )

EA = 1TR0 = 1

break

case 2 left 90 EA = 0

pl_counter = 50direction_flag = 1dsp_msg( left 90 )

EA = 1

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 57: WinEMS51

Experiment6 STEPC

MDA-WinEMS51 MANUAL - 59 -

TR0 = 1

break

case 4 left 180 EA = 0

pl_counter = 100direction_flag = 1dsp_msg( left 180 )

EA = 1TR0 = 1

break

case 6 left revolution EA = 0pl_counter = 0xffdirection_flag = 1dsp_msg( left revolution )EA = 1TR0 = 1

breakcase 0x0e stop

EA = 0TR0 = 0

pl_counter = 0dsp_msg( Motor Stop )

break

case 0x13 speed inc + EA = 0TR0 = 0speedi += 50

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 58: WinEMS51

5 Experiment

- 60 - MDA-WinEMS51 MANUAL

init_timer()dsp_speed()

EA = 1TR0 = 1

break

case 0x14 speed dec - EA = 0TR0 = 0speedi -= 50init_timer()dsp_speed()

EA = 1TR0 = 1

break

switch

while( 1 )

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 59: WinEMS51

Experiment7 Ch7_1C

MDA-WinEMS51 MANUAL - 61 -

Experiment7 Ch7_1C

Timer Experiment 1 include ltio51hgt

LED BUFFER data unsigned char led

--------------------------------------- Timer0 Interrupt service routine

interrupt [0x0b] void TIMER0(void)

TR0 = 0 Timer Stop

led = ( led ltlt 1 ) | 0x01if( ( led amp 0x10 ) == 0 ) led = 0xfeP1 = led LED ON

TH0 = 0TL0 = 0

TR0 = 1

-------------------------------------- MAIN program void main( void )

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 60: WinEMS51

5 Experiment

- 62 - MDA-WinEMS51 MANUAL

TMOD = 0x21 Timer MODE 0

TH0 = TL0 = 0

PT0 = 1ET0 = 1EA = 1

led = 0xfeP1 = led

TR0 = 1

while( 1 )

Experiment8 DACC

DC Motor speed will be displayed on the LCD module

Select the P0P1 switch to +12[v]

P0

+12V +5

P1

+12V +5

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 61: WinEMS51

Experiment8 DACC

MDA-WinEMS51 MANUAL - 63 -

Connect JB to JC with cable

======================================== DAC Experiment

include ltio51hgt

define PPI_A ((unsigned char )0x1c008)define PPI_B ((unsigned char )0x1c009)define PPI_C ((unsigned char )0x1c00a)define PPI_CR ((unsigned char )0x1c00b)

LCD Instruction define ALL_CLR 0x01define LN21 0xc0define LN11 0x80define DISP_OFF 0x08define DISP_ON 0x0e

Rotary Decoder Slot Number define SLOT 14

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 62: WinEMS51

5 Experiment

- 64 - MDA-WinEMS51 MANUAL

timer1 counter =gt Make 1Sec int time_counter Motor Rotation buffer char speed_buf

LCD Busy flag check void check_bf( void ) data unsigned char d

PPI_CR = 0x92 PPI_C = 0x73

do PPI_C = 0x76 d = PPI_B

PPI_C = 0x72 while( d amp 0x80 )

PPI_CR = 0x90 PPI_C = 0x73

LCD Instruction Write void lcd_cmd_write( unsigned char cmd )

check_bf()

PPI_C = 0x74 E = 1 PPI_B = cmd

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 63: WinEMS51

Experiment8 DACC

MDA-WinEMS51 MANUAL - 65 -

PPI_C = 0x70 E = 0 PPI_C = 0x73

LCD Instruction write void lcd_char_out( unsigned char ch ) check_bf()

PPI_C = 0x75 PPI_B = ch

PPI_C = 0x71 PPI_C = 0x73

LCD String write void lcd_string_out( char str ) while( str ) lcd_char_out( str ) str ++

void BinToBCD( char buf int v ) int t

buf[0] = v 100 + 0x30 t = v 100

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 64: WinEMS51

5 Experiment

- 66 - MDA-WinEMS51 MANUAL

buf[1] = t 10 + 0x30 buf[2] = t 10 + 0x30 buf[3] = 0

Main Program void main( void) char str[6] unsigned char da_buf bit flag

time_counter = 0 speed_buf = 0

lcd_cmd_write( ALL_CLR ) lcd_string_out( Motor Speed ) lcd_cmd_write( LN21 + 8 ) lcd_string_out( RPS )

TMOD = 0x16 timer 0 =gt mode 2 timer 1 =gt mode 1 TH0 = 256 - SLOT TL0 = 256 - SLOT ET0 = 1

TH1 = 0 TL1 = 0 ET1 = 1

TR0 = 1 TR1 = 1 EA = 1

do

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 65: WinEMS51

Experiment8 DACC

MDA-WinEMS51 MANUAL - 67 -

Speed Increment da_buf = 128 flag = 1 do P1 = da_buf if( time_counter gt= 30 ) 2sec delay time_counter = 0

speed_buf = 2 Speed Display ( rps ) BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf ++ DAC Output Increment if( da_buf gt 80 ) flag = 0

while( flag )

Speed Decrement flag = 1 do P1 = da_buf if( time_counter gt= 30 ) time_counter = 0

speed_buf = 2 BinToBCD( str speed_buf ) lcd_cmd_write( LN21 + 4 ) lcd_string_out( )

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 66: WinEMS51

5 Experiment

- 68 - MDA-WinEMS51 MANUAL

lcd_cmd_write( LN21 + 4 ) lcd_string_out( str )

speed_buf = 0 da_buf -- if( da_buf lt 69 ) flag = 0 while( flag ) while( 1 )

timer0 interrupt routine interrupt [0x0b] void TIMER0(void) EA = 0 speed_buf ++ EA = 1

timer1 interrupt routine interrupt [0x1b] void TIMER1(void) EA = 0 time_counter ++ EA = 1

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 67: WinEMS51

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 69 -

The Schematic of the MDA‐WinEMS51 kit

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 68: WinEMS51

The Schematic of the MDA-WinEMS51 Kit

- 70 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 69: WinEMS51

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 71 -

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 70: WinEMS51

The Schematic of the MDA-WinEMS51 Kit

- 72 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 71: WinEMS51

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 73 -

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 72: WinEMS51

The Schematic of the MDA-WinEMS51 Kit

- 74 - MDA-WinEMS51 MANUAL

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 73: WinEMS51

The Schematic of the MDA-WinEMS51 Kit

MDA-WinEMS51 MANUAL - 75 -

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 74: WinEMS51

The Schematic of the MDA-WinEMS51 Kit

- 76 - MDA-WinEMS51 MANUAL

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 75: WinEMS51

Printed in the Korea

Tel 82-2-2109-5964Fax 82-2-2109-5968E-mail infomidasengcomWeb wwwmidasengcom

MDA‐WinEMS51 User Guide

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)

Page 76: WinEMS51

Printed in the Korea

2005년 8월 23일에 수정함

- 37page Machin code 02 00 28 rarr 02 80 28

1 - 37page Mnemonic 0028 rarr 8028H

- 38page KEY + 0 0 rarr + 8 0

- 38page LCD Data 00_ rarr 80_

- 39page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01

- 39page Machin code 02 00 28 rarr 02 80 28

- 39page Mnemonic 0028 rarr 8028H

- 40page LCD A=F7 B=00 PSW=00 rarr A=F7 B=00 PSW=01 (2군데)