$MOD831
   	DB0 EQU P2.0
	DB1 EQU P2.1
	DB2 EQU P2.2
	DB3 EQU P2.3
	DB4 EQU P2.4
	DB5 EQU P2.5
	DB6 EQU P2.6
	DB7 EQU P2.7
	EN EQU P3.7
	RS EQU P3.6
	RW EQU P3.5
	DATA EQU P1

ORG 0100h

defineConstants:

clrLCDStr: DB 01h,0FFh
initLCDStr: DB   38h,0Eh,06h,0FFh

        LCDcursorOnline1Left: DB 60h,0FFh
	LCDcursorOnline2Left: DB 0C0h,0FFh

titleString2a: DB 'uP SYS',0FFh



ORG 0200h

MAIN:

	CLR RS
	CLR RW
	MOV LCDBUS,01h
        MOV SP,#2FH


LCALL defDefaultLCDCtrlSigs
LCALL initialiseLCD
LCALL clrLCD

mainLoop:

         LCALL mainSub1

   SJMP mainLoop   ; looping forever


; subroutines



defDefaultLCDCtrlSigs:

	MOV LCDBUS,#00h
	CLR RS
	CLR RW
	SETB EN

RET





chkLCDBusy:

	MOV LCDBUS,#0FF
	SETB RW
	waitBusy0:
	MOV A,LCDBUS
	JB ACC.7,waitBusy0
	exitChkLCDbusy:

	CLR RW

RET







wrCmdByte2LCD:

        MOV LCDBUS,A

        CLR EN

        SETB EN

        LCALL chkLCDBusy

RET





wrDatByte2LCD:

	MOV LCDBUS,A

	SETB RS

	CLR EN

	SETB EN

	CLR RS

	LCALL chkLCDBusy

RET





initialiseLCD:

        MOV DPTR, #initLCDStr

        LCALL wrCmdStr2LCD

ret





clrLCD:

        MOV DPTR, #clrLCDStr

        LCALL wrCmdStr2LCD

ret





wrCmdStr2LCD:



	MOV A,#00h

	MOVC A,@A+DPTR



wrCmdStr2LCDLoop:

	LCALL wrCmdByte2LCD

	INC DPTR

	MOV A,#00h

	MOVC A,@A+DPTR

	CJNE A,#0FFh,wrCmdStr2LCDLoop



RET







wrDatStr2LCD:



	MOV A,#00h

	MOVC A,@A+DPTR



wrDatStr2LCDLoop:

	LCALL wrDatByte2LCD

	INC DPTR

	MOV A,#00h

	MOVC A,@A+DPTR

	CJNE A,#0FFh,wrDatStr2LCDLoop

RET



mainSub1:



       ; MOV DPTR, #titleString1a

      ; LCALL wrDatStr2LCD

      ; LCALL delay3Sec

      ; LCALL clrLCD



	LCALL Move2LCDLine2

 	MOV DPTR, #titleString2a

 	LCALL wrDatStr2LCD

        LCALL delay3Sec

   	LCALL clrLCD

RET





Move2LCDLine2:

	CLR RS

	MOV DPTR,#LCDcursorOnline2Left

	LCALL WRCMDSTR2LCD

RET





delay3Sec:

	MOV R7,#30
	LOOP1: MOV R6,#200

	LOOP2: MOV R5,#250

	LOOP3: DJNZ R5,LOOP3

	DJNZ R6,LOOP2

	DJNZ R7,LOOP1
RET



