Professional Documents
Culture Documents
Micro Task 3 - Merged - Compressed
Micro Task 3 - Merged - Compressed
Algorithm:-
1.Initialize Timer 0 in Mode 1 with an appropriate reload value to generate a
100 microsecond delay.
2.Configure Port 0 as an output port to control the LED.
3.Turn on the LED by setting the corresponding bit in Port 0.
4.Start Timer 0.
5.Wait for Timer 0 to complete its 100 microsecond delay.
6.Turn off the LED by clearing the corresponding bit in Port 0.
7.End the program.
FlowChart:-
Start
Configure Port 0 as an
output port to control
the LED.Turn on the LED
by setting the
corresponding bit in
Port 0.
END
Code:-
ORG 0000H
LJMP MAIN
ORG 00BH
CPL P0.0
RETI
ORG 0030H
MAIN: MOV TMOD,#01H
MOV P0,#0FFH;
MOV TH0,#0A4H
MOV IE,#82H
SETB TR0
BACK: MOV A,P0
SJMP BACK
END
Output:-
Before Execution:
After Execution:-
Inference:-
The algorithm uses Timer 0 in Mode 1 to generate a precise delay of 100
microseconds, allowing the LED to glow for that duration before turning off.
Q2. Making an led connected to port0 to glow for 500us using timer0,mode1
or to generate a square wave of 2kHz using timer0 and mode1
Sol:-
Aim:-
To make an LED connected to Port 0 glow for 500 microseconds using Timer 0
in Mode 1 and generating square wave for 2KHz
Components required:-
https://www.keil.com/download/pro
duct/ http://www.edsim51.com/
https://www.electronicshub.org/8051
-simulators/
https://www.edgefxtech.com/blog/8051-microcontroller-
simulator-and- emulator/
https://www.onworks.net/software/app-gsim51-8051-
microcontroller- simulator/
Algorithm:-
1 Initialize Timer 0 in Mode 1 with a suitable reload value to generate a 500
microsecond delay.
2.Configure Port 0 as an output port to control the LED.
3.Turn on the LED by setting the corresponding bit in Port 0.
4.Start Timer 0.
5.Wait for Timer 0 to complete its 500 microsecond delay.
6.Turn off the LED by clearing the corresponding bit in Port 0.
7.End the program.
FlowChart:-
Start
Initialize the timer0
and mode 1
Configure Port 0 as an
output port to control the
LED.Turn on the LED by
setting the corresponding
bit in Port 0 and analyse
the wave
END
Code:-
ORG 0000H
LJMP MAIN
ORG 00BH
CPL P0.0
RETI
ORG 0030H
MAIN: MOV TMOD,#01H
MOV P0,#0FEH;
MOV TH0,#34H
MOV IE,#82H
SETB TR0
BACK:MOV A,P0
SJMP BACK
END
Output:-
Inference:-
The LED glow algorithm uses Timer 0 in Mode 1 to generate a precise delay of
500 microseconds, allowing the LED to glow for that duration before turning
off. The square wave algorithm utilizes Timer 0 in Mode 1 to generate a square
wave of 2 kHz on Port 0..
Q3. Making an led connected to port0 to glow for 150us and then off for
400us using timer1 in mode1
Sol:-
Aim:-
To make an LED connected to Port 0 glow for 150 microseconds using Timer 1
in Mode 1 and then off for 400us
Components required:-
https://www.keil.com/download/pro
duct/ http://www.edsim51.com/
https://www.electronicshub.org/8051
-simulators/
https://www.edgefxtech.com/blog/8051-microcontroller-
simulator-and- emulator/
https://www.onworks.net/software/app-gsim51-8051-
microcontroller- simulator/
Algorithm:-
1.Initialize Timer 1 in Mode 1 with suitable reload values to generate a 150
microsecond delay and a 400 microsecond delay.
2.Configure Port 0 as an output port to control the LED.
3.Turn on the LED by setting the corresponding bit in Port 0.
4.Start Timer 1 for the 150 microsecond delay.
5.Wait for Timer 1 to complete the 150 microsecond delay.
6.Turn off the LED by clearing the corresponding bit in Port 0.
7.Start Timer 1 again for the 400 microsecond delay.
8.Wait for Timer 1 to complete the 400 microsecond delay.
9.Repeat the process from step 3 to create the desired blinking pattern.
FlowChart:-
Start
Configure Port 0 as an
output port to control the
LED..Turn on the LED by
setting the corresponding
bit in Port 0.Start Timer 1
for the 150 microsecond
delay.
Code:-
DELAY_ON equ 150 ; 150 microseconds delay for LED on
DELAY_OFF equ 400 ; 400 microseconds delay for LED off
ORG 0000h ; Start of the program
MAIN:
; Initialize Timer 1 in Mode 1
MOV TMOD, #01h ; Timer 1, Mode 1 (16-bit timer, mode 1)
MOV TH1, #0 ; Initialize Timer 1 high byte
MOV TL1, #0 ; Initialize Timer 1 low byte
MOV P0, #0FFh ; Set all bits of Port 0 as output
LOOP:
; Turn on the LED (set bit 0 of Port 0)
SETB P0.0 ; Set bit 0 of Port 0
MOV TL1, #LOW(DELAY_ON)
MOV TH1, #HIGH(DELAY_ON)
SETB TR1 ; Start Timer 1
LOOP1:
JNB TF1, LOOP1 ; Wait for Timer 1 to overflow
CLR P0.0 ; Clear bit 0 of Port 0
MOV TL1, #LOW(DELAY_OFF)
MOV TH1, #HIGH(DELAY_OFF)
SETB TR1 ; Start Timer 1
LOOP2:
JNB TF1, LOOP2 ; Wait for Timer 1 to overflow
SJMP LOOP ; Repeat the loop indefinitely
END
Output:-
Before Execution:
After Execution:-
Inference:-
This algorithm will create the specified LED blinking pattern with the desired
durations of glow and off time using Timer 1 in Mode 1.
Q4. Making an led connected to port0 to glow for 100us in mode2 of timer1
Sol:-
Aim:-
To make an LED connected to Port 0 glow for 100 microseconds using Timer 1
in Mode 2
Components required:-
https://www.keil.com/download/pro
duct/ http://www.edsim51.com/
https://www.electronicshub.org/8051
-simulators/
https://www.edgefxtech.com/blog/8051-microcontroller-
simulator-and- emulator/
https://www.onworks.net/software/app-gsim51-8051-
microcontroller- simulator/
Algorithm:-
1.Initialize Timer 1 in Mode 2 with an appropriate reload value to generate a
100 microsecond delay.
2.Configure Port 0 as an output port to control the LED.
3.Turn on the LED by setting the corresponding bit in Port 0.
4.Start Timer 1.
5.Wait for Timer1 to complete its 100 microsecond delay.
6.Turn off the LED by clearing the corresponding bit in Port 0.
7.End the program.
FlowChart:-
Start
Initialize the timer1
and mode 2
Configure Port 0 as an
output port to control
the LED.Turn on the LED
by setting the
corresponding bit in
Port 0.
END
Code:-
ORG 0000H
LJMP MAIN
ORG 00BH
CPL P0.0
RETI
ORG 0030H
MAIN: MOV TMOD,#20H
MOV P0,#0FFH;
MOV TH0,#0A4H
MOV IE,#82H
SETB TR0
BACK: MOV A,P0
SJMP BACK
END
Output:-
Before Execution:
After Execution:-
Inference:-
The algorithm uses Timer 1 in Mode 2 to generate a precise delay of 100
microseconds, allowing the LED to glow for that duration before turning off.
Q5.Make P2.7 glow and off for 1000us in mode1 of timer0
Sol:-
Aim:-
To make an LED connected to Port 2.7 glow for 1000 microseconds using Timer
0 in Mode 1.
Components required:-
https://www.keil.com/download/pro
duct/ http://www.edsim51.com/
https://www.electronicshub.org/8051
-simulators/
https://www.edgefxtech.com/blog/8051-microcontroller-
simulator-and- emulator/
https://www.onworks.net/software/app-gsim51-8051-
microcontroller- simulator/
Algorithm:-
1.Initialize Timer 0 in Mode 1 with an appropriate reload value to generate a
1000 microsecond delay.
2.Configure Port 2.7 as an output port to control the LED.
3.Turn on the LED by setting the corresponding bit in Port 0.
4.Start Timer 0.
5.Wait for Timer 0 to complete its 1000 microsecond delay.
6.Turn off the LED by clearing the corresponding bit in Port 2.7
7.End the program.
FlowChart:-
Start
END
Code:-
ORG 0000H
LJMP MAIN
ORG 00BH
CPL P2.7
RETI
ORG 0030H
MAIN: MOV TMOD,#01H
MOV P2,#0FCH;
MOV TH0,#68H
MOV IE,#82H
SETB TR0
BACK: MOV A,P2
SJMP BACK
END
Output:-
Before Execution:
After Execution:-
Inference:-
The algorithm uses Timer 0 in Mode 1 to generate a precise delay of 1000
microseconds on port 2.7 pin, allowing the LED to glow for that duration
before turning off.
Q6. Make P0.0 and P1.0 LEDs glow and off for 200 microseconds using Timer
0 in Mode1
Sol:-
Aim:-
To make both P0.0 and P1.0 LEDs glow for 200 microseconds and then turn off
for 200 microseconds using Timer 0 in Mode 1.
Components required:-
https://www.keil.com/download/pro
duct/ http://www.edsim51.com/
https://www.electronicshub.org/8051
-simulators/
https://www.edgefxtech.com/blog/8051-microcontroller-
simulator-and- emulator/
https://www.onworks.net/software/app-gsim51-8051-
microcontroller- simulator/
Algorithm:-
1.Initialize Timer 0 in Mode 1.
2.Configure Port 0 and Port 1 as output ports to control the LEDs.
3.Set both P0.0 and P1.0 to turn on (glow) simultaneously.
4.Start Timer 0 for 200 microseconds.
5.Wait for Timer 0 to complete the 200-microsecond delay.
6.Clear both P0.0 and P1.0 to turn off simultaneously.
7.Start Timer 0 again for another 200 microseconds.
8.Repeat the process from step 3 to create the desired blinking pattern..
FlowChart:-
Start
Initialize the timer0
and mode 1
END
Code:-
DELAY_ON equ 200 ; 200 microseconds delay for LED on
DELAY_OFF equ 200 ; 200 microseconds delay for LED off
MAIN:
MOV TMOD, #01h ; Timer 0, Mode 1 (16-bit timer, mode 1)
MOV TH0, #0 ; Initialize Timer 0 high byte
MOV TL0, #0 ; Initialize Timer 0 low byte
MOV P0, #0FFh ; Set all bits of Port 0 as output
MOV P1, #0FFh ; Set all bits of Port 1 as output
LOOP:
SETB P0.0 ; Set bit 0 of Port 0
SETB P1.0 ; Set bit 0 of Port 1
MOV TL0, #LOW(DELAY_ON)
MOV TH0, #HIGH(DELAY_ON)
SETB TR0 ; Start Timer 0
LOOP1:
JNB TF0, LOOP1 ; Wait for Timer 0 to overflow
CLR P0.0
CLR P1.0 ; Clear bit 0 of Port 1
MOV TL0, #LOW(DELAY_OFF)
MOV TH0, #HIGH(DELAY_OFF)
SETB TR0 ; Start Timer 0
LOOP2:
JNB TF0, LOOP2 ; Wait for Timer 0 to overflow
SJMP LOOP ; Repeat the loop indefinitely
END
Output:-
Inference:-
The algorithm will use Timer 0 in Mode 1 to generate precise delays of 200
microseconds for LED glow and LED off cycles. This will create a blinking
pattern where both LEDs will alternately glow and turn off with a 200-
microsecond duration for each state.
Q7. Make inputs from P0.2,P0.1,P0.0 as switch and led connected to P1.0 is to
be glow as (001-1kHz),(010-2kHz),(100-4kHz),delay is given using
timer0,mode1
Sol:-
Aim:-
To use inputs from P0.2, P0.1, and P0.0 as switches to control the frequency of
the LED connected to P1.0 (001 - 1 kHz, 010 - 2 kHz, 100 - 4 kHz) using Timer 0
in Mode 1.
Components required:-
https://www.keil.com/download/pro
duct/ http://www.edsim51.com/
https://www.electronicshub.org/8051
-simulators/
https://www.edgefxtech.com/blog/8051-microcontroller-
simulator-and- emulator/
https://www.onworks.net/software/app-gsim51-8051-
microcontroller- simulator/
Algorithm:-
1. Initialize Timer 0 in Mode 1.
2. Configure Port 0 (P0) with P0.2, P0.1, and P0.0 as input switches and
Port 1 (P1) with P1.0 as the output for the LED.
3. Continuously monitor the states of P0.2, P0.1, and P0.0 to determine the
switch combinations.
4. If the switch combination is 001, set Timer 0 to generate a 1 kHz square
wave for the LED on P1.0.
5. If the switch combination is 010, set Timer 0 to generate a 2 kHz square
wave for the LED on P1.0.
6. If the switch combination is 100, set Timer 0 to generate a 4 kHz square
wave for the LED on P1.0.
7. Wait for Timer 0 to complete the delay for the specified frequency.
8. Repeat the process to continuously update the LED frequency based on
the switch inputs.
FlowChart:-
Start
END
Code:-
SWITCH_1KHZ equ 001b ; Switch combination for 1 kHz
SWITCH_2KHZ equ 010b ; Switch combination for 2 kHz
SWITCH_4KHZ equ 100b ; Switch combination for 4 kHz
ORG 0000h ; Start of the program
MAIN:
MOV TMOD, #01h ; Timer 0, Mode 1 (16-bit timer, mode 1)
MOV TH0, #0 ; Initialize Timer 0 high byte
MOV TL0, #0 ; Initialize Timer 0 low byte
MOV P0, #0FFh ; Set all bits of Port 0 as input
CLR P1.0 ; Clear bit 0 of Port 1 for LED output
LOOP:
MOV A, P0 ; Load switch inputs into accumulator
CJNE A, #SWITCH_1KHZ,LOOP1
MOV TH0, #0 ; Set Timer 0 high byte for 1 kHz
MOV TL0, #250 ; Set Timer 0 low byte for 1 kHz (1 ms delay)
SJMP start_timer
LOOP1:
CJNE A, #SWITCH_2KHZ, LOOP2
MOV TH0, #0 ; Set Timer 0 high byte for 2 kHz
MOV TL0, #125 ; Set Timer 0 low byte for 2 kHz (0.5 ms delay)
SJMP start_timer
LOOP2:
CJNE A, #SWITCH_4KHZ, LOOP ; If not 4 kHz, repeat loop
MOV TH0, #0 ; Set Timer 0 high byte for 4 kHz
MOV TL0, #62 ; Set Timer 0 low byte for 4 kHz (0.25 ms delay)
start_timer:
SETB TR0 ; Start Timer 0
timer_loop:
JNB TF0, timer_loop ; Wait for Timer 0 to overflow
CPL P1.0 ; Complement bit 0 of Port 1 for LED output
SJMP loop ; Repeat the loop indefinitely
END
Output:-
Inference:-
The algorithm will monitor the states of P0.2, P0.1, and P0.0 to determine the
desired frequency (1 kHz, 2 kHz, or 4 kHz) for the LED connected to P1.0. Timer
0 in Mode 1 will be used to generate the corresponding delays to achieve the
specified frequencies.