Expt. No. 4 Interfacing Display Devices With 8051
Expt. No. 4 Interfacing Display Devices With 8051
Expt. No. 4 Interfacing Display Devices With 8051
Expt. No. 4
INTERFACING DISPLAY DEVICES WITH 8051
Aim: To study Logic controller, LCD and Seven segment interface modules
Program 1.
Write a program to realize single bit AND logic function using logic controller interface.
Port pin details:
The logic controller interface consists essentially, of three 8 bit ports (i.e., Port A, Port B and Port C).
The 8 I/O lines of Port B and 4 I/O lines of Port C-Upper (total 12) configured as inputs and connected
to DIP switch array. The 8 I/O lines of Port A and 4 I/O lines of Port C-Lower (total 12) configured as
outputs and connected to LEDs.
Description:
1.Initialize the control word register to configure 8255 with port B as input and port
A as output port
2.Initialize 8255 with control word address
3.Read the inputs from port B (PB1 and PB0)
4.Perform logical AND operation
5.Display the output at port A (PA0)
ORG 8000h
MOV A,#CW
MOV DPTR,#CR-ADD
MOVX @DPTR,A
HERE: MOV DPTR,#PB-ADD
MOVX A,@DPTR
MOV C,ACC.0
ANL C,ACC.1
CLR A
MOV ACC.0,C
MOV DPTR,#PA-ADD
MOVX @DPTR,A
SJMP HERE
END
Program 2.
Write a program to implement hex counter from logic controller interface and display count on the
data field of the kit.
Description:
1.Initialize the control word register to configure 8255 with port B as input and port
A as output port
2.Initialize 8255 with control word address
3.Initialize accumulator with 00H
4.Call delay
5.Increment accumulator content till FFH
6.Display the output at port A
7.Also display the count on the data field
ORG 8000h
MOV A,#CW
MOV DPTR,#CR-ADD
MOVX @DPTR,A
CLR A
UP:MOV R3,A
MOV DPTR, #PA-ADD
MOVX @DPTR,A
MOV R6,A
LCALL 68EAH
LCALL 677DH
MOV R0,#0FFH
MOV R1,#0FFH
LCALL 6850H
MOV A,R3
INC A
SJMP UP
Description:
1.Initialize the control word register to configure 8255 with port B as input and port
A as output port
2. Initialize 8255 with control word address
3. Read the input from keyboard using LCALL 1777H instruction
4.Observe the LEDs blink on PORT A of logic controller
ORG 8000h
MOV A,#CW
MOV DPTR,#CR-ADD
MOVX @DPTR,A
ECE Department MIT Manipal Page 16
Microcontrollers Lab-V Sem.
HERE: LCALL 1777H
CJNE A,#31h,TWO
MOV DPTR, #PA-ADD
MOV A, #03H
MOVX @DPTR,A
SJMP HERE
TWO:CJNE A,#32h,THREE
MOV DPTR, #PA-ADD
MOV A, #0FH
MOVX @DPTR,A
SJMP HERE
THREE:CJNE A,#33h,FOUR
MOV DPTR, # PA-ADD
MOV A, #3FH
MOVX @DPTR,A
SJMP HERE
FOUR:CJNE A,#34h,HERE
MOV DPTR, # PA-ADD
MOV A, #0FFH
MOVX @DPTR,A
SJMP HERE
END
Connections and output:
Refer logic controller interface board manual.
LED s will glow as per the logic on PORT A of logic controller.
Program 4.
Write a program to display “MANIPAL” on LCD interface module.
Port pin details:
The LCD using here is a Single line alpha-numeric (16x1) LCD module.
The I/O ports of 8255 are configured to LCD as follows:
PA7-PA0 connected to 8-Data lines,
PC6 to Enable line (E),
PC5 to Read/Write (R/W),
PC4 to Register Select (RS) line of LCD
Description:
1. Initialize the control word register to configure 8255
2. Initialize 8255 with control word address.
3. Move command word address to DPTR
4. Call subroutine to get command word from code memory
5. Increment data pointer and save the data pointer address in some memory location
6. Write command word to LCD
7. Send control signals to LCD and call delay routine
8. Move saved DPTR address and repeat the loop till it encounters null command
9. Call another subroutine to send data to LCD
10. Repeat steps 5 to 8
ORG 9000H
MOV A, #CW
MOV DPTR, #CR-ADD
MOVX @DPTR, A
LOOP: MOV DPTR, #COMMAND
ACALL CMDWR
Program 5.
Write a program to display the message ‘PEOPLE’ on 7- segment display interface unit.
Description:
1. Store seven segment codes in the memory location
2. Initialize the control word register to configure 8255
3. Initialize 8255 with control word address
4. Move no of digits and starting address of the data to the registers
5. Move LED display address from the look up table to DPTR
6. Increment data pointer and save the data pointer address in some memory location
7. Send the seven segment codes to port C
8. Increment the data available register and store the digit in port A
9. Call delay routine
10. Repeat steps 5 to 8 for all the seven segment codes
ORG 8000H
START:MOV DPTR,#CR-ADD // 8255 initialization
MOV A,#CW
MOVX @DPTR,A
MOV DPTR, #WRD
MOV 30H,DPL
MOV 31H, DPH
UP: MOV R4,#06H // No. of characters
MOV R6,#0H
NXTCHR: MOV A, R6 // decoder address
MOV DPTR,#PC-ADD
MOVX @DPTR,A
CLR A // get value
MOV DPL,30H
MOV DPH,31H
MOVC A,@A+DPTR
JZ EXIT
INC DPTR
MOV 30H,DPL
MOV 31H,DPH
MOV DPTR,#PA-ADD // send to port A
ORG 8800H
WRD: DB 79H,38H,73H,3FH,79H,73H,0
END
Exercises:
1. Write a program to make the logic controller to function as (i) 8-bit BCD
counter, (ii)8-bit ring counter and (iii) 8 bit Johnson counter using serial
interrupt
2. Write a program to display characters typed on the computer keyboard, on
LCD module
3. Write a program to scroll the message ‘MANIPAL’ on LCD continuously.
4. Write a program to display a single digit number typed on computer keyboard,
on seven segment display.
5. Write a program to display eight bit BCD up-counte on the seven segment
display with a delay of 1 second.
Expt. No. 5
INTERFACING STEPPER MOTOR AND DC MOTOR
WITH 8051
Program 1.
Write a program to interface stepper motor and rotate it clockwise
Description:
1. Initialize the control word register to configure 8255 with Port C as output port
2 .Initialize 8255 with control word address
3. Send Hexadecimal numbers from the look-up table through Port C to excite four motor coils in
sequence.
ORG 0E000H
MOV A, #CW ; 8255 Initialization
MOV DPTR, #CW-ADD
MOVX @DPTR, A
HERE: MOV DPTR, #TABLE ; assign DPTR with step sequence address
ACALL SEND
SJMP HERE
SEND: CLR A
MOVC A,@A+DPTR
JZ EXIT
INC DPTR
MOV 20H, DPL ; save DPTR
MOV 21H, DPH
MOV DPTR, #PC-ADD
MOVX @DPTR, A
LCALL DELAY
ORG 0EE00H
TABLE: DB 0DH, 0EH, 07H, 0BH, 0
END
Program 2.
Write a program to control the speed of a DC motor.
ORG 8000H
MOV A, #CW ; 8255 Initialization
MOV DPTR, #CW-ADD
MOVX @DPTR, A
MOV DPTR, #PC-ADD
SETB ACC.4
MOVX @DPTR, A
LCALL 68EAH
MOV R1, #00
UP: LCALL 1777H
CJNE A, #41H, D1 ; Press A for 25% duty cycle.
Expt. No. 6
INTERFACING DATA CONVERTERS WITH 8051
Program 1.
Write a program to generate a square wave with 50% duty cycle using DAC.
Description:
1. Initialize the control word register to configure 8255 with Port A as output port.
2. Initialize 8255 with control word address.
3. Send 00H and FFH through Port A continuously with suitable delay in between.
4. 00H corresponds to 0 Volt and FFH corresponds to 5 Volt.
ORG 8000H
MOV A, #CW ; 8255 Initialization
MOV DPTR, #CR-ADD
MOVX @DPTR, A
MOV DPTR, #PA-ADD
UP: CLR A
MOVX @DPTR, A ; Send 00H through port A
ACALL DELAY
MOV A, #0FFH
MOVX @DPTR, A ; Send FFH through port A
ACALL DELAY
SJMP UP
Program 2.
Write a program to convert the dc voltage connected to ADC
Description:
1. Initialize the control word register to configure 8255 with Port A as input port and Port C as
output port
2. Initialize 8255 with control word address
3. Send a high to low signal on PC.7 to initiate start of conversion
4. Keep checking PA.7 for end of conversion signal from ADC
5. Set PC.6 to trigger Output Enable.
6. Read the converted data through Port A
7. Display the value on data field of the on board LCD.
ORG 8000H
MOV DPTR, #CR_ADD
MOV A, # CW ;8255 Initialization
MOVX @DPTR, A
NXT: MOV DPTR, #CR_ADD
MOV A, #0FH ; Set PC.7 (SOC)
MOVX @DPTR, A
MOV R3, #30H ; Delay
LOP: MOV R4, #0FFH
LOP1: NOP
DJNZ R4, LOP1
DJNZ R3, LOP
MOV A, #0EH ; Reset PC.7 (SOC)
MOVX @DPTR, A
MOV A, #0CH ; Reset PC.6
MOVX @DPTR, A
MOV DPTR, #PA-ADD
BACK:MOVX A, @DPTR
Exercises:
1. Write a program to flash 00 on the kit display unit if the applied analog input voltage exceeds 3V
2. Write a program to generate a square wave of 4V peak to peak and frequency 1 KHz and duty
cycle of 75%.
3. Write a program to generate a triangular wave.
4. Write a program to generate a staircase wave of 5 steps.
5. Write a program to generate a sine wave.