You are on page 1of 16

COURSE CODE - ECE3003

TITLE - MICROCONTROLLER AND ITS


APPLICATION

TASK 3

ASSESSMENT 3

NAME – TANMAY PATHAK


REGISTRATION NUMBER-16BEC0336
SLOT- L11+L12
3/09/18

Program 1: Write a program using Timer 0 Mode 1 to generate a 500 Hz square


wave frequency on one of the pins of P1. Then examine the frequency using KEIL
IDE inbuilt logic analyzer.

Code:

ORG 0000H
MOV TMOD, #01H ; Timer 0 Mode 1
HERE:MOV TL0,#66H
MOV TH0,#0FCH
CPL P1.0
ACALL DELAY
SJMP HERE
DELAY: SETB TR0
AGAIN:JNB TF0,AGAIN
CLR TR0
CLR TF0
RET
END

Calculations:
Given,

Frequency, f = 500 Hz ∴ Time

Period, T = 1/f = 1/500 = 0.002

Therefore T/2= 0.001


3/09/18

∴ (64614.342)10 = (FC66)16

∴ 0FCH will be loaded in THO and 66H will be loaded in TL0

EXECUTION :

Implementation:

1. Write the TMOD value according to Timer 0 and Mode 1 configurations as


MOV TMOD,#01H.
2. Calculate the values to be loaded in TH (0FCH) and TL (66H) according to
given frequency of 500 Hz, set those values using MOV TL0,#66H & MOV
THO,#0FCH.
3. Complement the desired output port P1.0 using CPL P1.0.
4. Use ACALL DELAY command to call the DELAY fuction.
5. SJMP HERE command will be executed. Use HERE label before the
commands used to load values in TL0 & TH0 to give the continuous output
waveform.
6. Under DELAY function, use SETB TR0 command to start the timer, after the
timer starts the value of timer is incremented by 1. Use JNB TF0 command to
check the value of TF0; and jump out of the loop when TF0 will turn 1. TF0
will turn 1 when the timer reaches maxixum value (FFFF).
3/09/18

7. Use CLR TR0, CLR TF0 command to stop the timer and to clear the timer
flag 0 respectively.
8. Use RET command to return to the command just after ACALL DELAY.

Program 2: Write a program using Timer 1 Mode 0 to generate a 1 KHz square


wave frequency on one of the pins of P1. Then examine the frequency using KEIL
IDE inbuilt logic analyzer.

Code:

ORG 0000H
MOV TMOD, #10H; Timer 1 Mode 0
HERE:MOV TL1,#33H
MOV TH1,#0FEH
CPL P1.0
ACALL DELAY
SJMP HERE
DELAY: SETB TR1
AGAIN:JNB TF1,AGAIN
CLR TR1
CLR TF1
RET
END

Calculations:
Given,

Frequency, f = 1000 Hz

∴ Time Period, T = 1/f = 1/1000= 0.001


3/09/18

So, T/2 = 0.0005

∴ (65075.171)10 = (FE33)16 16BEC0887

∴ 0FEh will be loaded in THO and 33H will be loaded


in TL0

EXECUTION :

Implementation:

1. Write the TMOD value according to Timer 1 and Mode 0 configurations as


MOV TMOD,#10H.
2. Calculate the values to be loaded in TH (0FEH) and TL (33H) according to
given frequency of 1 KHz, set those values using MOV TL1,#33H & MOV
TH1,#0FEH.
3. Complement the desired output port P1.0 using CPL P1.0.
4. Use ACALL DELAY command to call the DELAY fuction.
5. SJMP HERE command will be executed. Use HERE label before the
commands used to load values in TL1 & TH1 to give the continuous output
waveform.
3/09/18

6. Under DELAY function, use SETB TR1 command to start the timer, after the
timer starts the value of timer is incremented by 1. Use JNB TF1 command to
check the value of TF1; and jump out of the loop when TF1 will turn 1. TF1
will turn 1 when the timer reaches maxixum value (FFFF).
7. Use CLR TR1, CLR TF1 command to stop the timer and to clear the timer
flag 0 respectively.
8. Use RET command to return to the command just after ACALL DELAY.

Program 3: Write a program using Timer 1 Mode 2 to generate a 3 KHz square


wave frequency on one of the pins of P1. Then examine the frequency using KEIL
IDE inbuilt logic analyzer.

Code:

ORG 0000H
MOV TMOD, #20H ; Timer 1 Mode 2 HERE:
MOV TH1,#76H
CPL P1.0
ACALL DELAY
SJMP HERE
DELAY: SETB TR1
AGAIN:JNB TF1,AGAIN
CLR TR1
CLR TF1
RET
END
3/09/18

Calculations:
Given,
Frequency, f = 3000 Hz

∴ Time Period, T = 1/f= 1/3000= 0.0003

So, T/2 = 0.00015

∴ 76 will be loaded in TH1 and no value will be loaded in TL1 as it is Auto Reload
Mode.

Execution:
3/09/18

Implementation:

1. Write the TMOD value according to Timer 1 and Mode 2 configurations as


MOV TMOD,#20H.
2. Calculate the value to be loaded in TH1 (76H) according to given frequency
of 3 KHz, set this value using MOV TH1,#76H. There is no need to load value
in TL of Mode 2 as it is Auto Reload Mode. The value which will be loaded
to TH will be automatically copied toTL.
3. Complement the desired output port P1.0 using CPL P1.0.
4. Use ACALL DELAY command to call the DELAY fuction.
5. SJMP HERE command will be executed. Use HERE label before the
command used to load value in TH1 to give the continuous output waveform.
6. Under DELAY function use SETB TR1 command to start the timer, after the
timer starts the value of timer is incremented by 1. Use JNB TF1 command to
check the value of TF1; and jump out of the loop when TF1 will turn 1. TF1
will turn 1 when the timer reaches maxixum value (FFFF).
7. Use CLR TR1, CLR TF1 command to stop the timer and to clear the timer
flag 0 respectively.
8. Use RET command to return to the command just after ACALL DELAY.
11/09/18

Program 4: Develop an 8051 ALP program to generate square waves as shown


below. Examine the same using the KEIL IDE inbuilt Logic Analyzer.

Code:

ORG 0000H
MOV TMOD,#01H ; TIMER 0 MODE 1
MOV TL0,#000H
MOV TH0,#0DCH
SETB P1.0 ACALL
DELAY HERE:
MOV TL0,#00H
MOV TH0,#0DCH
CPL P1.0
ACALL DELAY
MOV TL0,#00H
MOV TH0,#0DCH
CPL P2.0

ACALL DELAY
11/09/18

SJMP HERE
DELAY: SETB TR0
AGAIN:JNB TF0,AGAIN
CLR TR0
CLR TF0
RET
END

Calculations:

For Time Period, T=20ms

So, T/2 = 10ms = 0.01s

∴ (56320)10 = (DC00)16
∴ 0DCH will be loaded in THO and 00H will be loaded in TL0
11/09/18

EXECUTION:

Implementation:

1. Write the TMOD value according to Timer 0 and Mode 1 configurations as


MOV TMOD,#01H.
2. Calculate the values to be loaded in TH (0DCH) and TL (00H) for port 1.0 to
give a delay of 10 mS, set those values using MOV TL0,#00H & MOV
THO,#0DCH.
3. Use SETB P1.0 command to set the value of port P1.0 = 1 for intitial 10 mS.
4. Use ACALL DELAY command to call the DELAY fuction. 5. Write MOV
TL0,#00H & MOV THO,#0DCH for port P1.0.
6. Complement the desired output port P1.0 using CPL P1.0.
7. Use ACALL DELAY command to call the DELAY fuction.
8. Again write MOV TL0,#00H & MOV THO,#0DCH for port P2.0.
9. Complement the desired output port P2.0 using CPL P2.0.
10.Use ACALL DELAY command to call the DELAY fuction.
11/09/18

11.SJMP HERE command will be executed. Use HERE label after the command
used to give the initial delay of 10 mS to give the continuous output waveform.
12.Under DELAY function, use SETB TR0 command to start the timer, after the
timer starts the value of timer is incremented by 1. Use JNB TF0 command to
check the value of TF0; and jump out of the loop when TF0 will turn 1. TF0
will turn 1 when the timer reaches maxixum value (FFFF).
13.Use CLR TR0, CLR TF0 command to stop the timer and to clear the timer
flag 0 respectively.
14.Use RET command to return to the command just after ACALL DELAY.
Program 5: Write an ALP using 8051 to check the status of two switches connected
to port P2.1 and P2.2. If any one of the switches is ON (logic 1) make the LED
connected to port 2.7 to toggle for 250 microseconds. Repeat this continuously.

Code:

ORG 0000H
SETB P2.1
SETB P2.2
CLR P2.6 XX:
MOV C,P2.1
ORL C,P2.2
MOV P2.6,C
JNB P2.6,XX
MOV TMOD,#01H
MOV TL0,#1AH
MOV TH0,#0FFH
SETB P2.7
ACALL DELAY
MOV TMOD,#01H
MOV TL0,#1AH
MOV TH0,#0FFH
CLR P2.7
ACALL DELAY
SJMP XX
DELAY: SETB TR0
AGAIN:JNB TF0,AGAIN
CLR TR0
CLR TF0
RET
END

Calculations:

For Time Period, T=500µs

So, T/2 = 250µs

∴ (65306)10 = (FF1A)16
∴ 0FFH will be loaded in THO and 1AH will be loaded in TL0
Execution:

Input to P2.1 as 0 and to P2.2 as 1; hence we get corresponding toggling output at


P2.7
Input to P2.1 as 0 and to P2.2 as 0; hence we get output in P2.7 as 0
Implementation:

1. Declare the ports P2.1 & P2.2 as input ports using SETB.
2. Declare the port P2.6 as output ports using CLR.
3. Use ORL command to get the ORL gate output and store the result in port
P2.6.
4. Use JNB P2.6 command to check the value of port P2.6; and jump out of the
loop when port P2.6 will turn 1. If value of port P2.6 will be 0, move to label
XX . Use XX label before the commands used to get the OR gate result.
5. Write the TMOD value according to Timer 0 and Mode 1 configurations as
MOV TMOD,#01H.
6. Calculate the values to be loaded in TH (0FFH) and TL (1AH) according to
given time period of 250µs, set those values using MOV TL0,#1AH & MOV
THO,#0FFH.
7. Use SETB P2.7 command to set the value of port P2.7 = 1.
8. Use ACALL DELAY command to call the DELAY fuction.
9. Again write MOV TL#1AH & MOV THO,#0FFH.
10.Use CLR P2.7 command to set the value of port P2.7 = 0.
11.Use ACALL DELAY command to call the DELAY fuction.
12.SJMP XX command will be executed. Use XX label before the commands
used to get the OR gate result.
13.Under DELAY function, use SETB TR0 command to start the timer, after
the timer starts the value of timer is incremented by 1. Use JNB TF0
command to check the value of TF0; and jump out of the loop when TF0 will
turn 1. TF0 will turn 1 when the timer reaches maxixum value (FFFF).
14.Use CLR TR0, CLR TF0 command to stop the timer and to clear the timer
flag 0 respectively.
15.Use RET command to return to the command just after ACALL DELAY.

You might also like