Вы находитесь на странице: 1из 6

Lab Report 02

Microprocessors and Interfacing

ECX 4236

Name : S.A.D.L. Janaka


Reg.No : 50564695
Center : Colombo
Aim:

 Study to write assembly language programs using 8051 microcontroller timers and counters.
 Study to write assembly language programs to display values on LCD display in the 8051
development board.

Objectives:

 Familiar with the use of the 8051 timer and counter in 8051.
 Familiar with the use of LCD display on the 8051 development board.
 Writing ASM program to generate PWM signals.
 Identify to connect DC motor to 8051 microcontroller.
 Identify DC motor operating state using 8051 microcontroller.

Equipments Used:

 AES-51 Development board


 Power Adaptor
 6-Foot serial ribbon cable
 DC motor
 Computer

Software Tools used:

 Note pad
 ASM-51 Assembler
 8052 Simulator
 Terminal Emulator

Procedure:

 Connect the power adaptor to the AES-51 development board


 Power up the board
 Write AL program to generate duty cycle of 25% PWM signal which has 40Hz frequency.
 Write AL program to detect DC motor direction.
 Write AL program to display the motor RPM on LCD.
 Connect the PC to the AES-51 Board using serial ribbon cable and power up the PC
 Write the source code (ALP) in Notepad and save it as ASM (File name .ASM) file
 Use ASM-51 Assembler to produced HEX file (Which contains machine codes in hex format plus
address) and LST file (Which contains detail records of both the source file and the hex machine
code)
 Using LST (List) file check whether is there any errors in the program
 Use 8052 Simulator to simulate our program
 Use Terminal Emulator (TE) to download the program to the AES-51 Development board and
execute assembly language programs.

* Program 1:

AL program that generate duty cycle of 25% PWM signal which has 40 Hz frequency

P1_4 BIT 94H ; Enable port 1.4 bit addressable


P1_5 BIT 95H ; Enable port 1.5 bit addressable
TMOD DATA 89H ; Enable TMOD register data addressable
TR0 BIT 8CH ; Enable TR0 bit in TCON register bit addressable
TF0 BIT 8DH ; Enable TF0 bit in TCON register bit addressable
TL0 DATA 8AH ; Enable TL0 data addressable
TH0 DATA 8CH ; Enable TH0 data addressable

ORG 7000H

HERE:
CLR P1_4 ; Clear port 1.4
SETB P1_5 ; Clear port 1.5
ACALL DELAY
SETB P1_4
CLR P1_5
ACALL DELAY
ACALL DELAY
ACALL DELAY
SJMP HERE

;************************** Timer delay ***********************

DELAY:
MOV TMOD,#01H ; select Timer0 as 16 bit mode
MOV TH0,#0E7H ; load Timer value to get 6.25ms timer delay
MOV TL0,#96H
SETB TR0 ; Start timer

BACK: JNB TF0,BACK ; Stay Back until timer over flow


CLR TR0 ; Stop timer
CLR TF0 ; Clear timer overflow flag bit
RET ; Return from Delay subroutine

END
* Program 2:

AL program that detect DC motor direction and give a signal to the P1 using counter

TMOD DATA 89H ; Enable TMOD register data addressable


T0 BIT 0B4H ; 8051 TO PIN IS SET AS BIT ADDRESIBLE FOR CHANNEL A
T1 BIT 0B5H ; 8051 T1 PIN IS SET AS BIT ADDRESIBLE FOR CHANNEL B
P_1 DATA 90H ; Enable port P1 data addressable
TR0 BIT 8CH ; Enable TR0 bit in TCON register bit addressable
TF0 BIT 8DH ; Enable TF0 bit in TCON register bit addressable
TL0 DATA 8AH ; Enable TL0 data addressable
TH0 DATA 8CH ; Enable TH0 data addressable

ORG 7000H

COUNTER:

MOV TMOD,#00000100B ; Select timer0 as 8 bit counter


MOV TL0,#0FEH ; Load counter value
MOV TH0,#00H
SETB TR0 ; Start counter

JNB TF0,$ ; Stay hear until counter overflow


JB T1,CCW ; Detect falling edge of channel B
SJMP CW

CW:
MOV P_1,#11000000B ;Signal by on most left LED in port 1 after clockwise
;detection
CLR TR0
CLR TF0
SJMP COUNTER

CCW:
MOV P_1,#00110000B ; Signal by on most left LED in port 1 after counter
;clockwise detection
CLR TF0
CLR TR0
SJMP COUNTER
RET
END
 Program 3:
AL program that detect the motor direction and display on LCD

TMOD DATA 89H ; Enable TMOD register data addressable


T0 BIT 0B4H ; 8051 TO PIN IS SET AS BIT ADDRESIBLE FOR CHANNEL A
T1 BIT 0B5H ; 8051 T1 PIN IS SET AS BIT ADDRESIBLE FOR CHANNEL B
P_1 DATA 90H ; Enable port P1 data addressable
TR0 BIT 8CH ; Enable TR0 bit in TCON register bit addressable
TF0 BIT 8DH ; Enable TF0 bit in TCON register bit addressable
TL0 DATA 8AH ; Enable TL0 data addressable
TH0 DATA 8CH ; Enable TH0 data addressable

ORG 7000H
COUNTER:

MOV TMOD,#00000100B ; Select timer0 as 8 bit counter


MOV TL0,#0FEH ; Load counter value
MOV TH0,#00H
SETB TR0 ; Start counter

JNB TF0,$ ; Stay hear until counter overflow


JB T1,CW ; Detect falling edge of channel B
SJMP CCW

CW:
call 4100h
MOV DPTR,#7504h
MOV R1,#9

display1:
CLR A
MOVC A,@A+DPTR
MOV R0,A
MOV 21h,R0
CALL 4104h ;Send the ascii codes in internal memory location 21h to LCD
;displayable
INC DPTR
DJNZ R1,display1
RET

CCW:
call 4100h
MOV DPTR,#7500h
MOV R1,#13

display2:CLR A
MOVC A,@A+DPTR ;move code address to accumulator
MOV R0,A
MOV 21h,R0
CALL 4104h
INC DPTR
DJNZ R1,display2
RET

ORG 7500h
db'anticlockwise'

END

Вам также может понравиться