Here it is shown how to build power supply for AT89C51 microcontroller and connect a LED to port pin P2.7 for blinking the LED. The following circuit diagram shows power supply connection for AT89C51 microcontroller and LED connected port pin P2.7.
The power supply consists of 9-0-9 two primary three secondary transformer which steps down the 220V AC 50Hz signal down to approximately 24V DC after diode bridge rectifier using the 1N4007 diodes. This is as shown below.
After the diode bridge the capacitor C3 of 1000uF is used to filter low frequencies to smooth the ripple seen on the signal after the bridge rectifier circuit.
The capacitor C4 of 0.1uF is used to reduce or eliminate high frequency noise before entering the linear voltage regulator LM7812. The output of LM7812 is a regulated 12V DC signal. A red LED D5 with resistor R1 of 330Ohm is connected as an indicator that the LM7812 output is producing DC volage. This then passes through the low frequency and high frequency filters made up of the capacitor C3 of 1000uF and C4 of 0.1uF. The 12V DC is then fed into the LM7805 voltage regulator that converts the 12V to 5V DC meant for the power supply for AT89C51 microcontroller. The output of LM7805 is again filtered using the capacitor C8 of 0.1uF. The blue LED D6 along with resistor R3 are used as an indicator that the LM7805 is working and outputting DC voltage. Finally, the 5V DC voltage is applied to VCC pin of AT89C51 microcontroller.
There are other connection in the circuit. The reset pin 9 is connected to +5V via the push button and the same pin is connected to the reset timing circuit made up of R2 of 10KOhm and C7 of 10uF. The crystal oscillator of 11.0592MHz is connected across the pin 18 and 19 as shown with grouding capacitor of 30pF for noise reduction and stability.
Finally, to test the functioning of the AT89C51 microcontroller, we have connected a yellow LED D7 along with resistor R4 of 270Ohm to the port pin P2.7.
Below is the program code to blink the yellow LED using the AT89C51 microcontroller.
#include <reg51.h>
// Define the LED pin at Port 2, Pin 7
sbit LED = P2^7;
// Software delay function
void delay(unsigned int ms) {
unsigned int i, j;
for (i = 0; i < ms; i++) {
for (j = 0; j < 1205; j++) {
// Empty loop for delaying execution
// 1205 iterations gives roughly 1ms delay with a 12MHz crystal
}
}
}
void main(void) {
// Optional: Explicitly initialize the pin as output low
LED = 0;
while(1) {
LED = 1; // Turn LED ON (assuming active-high configuration)
delay(500); // Wait for 500ms
LED = 0; // Turn LED OFF
delay(500); // Wait for 500ms
}
}