Embedded C Programming 5
Embedded C Programming 5
Digital Assignment
Submitted by
Full Name: Sudarshan Ravindran
Algorithm:
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.