0% found this document useful (0 votes)
79 views8 pages

Interfacing 8051 With LCD

The document describes interfacing an 8051 microcontroller with an LCD display and 7-segment display. It provides code to initialize the LCD and display text. It also provides code to interface with a 7-segment display and display numbers by accessing values from an array. Finally, it generates waves of different frequencies on an output pin and provides code to calculate frequency by measuring the timer.

Uploaded by

Umair Hameed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views8 pages

Interfacing 8051 With LCD

The document describes interfacing an 8051 microcontroller with an LCD display and 7-segment display. It provides code to initialize the LCD and display text. It also provides code to interface with a 7-segment display and display numbers by accessing values from an array. Finally, it generates waves of different frequencies on an output pin and provides code to calculate frequency by measuring the timer.

Uploaded by

Umair Hameed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Interfacing 8051 with LCD

ORG 0X00 MOV P2, #0x80


CLR P3.7
;RW = GND SETB P3.6
;RS = P3.7 CLR P3.6
;E = P3.6 call onems
;Data = P2
MOV P2, #'M'
MOV P2, #0x38 SETB P3.7
CLR P3.7 SETB P3.6
SETB P3.6 CLR P3.6
CLR P3.6 call onems
call onems
MOV P2, #'P'
SETB P3.7
MOV P2, #0x0E SETB P3.6
CLR P3.7 CLR P3.6
SETB P3.6 call onems
CLR P3.6
call onems MOV P2, #'I'
SETB P3.7
SETB P3.6
MOV P2, #0x01 CLR P3.6
CLR P3.7 call onems
SETB P3.6
CLR P3.6 sjmp $
call onems
onems: Mov R4, #100
MOV P2, #0x06 L11: Mov R5, #5
CLR P3.7 L22: Djnz R5, L22
SETB P3.6 Djnz R4, L11
CLR P3.6 Ret
call onems
END
Interfacing seven segment with 8051
ORG 0X00 MOVC A, @A+DPTR
MOV A , #0X00 CPL A
MOV R0, #0X09 MOV P2, A
MOV R1, #0X04 acall delay
MOV R2, #0X06
MOV R3, #0X08
MOV DPTR, #array MOV P3, #0X08
MOV A, R3
MOVC A, @A+DPTR
loop: CPL A
MOV P3, #0x01 MOV P2, A
MOV A, R0 acall delay
MOVC A, @A+DPTR
CPL A SJMP loop
MOV P2, A array: db
acall delay 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,
0x67
MOV P3, #0X02
MOV A, R1 Delay: Mov R4, #10
MOVC A, @A+DPTR L1: Mov R5, #200
CPL A L2: Djnz R5, L2
MOV P2, A Djnz R4, L1
acall delay Ret

MOV P3, #0X04 END


MOV A, R2
Generating two waves of frequencies f1 and f2 (f1 is multiple of f2)

// 1KHz and 2 KHz waves with 50% duty cycle


ORG 0H

WAVE1 BIT P1.0


WAVE2 BIT P1.1
AGAIN:
SETB WAVE1
SETB WAVE2
LCALL DELAY
CLR WAVE2
LCALL DELAY
CLR WAVE1
SETB WAVE2
LCALL DELAY
CLR WAVE2
LCALL DELAY
SJMP AGAIN

DELAY:
MOV TMOD,#01H
MOV TH0,#0FFH
MOV TL0,#06H
SETB TR0
JNB TF0,$
CLR TF0
RET

END

Code for calculating frequency


ORG 0H
MOV TMOD , #0X15
SETB P3.4

REPEAT:
MOV TL0, #00
MOV TH0, #00
SETB TR0
ACALL DELAY
CLR TR0
MOV A, TL0
MOV P2, A
MOV A, TH0
MOV P1,A
SJMP REPEAT

DELAY:
MOV R1, #28
AGAIN: MOV TH1,#00H
MOV TL1,#00H
SETB TR1
JNB TF1,$
CLR TF1
CLR TR1
DJNZ R1, AGAIN
RET

END
PWM code, duty cycle changes after every 1 second

//4 KHz, 10%, 30%, 50%, 70% and 90%


//each duty cycle is run for 1 sec, and then shifted to next
//process goes on inifitely in a circuler manner, overheads can be minimized by adjusting timer
values
ORG 0H

MOV DPTR,#TABLE
MOV TMOD,#02
SETB TR0

AGAIN:
MOV R0,#0
CALL NEXT_DC
SJMP AGAIN

NEXT_DC:
/*************************************/
MOV R1,#16
THERE2:
MOV R2,#250
THERE:
MOV A,R0
MOVC A,@A+DPTR
MOV TH0,A
MOV TL0,A
SETB P1.0
JNB TF0,$
CLR TF0
INC R0
MOV A,R0
MOVC A,@A+DPTR
MOV TH0,A
MOV TL0,A
CLR P1.0
JNB TF0,$
CLR TF0
DEC R0
DJNZ R2,THERE
DJNZ R1,THERE2
INC R0
INC R0
CJNE R0,#10,NEXT_DC

RET

/************************************/

TABLE: DB 231,31, 181,81, 131,131, 81,181, 31,231

END

You might also like