các bạn cho mình hỏi nếu muốn các led sáng mờ rồi từ từ sáng thì viết như thế nào
và ngược lại
bạn nào có doạn code nào nháy đẹp chỉ cho mình với
#include <regx51.h>
#define led1 P1_0
#define led2 P1_1
#define led3 P1_2
#define led4 P1_3
#define led5 P1_4
#define led6 P1_5
#define led7 P1_6
#define led8 P1_7
//+++++++++++++++++++++++++++
// ham delay de tri hoan 1 thoi gian
//+++++++++++++++++++++++++++
void delay(unsigned char time)
{
unsigned char i,j;
for(i=0;i<time;i++)
for(j=0;j<200;j++);
}
void dat(bit a, bit b, bit c, bit d,bit e,bit f , bit g , bit h)
{
led1=a;
led2=b;
led3=c;
led4=d;
led5=e;
led6=f;
led7=g;
led8=h;
}
void choptat()
{
dat(0,0,0,0,0,0,0,0); //
delay(30); // muon nhanh cham j do thi tuy ban
dat(1,1,1,1,1,1,1,1);
delay(30);
}
void chaser(unsigned char times)
{
unsigned char i;
for(i=0;i<times;i++)
{
dat(1,0,0,0,0,0,0,0); delay(150);
dat(0,1,0,0,0,0,0,0); delay(150);
dat(0,0,1,0,0,0,0,0); delay(150);
dat(0,0,0,1,0,0,0,0); delay(150);
dat(0,0,0,0,1,0,0,0); delay(150);
dat(0,0,0,0,0,1,0,0); delay(150);
dat(0,0,0,0,0,0,1,0); delay(150);
dat(0,0,0,0,0,0,0,1); delay(150);
dat(0,0,0,0,0,0,1,0); delay(150);
dat(0,0,0,0,0,1,0,0); delay(150);
dat(0,0,0,0,1,0,0,0); delay(150);
dat(0,0,0,1,0,0,0,0); delay(150);
dat(0,0,1,0,0,0,0,0); delay(150);
dat(0,1,0,0,0,0,0,0); delay(150);
dat(1,0,0,0,0,0,0,0); delay(150);
dat(1,1,1,1,1,1,1,1); delay(150);
dat(0,1,1,1,1,1,1,1); delay(150);
dat(1,0,1,1,1,1,1,1); delay(150);
dat(1,1,0,1,1,1,1,1); delay(150);
dat(1,1,1,0,1,1,1,1); delay(150);
dat(1,1,1,1,0,1,1,1); delay(150);
dat(1,1,1,1,1,0,1,1); delay(150);
dat(1,1,1,1,1,1,0,1); delay(150);
dat(1,1,1,1,1,1,1,0); delay(150);
dat(1,1,1,1,1,1,0,1); delay(150);
dat(1,1,1,1,1,0,1,1); delay(150);
dat(1,1,1,1,0,1,1,1); delay(150);
dat(1,1,1,0,1,1,1,1); delay(150);
dat(1,1,0,1,1,1,1,1); delay(150);
dat(1,0,1,1,1,1,1,1); delay(150);
dat(0,1,1,1,1,1,1,1); delay(150);
dat(1,1,0,0,0,0,0,0); delay(150);
dat(0,0,1,1,0,0,0,0); delay(150);
dat(0,0,0,1,1,0,0,0); delay(150);
dat(0,0,0,0,0,1,1,0); delay(150);
dat(0,0,0,0,0,0,1,1); delay(150);
dat(0,0,0,0,1,1,0,0); delay(150);
dat(0,0,1,1,0,0,0,0); delay(150);
dat(1,1,0,0,0,0,0,0); delay(150);
dat(0,0,0,0,1,0,0,0); delay(150);
dat(0,0,0,1,1,1,0,0); delay(150);
dat(0,0,1,1,1,1,1,0); delay(150);
dat(1,1,1,1,1,1,1,1); delay(150);
dat(0,1,1,1,1,1,1,0); delay(150);
dat(0,0,1,1,1,1,0,0); delay(150);
dat(0,0,0,1,1,0,0,0); delay(150);
dat(0,0,0,0,1,0,0,0); delay(150);
dat(0,0,0,0,1,0,0,0); delay(150);
dat(0,0,0,1,1,1,0,0); delay(150);
dat(0,0,1,1,1,1,1,0); delay(150);
dat(1,1,1,1,1,1,1,1); delay(150);
dat(1,1,1,0,0,1,1,1); delay(150);
}
}
void main()
{
while(1) // vong lap vo tan
{
chaser(10);
}
}
và ngược lại
bạn nào có doạn code nào nháy đẹp chỉ cho mình với
#include <regx51.h>
#define led1 P1_0
#define led2 P1_1
#define led3 P1_2
#define led4 P1_3
#define led5 P1_4
#define led6 P1_5
#define led7 P1_6
#define led8 P1_7
//+++++++++++++++++++++++++++
// ham delay de tri hoan 1 thoi gian
//+++++++++++++++++++++++++++
void delay(unsigned char time)
{
unsigned char i,j;
for(i=0;i<time;i++)
for(j=0;j<200;j++);
}
void dat(bit a, bit b, bit c, bit d,bit e,bit f , bit g , bit h)
{
led1=a;
led2=b;
led3=c;
led4=d;
led5=e;
led6=f;
led7=g;
led8=h;
}
void choptat()
{
dat(0,0,0,0,0,0,0,0); //
delay(30); // muon nhanh cham j do thi tuy ban
dat(1,1,1,1,1,1,1,1);
delay(30);
}
void chaser(unsigned char times)
{
unsigned char i;
for(i=0;i<times;i++)
{
dat(1,0,0,0,0,0,0,0); delay(150);
dat(0,1,0,0,0,0,0,0); delay(150);
dat(0,0,1,0,0,0,0,0); delay(150);
dat(0,0,0,1,0,0,0,0); delay(150);
dat(0,0,0,0,1,0,0,0); delay(150);
dat(0,0,0,0,0,1,0,0); delay(150);
dat(0,0,0,0,0,0,1,0); delay(150);
dat(0,0,0,0,0,0,0,1); delay(150);
dat(0,0,0,0,0,0,1,0); delay(150);
dat(0,0,0,0,0,1,0,0); delay(150);
dat(0,0,0,0,1,0,0,0); delay(150);
dat(0,0,0,1,0,0,0,0); delay(150);
dat(0,0,1,0,0,0,0,0); delay(150);
dat(0,1,0,0,0,0,0,0); delay(150);
dat(1,0,0,0,0,0,0,0); delay(150);
dat(1,1,1,1,1,1,1,1); delay(150);
dat(0,1,1,1,1,1,1,1); delay(150);
dat(1,0,1,1,1,1,1,1); delay(150);
dat(1,1,0,1,1,1,1,1); delay(150);
dat(1,1,1,0,1,1,1,1); delay(150);
dat(1,1,1,1,0,1,1,1); delay(150);
dat(1,1,1,1,1,0,1,1); delay(150);
dat(1,1,1,1,1,1,0,1); delay(150);
dat(1,1,1,1,1,1,1,0); delay(150);
dat(1,1,1,1,1,1,0,1); delay(150);
dat(1,1,1,1,1,0,1,1); delay(150);
dat(1,1,1,1,0,1,1,1); delay(150);
dat(1,1,1,0,1,1,1,1); delay(150);
dat(1,1,0,1,1,1,1,1); delay(150);
dat(1,0,1,1,1,1,1,1); delay(150);
dat(0,1,1,1,1,1,1,1); delay(150);
dat(1,1,0,0,0,0,0,0); delay(150);
dat(0,0,1,1,0,0,0,0); delay(150);
dat(0,0,0,1,1,0,0,0); delay(150);
dat(0,0,0,0,0,1,1,0); delay(150);
dat(0,0,0,0,0,0,1,1); delay(150);
dat(0,0,0,0,1,1,0,0); delay(150);
dat(0,0,1,1,0,0,0,0); delay(150);
dat(1,1,0,0,0,0,0,0); delay(150);
dat(0,0,0,0,1,0,0,0); delay(150);
dat(0,0,0,1,1,1,0,0); delay(150);
dat(0,0,1,1,1,1,1,0); delay(150);
dat(1,1,1,1,1,1,1,1); delay(150);
dat(0,1,1,1,1,1,1,0); delay(150);
dat(0,0,1,1,1,1,0,0); delay(150);
dat(0,0,0,1,1,0,0,0); delay(150);
dat(0,0,0,0,1,0,0,0); delay(150);
dat(0,0,0,0,1,0,0,0); delay(150);
dat(0,0,0,1,1,1,0,0); delay(150);
dat(0,0,1,1,1,1,1,0); delay(150);
dat(1,1,1,1,1,1,1,1); delay(150);
dat(1,1,1,0,0,1,1,1); delay(150);
}
}
void main()
{
while(1) // vong lap vo tan
{
chaser(10);
}
}
Comment