วงจรขับ LED สองขั้ว

Components Required
8051 Microcontroller (AT89C51 is used here)
Programmer for 8051 Microcontroller
11.0592 MHz Crystal
Capacitors – 2 X 33pF, 10µF
Resistors – 150Ω, 10KΩ X 2
Push Buttons X 3
Bipolar LED (two leads)
Connecting Wires
Breadboard
Power Supply

Code
#include<reg51.h>

sbit red = P0^0;
sbit green = P0^1;

sbit red_switch = P0^6;
sbit green_switch = P0^7;


unsigned char i=0;
void delay (int);

void main()
{
red=0;
green=0;

while(1)
{

red=0;
green=0;

while(1)
{
if(red_switch==0)
{
green=0;
red=1;
while(red_switch==0);
}
else if(green_switch==0)
{
green=1;
red=0;
while(green_switch==0);
}
}
}

ความคิดเห็น