Professional Documents
Culture Documents
ORG 00H
HARDWARE_CONNECTION:
LCD_DATA EQU P2
SOFTWARE_VARIABLE:
TEMPVAR_1 EQU R0
TEMPVAR_2 EQU R1
TEMPVAR_3 EQU R2
TEMPVAR_4 EQU R3
TEMPVAR_5 EQU R4
TEMPVAR_6 EQU R5
TEMPVAR_7 EQU R6
TEMPVAR_8 EQU R7
LCD_INITIALIZATION:
MOV A,#38H
ACALL LCD_COMND_WRT
MOV A,#0CH
ACALL LCD_COMND_WRT
MOV A,#01H
ACALL LCD_COMND_WRT
MOV A,#80H
ACALL LCD_COMND_WRT
CLOCK:
ORIGIN:
MOV TH1,#00H
MOV TMOD,#60H
SETB TR1
ACALL DELAY_ONESEC
CLR TR1
MOV A,TL1
MOV A,#00H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#60H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
ACALL BCD_TO_ASCII
MOV A,#20H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#01H
ACALL BCD_TO_ASCII
MOV A,#80H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#02H
ACALL BCD_TO_ASCII
MOV A,#40H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#03H
ACALL BCD_TO_ASCII
MOV A,#00H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#03H
ACALL BCD_TO_ASCII
MOV A,#60H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#04H
ACALL BCD_TO_ASCII
MOV A,#20H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#04H
ACALL BCD_TO_ASCII
MOV A,#80H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#05H
ACALL BCD_TO_ASCII
MOV A,#40H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#06H
ACALL BCD_TO_ASCII
MOV A,#00H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#06H
ACALL BCD_TO_ASCII
MOV A,#60H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#07H
ACALL BCD_TO_ASCII
MOV A,#20H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#07H
ACALL BCD_TO_ASCII
MOV A,#80H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#08H
ACALL BCD_TO_ASCII
MOV A,#40H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
ACALL BCD_TO_ASCII
MOV A,#00H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#09H
ACALL BCD_TO_ASCII
MOV A,#60H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#10H
ACALL BCD_TO_ASCII
MOV A,#20H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#10H
ACALL BCD_TO_ASCII
MOV A,#80H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#11H
ACALL BCD_TO_ASCII
MOV A,#40H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#12H
ACALL BCD_TO_ASCII
MOV A,#00H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#12H
ACALL BCD_TO_ASCII
MOV A,#60H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#13H
ACALL BCD_TO_ASCII
MOV A,#20H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#13H
ACALL BCD_TO_ASCII
MOV A,#80H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#14H
ACALL BCD_TO_ASCII
MOV A,#40H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#15H
ACALL BCD_TO_ASCII
MOV A,#00H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#15H
ACALL BCD_TO_ASCII
MOV A,#60H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#16H
ACALL BCD_TO_ASCII
MOV A,#20H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
ACALL BCD_TO_ASCII
MOV A,#80H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#17H
ACALL BCD_TO_ASCII
MOV A,#40H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#18H
ACALL BCD_TO_ASCII
MOV A,#00H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#18H
ACALL BCD_TO_ASCII
MOV A,#60H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#19H
ACALL BCD_TO_ASCII
MOV A,#20H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#19H
ACALL BCD_TO_ASCII
MOV A,#80H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#20H
ACALL BCD_TO_ASCII
MOV A,#40H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#21H
ACALL BCD_TO_ASCII
MOV A,#00H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#21H
ACALL BCD_TO_ASCII
MOV A,#60H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#22H
ACALL BCD_TO_ASCII
MOV A,#20H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#22H
ACALL BCD_TO_ASCII
MOV A,#80H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#23H
ACALL BCD_TO_ASCII
MOV A,#40H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#24H
ACALL BCD_TO_ASCII
MOV A,#00H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
ACALL BCD_TO_ASCII
MOV A,#60H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#25H
ACALL BCD_TO_ASCII
MOV A,#20H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#25H
ACALL BCD_TO_ASCII
MOV A,#80H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#26H
ACALL BCD_TO_ASCII
MOV A,#40H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#27H
ACALL BCD_TO_ASCII
MOV A,#20H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#27H
ACALL BCD_TO_ASCII
MOV A,#80H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#28H
ACALL BCD_TO_ASCII
MOV A,#40H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#29H
ACALL BCD_TO_ASCII
MOV A,#00H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#29H
ACALL BCD_TO_ASCII
MOV A,#60H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#30H
ACALL BCD_TO_ASCII
MOV A,#20H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#30H
ACALL BCD_TO_ASCII
MOV A,#80H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#31H
ACALL BCD_TO_ASCII
MOV A,#40H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#32H
ACALL BCD_TO_ASCII
MOV A,#00H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
ACALL BCD_TO_ASCII
MOV A,#60H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#33H
ACALL BCD_TO_ASCII
MOV A,#20H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#33H
ACALL BCD_TO_ASCII
MOV A,#80H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#34H
ACALL BCD_TO_ASCII
MOV A,#40H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#35H
ACALL BCD_TO_ASCII
MOV A,#00H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#35H
ACALL BCD_TO_ASCII
MOV A,#60H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#36H
ACALL BCD_TO_ASCII
MOV A,#20H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#36H
ACALL BCD_TO_ASCII
MOV A,#80H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#37H
ACALL BCD_TO_ASCII
MOV A,#40H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#38H
ACALL BCD_TO_ASCII
MOV A,#00H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#38H
ACALL BCD_TO_ASCII
MOV A,#60H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#39H
ACALL BCD_TO_ASCII
MOV A,#20H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#39H
ACALL BCD_TO_ASCII
MOV A,#80H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
ACALL BCD_TO_ASCII
MOV A,#40H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#41H
ACALL BCD_TO_ASCII
MOV A,#00H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#41H
ACALL BCD_TO_ASCII
MOV A,#60H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
MOV A,#42H
ACALL BCD_TO_ASCII
MOV A,#20H
ACALL BCD_TO_ASCII
LJMP RPM_DISPLAY
ACALL STRING_DISPLAY
SJMP $
RPM_DISPLAY:
ACALL LCD_DATA_WRT
MOV DPTR,#RPM
ACALL STRING_DISPLAY
SJMP $
LCD_COMND_WRT:
MOV LCD_DATA,A
CLR LCD_RS
SETB LCD_EN
ACALL DELAY_NINE
CLR LCD_EN
RET
LCD_DATA_WRT:
MOV LCD_DATA,A
SETB LCD_RS
SETB LCD_EN
ACALL DELAY_NINE
CLR LCD_EN
RET
BCD_TO_ASCII:
MOV TEMPVAR_4,A
ANL A,#0FH
ORL A,#30H
MOV TEMPVAR_3,A
MOV A,TEMPVAR_4
ANL A,#0F0H
SWAP A
ORL A,#30H
ACALL LCD_DATA_WRT
ACALL DELAY_NINE
MOV A,TEMPVAR_3
ACALL LCD_DATA_WRT
ACALL DELAY_NINE
RET
DELAY_NINE:
MOV TEMPVAR_5,#16
NINE_BACK:MOV TEMPVAR_6,#250
DJNZ TEMPVAR_6,$
DJNZ TEMPVAR_5,NINE_BACK
RET
DELAY_ONESEC:
MOV TEMPVAR_5,#10
DJNZ TEMPVAR_6,BK_B
DJNZ TEMPVAR_5,BK_C
MOV TEMPVAR_6,#50
DJNZ TEMPVAR_6,BK_E
RET
STRING_DISPLAY:
DIS_BACK:CLR A
MOVC A,@A+DPTR
JZ DIS_OUT
ACALL LCD_DATA_WRT
INC DPTR
SJMP DIS_BACK
DIS_OUT:RET
RPM: DB 'RPM',0
END
CIRCUIT DIAGRAM
COMPONENTS
1. AT89S52 Microcontroller
4. 5V Power Supply
2. Plywood
3. Screw bearing
7. Capacitor (47uF)
8. Resistor (100R)
Take out the wheel of a damaged optical mouse and make a hole at the center of
the wheel. Put the steel rod at the hole and glue it tightly so that the rod and the
wheel rotate simultaneously. Make the plywood frame as shown in figure and screw
the screw bearings on both sides so that the rod with the wheel can be mounted.
After mounting the rod (with the wheel) on the screw bearings, try rotating the
wheel with your finger. While rotating, the rod should have a minimum friction with
the screw bearings. This will help measuring the exact speed. Then make the
connections of the Infrared Transmitter and the Infrared Receiver as shown in the
circuit diagram. Place the Infrared Transmitter on one side of the wheel and the
Infrared Receiver on another side both facing each other. Here is a top view of the
arrangement.
Make a hole on the wheel as shown in the picture below. It is extremely important.
The hole will allow passing the infrared rays from the infrared transmitter to the
infrared receiver.
This module should have four wires coming out of it. They are:- +5V Power Supply,
Power Ground, wire connecting the ve terminal of the Infrared Transmitter and the
wire connecting the output terminal of the TSOP1738 Infrared Receiver
OPERATION
To measure speed of a rotational body, you need to hold the speed sensor module
by its frame and make contact of the wheel with the rotating body. Soon the wheel
will start rotating at the speed of the rotational body. Holding the module in that
position, press the reset button of the microcontroller. The speed of the rotational
body will be displayed on the LCD screen.
Now let us go inside the process and discover what happens during the whole
process. When the wheel of the module has no contact with any rotating body, it
remains in a still position. So the infrared rays coming out from the transmitter are
restricted by the wheel from entering the Infrared receiver. So the output of the
infrared receiver is also still and not pulsating. The output of the infrared receiver is
connected to COUNTER1 of the microcontroller and it can count only pulsating
signals (not a still signal). So no pulses are generated by the infrared receiver and
consequently no counting occurs. The display shows 00 rpm in this position.
When the user makes contact of the wheel of the module with a rotational body, the
wheel starts rotating at the speed of the rotational body and the hole in the wheel
will allow infrared rays to pass from the transmitter to the receiver once in a
rotation. This will form a pulsating output of the infrared receiver and the counter in
the microcontroller now can count the pulse. As these pulses are proportional to the
speed, the counted pulse will represent the speed of the rotational body. That is
what happens during the process.
PROGRAM STRUCTURE
The program first sets the TIMER2 of the microcontroller to generate 38 KHz
frequency. This frequency is then supplied to the Infrared Transmitter so that the
Infrared Transmitter LED sends out infrared rays at the same frequency. It is
because the TSOP1738 Infrared Receiver can receive infrared rays of 38 KHz only.
The program then starts the COUNTER1 of the microcontroller for one second so
that the pulses coming from the Infrared Receiver can be counted. After one second,
the counter is stopped again. It is because of the fact that a tachometer generally
gives out reading with a unit of ROTATION PER MINUTE (RPM). So for the process
someone needs to hold the speed sensor module in contact with a rotational body
for a whole minute and then the counted value to be displayed with a unit of RPM.
This process will be too tedious. But if the number of rotation in one second can be
counted then multiplying the value with 60 will give rotation in one minute. So the
counter is opened for one second by the program and the pulses are counted during
the second. The counted value is then multiplied by 60 and then the final value is
displayed on the LCD screen with a unit of RPM.
It is to mention here that though the words PULSE and ROTATION are used
alternately during the description, they actually mean the same. Because for one
rotation of the wheel, the hole in the wheel will allow the rays of the infrared
transmitter to pass to the receiver once and consequently one pulse will be formed
by the receiver. So the total numbers of pulses denote total number of rotation.