Professional Documents
Culture Documents
INTERFACING STEPPER MOTOR WITH 8051 AIM: To interface stepper motor with 8051 microprocessor and to run it at different speed. ALGORITHM: Step 1: Get the data which inidicates the directionof rotation of motor in destination index or dptr. Step 2: Store the count in RD register Step 3: Get the speed of the moto in R0, R1, R2 register Step 4: Get the data in AL register from Dptr Step 5: Send the data through output port Step 6: Keep decrementing the value in DX register till it becomes zero. Step 7: Increment dptr and repeat from step 4 Step 8: Loop till the count becomes zero Step 9: Go to step 1 Programe Name: Interfacing Steppermotor with 8051 Address
4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 410A 410B 410C 410D 410E 410F 4110 4111 4112 4113 4114 4115 4116 4117
Date:
Label
Start
Mnemonic
MOV Dptr, # 4500 MOV R0, # 04
Opcodes
90 45 00 78 04 E0 C0 83 C0 82 90 FF C0 7A 04 79 OF 7B OF DB FF D9 FA DA
Comments
Initialize Dprt With 4500H Move the count 04 to R0 Move the data in dptr to A Push the higher byte Of dprt Push the lower byte Of dptr Move the port Address the dprt Move the data 004 to R2 Move OOF to R1 Move OF to R3 Decrement and on No Zero kept looping Decrement R1 and on No Zero jump to DLY1 Decrement R2 and on
To
MOV X A, @ dptr PUSH DPH PUSH DPL MOV dptr, # FF COH MOV R2, # 004 H MOV R1, # 00FH
DLY1 DLY
MOV R3, # OF DJNZ R3 DLY DJNZ R1, DLY DJNZ R2, DLY
4118 4119 411A 411B 411C 411D 411E 411F 4120 4121 4122
MOV X @ dptr , A POP DPL POP DPH INC Dptr DJNZ R0, J0 S JUMP Start
F8 FO DO 82 00 83 08 E4 80 DD
No zero jum to DLY1 Move the data in A to dptr Pop the lower byte Of dptr Pop the higher byte Of dptr Increment Dptr Decrement and on No zero jump to J0 Short jump to Start
09 05 06 0A
04 06 05 09
RESULT: Thus the assembly language program to interface a stepper motor with 8051 was written and verified.
SQUARE WAVE GENERATING USING 8254 WITH 8051 Ex.No. AIM: To write an assembly language program to generate a square wave using timer in 8051. ALGORITHM: Step 1: Initialize the Dptr with port address Step 2: Send the control word through port FFCE Step 3: Send the lower byte and upper byte of the count through port FFC8 Step 4: Stop Programe Name: Square wave generation using timer in 8051 Address
4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 410A 410B 410C 410D 410E 410F
Date:
Label
Mnemonic
MOV dptr, # FFCE MOV A, # 36 MOV X @ dptr, A MOV A, # 0A MOV Dptr, # FFC8 MOV X@ dptr, A MOV A, # OD
Opcodes
90 FF CE 74 36 F0 74 OA 90 FF C8 F0 74 00 F0 80, FE
Comments
Move the port Address for control Register to dptr Move the control Word 36H to A Move the lower byte Of the count to A Move the port address To dptr Send the data from A to dptr Move the upper byte Of the count to A Short jump to terminate the programe
HLT
OUTPUT
FLOW CHART
Start
Get the higher and lower byte of count and send it to FFCE
Stop
RESULT: Thus the assembly language program to interface a stepper motor with 8051 was written and verified.
PROGRAMMING INTERNAL INTERUPT IN 8051 Ex. No. AIM: To write an assembly language program to an internal interrupt in 8051. ALGORITHM: Step 1: Set the mode in TMOD Step 2: Set the interrupt enable register Step 3: Initialize TL1 and TH1 as 000H Step 4: Set the TR1 bit Step 5: If there is no bit in TF1 (i.e) if the TF1 bit is not set kept looping else if the TF1 bit is set, it is cleared when the processor vectors to ISR Step 6: Clear the TR1 bit Step 7: ISR : Add two input data and store the result in dprt Step 8: Stop Programe Name: Programming internal interrupt in 8051 Address
4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 410A 410B 410C 410D 410E 410F 4110 4111 4112 4113 4114
Date:
Label
Mnemonic
MOV TMOD, # 10 MOV 1 E, # 88H MOV TH1, # 000H MOV, TF1, # 000H SET B TR1
Opcodes
75 89 10 75 A8 88 75 8D 00 75 8C 00 D2 8E 30 8F FDE C2 8E 80 FE
Comments
Set the TMOD Register Set the interrupt Enable register Initialize TH1 as 000H Initialize TL1 as 000H SET the TR1 B (8E) If the TF1 big in Not set loop There Clear the TR1 bit Terminate the Program
L1
L2
S JMP L2
Interrupt 5030 5031 5032 5033 5034 5035 5036 5037 5038
Service
Routine MOV A, # 12H ADD A, # 12 MOV DPTR, # 4500 MOV X @ DPTR, A S JMP HLT
HLT
74 12 74 12 90 45 00 F0 80, FE
Move the data 12H To A Add the contents Of A with 12H Initialize the dptr With 4500
88H
Enable Interrupt
OUTPUT 4500
24H
Initialize the control word in TMOD + 1E Initialize TH1 and TL1 as 000H Set the TR1 bit
If TF1 = 1
Processor vectors to ISR ISR: Add two input values and store the result in dptr Clear TR1 bit Stop
PROGRAMMING THE UART IN 8051 Ex.No. AIM: To write an assembly language program to UART in 8051. ALGORITHM: Step 1 : Step 2 : Step 3 : Step 4 : Step 5 : Step 6 : Step 7 : Step 8 : Step 9 : Step 10: Set the TMOD value Initialize TH1 as FDH and TL1 as 00H Set the TCON value Set the SCON value Get the data in SBUF Keep looping till the SCON.0 bit (receiver interrupt flag) is set If the SCOn.0 is set, clear it Move the data from SBUF to A Initialize dptr and store the content of A in it Stop Date:
Programe Name: Programming UART in 8051 Address 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 412A 412B 412C 412D 412E 412F 4130 4131 4132 4133 4134 4135 Label Mnemonic MOV TMOD, # 20H MOV TH1, # TDH MOV TL1, # 000H MOV TCON, # 40H MOV SCON, # 58H MOV, SBUF, # 54H Re JNB SCON.0, Re CLR SCON.0 Opcodes 75 89 20 75 80 FD 75 8B 00 75 88 40 75 98 58 75 99 54 30 98 FD C2 Comments Set the TMOD value with 20H Move FD to TH1 Move 00H to TL1 Set the TCON With 40H Set the SCON with 58H Move the data 54H To SBUF Jump on No bit in SCON.0 to Re Clear SCON.0 bit
4136 4137 4138 4139 413A 413B 413C 413D TMOD Gate 0 TCON TF1 0 SCON SM0 0
HLT
98 E5 99 90 45 03 FO 80,FE
Move the data from SBUF to A Initialize the dptr With 4500 Move the data from A to dptr Terminate the program using short jump
C/T 0
M1 1
M0 0
Gate C/T 0 0
M1 0
M0 0 20
TR1 1
TF0 0
TR0 1E1 0 0
1T1 0
1E0 1T0 0 0 40
SM1 1
SM2 0
REN TB8 1 1
RB8 0
T1 0
R1 0 58
RESULT: Thus the assembly language program to UART of 8051 was written and verified.
FLOW CHART
Start Initialize TH1 as FDH and TL1 as 000H Get the control word for TCON and SCON and initialize it Get the data in SBUF
If SCON.0 = 1
Clear SCON.0
Stop
TRAFFIC LIGHT CONTROLLER Ex.No. AIM: To write an ALP to perform traffic light control. ALGORITHM: Step 1 Step 2 Step 3 Step 4 Step 5 Step 6 : : : : : : Start Initialize dptr with the port addresses Send the control word to the control register Send the control word to allow the traffic from North to east Call delay Send the control word to allow the traffic from east to south and call delay Send the control word to allow the traffic from south to west and call delay Send the control word to allow the traffic from west to North and call delay Repeat for various direction Stop Date:
Step 7 : Step 8 : Step 9 : Step 10: Programme Name: Address 4100 4101 4012 4103 4104 4105 4106 4107 4108 4109 410A 410B 410C 410D 410E 410F 4110
Label
Mnemonic MOV A, % 80H MOV dptr, # control Mov x @dptr, A Mov R4, # 04H Mov dptr, # loop1 Mov R2, DPH Mov R3, DPL Mov dptr, # loop
Start
Opcodes 24 80 90 FF OF FO 7C 04 70 41 91 AF 83 AB 82 70 41
Comments
4111 4112 4113 4114 4115 4116 4117 4118 4119 411A 411B 411C 411D 411E 411F 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 412A 412B 412C 412D 412E 412F 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 413A 413B 413C 413D
MOV R01, DPH MOV R1, DPL G0 MOV X A, @ dptr Mov R0, DPH MOV R1, DPL MOV dptr, # port A MOV X @ dptr, A INC R1 MOV DPH, R0 MOv DPL, R1 MOV X A, @ dptr MOV R0, DPH MOV R1, DPL MOV Dptr, @ port B MOV X @dptr, A INC R1 MOV DPH, R0 MOV DPL, R1 MOV X A, @ dptr MOV R0, DPH MOV R1, DPL MOV Dptr, # Port C MOV X @ dptr, A INC R1 Call Delay
81 A8 83 49 82 EO A8 83 A9 82 90 PF OC FO 09 88 83 89 82 EO A8 81 A9 82 70 PT OD FO OP 83 87 89 82 EO A8 80 A7 82 90 FF 82 FO 09 12 41
413E 413F 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 414B 414C 414D 414E 414F 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 415A 415B 415C 415D 415E 415F 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 416A
MOV DPH, R2 MOV DPL, R3 MOV X A, @ dptr MOV R2, DPH MOV R3, DPL MOV Dptr, # port A MOV X @ dptr, A INC R3 MOV DPH, R2 MOV R3, DPL MOV dptr, # port B MOV X @ dptr, A INC R3 MOV DPH, R2 MOV DPL, R3 MOV X A, @ dptr MOV R2, DPH MOV R3, DPL MOV dptr, # port C MOV X @ dptr, A INC R3 L call delay MOV DPH, R0
78 8A 83 8B 82 EO A9 83 AB 82 90 FF 09 FO DB 8A 83 AB 82 90 FF OB FO OB 8A 83 8B 82 EO AB 83 AB 82 90 FF OE FO OB 12 41 82 88 83
416B 416C 416D 416E 416F 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 417A 417B 417C 417D 417E 417F 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 418A 418B 418C 418D 418E 418F 4190 4191 4192 4193 4194 4195 4196 4197
MOV DPL, R1 DJNZ R4, G0 2 Call delay Delay L3 L2 L1 MOV R5, # 12H MOV R6,# OFFH MOV R7,# OFFH DJNZ R7, L1 DJNZ, R6, L2 DJNZ, R5, L3 RET Delay 1 L6 L5 L7 MOV R5, #12 MOV R6, #OFF MOV R7, #OFFH DJNZ R7, L4 DJNZ R6, L5 DJNZ R5, L6 RET Look DB, 44H, 27H, 12H DB, 92H, 2BH, 10H DB, 84H, 90H, 10H DB 94H, 9DH, 10H
89 82 PC A4 12 41 06 7D 12 RE FF 7E FF DF FF DF FE DE FA DD F6 70 7E FF 7E FF 7F FE DF FE DE FA DE F6 42 27 12 92 2B 10 84 90 10 84
4198 4199 419A 419B 419C 419D 419E 419F 4200 4201 4202 4203 4204 4205 4206 4207
Look1
9D 10 84 9D 10 48 27 12 92 4B 84 90 20 04 2F 49
RESULT: Thus the assembly language program to perform traffic light controller was written.