y tuong cua em la dung sw1,sw2 de bat tat led1,led2,chi don gian the thoi . nhung dung code nay de mo phong thi phai bam sw1,sw2 may lan thi led 1 led2 moi chiu sang hoac tat di duoc dc, em ko biet sai o dau mong cac bac chi giup...
#include<reg51.h>
#include<stdio.h>
sbit sw1=P1^0;
sbit sw2=P1^1;
sbit led1=P1^7;
sbit led2=P1^6;
bit x=1,y=1;
bit a=1,b=1;
unsigned char i,j;
void main()
{
while(1)
{
x=y;
y=sw1;
if((x==1)&&(sw1==0))
{
i++;
if(i%2==0) // phan du
led1=1;
else
led1=0;
}
//chuong trinh ki an sw2
a=b; // gan gia tri a=b
b=sw2; // gan gia tri b=sw2
if((a==1)&&(sw2==0))
{
j++;
if(j%2==0)
led2=1;
else
led2=0;
}
}
}
link mo phong:New folder.rar
#include<reg51.h>
#include<stdio.h>
sbit sw1=P1^0;
sbit sw2=P1^1;
sbit led1=P1^7;
sbit led2=P1^6;
bit x=1,y=1;
bit a=1,b=1;
unsigned char i,j;
void main()
{
while(1)
{
x=y;
y=sw1;
if((x==1)&&(sw1==0))
{
i++;
if(i%2==0) // phan du
led1=1;
else
led1=0;
}
//chuong trinh ki an sw2
a=b; // gan gia tri a=b
b=sw2; // gan gia tri b=sw2
if((a==1)&&(sw2==0))
{
j++;
if(j%2==0)
led2=1;
else
led2=0;
}
}
}
link mo phong:New folder.rar
Comment