20
INTERFACING IN 8051 Ex.No. Date: 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 Addres s Label Mnemonic Opcodes Comments 4100 Start MOV Dptr, # 4500 90 Initialize Dprt 4101 45 With 4500 H 4102 00 4103 MOV R 0 , # 04 78 Move the count 04 to 4104 04 R 0 4105 To MOV X A, @ dptr E 0 Move the data in dptr to A 4106 PUSH DPH C 0 Push the higher byte

Interfacing in 8051

Embed Size (px)

Citation preview

Page 1: Interfacing in 8051

INTERFACING IN 8051

Ex.No. Date: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 registerStep 3: Get the speed of the moto in R0, R1, R2 registerStep 4: Get the data in AL register from DptrStep 5: Send the data through output portStep 6: Keep decrementing the value in DX register till it becomes zero.Step 7: Increment dptr and repeat from step 4Step 8: Loop till the count becomes zeroStep 9: Go to step 1

Programe Name: Interfacing Steppermotor with 8051

Address Label Mnemonic Opcodes Comments4100 Start MOV Dptr, # 4500 90 Initialize Dprt 4101 45 With 4500H

4102 004103 MOV R0, # 04 78 Move the count 04 to4104 04 R0

4105 To MOV X A, @ dptr E0 Move the data in dptr to A4106 PUSH DPH C0 Push the higher byte4107 83 Of dprt4108 PUSH DPL C0 Push the lower byte4109 82 Of dptr410A MOV dptr, # FF COH 90 Move the port410B FF Address the dprt410C C0

410D MOV R2, # 004 H 7A Move the data 004 to R2410E 04410F MOV R1, # 00FH 79 Move OOF to R14110 OF4111 DLY1 MOV R3, # OF 7B Move OF to R34112 OF4113 DLY DJNZ R3 DLY DB Decrement and on No4114 FF Zero kept looping4115 DJNZ R1, DLY D9 Decrement R1 and on No4116 FA Zero jump to DLY14117 DJNZ R2, DLY DA Decrement R2 and on

Page 2: Interfacing in 8051

4118 F8 No zero jum to DLY14119 MOV X @ dptr , A FO Move the data in A to dptr411A POP DPL DO Pop the lower byte 411B 82 Of dptr411C POP DPH 00 Pop the higher byte411D 83 Of dptr411E INC Dptr Increment Dptr411F DJNZ R0, J0 08 Decrement and on4120 E4 No zero jump to J0

4121 S JUMP Start 80 Short jump to 4122 DD Start

EXCITATION TABLE:

Clock wise direction Anticlockwise directionA1 A2 B1 B2 A1 A2 B1 B2

1 0 0 1 09 1 0 1 0 040 1 0 1 05 0 1 1 0 060 1 1 0 06 0 1 0 1 051 0 1 0 0A 1 0 0 1 09

RESULT:Thus the assembly language program to interface a stepper motor with 8051 was

written and verified.

Page 3: Interfacing in 8051

SQUARE WAVE GENERATING USING 8254 WITH 8051

Ex.No. Date:

AIM:To write an assembly language program to generate a square wave using timer in

8051.

ALGORITHM:Step 1: Initialize the Dptr with port addressStep 2: Send the control word through port FFCEStep 3: Send the lower byte and upper byte of the count through port FFC8Step 4: Stop

Programe Name: Square wave generation using timer in 8051

Address Label Mnemonic Opcodes Comments4100 MOV dptr, # FFCE 90 Move the port4101 FF Address for control4102 CE Register to dptr4103 MOV A, # 36 74 Move the control4104 36 Word 36H to A4105 MOV X @ dptr, A F04106 MOV A, # 0A 74 Move the lower byte 4107 OA Of the count to A4108 MOV Dptr, # FFC8 90 Move the port address4109 FF To dptr410A C8410B MOV X@ dptr, A F0 Send the data from A to

dptr410C MOV A, # OD 74 Move the upper byte 410D 00 Of the count to A410E MOV X @ dptr, A F0410F HLT S jump hlt 80, FE Short jump to terminate the

programe

OUTPUT

t

v

Page 4: Interfacing in 8051

FLOW CHART

RESULT:Thus the assembly language program to interface a stepper motor with 8051 was

written and verified.

Start

Initialize the dptr with port address

Get the control word and send it to port FFCE

Get the higher and lower byte of count and send it to FFCE

Stop

Page 5: Interfacing in 8051

PROGRAMMING INTERNAL INTERUPT IN 8051

Ex. No. Date:

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 registerStep 3: Initialize TL1 and TH1 as 000H

Step 4: Set the TR1 bitStep 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 bitStep 7: ISR : Add two input data and store the result in dprtStep 8: Stop

Programe Name: Programming internal interrupt in 8051

Address Label Mnemonic Opcodes Comments4100 MOV TMOD, # 10 75 Set the TMOD

4101 89 Register4102 104103 MOV 1 E, # 88H 75 Set the interrupt4104 A8 Enable register4105 884106 MOV TH1, # 000H 75 Initialize TH1 as4107 8D 000H

4108 004109 MOV, TF1, # 000H 75 Initialize TL1 as410A 8C 000H

410B 00410C SET B TR1 D2 SET the TR1 B (8E)410D 8E410E L1 JNB TF1, L1 30 If the TF1 big in410F 8F Not set loop4110 FDE There4111 CLR TR1 C2 Clear the TR1 bit4112 8E4113 L2 S JMP L2 80 Terminate the 4114 FE Program

Page 6: Interfacing in 8051

Interrupt Service Routine5030 MOV A, # 12H 74 Move the data 12H

5031 12 To A5032 ADD A, # 12 74 Add the contents5033 12 Of A with 12H5034 MOV DPTR, # 4500 90 Initialize the dptr5035 45 With 45005036 005037 MOV X @ DPTR, A F05038 HLT S JMP HLT 80, FE Termination the program

CONTROL WORD

Gate C/T M1 M0 Gate C/T M1 M0

0 0 0 1 0 0 0 0

INTERRUPT ENABLE REGISTER

EA - ET2 ES ET1 EX1 ET0 EX0

1 0 0 0 1 0 0 0

OUTPUT4500 : 24H

– TMOD

–10H

– TMOD

– 88H

Enable Interrupt

Page 7: Interfacing in 8051

FLOW CHART

Start

Get the control word for TMOD + Interrupt enable

Initialize the control word in TMOD + 1E

Initialize TH1 and TL1 as 000H

Set the TR1 bit

IfTF1 = 1

N

Processor vectors to ISR

ISR: Add two input values and store the result in dptr

Clear TR1 bit

Stop

Page 8: Interfacing in 8051

PROGRAMMING THE UART IN 8051

Ex.No. Date:

AIM:To write an assembly language program to UART in 8051.

ALGORITHM:

Step 1 : Set the TMOD valueStep 2 : Initialize TH1 as FDH and TL1 as 00H

Step 3 : Set the TCON valueStep 4 : Set the SCON valueStep 5 : Get the data in SBUFStep 6 : Keep looping till the SCON.0 bit (receiver interrupt flag) is setStep 7 : If the SCOn.0 is set, clear itStep 8 : Move the data from SBUF to AStep 9 : Initialize dptr and store the content of A in itStep 10: Stop

Programe Name: Programming UART in 8051

Address Label Mnemonic Opcodes Comments4120 MOV TMOD, # 20H 75 Set the TMOD value4121 89 with 20H

4122 204123 MOV TH1, # TDH 75 Move FD to TH1

4124 804125 FD4126 MOV TL1, # 000H 75 Move 00H to TL1

4127 8B4128 004129 MOV TCON, # 40H 75 Set the TCON 412A 88 With 40H

412B 40412C MOV SCON, # 58H 75 Set the SCON with412D 98 58H

412E 58412F MOV, SBUF, # 54H 75 Move the data 54H

4130 99 To SBUF4131 544132 Re JNB SCON.0, Re 30 Jump on No bit in4133 98 SCON.0 to Re4134 FD4135 CLR SCON.0 C2 Clear SCON.0 bit

Page 9: Interfacing in 8051

4136 984137 MOV A, SBUF E5 Move the data from4138 99 SBUF to A4139 MOV dptr, # 4500 90 Initialize the dptr413A 45 With 4500413B 03413C MOV X @ dptr, A FO Move the data from A to dptr413D HLT S JMP.HLT 80,FE Terminate the program using short

jump

TMOD

Gate C/T M1 M0 Gate C/T M1 M0

0 0 1 0 0 0 0 0

TCON

TF1 TR1 TF0 TR0 1E1 1T1 1E0 1T0

0 1 0 0 0 0 0 0

SCON

SM0 SM1 SM2 REN TB8 RB8 T1 R1

0 1 0 1 1 0 0 0

RESULT:Thus the assembly language program to UART of 8051 was written and verified.

20

40

58

Page 10: Interfacing in 8051

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

IfSCON.0 =

1

N

Clear SCON.0

Move the data from SBUF to A

Initialize dptr and store the data in it

Stop

Page 11: Interfacing in 8051

TRAFFIC LIGHT CONTROLLEREx.No. Date:

AIM:To write an ALP to perform traffic light control.

ALGORITHM:

Step 1 : StartStep 2 : Initialize dptr with the port addressesStep 3 : Send the control word to the control registerStep 4 : Send the control word to allow the traffic from North to eastStep 5 : Call delayStep 6 : Send the control word to allow the traffic from east to south and

call delayStep 7 : Send the control word to allow the traffic from south to west and

call delayStep 8 : Send the control word to allow the traffic from west to North and

call delayStep 9 : Repeat for various directionStep 10: Stop

Programme Name:

Address Label Mnemonic Opcodes Comments4100 MOV A, % 80H 244101 804012 MOV dptr, # control 904103 FF4104 OF4105 Mov x @dptr, A FO4106 Start Mov R4, # 04H 7C4107 044108 Mov dptr, # loop1 704109 41410A 91410B Mov R2, DPH AF410C 83410D Mov R3, DPL AB410E 82410F Mov dptr, # loop 704110 41

Page 12: Interfacing in 8051

4111 814112 MOV R01, DPH A84113 834114 MOV R1, DPL 494115 G0 824116 MOV X A, @ dptr EO4117 Mov R0, DPH A84118 834119 MOV R1, DPL A9411A 82411B MOV dptr, # port A 90411C PF411D OC411E MOV X @ dptr, A FO411F INC R1 094120 MOV DPH, R0 884121 834122 MOv DPL, R1 894123 824124 MOV X A, @ dptr EO4125 MOV R0, DPH A84126 814127 MOV R1, DPL A94128 824129 MOV Dptr, @ port B 70412A PT412B OD412C MOV X @dptr, A FO412D INC R1 OP412E MOV DPH, R0 83412F 874130 894131 MOV DPL, R1 824132 EO4133 MOV X A, @ dptr A84134 MOV R0, DPH 804135 A74136 MOV R1, DPL 824137 904138 MOV Dptr, # Port C FF4139 82413A FO413B MOV X @ dptr, A 09413C INC R1 12413D Call Delay 41

Page 13: Interfacing in 8051

413E 78413F MOV DPH, R2 8A4140 834141 MOV DPL, R3 8B4142 824143 MOV X A, @ dptr EO4144 MOV R2, DPH A94145 834146 MOV R3, DPL AB4147 824148 MOV Dptr, # port A 904149 FF414B 09414C MOV X @ dptr, A FO414D INC R3 DB414E MOV DPH, R2 8A414F 8341504151 MOV R3, DPL AB4152 824153 MOV dptr, # port B 904154 FF4155 OB4156 MOV X @ dptr, A FO4157 INC R3 OB4158 MOV DPH, R2 8A4159 83415A MOV DPL, R3 8B415B 82415C MOV X A, @ dptr EO415D MOV R2, DPH AB415E 83415F MOV R3, DPL AB4160 824161 MOV dptr, # port C 904162 FF4163 OE4164 MOV X @ dptr, A FO

INC R3 OB4165 L call delay 124166 414167 824168 MOV DPH, R0 884169 83416A

Page 14: Interfacing in 8051

416B MOV DPL, R1 89416C 82416D DJNZ R4, G0 PC416E A4416F 2 Call delay 124170 414171 064172 Delay MOV R5, # 12H 7D4173 124174 L3 MOV R6,# OFFH RE4175 FF4176 L2 MOV R7,# OFFH 7E4177 FF4178 L1 DJNZ R7, L1 DF4179 FF417A DJNZ, R6, L2 DF417B FE417C DJNZ, R5, L3 DE417D FA417E RET DD417F4180 Delay 1 MOV R5, #12 F64181 L6 MOV R6, #OFF 704182 7E4183 FF4184 L5 MOV R7, #OFFH 7E4185 FF4186 L7 DJNZ R7, L4 7F4187 FE4188 DJNZ R6, L5 DF4189 FE418A DJNZ R5, L6 DE418B FA418C RET DE418D F6418E Look DB, 44H, 27H, 12H 42418F 274190 124191 DB, 92H, 2BH, 10H 924192 2B4193 104194 DB, 84H, 90H, 10H 844195 904196 104197 DB 94H, 9DH, 10H 84

Page 15: Interfacing in 8051

4198 9D4199 10419A Look1 DB 48H, 27H, 12H 84419B 9D419C 10419D DB, 92H, 4BH, 10H 48419E 27419F 124200 924201 4B4202 DB, 84H, 90H, 20H 844203 904204 204205 DB, 04H, 2EH, 49H 044206 2F4207 49

RESULT:Thus the assembly language program to perform traffic light controller was

written.