Sei sulla pagina 1di 9

#include <mcs51reg.

h>

//;# include <reg51.h>

//;#define display_port P2 //Data pins connected to port 2 on microcontroller

SFR ldata =0x90;

SBIT rs = P2^0; //RS pin connected to pin 2 of port 3

sbit rw = P2^1; // RW pin connected to pin 3 of port 3

sbit e = P2^2; //E pin connected to pin 4 of port 3

void msdelay(unsigned int time) // Function for creating delay in milliseconds.

unsigned i,j ;

for(i=0;i<time;i++)

for(j=0;j<1275;j++);

void lcd_cmd(unsigned char value) //Function to send command instruction to LCD

ldata=value;

rs= 0;

rw=0;

e=1;

msdelay(1);

e=0;
return;

void lcd_data(unsigned char value) //Function to send display data to LCD

ldata=value;

rs= 1;

rw=0;

e=1;

msdelay(1);

e=0;

return;

void main()

lcd_cmd(0x38); // for using 2 lines and 5X7 matrix of LCD

msdelay(250);

lcd_cmd(0x0E); // turn display ON, cursor blinking

msdelay(250);

lcd_cmd(0x01); //clear screen

msdelay(250);

lcd_cmd(0x06); // bring cursor to position 1 of line 1


msdelay(250);

lcd_cmd(0x86); // for using 2 lines and 5X7 matrix of LCD

msdelay(250);

lcd_data('M'); // turn display ON, cursor blinking

msdelay(250);

lcd_data('D'); //clear screen

msdelay(250);

lcd_data('E'); // bring cursor to position 1 of line 1

msdelay(250);

}]

;====================================================================

; Main.asm file generated by New Project wizard

; Created: Thu Aug 16 2018

; Processor: 80C31

; Compiler: ASEM-51 (Proteus)

;====================================================================
$NOMOD51

$INCLUDE (8051.MCU)

;====================================================================

; DEFINITIONS

;====================================================================

;====================================================================

; VARIABLES

;====================================================================

;====================================================================

; RESET and INTERRUPT VECTORS

;====================================================================

ORG 0H

MOV A,#38H

ACALL COMNWRT

ACALL DELAY

MOV A,#0EH

ACALL COMNWRT

ACALL DELAY

MOV A,#01

ACALL COMNWRT
ACALL DELAY

MOV A,#06H

ACALL COMNWRT

ACALL DELAY

MOV A,#84H

ACALL COMNWRT

ACALL DELAY

MOV P2, #0FFH

K1: MOV P1,#0

MOV A,P2

ANL A,#00001111B

CJNE A,#00001111B,K1

K2: ACALL DELAY

MOV A,P2

ANL A,#00001111B

CJNE A,#00001111B,OVER

SJMP K2
OVER: ACALL DELAY

MOV A,P2

ANL A,#00001111B

CJNE A,#00001111B,OVER1

SJMP K2

OVER1: MOV P1,#11111110B

MOV A,P2

ANL A,#00001111B

CJNE A,#00001111B,ROW_0

MOV P1,#11111101B

MOV A,P2

ANL A,#00001111B

CJNE A,#00001111B,ROW_1

MOV P1,#11111011B

MOV A,P2

ANL A,#00001111B

CJNE A,#00001111B,ROW_2

MOV P1,#11110111B
MOV A,P2

ANL A,#00001111B

CJNE A,#00001111B,ROW_3

LJMP K2

ROW_0: MOV DPTR, #KCODE0

SJMP FIND

ROW_1: MOV DPTR, #KCODE1

SJMP FIND

ROW_2: MOV DPTR, #KCODE2

SJMP FIND

ROW_3: MOV DPTR, #KCODE3

FIND: RRC A

JNC MATCH

INC DPTR

SJMP FIND

MATCH: CLR A

MOVC A, @A+DPTR

;MOV P0,A
ACALL DATAWRT

LJMP K1

COMNWRT:

MOV P3,A

CLR P1.4

CLR P1.5

SETB P1.6

ACALL DELAY

CLR P1.6

RET

DATAWRT:

MOV P3,A

SETB P1.4

CLR P1.5

SETB P1.6

ACALL DELAY

CLR P1.6

RET

DELAY: MOV R4, #255


HERE: DJNZ R4,HERE

RET

ORG 300H

KCODE0: DB '0', '1', '2', '3'

KCODE1: DB '4', '5', '6', '7'

KCODE2: DB '8', '9', 'A', 'B'

KCODE3: DB 'C', 'D', 'E', 'F'

END

Potrebbero piacerti anche