Expt. No. 4 Interfacing Display Devices With 8051

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Microcontrollers Lab-V Sem.

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

Connections and output:


Refer logic controller interface board manual.
Output is seen on PORT A of logic controller.

ECE Department MIT Manipal Page 15


Microcontrollers Lab-V Sem.

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

Connections and output:


Refer logic controller interface board manual.
Count is displayed on PORT A of logic controller.
Program 3.
Write a program to input a single digit number from keyboard. If the number is 1, light 2 LEDs, if
the number is 2, light 4 LEDs, if the number is 3, light 6 LEDs, if the number is 4, light 8 LEDs and
for all other cases LEDs are off.

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

ECE Department MIT Manipal Page 17


Microcontrollers Lab-V Sem.
MOV DPTR, #MESSAGE
ACALL DATAWR
SJMP LOOP ; Subroutine to write command words of LCD
CMDWR: CLR A
MOVC A, @A+DPTR ;Get command word from code memory
JZ EXIT
INC DPTR
MOV 30H, DPL ; Save DPTR (address of command word)
MOV 31H, DPH
MOV DPTR, #PA-ADD ; Write command word to LCD
MOVX @DPTR, A
MOV DPTR, PC-ADD ; send control signals to LCD
MOV A, #40H ; E=1, R/W=0, RS=0
MOVX @DPTR, A
MOV A, #00H ; E=0, R/W=0, RS=0
MOVX @DPTR, A
ACALL DELAY
MOV DPL, 30H
MOV DPH, 31H
SJMP CMDWR
EXIT: RET ;Subroutine to send data to LCD
DATAWR: CLR A
MOVC A, @A+DPTR ; Get data word from code memory
JZ EXIT1
INC DPTR
MOV 30H, DPL ; Save DPTR (Address of data word)
MOV 31H, DPH
MOV DPTR, #PA-ADD ; Write data word to LCD
MOVX @DPTR, A
MOV DPTR,#PC-ADD ; Send Control signals to LCD
MOV A, #50H ; E=1, R/W=0, RS=1
MOVX @DPTR, A
MOV A, #10H ; E=0, R/W=0, RS=1
MOVX @DPTR, A
ACALL DELAY
MOV DPL, 30H
MOV DPH, 31H
SJMP DATAWR
EXIT1: RET

DELAY: MOV R0, #0FFH ; Delay function


GO: MOV R1, #0FFH
HERE: DJNZ R1, HERE
DJNZ R0, GO
RET
ORG 9800H
COMMAND: DB 01H, 06H, 02H, 0EH, 80H, 0
MESSAGE: DB “MANIPAL”, 0
END

Program 5.
Write a program to display the message ‘PEOPLE’ on 7- segment display interface unit.

ECE Department MIT Manipal Page 18


Microcontrollers Lab-V Sem.

Port pin details:


The Seven segment display module using here is a 6-digit multiplexed seven segment display. The I/O
ports of 8255 are configured to seven segment interface module as follows:
PA0 connected to Segment A, PA1 connected to Segment B
PA2 connected to Segment C, PA3 connected to Segment D
PA4 connected to Segment E, PA5 connected to Segment F
PA6 connected to Segment G, PA7 connected to Segment Decimal point
PC6, PC5, PC4 are used to select one out of 6 seven segment display digits
[i.e., 0th to 5th digit]. (For Eg: If PC6=1, PC5=0, PC4=0 then 4th seven segment
display digit will be selected).

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

ECE Department MIT Manipal Page 19


Microcontrollers Lab-V Sem.
MOVX @DPTR,A
MOV A,R6
ADD A,#10H
MOV R6,A
ACALL DELAY
DJNZ R4,NXTCHR
SJMP UP
DELAY: MOV R7,#0FFH
GO: MOV R2,#05H
HERE: DJNZ R2,HERE
DJNZ R7,GO
RET
EXIT: SJMP START

ORG 8800H
WRD: DB 79H,38H,73H,3FH,79H,73H,0
END

Connections and output:


Refer Seven segment interface board manual.

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.

ECE Department MIT Manipal Page 20


Microcontrollers Lab-V Sem.

Expt. No. 5
INTERFACING STEPPER MOTOR AND DC MOTOR
WITH 8051

Aim: To study stepper motor and DC motor control

Program 1.
Write a program to interface stepper motor and rotate it clockwise

Port pin details:


The stepper motor used here is a two-phase motor with four windings. In stepper motor interface module,
a 5-way power mate connecter is provided to interface the motor. Out of five wires of power mate
connector, one is Vdd and remaining four wires are to the four windings of the motor which are useful to
provide four step sequence with active low logic. The I/O lines of 8255 configured to four motor
windings as follows:
PC3 connected to winding A
PC2 connected to winding B
PC1 connected to winding C
PC0 connected to winding D

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

ECE Department MIT Manipal Page 21


Microcontrollers Lab-V Sem.
MOV DPL, 20H
MOV DPH, 21H
SJMP SEND
EXIT: RET

DELAY: MOV R0, #0FFH


REPEAT: MOV R1, #0FFH
GO: DJNZ R1, GO
DJNZ R0, REPEAT
RET

ORG 0EE00H
TABLE: DB 0DH, 0EH, 07H, 0BH, 0
END

Connections and Output:


Refer stepper motor interface board manual

Program 2.
Write a program to control the speed of a DC motor.

Port pin details:


The DC motor interface NIFC- 55 is connected through the 26 pin FRC with trainer kit. Only PORT C
pin PC.4 is used to ON/OFF (0/1) the motor. The speed of the motor is controlled with duty cycle
variation by changing the delay. The various duty cycles are given through the PC keyboard. If PC.4 is 0,
motor is ON else motor is OFF.
Description:
1. Initialize the control word register to configure 8255 with Port C as output port.
2. Initialize 8255 with control word address.
3. Assign keys A, B, C, D for 25%, 50%,75%,90% duty cycle.
4. Scan the keyboard for the key pressed.
5. Display the ASCII equivalent of the key pressed on the data field of display.
6. Speed is controlled by varying the duty cycle.

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.

ECE Department MIT Manipal Page 22


Microcontrollers Lab-V Sem.
MOV R6, A
LCALL 677DH
MOV DPTR, #PC-ADD
MOVX @DPTR, A
MOV R0, #25
LCALL 6850H
SETB ACC.4
MOVX @DPTR, A
MOV R0, #75
LCALL 6850H
SJMP UP
D1: CJNE A, #42H, D2 ; Press B for 50% duty cycle.
MOV R6, A
LCALL 677DH
MOV DPTR, #PC-ADD
MOVX @DPTR, A
MOV R0, #50
LCALL 6850H
SETB ACC.4
MOVX @DPTR, A
MOV R0, #50
LCALL 6850H
SJMP UP
D2: CJNE A, #43H, D3 ; Press C for 75% duty cycle.
MOV R6, A
LCALL 677DH
MOV DPTR, #PC-ADD
MOVX @DPTR, A
MOV R0, #75
LCALL 6850H
SETB ACC.4
MOVX @DPTR, A
MOV R0, #25
LCALL 6850H
SJMP UP
D3: CJNE A, #44H, UP ; Press D for 90% duty cycle.
MOV R6, A
LCALL 677DH
MOV DPTR, #PC-ADD
MOVX @DPTR, A
MOV R0, #90
LCALL 6850H
SETB ACC.4
MOVX @DPTR, A

ECE Department MIT Manipal Page 23


Microcontrollers Lab-V Sem.
MOV R0, #10
LCALL 6850H
SJMP UP

Connections and Output:


Refer DC motor interface board manual
Exercises:
1. Write a program to rotate the stepper motor in clockwise direction for 90o.
2. Write a program to control the speed of the stepper motor using computer keyboard
3. Write a program to control the direction of rotation of the stepper motor using stepper motor
4. Write a program to rotate the DC motor for 5 second and turn off for 5 seconds.

ECE Department MIT Manipal Page 24


Microcontrollers Lab-V Sem.

Expt. No. 6
INTERFACING DATA CONVERTERS WITH 8051

Aim: To study DAC and ADC interface modules

Program 1.
Write a program to generate a square wave with 50% duty cycle using DAC.

Port pin details:


The DAC interface module consists of two 8-bit Digital to Analog converters (DAC 0800) the outputs
of which are converted to voltages using op-amps. The Port A and Port B lines of 8255 are used to
provide 8-bit digital input to DAC1 and DAC2 respectively. The analog output of DAC1 and DAC2 can
be taken from OUT1 and OUT2 of 4-way relia-mate connector respectively.

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

DELAY: MOV R0, #0FH ; Delay program


REPEAT:MOV R1, #0FFH
GO: DJNZ R1, GO
DJNZ R0, REPEAT
RET
END

Connections and Output:


Refer DAC interface manual

ECE Department MIT Manipal Page 25


Microcontrollers Lab-V Sem.
Square wave is seen on CRO

Program 2.
Write a program to convert the dc voltage connected to ADC

Port pin details:


The ADC interfacing module consists of ADC-0809, which is an 8-bit analog to digital converter with
8-channel multiplexed control logic. The I/O lines of 8255 configured to ADC module as follows
PA0-PA7 connected to digital o/p line D0-D7
PC0-PC2 for channel selection
PC7 connected to Start of Conversion (SOC)
PC6 connected to Output Enable (OE)
PA7 connected to End of Conversion (EOC)

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

ECE Department MIT Manipal Page 26


Microcontrollers Lab-V Sem.
ANL A, #80H
JNB ACC.7, BACK ; Check EOC
MOV A, #0DH ; Set PC.6
MOV DPTR, #CR_ADD
MOVX @DPTR, A
MOV DPTR, #PA-ADD
MOVX A,@DPTR ; Read Digital data
MOV R6, A
LCALL 68EAH ; Clear Display
LCALL 677DH ; Display Digital data
SJMP NXT
END

Connections and output:


Refer ADC interface manual
Digital data displayed on kit
Note: Analog voltage must be within the range 0 to +5 V.

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.

ECE Department MIT Manipal Page 27

You might also like