intel's mcs-51 family of microcontrollers and its …at this time user cannot write on to the...

49
LCD INTERFACE 1 CONTENTS PAGE NO 1.0 Introduction 2 2.0 Description of the LCD Module 2 3.0 Description of the Interface 3 4.0 Installation 3 5.0 Initialisation of the LCD Module 4 6.0 Demonstration Examples 7 6.1 Demonstration Program for MPS 85-3 Trainer 7 6.2 Demonstration Program for ESA 85-2 Trainer 13 6.3 Demonstration Program for ESA-31 Trainer 18 6.4 Demonstration Program for ESA 86/88-2 Trainer 24 6.5 Demonstration Program for ESA 80 Trainer 31 6.6 Demonstration Program for ESA 68-2 Trainer 36 6.7 Demonstration Program for ESA-51 Trainer 42 6.8 Demonstration Program for ESA-51E Trainer 46 Appendix A : Schematic Diagram

Upload: others

Post on 13-Mar-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

1

CONTENTS

PAGE NO

1.0 Introduction 2

2.0 Description of the LCD Module 2

3.0 Description of the Interface 3

4.0 Installation 3

5.0 Initialisation of the LCD Module 4

6.0 Demonstration Examples 7

6.1 Demonstration Program for MPS 85-3 Trainer 7

6.2 Demonstration Program for ESA 85-2 Trainer 13

6.3 Demonstration Program for ESA-31 Trainer 18

6.4 Demonstration Program for ESA 86/88-2 Trainer 24

6.5 Demonstration Program for ESA 80 Trainer 31

6.6 Demonstration Program for ESA 68-2 Trainer 36

6.7 Demonstration Program for ESA-51 Trainer 42

6.8 Demonstration Program for ESA-51E Trainer 46

Appendix A : Schematic Diagram

Page 2: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

2

LCD INTERFACE

1.0 INTRODUCTION

Electro Systems Associates Private Limited (ESA) manufactures trainers for most of the popular

microcomputers viz 8085, Z 80, 8031, 8086/88 and 68000. ESA offers a variety of modules which

can be effectively used for teaching/training in the laboratories.

LCD modules are widely used in areas where information is conveyed visually. They can be seen in

Calculators, mobile and cellular phones, pagers and other electronic products.

The interface is built around 20x4 (twenty character per line and four lines) LCD module with 15

pins. This can be directly coupled to the 8255 Programmable Peripheral Interface on any of the

trainers. The present interface module allows the user to become familiar with the techniques of using

the LCD module.

2.0 DESCRIPTION OF THE LCD MODULE

These modules come in variety of formats like 8x1(eight characters per line and one line), 8x2(eight

characters per line and two lines),16x1(sixteen characters per line and one line),16x2(sixteen

characters per line and two line),20x2(twenty characters per line and two lines), 20x4 (twenty

characters per line and four line) etc.

LCD accepts characters in ASCII format. Character display font in LCD module is by matrix of dots.

i.e each character in LCD module can be represented by 7x5 matrix (7 rows and 5 columns of dots)

or 10x5 matrix (10 rows and 5 columns of dots). This interface is built over 20x4 LCD module in

which the display data RAM address of LCD module for the first line starts from 00H to 14H and the

second line starts from 29H to 3CH. The third line has the address from 15H to 28H and the fourth

line from 3DH to 50H. Reset is required to be done during initialization for LCD modules. The pins

on LCD module ranges from 1 to 15.

PIN DESCRIPTION:

PIN SYMBOL FUNCTION

1 Vss Ground

2 Vdd +5v supply

3 Vo LCD contrast control

4 RS Register Select

RS=0 Instruction

Register

Page 3: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

3

RS=1 Data Register

5 R/W* Read/Write

1=Read

0=Write

6 E Enable

7 to 14 DB0 to DB7 Bi-directional data bus

15 L+ Back light power of

+5V

LCD module has got an automatic reset which is critically dependent upon power supply voltage.

Voltage has to rise from 0.2v to 5v with in 10 to 15ms for the LCD to reset. Since this is not accurate

we choose to reset the LCD module while initialising it. To reset the LCD module send hex number

30 three times with some delay. The Busy Flag of the LCD module will be set while LCD is

resetting. At this time user cannot write on to the LCD module. Data can be written on to the module

only when busy flag goes low, that means to say data is written only after LCD is reset. The program

for this interface does not read busy flag. User is requested not to concern about busy flag.

3.0 DESCRIPTION OF THE INTERFACE:

The interface module consists of 26 pin FRC (Flat Ribbon Cable) connector at the extreme right

which is used to interface the module to the microprocessor trainer. PORT A of 8255 is used as bi-

directional data bus for LCD module. Lower three bits of PORT B of 8255 supports three control

signals of LCD module. A jumper is provided which is named as Backlight Switch. When jumper is

closed backlight of LCD module will be ON. A potentiometer of value 1kohms is provided for

adjusting the contrast of LCD module. Refer to the schematic diagram of the interface presented at

the end of this manual.

4.0 INSTALLATION:

The interface is housed in a plastic enclosure which has a locking mechanism. To open the cover,

push the locking mechanism with the finger and lift the cover to open.

The interface module has a 26 pin connector at one

Page 4: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

4

edge of the card. This is used for connecting the interface to the trainer with a flat cable connector.

Table 2 shows the connectors on various trainers to which this interface can be connected. Some

trainers have two connectors to which this interface can be connected. The demonstration program

presented in this manual assumes that the interface is connected to connectors shown in column A. If

the connectors shown in column B are used, then user has to change the port addresses appropriately.

TABLE-2

MICROPROCESSOR

TRAINER

A B

MPS 85-3 J2 J1

ESA 85-2 J2 J1

ESA-80 J2 J1

ESA-65 P4

ESA-68K P3 P4

ESA 68K-2 J2 J1

ESA 68-2 J1 J6

ESA 196 J1 J2

ESA-31 J2 J1

ESA-51 J10 J7

ESA-51E J5 J3

ESA-86/88-2 J4 J5

ESA-86/88-3 J8 J9

ESA-86/88E J4 J6

5.0 INITIALISATION OF THE LCD MODULE

LCD module has to be initialised before writing any program on to it. Initializing includes resetting

the LCD module, choosing character font, initializing cursor for blinking and auto increment etc.

User has to choose the appropriate instruction code from the instruction set and send it over the

module. The control signals viz R/W* RS and E signals has to be sent through PORT B of 8255 and

the characters over the data bus which is mapped to PORT A of 8255.

Below given instruction set will be useful for users to initialize the LCD module to their needs.

Initialization subroutine is also given at the end. Users can refer to the subroutine and then can write

their own initialization subroutine to suit their needs.

INSTRUCTION SET:

Page 5: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

5

CODE

INSTRUCTION

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0

clear display 0 0 0 0 0 0 0 0 0 1

return home 0 0 0 0 0 0 0 0 1 X

cursor to 00

entry mode set 0 0 0 0 0 0 0 1 1/D S

display on/off 0 0 0 0 0 0 1 D C B

control

cursor on 0 0 0 0 0 1 S/C R/L X X

display shift

function set 0 0 0 0 1 DL N F X X

read busy flag 0 1 BF AC

address

X = don't care S = 1 display shift when data is written

1/D = 1 increment cursor for normal operation, set to 0

1/D = 0 decrement cursor DL = 1 8 bits data length

S/C = 1 display shift DL = 0 4 bits data length

S/C = 0 cursor move N = 1 2 display lines

R/L =1 shift to right N = 0 1 line

R/L = 0 shift to left F = 1 10x5 dots

B = 1 blink on F = 0 7x5 dots

B = 0 blink off D = 1 display on

AC = address D = 0 display off

C = 1 cursor on BF = 1 internally operating

C = 0 cursor off BF = 0 can accept instruction

INITIALISATION SUBROUTINE :

INIT: MVI A,80H CONFIGURE PORTS A,B AND C AS OUTPUT PORTS

OUT COMMAND_PORT

Page 6: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

6

MVI A,30H SEND SOFTWARE RESET THRICE

CALL CMD

LXI D,NUM

CALL DELAY

MVI A,30H

CALL CMD

LXI D,NUM

CALL DELAY

MVI A,30H

CALL CMD

LXI D,NUM

CALL DELAY

MVI A,38H FUNCTION SET 8 BIT

CALL CMD 2 LINE 5X7 FONT

MVI A,0FH DISPLAY ON/OFF CONTROL

CALL CMD DISPLAY ON,CURSOR ON,BLINK

MVI A,06H CURSOR INCREMENT

CALL CMD

MVI A,01H CLEAR DISPLAY

CALL CMD

RET

COMMAND WRITE SUBROUTINE :

CMD: OUT PORT_A OUTPUT COMMAND ON DATA BUS

MVI A,FBH E R/W* RS

OUT PORT_B 0 1 1

MVI A,F8H

OUT PORT_B 0 0 0

MVI A,FCH

OUT PORT_B 1 0 0

MVI A,F8H

OUT PORT_B 0 0 0

LXI D,NUM

CALL DELAY

RET

DELAY SUBROUTINE

DELAY: DCX D

MOV A,D

ORA E

JNZ DELAY

Page 7: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

7

RET

6.0 DEMONSTRATION EXAMPLES

Enter the following program and execute the same with the help of `GO' command. Now the LCD

interface will be waiting for the key to be typed by the user. If the user types `A' LCD interface

displays `A IS TYPED'. If the user types `F' LCD interface displays `F IS TYPED' and so on. The

program is in infinite loop. To come out of the program user has to press RESET key on the trainer.

6.1 DEMONSTRATION PROGRAM FOR MPS 85-3 TRAINER

;Assume the interface is connected over J2 of the trainer.

;The trainer can be in KEYBOARD mode or SERIAL mode.

;Execute the program from 8000H. The program is in loop, press

;RESET to come out of the program.

;When the trainer is in KEYBOARD mode it scans trainer

;keycodes.

;When the trainer is in SERIAL mode it scans system keycodes.

CMD_PORT EQU 43H

PORT_A EQU 40H

PORT_B EQU 41H

NUM EQU 01FFFH

RDKBD EQU 03BAH

GETCH EQU 0C12H

PAUSE EQU 0FFFFH

ADDRESS OPCODE LABLE MNEMONIC COMMENTS

ORG 8000H

8000 CD E3 80 CALL INIT ;Call LCD initialise

;subroutine

8003 3E 80 MVI A,80H ;Address for

8005 CD 18 81 CALL CMD ;first line.

8008 21 E4 81 LXI H,DISP1 ;Display the

800B CD 51 81 CALL STRING ;message "WAITING".

800E 3E C0 MVI A,0C0H ;Address for

8010 CD 18 81 CALL CMD ;second line.

8013 21 ED 81 LXI H,DISP2 ;Display the

8016 CD 51 81 CALL STRING ;message "FOR KEY".

8019 DB 50 START: IN 50H ;Check Serial or

Page 8: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

8

801B E6 08 ANI 08H ;KB mode of operation.

801D C2 2D 80 JNZ KBD

8020 CD 12 0C CALL GETCH ;Check any key pressed

8023 F5 PUSH PSW

8024 3E 01 MVI A,01 ;Clear display and

8026 CD 18 81 CALL CMD ;bring the cursor to

;home position.

8029 F1 POP PSW

802A C3 3E 80 JMP DEC

802D CD BA 03 KBD: CALL RDKBD ;Check any key pressed

8030 F5 PUSH PSW

8031 3E 01 MVI A,01 ;Clear display and

8033 CD 18 81 CALL CMD ;bring the cursor to

;home position.

8036 F1 POP PSW

8037 C6 30 ADI 30H ;Get the ASCII

;equivalent of the key

8039 FE 3A CPI 3AH ;Check whether key is

;a digit (0 to 9) or

803B D2 67 80 JNC ABCD ;HEX digit (A to F),

;If HEX digit,

;Jump to label ABCD.

803E F5 DEC: PUSH PSW

803F 3E 80 MVI A,80H ;Address for

8041 CD 18 81 CALL CMD ;first line.

8044 F1 POP PSW

8045 CD 31 81 CALL DWR

8048 0E 02 MVI C,02

804A 11 FF FF L1: LXI D,PAUSE

804D CD 4A 81 CALL DELAY

8050 0D DCR C

8051 C2 4A 80 JNZ L1

8054 3E C0 MVI A,0C0H ;Address for

8056 CD 18 81 CALL CMD ;second line.

8059 21 DA 81 LXI H,MESS ;Display the message

805C CD 51 81 CALL STRING ;"IS TYPED".

805F 3E 02 MVI A,02 ;Return the cursor

8061 CD 18 81 CALL CMD ;to home position.

8064 C3 19 80 JMP START

8067 C6 07 ABCD: ADI 07H ;Check whether

8069 FE 47 CPI 47H ;HEX digit or

806B D2 97 80 JNC NEXT ;any COMMAND key

806E F5 PUSH PSW

Page 9: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

9

806F 3E 80 MVI A,80H ;Address for

8071 CD 18 81 CALL CMD ;first line.

8074 F1 POP PSW

8075 CD 31 81 CALL DWR ;Display the

8078 0E 02 MVI C,02H ;HEX digit.

807A 11 FF FF L2: LXI D,PAUSE

807D CD 4A 81 CALL DELAY

8080 0D DCR C

8081 C2 7A 80 JNZ L2

8084 3E C0 MVI A,0C0H ;Address for

8086 CD 18 81 CALL CMD ;second line.

8089 21 DA 81 LXI H,MESS ;Display the message

808C CD 51 81 CALL STRING ;"IS TYPED".

808F 3E 02 MVI A,02 ;Bring the cursor

8091 CD 18 81 CALL CMD ;to home position.

8094 C3 19 80 JMP START

8097 01 6A 81 NEXT: LXI B,SCAN1 ;BC points the codes

;of CNTRL keys.

809A 21 5C 81 LXI H,SCAN ;HL points the

;description of keys.

809D BE NEXT2: CMP M ;compare ACC content

;with memory content.

;and check for zero.

809E C2 D9 80 JNZ NEXT1 ;No, Branch and

;compare with next

;code.

80A1 3E 80 ST1: MVI A,80H

80A3 F5 PUSH PSW

80A4 CD 18 81 CALL CMD

80A7 0A ST4: LDAX B ;Yes,display the cntrl

;key pressed.

80A8 FE 00 CPI 00H ;Is it last char.

80AA CA BA 80 JZ STOP ;Yes, stop.

80AD CD 31 81 CALL DWR ;No, disp the char

80B0 03 INX B ;Continue & disp all

80B1 F1 POP PSW ;char.

80B2 3C INR A

80B3 F5 PUSH PSW

80B4 CD 18 81 CALL CMD

80B7 C3 A7 80 JMP ST4

80BA 3E C0 STOP: MVI A,0C0H

80BC CD 18 81 CALL CMD

80BF 21 DA 81 LXI H,MESS

80C2 CD 51 81 CALL STRING

Page 10: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

10

80C5 0E 02 MVI C,02H

80C7 11 FF FF L3: LXI D,PAUSE

80CA CD 4A 81 CALL DELAY

80CD 0D DCR C

80CE C2 C7 80 JNZ L3

80D1 3E 02 MVI A,02

80D3 CD 18 81 CALL CMD

80D6 C3 19 80 JMP START

80D9 F5 NEXT1: PUSH PSW

80DA 79 MOV A,C

80DB C6 08 ADI 08H ;Set the description

80DD 4F MOV C,A ;of keycode to 8.

;i,e (SCAN1)

80DE F1 POP PSW

80DF 23 INX H

80E0 C3 9D 80 JMP NEXT2

;LCD initialization subroutine.

80E3 3E 80 INIT: MVI A,80H ;Configure 8255 in

80E5 D3 43 OUT CMD_PORT ;mode 0. Port A & B

;as O/P Ports.

80E7 11 FF 1F LXI D,NUM

80EA CD 4A 81 CALL DELAY

80ED 3E 38 MVI A,38H ;Send software

80EF CD 18 81 CALL CMD ;RESET thrice.

80F2 11 FF 1F LXI D,NUM

80F5 CD 4A 81 CALL DELAY

80F8 3E 38 MVI A,38H

80FA CD 18 81 CALL CMD

80FD 11 FF 1F LXI D,NUM

8100 CD 4A 81 CALL DELAY

8103 3E 38 MVI A,38H

8105 CD 18 81 CALL CMD

8108 3E 38 MVI A,38H ;Function set 8bit,

810A CD 18 81 CALL CMD ;2 line 5*7 font.

810D 3E 0C MVI A,0CH ;Display ON OFF

;control

810F CD 18 81 CALL CMD ;Disp ON,Cursor

;OFF,Blink OFF

8112 3E 01 MVI A,01H ;Clear display

8114 CD 18 81 CALL CMD

8117 C9 RET

;Command write subroutine.

Page 11: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

11

8118 D3 40 CMD: OUT PORT_A ;Output command

;on DB0-DB7.

811A 3E FB MVI A,FBH ;Make E R/W* RS

811C D3 41 OUT PORT_B ; 0 1 1

811E 3E F8 MVI A,F8H ;

8120 D3 41 OUT PORT_B ; 0 0 0

8122 3E FC MVI A,FCH ;

8124 D3 41 OUT PORT_B ; 1 0 0

8126 3E F8 MVI A,F8H ;

8128 D3 41 OUT PORT_B ; 0 0 0

812A 11 00 03 LXI D,0300H ;Delay loop

812D CD 4A 81 CALL DELAY ;count.

8130 C9 RET

;Data write subroutine.

8131 D3 40 DWR: OUT PORT_A ;Output data

;on DB0-DB7.

8133 3E FA MVI A,FAH ;Make E R/W* RS

8135 D3 41 OUT PORT_B ; 0 1 0

8137 3E F9 MVI A,F9H ;

8139 D3 41 OUT PORT_B ; 0 0 1

813B 3E FD MVI A,FDH ;

813D D3 41 OUT PORT_B ; 1 0 1

813F 3E F9 MVI A,F9H ;

8141 D3 41 OUT PORT_B ; 0 0 1

8143 11 00 03 LXI D,0300H ;Delay loop

8146 CD 4A 81 CALL DELAY ;count.

8149 C9 RET

814A 1B DELAY: DCX D ;Delay Routine.

814B 7A MOV A,D

814C B3 ORA E

814D C2 4A 81 JNZ DELAY

8150 C9 RET

;String write subroutine.

8151 7E STRING: MOV A,M ;Take the char to

;be disp to Acc

8152 FE 00 CPI 00H ;Is it Zero ?

8154 C8 RZ ;Yes, Return back

8155 CD 31 81 CALL DWR ;No, Display the char

8158 23 INX H ;Point to the next

Page 12: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

12

;char.

8159 C3 51 81 JMP STRING

815C 47 48 49 4A 4B SCAN: DB 47H,48H,49H,4AH,4BH,

8161 4C 4D 4E 4F 50 DB 4CH,4DH,4EH,4FH,50H,

8166 51 52 53 54 DB 51H,52H,53H,54H

816A 46 31 00 00 00 SCAN1: DB 46H,31H,00H,00H,00H,

816F 00 00 00 DB 00H,00H,00H ;F1 KEY

8172 42 4C 4B 4D 4F DB 42H,4CH,4BH,4DH,4FH,

8177 56 45 00 DB 56H,45H,00H ;BLK MOVE KEY

817A 46 32 00 00 00 DB 46H,32H,00H,00H,00H,

817F 00 00 00 DB 00H,00H,00H ;F2 KEY

8182 49 4E 53 45 52 DB 49H,4EH,53H,45H,52H,

8187 54 00 00 DB 54H,00H,00H ;INSERT KEY

818A 49 4E 42 59 54 DB 49H,4EH,42H,59H,54H,

818F 45 00 00 DB 45H,00H,00H ;IN-BYTE KEY

8192 44 45 4C 45 54 DB 44H,45H,4CH,45H,54H,

8197 45 00 00 DB 45H,00H,00H ;DELETE KEY

819A 4F 55 54 42 59 DB 4FH,55H,54H,42H,59H,

819F 54 45 00 DB 54H,45H,00H ;OUT-BYTE KEY

81A2 50 52 45 56 00 DB 50H,52H,45H,56H,00H,

81A7 00 00 00 DB 00H,00H,00H ;PREV KEY

81AA 53 47 5F 53 54 DB 53H,47H,5FH,53H,54H,

81AF 45 50 00 DB 45H,50H,00H ;SINGLE-STEP KEY

81B2 47 4F 00 00 00 DB 47H,4FH,00H,00H,00H,

81B7 00 00 00 DB 00H,00H,00H ;GO KEY

81BA 45 58 41 4D 4D DB 45H,58H,41H,4DH,4DH,

81BF 45 4D 00 DB 45H,4DH,00H ;EXAM-MEM KEY

81C2 45 58 41 4D 52 DB 45H,58H,41H,4DH,52H,

81C7 45 47 00 DB 45H,47H,00H ;EXAM-REG KEY

81CA 4E 45 58 54 00 DB 4EH,45H,58H,54H,00H,

81CF 00 00 00 DB 00H,00H,00H ;NEXT KEY

81D2 45 58 45 43 00 DB 45H,58H,45H,43H,00H,

81D7 00 00 00 DB 00H,00H,00H ;EXEC KEY

81DA 49 53 20 54 59 MESS: DB 49H,53H,20H,54H,59H,

81DF 50 45 44 20 00 DB 50H,45H,44H,20H,00H

81E4 57 41 49 54 49 DISP1: DB 57H,41H,49H,54H,49H,

81E9 4E 47 20 00 DB 4EH,47H,20H,00H

81ED 46 4F 52 20 4B DISP2: DB 46H,4FH,52H,20H,4BH,

81F2 45 59 20 00 DB 45H,59H,20H,00H

6.2 DEMONSTRATION PROGRAM FOR ESA 85-2 TRAINER

Page 13: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

13

;Assume the interface is connected over J2 of the trainer.

;The trainer can be in KEYBOARD mode or SERIAL mode.

;Execute the program from 8000H. The program is in loop, press

;RESET to come out of the program.

;When the trainer is in KEYBOARD mode it scans trainer

;keycodes.

;When the trainer is in SERIAL mode it scans system keycodes.

CMD_PORT EQU 43H

PORT_A EQU 40H

PORT_B EQU 41H

NUM EQU 01FFFH

RDKBD EQU 0514H

GETCH EQU 0B97H

PAUSE EQU 0FFFFH

ADDRESS OPCODE LABLE MNEMONIC COMMENTS

ORG 8000H

8000 CD E3 80 CALL INIT ;Call LCD initialise

;subroutine

8003 3E 80 MVI A,80H ;Address for

8005 CD 18 81 CALL CMD ;first line.

8008 21 E4 81 LXI H,DISP1 ;Display the

800B CD 51 81 CALL STRING ;message "WAITING".

800E 3E C0 MVI A,0C0H ;Address for

8010 CD 18 81 CALL CMD ;second line.

8013 21 ED 81 LXI H,DISP2 ;Display the

8016 CD 51 81 CALL STRING ;message "FOR KEY".

8019 DB 70 START: IN 70H ;Check Serial or

801B E6 08 ANI 08H ;KB mode of operation.

801D C2 2D 80 JNZ KBD

8020 CD 97 0B CALL GETCH ;Check any key pressed

8023 F5 PUSH PSW

8024 3E 01 MVI A,01 ;Clear display and

8026 CD 18 81 CALL CMD ;bring the cursor to

;home position.

8029 F1 POP PSW

802A C3 3E 80 JMP DEC

802D CD 14 05 KBD: CALL RDKBD ;Check any key pressed

8030 F5 PUSH PSW

8031 3E 01 MVI A,01 ;Clear display and

8033 CD 18 81 CALL CMD ;bring the cursor to

;home position.

Page 14: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

14

8036 F1 POP PSW

8037 C6 30 ADI 30H ;Get the ASCII

;equivalent of the key

8039 FE 3A CPI 3AH ;Check whether key is

;a digit (0 to 9)or

803B D2 67 80 JNC ABCD ;HEX digit (A to F),

;If HEX digit,

;Jump to label ABCD.

803E F5 DEC: PUSH PSW

803F 3E 80 MVI A,80H ;Address for

8041 CD 18 81 CALL CMD ;first line.

8044 F1 POP PSW

8045 CD 31 81 CALL DWR

8048 0E 02 MVI C,02

804A 11 FF FF L1: LXI D,PAUSE

804D CD 4A 81 CALL DELAY

8050 0D DCR C

8051 C2 4A 80 JNZ L1

8054 3E C0 MVI A,0C0H ;Address for

8056 CD 18 81 CALL CMD ;second line.

8059 21 DA 81 LXI H,MESS ;Display the message

805C CD 51 81 CALL STRING ;"IS TYPED".

805F 3E 02 MVI A,02 ;Return the cursor

8061 CD 18 81 CALL CMD ;to home position.

8064 C3 19 80 JMP START

8067 C6 07 ABCD: ADI 07H ;Check whether

8069 FE 47 CPI 47H ;HEX digit or

806B D2 97 80 JNC NEXT ;any COMMAND key

806E F5 PUSH PSW

806F 3E 80 MVI A,80H ;Address for

8071 CD 18 81 CALL CMD ;first line.

8074 F1 POP PSW

8075 CD 31 81 CALL DWR ;Display the

8078 0E 02 MVI C,02H ;HEX digit.

807A 11 FF FF L2: LXI D,PAUSE

807D CD 4A 81 CALL DELAY

8080 0D DCR C

8081 C2 7A 80 JNZ L2

8084 3E C0 MVI A,0C0H ;Address for

8086 CD 18 81 CALL CMD ;second line.

8089 21 DA 81 LXI H,MESS ;Display the message

808C CD 51 81 CALL STRING ;"IS TYPED".

808F 3E 02 MVI A,02 ;Bring the cursor

8091 CD 18 81 CALL CMD ;to home position.

Page 15: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

15

8094 C3 19 80 JMP START

8097 01 6A 81 NEXT: LXI B,SCAN1 ;BC points the

;description of keys.

809A 21 5C 81 LXI H,SCAN ;HL points the codes

;of CNTRL keys.

809D BE NEXT2: CMP M ;compare ACC content

;with memory content.

;and check for zero.

809E C2 D9 80 JNZ NEXT1 ;No, Branch & compare

;with next code.

80A1 3E 80 ST1: MVI A,80H

80A3 F5 PUSH PSW

80A4 CD 18 81 CALL CMD

80A7 0A ST4: LDAX B ;Yes,display the cntrl

;key pressed.

80A8 FE 00 CPI 00H ;Is it last char.

80AA CA BA 80 JZ STOP ;Yes, stop.

80AD CD 31 81 CALL DWR ;No, disp the char

80B0 03 INX B ;Continue & disp all

80B1 F1 POP PSW ;char.

80B2 3C INR A

80B3 F5 PUSH PSW

80B4 CD 18 81 CALL CMD

80B7 C3 A7 80 JMP ST4

80BA 3E C0 STOP: MVI A,0C0H

80BC CD 18 81 CALL CMD

80BF 21 DA 81 LXI H,MESS

80C2 CD 51 81 CALL STRING

80C5 0E 02 MVI C,02H

80C7 11 FF FF L3: LXI D,PAUSE

80CA CD 4A 81 CALL DELAY

80CD 0D DCR C

80CE C2 C7 80 JNZ L3

80D1 3E 02 MVI A,02

80D3 CD 18 81 CALL CMD

80D6 C3 19 80 JMP START

80D9 F5 NEXT1: PUSH PSW

80DA 79 MOV A,C

80DB C6 08 ADI 08H ;Set the description

80DD 4F MOV C,A ;of keycode to 8.

;i,e (SCAN1)

80DE F1 POP PSW

80DF 23 INX H

Page 16: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

16

80E0 C3 9D 80 JMP NEXT2

;LCD initialization subroutine.

80E3 3E 80 INIT: MVI A,80H ;Configure 8255 in

80E5 D3 43 OUT CMD_PORT ;mode 0. Port A & B

;as O/P Ports.

80E7 11 FF 1F LXI D,NUM

80EA CD 4A 81 CALL DELAY

80ED 3E 38 MVI A,38H ;Send software

80EF CD 18 81 CALL CMD ;RESET thrice.

80F2 11 FF 1F LXI D,NUM

80F5 CD 4A 81 CALL DELAY

80F8 3E 38 MVI A,38H

80FA CD 18 81 CALL CMD

80FD 11 FF 1F LXI D,NUM

8100 CD 4A 81 CALL DELAY

8103 3E 38 MVI A,38H

8105 CD 18 81 CALL CMD

8108 3E 38 MVI A,38H ;Function set 8bit,

810A CD 18 81 CALL CMD ;2 line 5*7 font.

810D 3E 0C MVI A,0CH ;Display ON OFF

;control

810F CD 18 81 CALL CMD ;Disp ON, Cursor

;'OFF, Blink OFF

8112 3E 01 MVI A,01H ;Clear display

8114 CD 18 81 CALL CMD

8117 C9 RET

;Command write subroutine.

8118 D3 40 CMD: OUT PORT_A ;Output command

;on DB0-DB7.

811A 3E FB MVI A,FBH ;Make E R/W* RS

811C D3 41 OUT PORT_B ; 0 1 1

811E 3E F8 MVI A,F8H ;

8120 D3 41 OUT PORT_B ; 0 0 0

8122 3E FC MVI A,FCH ;

8124 D3 41 OUT PORT_B ; 1 0 0

8126 3E F8 MVI A,F8H ;

8128 D3 41 OUT PORT_B ; 0 0 0

812A 11 00 03 LXI D,0300H ;Delay loop

812D CD 4A 81 CALL DELAY ;count.

8130 C9 RET

Page 17: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

17

;Data write subroutine.

8131 D3 40 DWR: OUT PORT_A ;Output data

;on DB0-DB7.

8133 3E FA MVI A,FAH ;Make E R/W* RS

8135 D3 41 OUT PORT_B ; 0 1 0

8137 3E F9 MVI A,F9H ;

8139 D3 41 OUT PORT_B ; 0 0 1

813B 3E FD MVI A,FDH ;

813D D3 41 OUT PORT_B ; 1 0 1

813F 3E F9 MVI A,F9H ;

8141 D3 41 OUT PORT_B ; 0 0 1

8143 11 00 03 LXI D,0300H ;Delay loop

8146 CD 4A 81 CALL DELAY ;count.

8149 C9 RET

814A 1B DELAY: DCX D ;Delay Routine.

814B 7A MOV A,D

814C B3 ORA E

814D C2 4A 81 JNZ DELAY

8150 C9 RET

;String write subroutine.

8151 7E STRING: MOV A,M ;Take the char to

;be disp to Acc

8152 FE 00 CPI 00H ;Is it Zero ?

8154 C8 RZ ;Yes, Return back

8155 CD 31 81 CALL DWR ;No, Display the char

8158 23 INX H ;Point to the next

;char.

8159 C3 51 81 JMP STRING

815C 47 48 49 4A 4B SCAN: DB 47H,48H,49H,4AH,4BH,

8161 4C 4D 4E 4F 50 DB 4CH,4DH,4EH,4FH,50H,

8166 51 52 53 54 DB 51H,52H,53H,54H

816A 46 31 00 00 00 SCAN1: DB 46H,31H,00H,00H,00H,

816F 00 00 00 DB 00H,00H,00H ;F1 KEY

8172 42 4C 4B 4D 4F DB 42H,4CH,4BH,4DH,4FH,

8177 56 45 00 DB 56H,45H,00H ;BLK MOVE KEY

817A 43 4F 4D 50 00 DB 43H,4FH,4DH,50H,00H,

817F 00 00 00 DB 00H,00H,00H ;COMP KEY

8182 49 4E 53 45 52 DB 49H,4EH,53H,45H,52H,

Page 18: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

18

8187 54 00 00 DB 54H,00H,00H ;INSERT KEY

818A 49 4E 42 59 54 DB 49H,4EH,42H,59H,54H,

818F 45 00 00 DB 45H,00H,00H ;IN-BYTE KEY

8192 44 45 4C 45 54 DB 44H,45H,4CH,45H,54H,

8197 45 00 00 DB 45H,00H,00H ;DELETE KEY

819A 4F 55 54 42 59 DB 4FH,55H,54H,42H,59H,

819F 54 45 00 DB 54H,45H,00H ;OUT-BYTE KEY

81A2 50 52 45 56 00 DB 50H,52H,45H,56H,00H,

81A7 00 00 00 DB 00H,00H,00H ;PREV KEY

81AA 53 47 5F 53 54 DB 53H,47H,5FH,53H,54H,

81AF 45 50 00 DB 45H,50H,00H ;SINGLE-STEP

;KEY

81B2 47 4F 00 00 00 DB 47H,4FH,00H,00H,00H,

81B7 00 00 00 DB 00H,00H,00H ;GO KEY

81BA 45 58 41 4D 4D DB 45H,58H,41H,4DH,4DH,

81BF 45 4D 00 DB 45H,4DH,00H ;EXAM-MEM KEY

81C2 45 58 41 4D 52 DB 45H,58H,41H,4DH,52H,

81C7 45 47 00 DB 45H,47H,00H ;EXAM-REG KEY

81CA 4E 45 58 54 00 DB 4EH,45H,58H,54H,00H,

81CF 00 00 00 DB 00H,00H,00H ;NEXT KEY

81D2 45 58 45 43 00 DB 45H,58H,45H,43H,00H,

81D7 00 00 00 DB 00H,00H,00H ;EXEC KEY

81DA 49 53 20 54 59 MESS: DB 49H,53H,20H,54H,59H,

81DF 50 45 44 20 00 DB 50H,45H,44H,20H,00H

81E4 57 41 49 54 49 DISP1: DB 57H,41H,49H,54H,49H,

81E9 4E 47 20 00 DB 4EH,47H,20H,00H

81ED 46 4F 52 20 4B DISP2: DB 46H,4FH,52H,20H,4BH,

81F2 45 59 20 00 DB 45H,59H,20H,00H

6.3 DEMONSTRATION PROGRAM FOR ESA 31 TRAINER

;Assume the interface is connected over J2 of the trainer.

;The trainer can be in KB mode or SERIAL mode.

;Execute the program from 8000H. The program is in loop, press

;RESET to come out of the program.

;When the trainer is in KEYBOARD mode it scans trainer

;keycodes.

;When the trainer is in SERIAL mode it scans system keycodes.

CMD_PORT EQU 03H

PORT_A EQU 00H

PORT_B EQU 01H

RDKBD EQU 02A2H

Page 19: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

19

GETCH EQU 016E2H

ADDRESS OPCODE LABLE MNEMONIC COMMENTS

ORG 8000H

8000 11 AE ACALL INIT ;Call LCD

;initialise

;subroutine.

8002 74 80 MOV A,#80H ;Address for

8004 12 80 D9 LCALL CMD ;first line.

8007 90 81 DD MOV DPTR,#DISP1 ;Display the

800A 7B 08 MOV R3,#08H ;message WAITING.

800C 12 81 20 LCALL STRING

800F 74 C0 MOV A,#0C0H ;Address for

8011 12 80 D9 LCALL CMD ;second line.

8014 90 81 E6 MOV DPTR,#DISP2 ;Display the

8017 7B 08 MOV R3,#08H ;message FOR KEY.

8019 12 81 20 LCALL STRING

801C 7E 80 START: MOV R6,#80H ;Check Serial or

801E 90 E1 02 MOV DPTR,#0E102H ;KB mode of

;operation.

8021 E0 MOVX A,@DPTR

8022 20 E3 0E JB ACC.3,KBD

8025 12 16 E2 LCALL GETCH ;Check any key

;pressed.

8028 C0 E0 PUSH A

802A 74 01 MOV A,#01H ;Clear display and

802C 12 80 D9 LCALL CMD ;bring the cursor

802F D0 E0 POP A ;to home position.

8031 80 11 SJMP DISPLY

8033 12 02 A2 KBD: LCALL RDKBD ;Check any key

;pressed.

8036 C0 E0 PUSH A

8038 74 01 MOV A,#01H ;Clear display and

803A 12 80 D9 LCALL CMD ;bring the cursor

803D D0 E0 POP A ;to home position.

803F 24 30 ADD A,#30H ;Convert into

;ASCII

8041 B4 39 29 CJNE A,#39H,ABCD ;Is the key code =

;'39H'?

8044 C0 E0 DISPLY: PUSH A

8046 74 80 MOV A,#80H ;Address for

8048 12 80 D9 LCALL CMD ;first line.

804B D0 E0 POP A

804D 12 80 F9 LCALL DWR ;Display the key.

Page 20: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

20

8050 7B 01 DELAY2: MOV R3,#01H

8052 79 FF L1: MOV R1,#0FFH

8054 12 81 19 LCALL DELAY

8057 DB F9 DJNZ R3,L1

8059 74 C0 MOV A,#0C0H ;Address for

805B 12 80 D9 LCALL CMD ;second line.

805E 90 81 D3 MOV DPTR,#MESS ;Display the

;message

8061 7B 08 MOV R3,#08H ;IS TYPED.

8063 12 81 20 LCALL STRING

8066 74 02 MOV A,#02H ;Return the cursor

8068 12 80 D9 LCALL CMD ;to home position.

806B 01 1C AJMP START

806D 40 D5 ABCD: JC DISPLY ;Is the key code <

;39H?

806F 24 07 ADD A,#07H ;No, ASCII adjust

;or HEX digit

8071 B4 46 02 CJNE A,#46H,NEXT ;Is the key code =

;'46H' i.e,'F'

8074 80 CE SJMP DISPLY ;Yes, display the

;key

8076 40 CC NEXT: JC DISPLY ;Is the key code <

;'46H'?

8078 F5 F0 MOV B,A ;No, then it is a

;CNTRL key

807A 90 81 43 MOV DPTR,#SCAN1 ;Load the address

;of description of

807D A8 82 MOV R0,DPL ;command keys into

807F A9 83 MOV R1,DPH ;R0 & R1

8081 90 81 28 MOV DPTR,#SCAN ;Dptr to point to

;command key codes

;TABLE

8084 E4 NEXT2: CLR A

8085 93 MOVC A,@A+DPTR ;Get the command

;key code from

;table

8086 B5 F0 1A CJNE A,B,NEXT1 ;Is it same as the

;key pressed ?

8089 88 82 ST1: MOV DPL,R0 ;Yes, display the

;description

808B 89 83 MOV DPH,R1 ;of the key

808D E4 ST3: CLR A

Page 21: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

21

808E 93 MOVC A,@A+DPTR

808F B4 00 02 CJNE A,#00H,ST2 ;Is it last char

;of the description?

8092 01 50 JMP DELAY2 ;Yes, go back

8094 C0 E0 ST2: PUSH A

8096 EE MOV A,R6

8097 12 80 D9 LCALL CMD

809A D0 E0 POP A

809C 12 80 F9 LCALL DWR ;No, display

;the char

809F A3 INC DPTR ;Inc dptr to

;display next char

80A0 0E INC R6

80A1 01 8D JMP ST3

80A3 A3 NEXT1: INC DPTR ;No, Inc dptr to

;point to next

80A4 E8 MOV A,R0 ;keycode

80A5 24 08 ADD A,#08H ;Increment R0 & R1

;pair by '08H'

80A7 F8 MOV R0,A ;to point the

;description of

80A8 E9 MOV A,R1 ;the next key code

80A9 34 00 ADDC A,#00H

80AB F9 MOV R1,A

80AC 01 84 JMP NEXT2

;LCD initialisation subroutine.

80AE 74 80 INIT: MOV A,#80H ;Configure 8255 for

80B0 75 A0 E8 MOV P2,#0E8H ;mode 0.

80B3 78 03 MOV R0,#03H ;Port A & B as

80B5 F2 MOVX @R0,A ;O/P ports.

80B6 79 1F MOV R1,#1FH

80B8 12 81 19 LCALL DELAY

80BB 7B 03 MOV R3,#03H ;Send software

;reset 3 times to

80BD 74 38 INIT1: MOV A,#38H ;reset the display

80BF 12 80 D9 LCALL CMD

80C2 79 3F MOV R1,#3FH

80C4 12 81 19 LCALL DELAY

80C7 DB F4 DJNZ R3,INIT1

80C9 74 38 MOV A,#38H ;Function set 8bit,

80CB 12 80 D9 LCALL CMD ;1 line 5x7 font.

80CE 74 0C MOV A,#0CH ;Display on off

Page 22: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

22

80D0 12 80 D9 LCALL CMD ;control disp on,

;cursor off, blink

;off

80D3 74 01 MOV A,#01H ;clear display

80D5 12 80 D9 LCALL CMD

80D8 22 RET

;Command write subroutine.

80D9 75 A0 E8 CMD: MOV P2,#0E8H ;Output command

80DC 78 00 MOV R0,#PORT_A ;on DB0-DB7.

80DE F2 MOVX @R0,A

80DF 74 FB MOV A,#0FBH ;Make E R/W* RS

80E1 78 01 MOV R0,#PORT_B ; 0 1 1

80E3 F2 MOVX @R0,A ;

80E4 74 F8 MOV A,#0F8H ;

80E6 78 01 MOV R0,#PORT_B ; 0 0 0

80E8 F2 MOVX @R0,A ;

80E9 74 FC MOV A,#0FCH ;

80EB 78 01 MOV R0,#PORT_B ; 1 0 0

80ED F2 MOVX @R0,A ;

80EE 74 F8 MOV A,#0F8H ;

80F0 78 01 MOV R0,#PORT_B ; 0 0 0

80F2 F2 MOVX @R0,A

80F3 79 10 MOV R1,#10H ;Delay loop count.

80F5 12 81 19 LCALL DELAY

80F8 22 RET

;Data write subroutine.

80F9 75 A0 E8 DWR: MOV P2,#0E8H ;Output data

80FC 78 00 MOV R0,#PORT_A ;on DB0-DB7.

80FE F2 MOVX @R0,A

80FF 74 FA MOV A,#0FAH ;Make E R/W* RS

8101 78 01 MOV R0,#PORT_B ; 0 1 0

8103 F2 MOVX @R0,A ;

8104 74 F9 MOV A,#0F9H ;

8106 78 01 MOV R0,#PORT_B ; 0 0 1

8108 F2 MOVX @R0,A ;

8109 74 FD MOV A,#0FDH ;

810B 78 01 MOV R0,#PORT_B ; 1 0 1

810D F2 MOVX @R0,A ;

810E 74 F9 MOV A,#0F9H ;

Page 23: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

23

8110 78 01 MOV R0,#PORT_B ; 0 0 1

8112 F2 MOVX @R0,A

8113 79 10 MOV R1,#10H ;Delay loop count.

8115 12 81 19 LCALL DELAY

8118 22 RET

;Delay subroutine.

8119 7A 02 DELAY: MOV R2,#02H

811B DA FE DLY: DJNZ R2,DLY

811D D9 FC DJNZ R1,DLY

811F 22 RET

;String write subroutine.

8120 E4 STRING: CLR A

8121 93 MOVC A,@A+DPTR ;Get the char

;to be displayed

8122 11 F9 ACALL DWR ;display it

8124 A3 INC DPTR ;Point to the

;next char

8125 DB F9 DJNZ R3,STRING ;Is all char

;over ?

8127 22 RET ;Yes, return

;back

8128 47 48 49 4A 4B SCAN: DB 47H,48H,49H,4AH,4BH,

812D 4C 4D 4E 4F 50 DB 4CH,4DH,4EH,4FH,50H,

8132 51 52 53 54 DB 51H,52H,53H,54H

8136 55 56 57 58 59 DB 55H,56H,57H,58H,59H,

813B 5A 5B 5C 5D 5E DB 5AH,5BH,5CH,5DH,5EH,

8140 5F 60 61 DB 5FH,60H,61H

8143 53 45 54 20 42 SCAN1: DB 53H,45H,54H,20H,42H,

8148 52 4B 00 DB 52H,4BH,00H ; SET BRK KEY

814B 43 4C 52 20 42 DB 43H,4CH,52H,20H,42H,

8150 52 4B 00 DB 52H,4BH,00H ; CLR BRK KEY

8153 45 4E 41 20 42 DB 45H,4EH,41H,20H,42H,

8158 52 4B 00 DB 52H,4BH,00H ; ENA BRK KEY

815B 44 53 41 20 42 DB 44H,53H,41H,20H,42H,

8160 52 4B 00 DB 52H,4BH,00H ; DSA BRK KEY

8163 4E 45 58 54 00 DB 4EH,45H,58H,54H,00H,

8168 00 00 00 DB 00H,00H,00H ; NEXT KEY

816B 50 52 45 56 00 DB 50H,52H,45H,56H,00H,

8170 00 00 00 DB 00H,00H,00H ; PREV KEY

8173 50 52 47 20 4D DB 50H,52H,47H,20H,4DH,

Page 24: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

24

8178 45 4D 00 DB 45H,4DH,00H ; PRG MEM KEY

817B 45 58 54 20 44 DB 45H,58H,54H,20H,44H,

8180 41 54 00 DB 41H,54H,00H ; EXT DAT KEY

8183 46 49 4C 4C 00 DB 46H,49H,4CH,4CH,00H,

8188 00 00 00 DB 00H,00H,00H ; FILL KEY

818B 43 4F 4D 50 00 DB 43H,4FH,4DH,50H,00H,

8190 00 00 00 DB 00H,00H,00H ; COMP KEY

8193 53 47 2D 53 54 DB 53H,47H,2DH,53H,54H,

8198 45 50 00 DB 45H,50H,00H ; SG_STEP KEY

819B 42 4C 4B 20 4D DB 42H,4CH,4BH,20H,4DH,

81A0 4F 56 00 DB 4FH,56H,00H ; BLK MOV KEY

81A3 45 58 4D 20 52 DB 45H,58H,4DH,20H,52H,

81A8 45 47 00 DB 45H,47H,00H ; EXM REG KEY

81AB 45 58 4D 20 4D DB 45H,58H,4DH,20H,4DH,

81B0 45 4D 00 DB 45H,4DH,00H ; EXM MEM KEY

81B3 47 4F 00 00 00 DB 47H,4FH,00H,00H,00H,

81B8 00 00 00 DB 00H,00H,00H ; GO KEY

81BB 45 58 45 43 00 DB 45H,58H,45H,43H,00H,

81C0 00 00 00 DB 00H,00H,00H ; EXEC KEY

81C3 42 49 54 20 4D DB 42H,49H,54H,20H,4DH,

81C8 45 4D 00 DB 45H,4DH,00H ; BIT MEM KEY

81CB 49 4E 54 20 44 DB 49H,4EH,54H,20H,44H,

81D0 41 54 00 DB 41H,54H,00H ; INT DAT KEY

81D3 49 53 20 54 59 MESS: DB 49H,53H,20H,54H,59H,

81D8 50 45 44 20 00 DB 50H,45H,44H,20H,00H

81DD 57 41 49 54 49 DISP1:DB 57H,41H,49H,54H,49H,

81E2 4E 47 20 00 DB 4EH,47H,20H,00H

81E6 46 4F 52 20 4B DISP2:DB 46H,4FH,52H,20H,4BH,

81EB 45 59 20 00 DB 45H,59H,20H,00H

6.4 DEMONSTRATION PROGRAM FOR ESA 86/88-2 TRAINER

;Assume the interface is connected over J4 of the trainer.

;The trainer can be in KEYBOARD MODE or SERIAL MODE.

;Execute the program from 2100H. The program is in a

;continuous loop, press RESET to come out of the program.

;When it is in KEYBOARD MODE, it will scan trainer keycodes.

;When it is in SERIAL MODE, it will scan system keycodes.

PORT_A EQU 0FFE0H

PORT_B EQU 0FFE2H

PORT_C EQU 0FFE4H

Page 25: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

25

CTRLPRT EQU 0FFE6H

NUM EQU 0FFFH

PAUSE EQU 0FFFFH

RDKBD EQU 0FF00:0B1CH

SE_RDKBD EQU 0FE00:1B70H

SCAN EQU 2300H

SCAN1 EQU 2400H

DISP1 EQU 2500H

DISP2 EQU 2600H

ORG 2100H

CS = 0

ADDRESS OPCODE LABLE MNEMONIC COMMENTS

2100 E8 E3 00 CALL INIT ;Call LCD initialise

;subroutine

2103 B8 80 00 MOVW AX,#80H ;Address for 1st line

2106 E8 0A 01 CALL CMD

2109 BB 00 25 MOVW BX,DISP1 ;Display the word

;WAITING

210C BE 08 00 MOVW SI,#08H

210F E8 38 01 CALL STRING

2112 B8 C0 00 MOVW AX,#0C0H ;Address for 2nd line

2115 E8 FB 00 CALL CMD

2118 BB 00 26 MOVW BX,DISP2 ;Display the word FOR

;KEY.

211B BE 08 00 MOVW SI,#08H

211E E8 29 01 CALL STRING

2121 BA ED FF START: MOVW DX,#0FFEDH;Read the DIP

;switch.

2124 EC INB DX

2125 24 80 ANDB AL,#80H ;Checks for SERIAL

;or KEYBOARD MODE.

2127 74 10 JZ KBD ;Go to KEYBOARD

;MODE.

2129 9A 70 1B 00 FE CALLS SE_RDKBD ;SERIAL MODE.

;Waiting for

212E 50 PUSH AX ;key to be pressed.

212F B8 01 00 MOVW AX,01 ;Clear the LCD

;display.

2132 E8 DE 00 CALL CMD

2135 58 POP AX

2136 E9 13 00 JMP DEC

Page 26: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

26

2139 9A 1C 0B 00 FF KBD:CALLS RDKBD ;Waiting for key to

;be pressed.

213E 50 PUSH AX

213F B8 01 00 MOVW AX,#01

2142 E8 CE 00 CALL CMD

2145 58 POP AX

2146 04 30 ADDB AL,#30H ;Convert the

;keycode to ASCII

2148 3C 39 CMPB AL,#39H ;Is it DECIMAL

;digit ?

214A 7F 38 JG ABCD ;No, Then display

;HEX digit.

214C 50 DEC: PUSH AX

214D B8 80 00 MOVW AX,#80H

2150 E8 C0 00 CALL CMD

2153 58 POP AX

2154 E8 D6 00 CALL DWR ;Yes, Display the

;DECIMAL digit.

2157 B8 C0 00 DEC1: MOVW AX,#0C0H ;Send the message

215A E8 B6 00 CALL CMD ;IS TYPED to

215D BB 70 22 MOVW BX,MESS ;2nd line of LCD

;display.

2160 BE 08 00 MOVW SI,#08H

2163 E8 E4 00 CALL STRING

2166 B8 02 00 MOVW AX,#02H

2169 B9 FF FF LOOP: MOVW CX,PAUSE ;Wait for sometime

216C E8 D8 00 CALL DELAY

216F E8 D5 00 CALL DELAY

2172 E8 D2 00 CALL DELAY

2175 48 DECW AX

2176 3D 00 00 CMPW AX,#00H

2179 75 EE JNZ LOOP

217B B8 02 00 MOVW AX,#02 ;Move the LCD

;display cursor

217E E8 92 00 CALL CMD ;to home position.

2181 E9 9D FF JMP START

2184 04 07 ABCD: ADDB AL,#07H ;Adjust the key

;code to ASCII

2186 3C 46 CMPB AL,#46H ;Is it HEX digit ?

2188 7F 03 JG NEXT ;No, Then display

;the CNTRL key

218A E9 BF FF JMP DEC ;Display the HEX

;digit.

Page 27: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

27

218D BA 00 24 NEXT: MOVW DX,SCAN1 ;DX points the

;description

;of keys.

2190 BB 00 23 MOVW BX,SCAN ;BX points the

;codes of

;CNTRL keys.

2193 8A 27 NEXT2: MOVB AH,[BX]

2195 3A E0 CMPB AH,AL ;Is the CODE in AL

;same as pointed

;by BX

2197 75 46 JNZ NEXT1 ;No, Branch and

;compare with

;NEXT code

2199 8B DA MOVW BX,DX ;YES, Disp the

;CNTRL key

;pressed.

219B B8 80 00 ST1: MOVW AX,#80H

219E 50 PUSH AX

219F E8 71 00 CALL CMD

21A2 8A 07 ST4: MOVB AL,[BX]

21A4 3C 00 CMPB AL,#00H ;Is it last char

21A6 74 0D JZ STOP ;Yes STOP

21A8 E8 82 00 CALL DWR ;No, Display the

;char

21AB 43 INCW BX

21AC 58 POP AX

21AD 40 INCW AX

21AE 50 PUSH AX

21AF E8 61 00 CALL CMD

21B2 E9 ED FF JMP ST4

21B5 B8 C0 00 STOP: MOVW AX,#0C0H

21B8 E8 58 00 CALL CMD

21BB BB 70 22 MOVW BX,MESS

21BE BE 08 00 MOVW SI,#08H

21C1 E8 86 00 CALL STRING

21C4 B8 02 00 MOVW AX,#02H

21C7 B9 FF FF LOOP1: MOVW CX,PAUSE

21CA E8 7A 00 CALL DELAY

21CD E8 77 00 CALL DELAY

21D0 E8 74 00 CALL DELAY

21D3 48 DECW AX

21D4 75 F1 JNZ LOOP1

21D6 E9 42 FF JMP START

21D9 83 C2 08 NEXT1: ADDW DX,#0008H ;Increment DX by 08

Page 28: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

28

;to point the

21DC 43 INCW BX ;Description of

21DD E9 AD FF JMP NEXT2 ;next keycodes.

;LCD initialisation subroutine.

21E0 B0 80 INIT: MOVB AL,#80H ;Configure PA,PB,PC

21E2 BA E6 FF MOVW DX,CTRLPRT ;as output ports.

21E5 EE OUTB DX

21E6 B9 FF 0F MOVW CX,NUM

21E9 E8 55 00 CALL DELAY

21EC B3 03 MOVB BL,#03H ;Send software

;RESET 3 times

21EE B0 38 INIT1: MOVB AL,#38H ;to Reset the

;display.

21F0 E8 1A 00 CALL CMD

21F3 B9 FF 0F MOVW CX,NUM

21F6 E8 48 00 CALL DELAY

21F9 FE CB DECB BL

21FB 75 F1 JNZ INIT1

21FD B0 38 MOVB AL,#38H ;Function set

;8 bit, 1 line

21FF E8 0B 00 CALL CMD ;5*7 FONT

2202 B0 0C MOVB AL,#0CH ;Display ON OFF

;control

2204 E8 06 00 CALL CMD ;Display ON, cursor

;OFF, blink OFF

2207 B0 01 MOVB AL,#01H ;Clear display

2209 E8 01 00 CALL CMD

220C C3 RET

;Command write subroutine.

220D BA E0 FF CMD: MOVW DX,PORT_A ;Output command

2210 EE OUTB DX ;on DB0-DB7.

2211 B0 FB MOVB AL,#0FBH ;Make E R/W* RS

2213 BA E2 FF MOVW DX,PORT_B ; 0 1 1

2216 EE OUTB DX

2217 B0 F8 MOVB AL,#0F8H ; 0 0 0

2219 EE OUTB DX

221A B0 FC MOVB AL,#0FCH ; 1 0 0

221C EE OUTB DX

221D B0 F8 MOVB AL,#0F8H ; 0 0 0

221F EE OUTB DX

Page 29: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

29

2220 B9 FF 0F MOVW CX,#0FFFH

2223 E8 1B 00 CALL DELAY ;Delay loop

2226 C3 RET

;Data write subroutine.

2227 BA E0 FF DWR: MOVW DX,PORT_A ;Output data

222A EE OUTB DX ;on DB0-DB7.

222B B0 FA MOVB AL,#0FAH ;Make E R/W* RS

222D BA E2 FF MOVW DX,PORT_B ; 0 1 0

2230 EE OUTB DX

2231 B0 F9 MOVB AL,#0F9H ; 0 0 1

2233 EE OUTB DX

2234 B0 FD MOVB AL,#0FDH ; 1 0 1

2236 EE OUTB DX

2237 B0 F9 MOVB AL,#0F9H ; 0 0 1

2239 EE OUTB DX

223A B9 FF 7F MOVB CX,#7FFFH ;Delay routine.

223D E8 01 00 CALL DELAY

2240 C3 RET

;Delay subroutine.

2241 E2 FE DELAY: LOOP DELAY

2243 C3 RET

;String write subroutine.

2244 8A 07 STRING: MOVB AL,[BX] ;Display the char

;pointed by BX

2246 E8 DE FF CALL DWR

2249 43 INCW BX ;Increment the BX

;to point to next

224A 4E DECW SI ;char, Check all

;char are over.

224B 75 F7 JNZ STRING ;No, Display the

;next char

224D C3 RET ;Yes, Return back.

ORG 2270H

2270 49 53 20 54 59 50 DB 49H,53H,20H,54H,59H,50H,

2276 45 44 20 00 45H,44H,20H,00H

ORG 2300H

Page 30: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

30

2300 47 48 49 4A 4B 4C DB 47H,48H,49H,4AH,4BH,4CH,

2306 4D 4E 4F 50 51 52 4DH,4EH,4FH,50H,51H,52H,

230C 53 54 53H,54H

230E 55 56 57 58 59 5A DB 55H,56H,57H,58H,59H,5AH,5BH

2314 5B

ORG 2400H

2400 45 58 45 43 00 00 DB 45H,58H,45H,43H,00H,00H,

2406 00 00 00H,00H ; EXEC KEY

2408 4E 45 58 54 00 00 DB 4EH,45H,58H,54H,00H,00H,

240E 00 00 00H,00H ; NEXT KEY

2410 2D 00 00 00 00 00 DB 2DH,00H,00H,00H,00H,00H,

2416 00 00 00H,00H ; '-' KEY

2418 2B 00 00 00 00 00 DB 2BH,00H,00H,00H,00H,00H,

241E 00 00 00H,00H ; '+' KEY

2420 4F 46 46 53 45 54 DB 4FH,46H,46H,53H,45H,54H,

2426 00 00 00H,00H ; OFFSET KEY

2428 52 45 47 00 00 00 DB 52H,45H,47H,00H,00H,00H,

242E 00 00 00H,00H ; REG KEY

2430 46 31 00 00 00 00 DB 46H,31H,00H,00H,00H,00H,

2436 00 00 00H,00H ; F1 KEY

2438 46 32 00 00 00 00 DB 46H,32H,00H,00H,00H,00H,

243E 00 00 00H,00H ; F2 KEY

2440 46 33 00 00 00 00 DB 46H,33H,00H,00H,00H,00H,

2446 00 00 00H,00H ; F3 KEY

2448 46 34 00 00 00 00 DB 46H,34H,00H,00H,00H,00H,

244E 00 00 00H,00H ; F4 KEY

2450 50 52 45 56 00 00 DB 50H,52H,45H,56H,00H,00H,

2456 00 00 00H,00H ; PREV KEY

2458 46 35 00 00 00 00 DB 46H,36H,00H,00H,00H,00H,

245E 00 00 00H,00H ; F6 KEY

2460 46 36 00 00 00 00 DB 46H,35H,00H,00H,00H,00H,

2466 00 00 00H,00H ; F5 KEY

2468 46 37 00 00 00 00 DB 46H,37H,00H,00H,00H,00H,

246E 00 00 00H,00H ; F7 KEY

ORG 2500H

2500 57 41 49 54 49 4E DB 57H,41H,49H,54H,49H,4EH,

2506 47 20 00 47H,20H,00H

ORG 2600H

2600 46 4F 52 20 4B 45 DB 46H,4FH,52H,20H,4BH,45H,

2606 59 20 00 59H,20H,00H

Page 31: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

31

6.5 DEMONSTRATION PROGRAM FOR ESA 80 TRAINER

;Assume the interface is connected over J2 of the trainer.

;The trainer can be in KEYBOARD mode or SERIAL mode.

;Execute the program from 8000H. The program is in a

;continuous loop, press RESET to come out of the program.

;When it is in KEYBOARD MODE, it will scan trainer keycodes.

;When it is in SERIAL MODE, it will scan system keycodes.

CMD_PORT EQU 43H

PORT_A EQU 40H

PORT_B EQU 41H

NUMH EQU 1FH

NUML EQU 0FFH

GETCH EQU 0C12H

RDKBD EQU 05FEH

PAUSE EQU 0FFFFH

HEX7SG EQU 0678H

ADDRESS OPCODE LABLE MNEMONIC COMMENTS

ORG 8000H

8000 CD E3 80 CALL INIT ;Call LCD initialise

;subroutine

8003 3E 80 LD A,80H ;Address for

8005 CD CB 80 CALL CMD ;first line.

8008 DD 21 56 81 LD IX,DISP1 ;Display the

800C 2E 08 LD L,08H ;message WAITING.

800E CD 39 81 CALL STRING

8011 3E C0 LD A,C0H ;Address for

8013 CD CB 80 CALL CMD ;second line.

8016 DD 21 5F 81 LD IX,DISP2 ;Display the

801A 2E 08 LD L,08H ;message FOR KEY.

801C CD 39 81 CALL STRING

801F DB 50 START: IN A,(50H) ;Check Serial or

8021 E6 08 AND A,08H ;KB mode of

;operation.

8023 C2 2D 80 JP NZ,KBD

8026 CD 12 0C CALL GETCH ;Check any key

;pressed.

8029

8029 79 LD A,C

802A C3 A1 80 JP DEC

802D DD 21 46 81 KBD: LD IX,OUTBUF ;Initialize IX to

8031 CD FE 05 CALL RDKBD ;outbuf to blank

Page 32: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

32

8034 F5 PUSH AF ;7-seg display of

8035 3E 01 LD A,01H ;the trainer.

8037 CD CB 80 CALL CMD

803A F1 POP AF

803B C6 30 ADD A,30H

803D FE 3A CP 3AH

803F D2 45 80 JP NC,ABCD

8042 C3 A1 80 JP DEC

8045 C6 07 ABCD: ADD A,07H

8047 FE 47 CP 47H

8049 D2 4F 80 JP NC,NEXT

804C C3 A1 80 JP DEC

804F DD 21 78 81 NEXT: LD IX,SCAN1;IX points the codes

;of CNTRL keys

8053 21 68 81 LD HL,SCAN ;HL points the

;description of

;keys.

8056 4E NEXT2: LD C,(HL) ;compare ACC content

8057 B9 CP A,C ;with memory content

8058 C2 96 80 JP NZ,NEXT1 ;and check for zero.

;No, Branch and

;compare with next

;code.

805B 3E 80 ST1: LD A,80H

805D F5 PUSH AF

805E CD CB 80 CALL CMD

8061 DD 7E 00 ST4: LD A,(IX) ;Yes,display the

;cntrl key pressed.

8064 FE 00 CP 00H

8066 28 0E JR Z,STOP

8068 CD 1A 81 CALL DWR

806B DD 23 INC IX

806D F1 POP AF

806E 3C INC A

806F F5 PUSH AF

8070 CD CB 80 CALL CMD

8073 C3 61 80 JP ST4

8076 3E C0 STOP: LD A,0C0H

8078 CD CB 80 CALL CMD

807B DD 21 4C 81 LD IX,MESS

807F 2E 08 LD L,08

8081 CD 39 81 CALL STRING

8084 26 10 LD H,010H

8086 1E FF L1: LD E,0FFH

Page 33: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

33

8088 CD 34 81 CALL DELAY

808B 25 DEC H

808C 20 F8 JR NZ,L1

808E 3E 02 LD A,02

8090 CD CB 80 CALL CMD

8093 C3 1F 80 JP START

8096 0E 08 NEXT1: LD C,08H ;Set the description

8098 DD 23 NEXT3: INC IX ;of keycode to 8.

809A 0D DEC C ;i,e (SCAN1)

809B 20 FB JR NZ,NEXT3

809D 23 INC HL

809E C3 56 80 JP NEXT2

80A1 F5 DEC: PUSH AF

80A2 3E 01 LD A,01H ;Clear display and

80A4 CD CB 80 CALL CMD ;bring the cursor to

80A7 3E 80 LD A,80H ;home position

80A9 CD CB 80 CALL CMD

80AC F1 POP AF

80AD CD 1A 81 CALL DWR

80B0 26 10 WAIT: LD H,010H ;WAIT FOR SOME TIME

80B2 1E FF L5: LD E,0FFH

80B4 CD 34 81 CALL DELAY

80B7 25 DEC H

80B8 20 F8 JR NZ,L5

80BA 3E C0 LD A,C0H

80BC CD CB 80 CALL CMD

80BF DD 21 4C 81 LD IX,MESS

80C3 2E 08 LD L,08H

80C5 CD 39 81 CALL STRING

80C8 C3 1F 80 JP START

;Command write subroutine.

80CB D3 40 CMD: OUT (PORT_A),A ;Output command

;on DB0-DB7.

80CD 3E FB LD A,FBH ;Make E R/W* RS

80CF D3 41 OUT (PORT_B),A ; 0 1 1

80D1 3E F8 LD A,F8H ;

80D3 D3 41 OUT (PORT_B),A ; 0 0 0

80D5 3E FC LD A,FCH ;

80D7 D3 41 OUT (PORT_B),A ; 1 0 0

80D9 3E F8 LD A,F8H ;

80DB D3 41 OUT (PORT_B),A ; 0 0 0

80DD 1E FF LD E,0FFH ;Delay loop

Page 34: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

34

80DF CD 34 81 CALL DELAY ;count.

80E2 C9 RET

;LCD initialisation subroutine.

80E3 3E 80 INIT: LD A,80H ;Configure 8255 in

80E5 D3 43 OUT (CMD_PORT),A ;mode0. Port A & B

80E7 1E 1F LD E,NUMH ;as O/P Ports.

80E9 CD 34 81 CALL DELAY

80EC 3E 38 LD A,38H ;Send software

80EE CD CB 80 CALL CMD ;RESET thrice.

80F1 1E 1F LD E,NUMH

80F3 CD 34 81 CALL DELAY

80F6 3E 38 LD A,38H

80F8 CD CB 80 CALL CMD

80FB 1E 1F LD E,NUMH

80FD CD 34 81 CALL DELAY

8100 3E 38 LD A,38H

8102 CD CB 80 CALL CMD

8105 1E 1F LD E,NUMH

8107 CD 34 81 CALL DELAY

810A 3E 38 LD A,38H ;Function set 8bit,

810C CD CB 80 CALL CMD ;2 line 5*7 font.

810F 3E 0C LD A,0CH ;Display ON OFF

;control

8111 CD CB 80 CALL CMD ;Disp ON, Cursor

;OFF, Blink OFF

8114 3E 01 LD A,01H ;Clear display

8116 CD CB 80 CALL CMD

8119 C9 RET

;Data write subroutine.

811A D3 40 DWR: OUT (PORT_A),A ;Output data

;on DB0-DB7.

811C 3E FA LD A,FAH ;Make E R/W* RS

811E D3 41 OUT (PORT_B),A ; 0 1 0

8120 3E F9 LD A,F9H ;

8122 D3 41 OUT (PORT_B),A ; 0 0 1

8124 3E FD LD A,FDH ;

8126 D3 41 OUT (PORT_B),A ; 1 0 1

8128 3E F9 LD A,F9H ;

812A D3 41 OUT (PORT_B),A ; 0 0 1

812C 1E FF L2: LD E,0FFH ;Delay loop

Page 35: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

35

812E CD 34 81 CALL DELAY ;count.

8131 20 F9 JR NZ,L2

8133 C9 RET

8134 1D DELAY: DEC E ;Delay Routine.

8135 C2 34 81 JP NZ,DELAY

8138 C9 RET

8139 DD 7E 00 STRING: LD A,(IX)

813C CD 1A 81 CALL DWR

813F DD 23 INC IX

8141 2D DEC L

8142 C2 39 81 JP NZ,STRING

8145 C9 RET

8146 00 OUTBUF: DEFB 00H

8147 00 DEFB 00H

8148 00 DEFB 00H

8149 00 DEFB 00H

814A 00 DEFB 00H

814B 00 DEFB 00H

814C 49 53 20 54 59 MESS: DEFB 49H,53H,20H,54H,59H,

8151 50 45 44 20 00 DEFB 50H,45H,44H,20H,00H

8156 57 41 49 54 49 DISP1: DEFB 57H,41H,49H,54H,49H,

815B 4E 47 20 00 DEFB 4EH,47H,20H,00H

815F 46 4F 52 20 4B DISP2: DEFB 46H,4FH,52H,20H,4BH,

8164 45 59 20 00 DEFB 45H,59H,20H,00H

8168 47 48 49 4A 4B SCAN: DEFB 47H,48H,49H,4AH,4BH,

816D 4C 4D 4E 4F 50 DEFB 4CH,4DH,4EH,4FH,50H,

8172 51 52 53 54 DEFB 51H,52H,53H,54H

8176 55 56 DEFB 55H,56H

8178 4E 45 58 54 00 SCAN1: DEFB 4EH,45H,58H,54H,00H,

817D 00 00 00 DEFB 00H,00H,00H ; NEXT KEY

8180 50 52 45 56 00 DEFB 50H,52H,45H,56H,00H,

8185 00 00 00 DEFB 00H,00H,00H ; PREV KEY

8188 45 58 45 43 00 DEFB 45H,58H,45H,43H,00H,

818D 00 00 00 DEFB 00H,00H,00H ; EXEC KEY

8190 53 47 2D 53 54 DEFB 53H,47H,2DH,53H,54H,

8195 45 50 00 DEFB 45H,50H,00H ; SG-STEP KEY

8198 44 41 54 41 00 DEFB 44H,41H,54H,41H,00H,

819D 00 00 00 DEFB 00H,00H,00H ; DATA KEY

81A0 53 45 54 20 42 DEFB 53H,45H,54H,20H,42H,

81A5 52 4B 00 DEFB 52H,4BH,00H ; SET BRK KEY

81A8 49 4E 53 45 52 DEFB 49H,4EH,53H,45H,52H,

81AD 54 00 00 DEFB 54H,00H,00H ; INSERT KEY

81B0 44 45 4C 45 54 DEFB 44H,45H,4CH,45H,54H,

81B5 45 00 00 DEFB 45H,00H,00H ; DELETE KEY

Page 36: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

36

81B8 50 43 00 00 00 DEFB 50H,43H,00H,00H,00H,

81BD 00 00 00 DEFB 00H,00H,00H ; PC KEY

81C0 41 44 44 52 00 DEFB 41H,44H,44H,52H,00H,

81C5 00 00 00 DEFB 00H,00H,00H ; ADDR KEY

81C8 43 4C 52 20 42 DEFB 43H,4CH,52H,20H,42H,

81CD 52 4B 00 DEFB 52H,4BH,00H ; CLR BRK KEY

81D0 45 58 4D 20 52 DEFB 45H,58H,4DH,20H,52H,

81D5 45 47 00 DEFB 45H,47H,00H ; EXM REG KEY

81D8 42 4C 4B 5F 4D DEFB 42H,4CH,4BH,5FH,4DH,

81DD 4F 56 00 DEFB 4FH,56H,00H ; BLKMOVE KEY

81E0 52 45 4C 41 00 DEFB 52H,45H,4CH,41H,00H,

81E5 00 00 00 DEFB 00H,00H,00H ; RELA KEY

81E8 54 41 50 45 5F DEFB 54H,41H,50H,45H,5FH,

81ED 57 52 00 DEFB 57H,52H,00H ; TAPEWR KEY

81F0 54 41 50 45 5F DEFB 54H,41H,50H,45H,5FH,

81F5 52 44 00 DEFB 52H,44H,00H ; TAPERD KEY

6.6 DEMONSTRATION PROGRAM FOR ESA 68-2 TRAINER

;Assume the interface is connected over J1 of the trainer.

;The trainer can be in KEYBOARD mode or SERIAL mode.

CNTL_A1 EQU 0C801H

CNTL_B1 EQU 0C803H

DIR_A1 EQU 0C800H

DIR_B1 EQU 0C802H

RDKBD EQU 0E374H

NMOUT EQU 0E518H

DISPM EQU 0E546H

GETCH EQU 0E507H

SOUTPT EQU 0E52CH

ADDRESS OPCODE LABLE MNEMONIC COMMENTS

ORG 400H

0400 BD 04 FB JSR INIT ;Call LCD initialise

;subroutine.

0403 86 80 LDA #80H ;Address for

0405 BD 05 39 JSR CMD ;first line.

0408 8E 05 96 LDX #DISP1 ;Display the

040B BD 05 7C JSR STRING ;message WAITING.

040E 86 C0 LDA #0C0H ;Address for

0410 BD 05 39 JSR CMD ;second line.

0413 8E 05 9F LDX #DISP2 ;Display the

Page 37: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

37

0416 BD 05 7C JSR STRING ;message FOR KEY.

0419 0D 26 START: TST 26H ;Check Serial or

041B 27 0F BEQ KBD ;KB mode of operation.

041D BD E5 07 JSR GETCH ;Check any key pressed.

0420 36 02 PSHU A

0422 86 01 LDA #01H ;Clear display and

0424 BD 05 39 JSR CMD ;bring the cursor to

0427 37 02 PULU A ;home position.

0429 7E 04 3E JMP DEC

042C BD E3 74 KBD: JSR RDKBD ;Check any key pressed.

042F 36 02 PSHU A

0431 86 01 LDA #01H ;Clear display and

0433 BD 05 39 JSR CMD ;bring the cursor to

0436 37 02 PULU A ;home position.

0438 8B 30 ADDA #30H ;Get the ASCII

;equivalent of the key

043A 81 3A CMPA #3AH ;Check whether key is

;a digit (0 to 9) or

043C 24 30 BHS ABCD ;HEX digit (A to F),

;If HEX digit,

;Jump to lable ABCD.

043E 36 02 DEC: PSHU A

0440 86 80 LDA #80H ;Address for

0442 BD 05 39 JSR CMD ;first line.

0445 37 02 PULU A

0447 BD 05 54 JSR DWR

044A 86 02 LDA #02H

044C B7 05 89 STA LOC1

044F BD 05 6F L1: JSR DELAY

0452 B6 05 89 LDA LOC1

0455 4A DECA

0456 B7 05 89 STA LOC1

0459 26 F4 BNE L1

045B 86 C0 LDA #0C0H ;Address for

045D BD 05 39 JSR CMD ;second line.

0460 8E 05 8C LDX #MESS ;Display the message

0463 BD 05 7C JSR STRING ;IS TYPED.

0466 86 02 LDA #02H ;Return the cursor

0468 BD 05 39 JSR CMD ;to home position.

046B 7E 04 19 JMP START

046E 8B 07 ABCD: ADDA #07H ;Check whether

0470 81 47 CMPA #47H ;HEX digit (A to F)

0472 24 30 BHS NEXT ;or any COMMAND key

0474 36 02 PSHU A

Page 38: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

38

0476 86 80 LDA #80H ;Address for

0478 BD 05 39 JSR CMD ;first line.

047B 37 02 PULU A

047D BD 05 54 JSR DWR ;Display the

;HEX digit.

0480 86 02 LDA #02H

0482 B7 05 8A STA LOC2

0485 BD 05 6F L2: JSR DELAY

0488 B6 05 8A LDA LOC2

048B 4A DECA

048C B7 05 8A STA LOC2

048F 26 F4 BNE L2

0491 86 C0 LDA #0C0H ;Address for

0493 BD 05 39 JSR CMD ;second line.

0496 8E 05 8C LDX #MESS ;Display the message

0499 BD 05 7C JSR STRING ;IS TYPED.

049C 86 02 LDA #02H ;Bring the cursor

049E BD 05 39 JSR CMD ;to home position.

04A1 7E 04 19 JMP START

04A4 10 8E 05 B6 NEXT: LDY #SCAN1 ;Y reg points the

;codes of CNTRL keys.

04A8 8E 05 A8 LDX #SCAN ;X reg points the

;discription of keys.

04AB A1 80 NEXT2: CMPA 0,X+ ;compare ACC with

;memory and check

;for zero.

04AD 26 3F BNE NEXT1 ;No, Branch and compare

;with next code.

04AF 86 80 ST1: LDA #80H

04B1 36 02 PSHU A

04B3 BD 05 39 JSR CMD

04B6 A6 A0 ST4: LDA ,Y+ ;Yes,display the cntrl

;key pressed.

04B8 81 00 CMPA #00H ;Is it last char.

04BA 27 0E BEQ STOP ;Yes, stop.

04BC BD 05 54 JSR DWR ;No, disp the char

04BF 37 02 PULU A ;Continue & disp all

04C1 4C INCA ;char.

04C2 36 02 PSHU A

04C4 BD 05 39 JSR CMD

04C7 7E 04 B6 JMP ST4

04CA 86 C0 STOP: LDA #0C0H

04CC BD 05 39 JSR CMD

04CF 8E 05 8C LDX #MESS

Page 39: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

39

04D2 BD 05 7C JSR STRING

04D5 86 02 LDA #02H

04D7 B7 05 8B STA LOC3

04DA BD 05 6F L3: JSR DELAY

04DD B6 05 8B LDA LOC3

04E0 4A DECA

04E1 B7 05 8B STA LOC3

04E4 27 F4 BEQ L3

04E6 86 02 LDA #02H

04E8 BD 05 39 JSR CMD

04EB 7E 04 19 JMP START

04EE 36 02 NEXT1: PSHU A

04F0 1F 20 TFR Y,D

04F2 CB 08 ADDB #08

04F4 1F 02 TFR D,Y

04F6 37 02 PULU A

04F8 7E 04 AB JMP NEXT2

;LCD initialisation subroutine.

04FB CE 07 D0 INIT: LDU #2000

04FE 86 00 LDA #00H ;Configure 6821 at

;(U1) as mode 0.

0500 B7 C8 01 STA CNTL_A1

0503 B7 C8 03 STA CNTL_B1

0506 86 FF LDA #0FFH ;Port A & B as

0508 B7 C8 00 STA DIR_A1 ;O/P Ports.

050B B7 C8 02 STA DIR_B1

050E 86 04 LDA #04

0510 B7 C8 01 STA CNTL_A1

0513 B7 C8 03 STA CNTL_B1

0516 BD 05 6F JSR DELAY

0519 86 38 LDA #38H ;Send software

051B BD 05 39 JSR CMD ;RESET thrice.

051E BD 05 6F JSR DELAY

0521 86 38 LDA #38H

0523 BD 05 39 JSR CMD

0526 BD 05 6F JSR DELAY

0529 86 38 LDA #38H ;Function set 8bit,

052B BD 05 39 JSR CMD ;2 line 5*7 font.

052E 86 0C LDA #0CH ;Display ON OFF control

0530 BD 05 39 JSR CMD ;Disp ON,Cursor

;OFF,Blink OFF

0533 86 01 LDA #01H ;Clear display

Page 40: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

40

0535 BD 05 39 JSR CMD

0538 39 RTS

;Command write subroutine.

0539 B7 C8 00 CMD: STA DIR_A1 ;Output command

;on DB0-DB7.

053C 86 FB LDA #0FBH ;Make E R/W* RS

053E B7 C8 02 STA DIR_B1 ; 0 1 1

0541 86 F8 LDA #0F8H ;

0543 B7 C8 02 STA DIR_B1 ; 0 0 0

0546 86 FC LDA #0FCH ;

0548 B7 C8 02 STA DIR_B1 ; 1 0 0

054B 86 F8 LDA #0F8H ;

054D B7 C8 02 STA DIR_B1 ; 0 0 0

0550 BD 05 6F JSR DELAY ;Delay loop

0553 39 RTS

;Data write subroutine.

0554 B7 C8 00 DWR: STA DIR_A1 ;Output data

;on DB0-DB7.

0557 86 FA LDA #0FAH ;Make E R/W* R

0559 B7 C8 02 STA DIR_B1 ; 0 1 0

055C 86 F9 LDA #0F9H

055E B7 C8 02 STA DIR_B1 ; 0 0 1

0561 86 FD LDA #0FDH

0563 B7 C8 02 STA DIR_B1 ; 1 0 1

0566 86 F9 LDA #0F9H

0568 B7 C8 02 STA DIR_B1 ; 0 0 1

056B BD 05 6F JSR DELAY ;Delay loop

056E 39 RTS

056F 36 02 DELAY: PSHU A ;Delay Routine.

0571 CC 00 00 LDD #$0

0574 83 00 04 DELAY1: SUBD #4H

0577 26 FB BNE DELAY1

0579 37 02 PULU A

057B 39 RTS

;String write subroutine.

057C A6 80 STRING: LDA ,X+ ;Take the char to

;be disp to Acc

057E 81 00 CMPA #$00 ;Is it Zero ?

Page 41: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

41

0580 27 06 BEQ DD ;Yes, Return back

0582 BD 05 54 JSR DWR ;No, Display the char

0585 7E 05 7C JMP STRING ;Point to the next

;char.

0588 39 DD: RTS

0589 00 LOC1: FCB 0

058A 00 LOC2: FCB 0

058B 00 LOC3: FCB 0

058C 49 53 20 54 59 MESS: FCB 49H,53H,20H,54H,59H,

50 45 44 20 00 FCB 50H,45H,44H,20H,00H

0596 57 41 49 54 49 DISP1: FCB 57H,41H,49H,54H,49H,

4E 47 20 00 FCB 4EH,47H,20H,00H

059F 46 4F 52 20 4B DISP2: FCB 46H,4FH,52H,20H,4BH,

45 59 20 00 FCB 45H,59H,20H,00H

05A8 47 48 49 4A 4B SCAN: FCB 47H,48H,49H,4AH,4BH,

4C 4D 4E 4F 50 FCB 4CH,4DH,4EH,4FH,50H,

51 52 53 54 FCB 51H,52H,53H,54H

05B6 4E 45 58 54 00 SCAN1: FCB 4EH,45H,58H,54H,00H,

00 00 00 FCB 00H,00H,00H ;NEXT KEY

05BE 50 52 45 56 00 FCB 50H,52H,45H,56H,00H,

00 00 00 FCB 00H,00H,00H ;PREV KEY

05C6 45 58 45 43 00 FCB 45H,58H,45H,43H,00H,

00 00 00 FCB 00H,00H,00H ;EXEC KEY

05CE 53 47 2D 53 54 FCB 53H,47H,2DH,53H,54H,

45 50 00 FCB 45H,50H,00H ;SINGLE-STEP

;KEY

05D6 47 4F 00 00 00 FCB 47H,4FH,00H,00H,00H,

00 00 00 FCB 00H,00H,00H ;GO KEY

05DE 45 58 41 4D 4D FCB 45H,58H,41H,4DH,4DH,

45 4D 00 FCB 45H,4DH,00H ;EXAM-MEM

;KEY

05E6 45 58 41 4D 52 FCB 45H,58H,41H,4DH,52H,

45 47 00 FCB 45H,47H,00H ;EXAM-REG

;KEY

05EE 42 4C 4B 4D 4F FCB 42H,4CH,4BH,4DH,4FH,

56 45 00 FCB 56H,45H,00H ;BLK MOVE

;KEY

05F6 46 31 00 00 00 FCB 46H,31H,00H,00H,00H,

00 00 00 FCB 00H,00H,00H ;F1 KEY

05FE 53 45 52 49 41 FCB 53H,45H,52H,49H,41H,

4C 00 00 FCB 4CH,00H,00H ;SERIAL KEY

6.7 DEMONSTRATION PROGRAM FOR ESA 51 TRAINER

Page 42: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

42

;Assume the interface is connected over J10 of the trainer.

;The trainer can be in KEYBOARD MODE or in SERIAL MODE.

;When it is in KEYBOARD MODE, it will scan only the

;Keys supported in KEYBOARD MODE.

;When it is in SERIAL MODE it will scan system keycodes.

CMD_PORT EQU 03H

PORT_A EQU 00H

PORT_B EQU 01H

GETKB EQU 161H

GETCH EQU 12BBH

ADDRESS OPCODE LABLE MNEMONIC COMMENT

8000 ORG 8000H

8000 11 5B ACALL INIT ;Call LCD

;initialise

;subroutine

8002 74 80 MOV A,#80H ;Address for

;first line

8004 12 80 86 LCALL CMD ;display the

;message

8007 90 80 E0 MOV DPTR,#DISP1 ;'WAITING'

800A 7B 08 MOV R3,#08H

800C 12 80 CD LCALL STRING

800F 74 C0 MOV A,#0C0H ;address for

8011 12 80 86 LCALL CMD ;second line

8014 90 80 E8 MOV DPTR,#DISP2 ;display the

;message

8017 7B 08 MOV R3,#08H ;'FOR KEY'

8019 12 80 CD LCALL STRING

801C 7E 80 START: MOV R6,#80H ;check Serial

801E 90 E9 04 MOV DPTR,#0E904H ;or KB mode

;of operation

8021 E0 MOVX A,@DPTR

8022 20 E3 05 JB ACC.3,KBD

8025 12 12 BB LCALL GETCH ;check any

;key pressed

8028 80 03 SJMP DISP

802A 12 01 61 KBD: LCALL GETKB

802D C0 E0 DISP: PUSH A

802F 74 01 MOV A,#01H ;Clear

;display &

Page 43: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

43

8031 12 80 86 LCALL CMD ;bring the

;cursor to

;home position

8034 74 80 MOV A,#80H ;Address for

;1st line

8036 12 80 86 LCALL CMD

8039 D0 E0 POP A

803B 12 80 A6 LCALL DWR ;Display the

;key

803E 7B 01 DELAY2:MOV R3,#01H

8040 79 FF L1: MOV R1,#0FFH

8042 12 80 C6 LCALL DELAY

8045 DB F9 DJNZ R3,L1

8047 74 C0 MOV A,#0C0H ;Address for

8049 12 80 86 LCALL CMD ;second line

804C 90 80 D7 MOV DPTR,#MESS ;Display the

;message

804F 7B 08 MOV R3,#08H ;'IS TYPED'

8051 12 80 CD LCALL STRING

8054 74 02 MOV A,#02H ;return the

;cursor to

8056 12 80 86 LCALL CMD ;home position

8059 01 1C AJMP START

;LCD initialization subroutine

805B 74 80 INIT: MOV A,#80H ;Configure

;PA,PB,PC

805D 75 A0 E8 MOV P2,#0E8H ;as O/P PORTS

8060 78 03 MOV R0,#03H

8062 F2 MOVX @R0,A

8063 79 1F MOV R1,#1FH

8065 12 80 C6 LCALL DELAY

8068 7B 03 MOV R3,#03H ;Send software

806A 74 38 INIT1: MOV A,#38H ;reset 3 times

;to reset

806C 12 80 86 LCALL CMD ;the display

806F 79 3F MOV R1,#3FH

8071 12 80 C6 LCALL DELAY

8074 DB F4 DJNZ R3,INIT1

8076 74 38 MOV A,#38H ;Function set

;8BIT,1LINE

8078 12 80 86 LCALL CMD ;5*7 font

807B 74 0C MOV A,#0CH ;Display ON/

Page 44: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

44

;OFF control

807D 12 80 86 LCALL CMD ;Disp ON,Cursor

;OFF,Blink OFF

8080 74 01 MOV A,#01H ;Clear display

8082 12 80 86 LCALL CMD

8085 22 RET

;Command write subroutine

8086 75 A0 E8 CMD: MOV P2,#0E8H ;Output

;Command

8089 78 00 MOV R0,#PORT_A ;on DB0-DB7

808B F2 MOVX @R0,A

808C 74 FB MOV A,#0FBH ;Make E R/W* RS

808E 78 01 MOV R0,#PORT_B ; 0 1 1

8090 F2 MOVX @R0,A ;

8091 74 F8 MOV A,#0F8H ;

8093 78 01 MOV R0,#PORT_B ; 0 0 0

8095 F2 MOVX @R0,A ;

8096 74 FC MOV A,#0FCH ;

8098 78 01 MOV R0,#PORT_B ; 1 0 0

809A F2 MOVX @R0,A ;

809B 74 F8 MOV A,#0F8H ;

809D 78 01 MOV R0,#PORT_B ; 0 0 0

809F F2 MOVX @R0,A ;

80A0 79 10 MOV R1,#10H ;Delay loop

;count

80A2 12 80 C6 LCALL DELAY

80A5 22 RET

;Data write subroutine

80A6 75 A0 E8 DWR: MOV P2,#0E8H ;Output data

80A9 78 00 MOV R0,#PORT_A ;on DB0-DB7

80AB F2 MOVX @R0,A

80AC 74 FA MOV A,#0FAH ;Make E R/W* RS

80AE 78 01 MOV R0,#PORT_B ; 0 1 0

80B0 F2 MOVX @R0,A ;

80B1 74 F9 MOV A,#0F9H ;

80B3 78 01 MOV R0,#PORT_B ; 0 0 1

80B5 F2 MOVX @R0,A ;

80B6 74 FD MOV A,#0FDH ;

80B8 78 01 MOV R0,#PORT_B ; 1 0 1

80BA F2 MOVX @R0,A ;

Page 45: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

45

80BB 74 F9 MOV A,#0F9H ;

80BD 78 01 MOV R0,#PORT_B ; 0 0 1

80BF F2 MOVX @R0,A

80C0 79 10 MOV R1,#10H ;Delay loop

;count

80C2 12 80 C6 CALL DELAY

80C5 22 RET

;delay subroutine

80C6 7A 02 DELAY: MOV R2,#02H

80C8 DA FE DLY: DJNZ R2,DLY

80CA D9 FC DJNZ R1,DLY

80CC 22 RET

;string write subroutine

80CD E4 STRING:CLR A

80CE 93 MOVC A,@A+DPTR ;Get the

;character

80CF 60 05 JZ L3 ;to be

;displayed

80D1 11 A6 ACALL DWR ;Display it

80D3 A3 INC DPTR ;point to next

;char

80D4 DB F7 DJNZ R3,STRING ;all character

;over?

80D6 22 L3: RET ;yes, return

;back

80D7 49 53 20 54 59 MESS: DB 'IS TYPED',00H

80DC 50 45 44 00

80E0 57 41 49 54 49 DISP1: DB 'WAITING',00H

80E5 4E 47 00

80E8 46 4F 52 20 4B DISP2: DB 'FOR KEY',00H

80ED 45 59 00

6.8 DEMONSTRATION PROGRAM FOR ESA 51E TRAINER

;Assume the interface is connected over J5 of the trainer.

;The trainer can be in KEYBOARD MODE or in SERIAL MODE.

;When it is in KEYBOARD MODE, it will scan only the

;Keys supported in KEYBOARD MODE.

;When it is in SERIAL MODE it will scan system keycodes.

Page 46: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

46

CMD_PORT EQU 03H

PORT_A EQU 00H

PORT_B EQU 01H

GETKB EQU 0142H

GETCH EQU 12A5H

ADDRESS OPCODE LABLE MNEMONIC COMMENTS

8000 ORG 8000H

8000 11 5D ACALL INIT ;Call LCD

;initialise

;subroutine

8002 74 80 MOV A,#80H ;Address for first

;line

8004 12 80 88 CALL CMD ;display the

8007 90 80 E2 MOV DPTR,#DISP1 ;message

;'WAITING'

800A 7B 08 MOV R3,#08H

800C 12 80 CF CALL STRING

800F 74 C0 MOV A,#0C0H ;address for

8011 12 80 88 CALL CMD ;second line

8014 90 80 EA MOV DPTR,#DISP2 ;display the

8017 7B 08 MOV R3,#08H ;message 'FOR

;KEY'

8019 12 80 CF CALL STRING

801C 7E 80 START: MOV R6,#80H ;check Serial or

801E 90 E9 04 MOV DPTR,#0E904H ;KB mode of

;operation

8021 E0 MOVX A,@DPTR

8022 20 E3 05 JB ACC.3,KBD

8025 C2 B4 CLR P3.4

8027 12 12 A5 CALL GETCH ;check any key

;pressed

802A 80 03 SJMP DISP

802C 12 01 42 KBD: CALL GETKB

802F C0 E0 DISP: PUSH A

8031 74 01 MOV A,#01H ;Clear display

8033 12 80 88 CALL CMD ;and bring the

;cursor to

;home position

8036 74 80 MOV A,#80H ;Address for

;1st line

8038 12 80 88 CALL CMD

803B D0 E0 POP A

Page 47: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

47

803D 12 80 A8 CALL DWR ;Display the

;key

8040 7B 01 DELAY2:MOV R3,#01H

8042 79 FF L1: MOV R1,#0FFH

8044 12 80 C8 CALL DELAY

8047 DB F9 DJNZ R3,L1

8049 74 C0 MOV A,#0C0H ;Address for

804B 12 80 88 CALL CMD ;second line

804E 90 80 D9 MOV DPTR,#MESS ;Display the

;message

8051 7B 08 MOV R3,#08H ;'IS TYPED'

8053 12 80 CF CALL STRING

8056 74 02 MOV A,#02H ;return the

8058 12 80 88 CALL CMD ;cursor to home

;position

805B 01 1C AJMP START

;LCD initialisation subroutine

805D 74 80 INIT: MOV A,#80H ;Configure PA,

;PB,PC as

;O/P PORTS

805F 75 A0 E8 MOV P2,#0E8H

8062 78 03 MOV R0,#03H

8064 F2 MOVX @R0,A

8065 79 1F MOV R1,#1FH

8067 12 80 C8 CALL DELAY

806A 7B 03 MOV R3,#03H ;Send software

;reset 3 times

806C 74 38 INIT1: MOV A,#38H ;to reset the

;display

806E 12 80 88 CALL CMD

8071 79 3F MOV R1,#3FH

8073 12 80 C8 CALL DELAY

8076 DB F4 DJNZ R3,INIT1

8078 74 38 MOV A,#38H ;Function set

;8BIT,1 LINE

807A 12 80 88 CALL CMD ;5*7 font

807D 74 0C MOV A,#0CH ;Display ON/OFF

;control

807F 12 80 88 CALL CMD ;Disp ON,Cursor

;OFF,Blink OFF

8082 74 01 MOV A,#01H ;Clear display

8084 12 80 88 CALL CMD

Page 48: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

48

8087 22 RET

;Command write subroutine

8088 75 A0 E8 CMD: MOV P2,#0E8H

808B 78 00 MOV R0,#PORT_A

808D F2 MOVX @R0,A

808E 74 FB MOV A,#0FBH

8090 78 01 MOV R0,#PORT_B

8092 F2 MOVX @R0,A

8093 74 F8 MOV A,#0F8H

8095 78 01 MOV R0,#PORT_B

8097 F2 MOVX @R0,A

8098 74 FC MOV A,#0FCH

809A 78 01 MOV R0,#PORT_B

809C F2 MOVX @R0,A

809D 74 F8 MOV A,#0F8H

809F 78 01 MOV R0,#PORT_B

80A1 F2 MOVX @R0,A

80A2 79 10 MOV R1,#10H

80A4 12 80 C8 CALL DELAY

80A7 22 RET

;Date write subroutine

80A8 75 A0 E8 DWR: MOV P2,#0E8H

80AB 78 00 MOV R0,#PORT_A

80AD F2 MOVX @R0,A

80AE 74 FA MOV A,#0FAH

80B0 78 01 MOV R0,#PORT_B

80B2 F2 MOVX @R0,A

80B3 74 F9 MOV A,#0F9H

80B5 78 01 MOV R0,#PORT_B

80B7 F2 MOVX @R0,A

80B8 74 FD MOV A,#0FDH

80BA 78 01 MOV R0,#PORT_B

80BC F2 MOVX @R0,A

80BD 74 F9 MOV A,#0F9H

80BF 78 01 MOV R0,#PORT_B

80C1 F2 MOVX @R0,A

80C2 79 10 MOV R1,#10H

80C4 12 80 C8 CALL DELAY

80C7 22 RET

Page 49: Intel's MCS-51 family of microcontrollers and its …At this time user cannot write on to the LCD module. Data can be written on to the module only when busy flag goes low, that means

LCD INTERFACE

49

;delay subroutine

80C8 7A 02 DELAY: MOV R2,#02H

80CA DA FE DLY: DJNZ R2,DLY

80CC D9 FC DJNZ R1,DLY

80CE 22 RET

;string write subroutine

80CF E4 STRING: CLR A

80D0 93 MOVC A,@A+DPTR

80D1 60 05 JZ L3

80D3 11 A8 ACALL DWR

80D5 A3 INC DPTR

80D6 DB F7 DJNZ R3,STRING

80D8 22 L3: RET

80D9 49 53 20 54 59 MESS: DB 'IS TYPED',00H

80DE 50 45 44 00

80E2 57 41 49 54 49 DISP1: DB 'WAITING',00H

80E7 4E 47 00

80EA 46 4F 52 20 4B DISP2: DB 'FOR KEY',00H

80EF 45 59 00