SCHOOL OF ELECTRICAL ENGINEERING
VELLORE INSTITUTE OF TECHNOLOGY
VELLORE – 632 014, TAMIL NADU, INDIA
BECE320P– EMBEDDED C PROGRAMMING LAB
WINTER SEMESTER – 2024-2025
SLOT – L19+L20
Digital Assignment
Submitted by
Full Name: Sudarshan Ravindran
Registration No: 22BEE0330
Faculty Name: MARIMUTHU R
Name: Sudarshan Ravindran
Reg. No: 22BEE0330
Lab Slot: L19 + L20
Faculty: Prof. MARIMUTHU R
Assignment-5(a)
8051 Embedded-C programming
Date: 27-03-2025
Aim:
To generate a 1 kHz square wave on pin P1.1 of the
8051 microcontroller.
Algorithm:
• Start the program and include the necessary header
file (reg51.h).
• Define the output pin (P1.1) using sbit.
• Initialize Timer 0 in Mode 1 (16-bit mode).
• Enter an infinite loop (while(1)) to continuously
generate the waveform.
• Inside the loop:
a. Initialize a counter variable x = 0.
b. Start a nested loop to run 10 times (to achieve the
required delay).
c. Load the Timer 0 registers (TH0 and TL0) with
appropriate values to generate a 500 µs delay.
d. Start Timer 0 by setting TR0 = 1.
e. Wait for the Timer Overflow flag (TF0 == 1).
f. Stop the timer (TR0 = 0) and reset the overflow
flag (TF0 = 0).
g. Increment x and repeat the loop until x == 10.
• After exiting the loop, toggle the output pin (P1.1)
to create the square wave.
• Reset x = 0 and repeat the process.
Programs:
Outputs:
Conclusion:
Through this experiment, a 1 kHz square wave was successfully
generated on pin P1.1 of the 8051-microcontroller using Timer 0 in
Mode 1. The timer was configured to provide a 500 µs delay,
ensuring a 10 ms time period for the waveform. This experiment
demonstrated the effective use of timers for precise waveform
generation in embedded systems.
Assignment-5(b)
8051 Embedded-C programming
Date: 27-03-2025
Aim:
To generate a 100 Hz square wave on Port 1.1 (P1.1) of the 8051 microcontroller.
Additionally, when External Interrupt 0 (INT0) is activated, the frequency of the
generated square wave should double.
Algorithm:
1. Initialize Timer 0 in Mode 1 (16-bit mode).
2. Configure External Interrupt 0 (INT0) for edge-triggered operation.
3. Set up Timer 0 values for generating a 100 Hz square wave (TH0 = 0xEE, TL0 =
0x00).
4. Enable global and external interrupts.
5. Start an infinite loop:
o Load Timer 0 initial values (TH0, TL0).
o Start Timer 0.
o Wait for TF0 (Timer Overflow Flag) to set.
o Toggle P1.1 (square wave output).
o Stop Timer 0 and clear TF0.
o Repeat the process.
6. When External Interrupt 0 (INT0) is triggered:
o Change the timer values to generate a 200 Hz frequency (TH0 = 0xF7, TL0 = 0x00).
7. If INT0 is triggered again, revert to 100 Hz.
8. Repeat the process indefinitely.
Program:
Output:
Conclusion:
In this experiment, a 100 Hz square wave was successfully generated on Port
1.1 (P1.1) of the 8051-microcontroller using Timer 0 in Mode 1 (16-bit mode).
Upon activation of External Interrupt 0 (INT0), the frequency of the square
wave doubled to 200 Hz, demonstrating the ability to dynamically control
signal frequency using external interrupts.