Write an assembly language program to interface LCD and display a string with 8051 Microcontroller.
Apparatus:
Theory:Read an analog voltage at the input of ADC given as the knob position using 8051 microcontrollers. An Analog to Digital Converter (ADC) is a very useful feature that converts an analog voltage on a pin to a digital number. The binary counter is initially reset to 0000; the output of integrator reset to 0V and the input to the ramp generator or integrator is switched to the unknown analog input voltage VA. The analog input voltage VA is integrated by the inverting integrator and generates a negative ramp output. The output of comparator is positive and the clock is passed through the AND gate. This results in counting up of the binary counter.
Operating Procedure for ADC Cards:
Program:
ORG 0000H
LJMP MAIN
ORG 0030H
MAIN: NOP
EN EQU P2.0
RS EQU P2.2
// RW EQU P1.1
DAT EQU P2
LCALL LCD_INT
LCALL CLEAR
LCALL LINE1
MOV DPTR, #MYDATA
LCALL LOOP
LCALL LINE2
MOV DPTR, #MYDAT2
LCALL LOOP
LCALL LINE5
lcall dispH
again: lcall adconver
LCALL LINE3
lcall adisph
lcall adispl
SJMP again
;================================================================== =======
W_NIB: PUSH ACC ;Save A for low nibble
ORL DAT,#0F0h ;Bits 4..7 <- 1
ORL A,#0Fh ;Don't affect bits 0-3
ANL DAT,A ;High nibble to display
SETB EN
CLR EN
POP ACC ;Prepare to send
SWAP A ;...second nibble
ORL DAT,#0F0h ; Bits 4...7 <- 1
ORL A,#0Fh ; Don't affect bits 0...3
ANL DAT,A ;Low nibble to display
SETB EN
CLR EN
RET
;================================================================== =======
LCD_INT: CLR RS
// CLR RW
SETB EN
MOV DAT,#028h
CLR EN
LCALL SDELAY
MOV A,#28h
LCALL COM
MOV A,#0Ch
LCALL COM
MOV A,#06h
LCALL COM
LCALL CLEAR
MOV A,#080H
LCALL COM
RET
;================================================================== =======
DATAW: SETB RS
CLR RW
LCALL W_NIB
LCALL LDELAY
RET
;================================================================== =======
SDELAY: MOV R6,#1
HERE2: MOV R7,#255
HERE: DJNZ R7,HERE
DJNZ R6,HERE2
RET
;================================================================== =======
LDELAY: MOV R6,#1
HER2: MOV R7,#255
HER: DJNZ R7,HER
DJNZ R6,HER2
RET
;================================================================== =======
COM: CLR RS
CLR RW
LCALL W_NIB
LCALL SDELAY
RET
;================================================================== =======
LINE1: MOV A,#80H
LCALL COM
RET
LINE 2: MOV A,#0C0H
LCALL COM
RET
LINE 3: MOV A,#0c9H
LCALL COM
RET
LINE 4: MOV A,#0cah
LCALL COM
RET
LINE 5: MOV A,#0cbh
LCALL COM
RET
;================================================================== =======
LOOP: CLR A
MOVC A,@A+DPTR
JZ GO_B2
LCALL DATAW
LCALL SDELAY
INC DPTR
SJMP LOOP
GO_B2: RET
ADisph:
MOV a,r3
LCALL DATAW
LCALL SDELAY
ret
ADispl:
MOV a,r4
LCALL DATAW
LCALL SDELAY
ret
;================================================================== =======
MYDATA: DB " PIO-ADC-01 ",0
MYDAT2: DB " ADC i/p= ",0
dispH:
MOV a,#48H ;ascii for H
LCALL DATAW
LCALL SDELAY
ret
;================================================================== =======
adconvert:
;----------------------------------------------------------
START EQU P1.0 ; Pin 6 Start
EOC EQU P1.3 ; Pin 7 EOC
OE EQU P1.1 ; Pin 9 Output Enable
ALE EQU P1.2 ; Pin 22 ALE
adata EQU P0 ; Data Lines
;----------------------------------------------------------
; Read one byte of data from adc
; Performs a analog conversion cycle.
; address of channel in register "ADDRESS",
; Returns data in BUFFER
; Destroys A.
MOV adata,#0FFH ; Data lines for input
SETB OE ; Disable output
SETB ALE ; Latch the address
NOP
nop
nop
NOP
SETB START ; Start the conversion
NOP
NOP
NOP
CLR START
NOP
NOP
EOCLOOP:
JNB EOC, EOCLOOP ; Do until EOC high
CLR OE ; Output Enable
MOV a,adata ; Get data in buffer
SETB OE
CLR ALE
Result:The Digital data corresponding to the analog input is shown in the LCD.
Viva Questions:
Get all latest content delivered to your email a few times a month.