các bạn giúp m sửa cái code này cái. Mình làm đề thiết kế mạch đk 8led đơn dùng 1 phím bấm để thay đổi các hiệu ứng, mỗi lần bấm phím là nó sang 1 hiệu ứng mới. ai giúp m nhé. m mới làm code đc tới đây thôi
#include <AT89X51.H>
#include<stdio.h>
#include<intrins.h>
sfr dataP0 = 0x80;
unsigned char i,p,ht,t,n;
void delay(long n)
{
unsigned char i,j;
for(i=1; i<n; i++)
{
for(j=0; j<255; j++);
}
}
void hu1(void) //sang dan tu trai qua phai //
{
{
ht=0;
t=0x80;
for(i=0; i<8; i++)
{
ht+= t;
t>>=1;
dataP0= ht;
delay(200);
}
}
}
void hu2(void) ///sang dan tu phai qua trai/
{
while(1)
{
ht=0;
p=0x01;
for(i=0; i<8; i++)
{
ht+= p;
p<<=1;
dataP0= ht;
delay(200);
}
}
}
void hu3(void) //sang dan tu ngoai vao//
{
while(1)
{
ht=0;
t= 0x80;
p= 0x01;
for(i=0; i<4; i++)
{
ht += t+p;
dataP0= ht;
t >>=1;
p <<=1;
delay(200);
}
}
}
void hu4(void) //sang dan tu giua ra//
{
while(1)
{
ht= 0;
t= 0x08;
p= 0x10;
for(i=0; i<4; i++)
{
ht += t+p;
dataP0= ht;
p <<=1;
t >>=1;
delay(250);
}
}
}
void hu5(void)
{
while(1)
{
dataP0= 0x01;
delay(200);
for(i=0; i<8; i++)
{
dataP0 = dataP0<<1;
delay(200);
}
}
}
void hu6(void)
{
while(1)
{
for(i=128; i>0; i>>=1)
{
dataP0 = i;
delay(200);
}
}
}
void hu7(void)
{
while(1)
{
ht=0;
p= 0x01;
t= 0x80;
for(i=0; i<4; i++)
{
ht = t+p;
dataP0= ht;
t >>=1;
p <<=1;
delay(200);
}
}
}
void hu8(void)
{
while(1)
{
ht= 0;
t= 0x08;
p= 0x10;
for(i=0; i<4; i++)
{
ht = t+p;
dataP0= ht;
p <<=1;
t >>=1;
delay(200);
}
}
}
void hu9(void)
{
while(1)
{
dataP0= 0xff;
delay(200);
dataP0=0x00;
delay(200);
dataP0=0xff;
delay(200);
}
}
void hienthi(unsigned char so)
{
{
switch (so)
{
case 1: {hu1(); delay(200); break;}
case 2: {hu2(); delay(200); break;}
case 3: {hu3(); delay(200); break;}
case 4: {hu4(); delay(200); break;}
case 5: {hu5(); delay(200); break;}
case 6: {hu6(); delay(200); break;}
case 7: {hu7(); delay(200); break;}
case 8: {hu8(); delay(200); break;}
case 9: {hu9(); delay(200); break;}
}
}
}
void ngat(void) interrupt 0
{
EA=0;
n++;
if(n>10) n=1;
EA =1;
}
void main()
{
IE = 0x81;
IT0 = 1;
while (1)
{
hienthi(n);
}
}
#include <AT89X51.H>
#include<stdio.h>
#include<intrins.h>
sfr dataP0 = 0x80;
unsigned char i,p,ht,t,n;
void delay(long n)
{
unsigned char i,j;
for(i=1; i<n; i++)
{
for(j=0; j<255; j++);
}
}
void hu1(void) //sang dan tu trai qua phai //
{
{
ht=0;
t=0x80;
for(i=0; i<8; i++)
{
ht+= t;
t>>=1;
dataP0= ht;
delay(200);
}
}
}
void hu2(void) ///sang dan tu phai qua trai/
{
while(1)
{
ht=0;
p=0x01;
for(i=0; i<8; i++)
{
ht+= p;
p<<=1;
dataP0= ht;
delay(200);
}
}
}
void hu3(void) //sang dan tu ngoai vao//
{
while(1)
{
ht=0;
t= 0x80;
p= 0x01;
for(i=0; i<4; i++)
{
ht += t+p;
dataP0= ht;
t >>=1;
p <<=1;
delay(200);
}
}
}
void hu4(void) //sang dan tu giua ra//
{
while(1)
{
ht= 0;
t= 0x08;
p= 0x10;
for(i=0; i<4; i++)
{
ht += t+p;
dataP0= ht;
p <<=1;
t >>=1;
delay(250);
}
}
}
void hu5(void)
{
while(1)
{
dataP0= 0x01;
delay(200);
for(i=0; i<8; i++)
{
dataP0 = dataP0<<1;
delay(200);
}
}
}
void hu6(void)
{
while(1)
{
for(i=128; i>0; i>>=1)
{
dataP0 = i;
delay(200);
}
}
}
void hu7(void)
{
while(1)
{
ht=0;
p= 0x01;
t= 0x80;
for(i=0; i<4; i++)
{
ht = t+p;
dataP0= ht;
t >>=1;
p <<=1;
delay(200);
}
}
}
void hu8(void)
{
while(1)
{
ht= 0;
t= 0x08;
p= 0x10;
for(i=0; i<4; i++)
{
ht = t+p;
dataP0= ht;
p <<=1;
t >>=1;
delay(200);
}
}
}
void hu9(void)
{
while(1)
{
dataP0= 0xff;
delay(200);
dataP0=0x00;
delay(200);
dataP0=0xff;
delay(200);
}
}
void hienthi(unsigned char so)
{
{
switch (so)
{
case 1: {hu1(); delay(200); break;}
case 2: {hu2(); delay(200); break;}
case 3: {hu3(); delay(200); break;}
case 4: {hu4(); delay(200); break;}
case 5: {hu5(); delay(200); break;}
case 6: {hu6(); delay(200); break;}
case 7: {hu7(); delay(200); break;}
case 8: {hu8(); delay(200); break;}
case 9: {hu9(); delay(200); break;}
}
}
}
void ngat(void) interrupt 0
{
EA=0;
n++;
if(n>10) n=1;
EA =1;
}
void main()
{
IE = 0x81;
IT0 = 1;
while (1)
{
hienthi(n);
}
}
Comment