em là lính mới. em viết đoạn code này hơi dài và là sản phẩm đầu tiên của em. nhưng em chạy trên proteus thì nó chạy loạn xạ hết các bác làm ơn chỉ bảo giúp dùm.
#include <at89x52.h>
#define led P1
void delay (unsigned int ms)
{
unsigned int i ;
unsigned char j ;
for (i=0;i<ms;i++)
{
for (j=0;j<125;j++)
{}
}
}
void sangdon(void)
{
P1=00000001;
delay(1000);
P1=00000010;
delay(1000);
P1=00000100;
delay(1000);
P1=00001000;
delay(1000);
P1=00010000;
delay(1000);
P1=00100000;
delay(1000);
P1=01000000;
delay(1000);
P1=10000000;
delay(1000);
P1=10000001;
delay(1000);
P1=10000010;
delay(1000);
P1=10000100;
delay(1000);
P1=10001000;
delay(1000);
P1=10010000;
delay(1000);
P1=10100000;
delay(1000);
P1=11000000;
delay(1000);
P1=11000001;
delay(1000);
P1=11000010;
delay(1000);
P1=11000100;
delay(1000);
P1=11001000;
delay(1000);
P1=11010000;
delay(1000);
P1=11100000;
delay(1000);
P1=11100001;
delay(1000);
P1=11100010;
delay(1000);
P1=11100100;
delay(1000);
P1=11101000;
delay(1000);
P1=11110000;
delay(1000);
P1=11110001;
delay(1000);
P1=11110010;
delay(1000);
P1=11110100;
delay(1000);
P1=11111000;
delay(1000);
P1=11111001;
delay(1000);
P1=11111010;
delay(1000);
P1=11111100;
delay(1000);
P1=11111101;
delay(1000);
P1=11111110;
delay(1000);
P1=0xff;
delay(1000);
}
void xenke(void)
{
P1=0x85;
delay(1000);
P1=0x170;
delay(1000);
}
void dongiua(void)
{
P1=0x00;
delay(1000);
P1=0x66;
delay(1000);
P1=0x36;
delay(1000);
P1=0x24;
delay(1000);
P1=0x153;
delay(1000);
P1=0x90;
delay(1000);
P1=0x60;
delay(1000);
P1=0x189;
delay(1000);
P1=0x126;
delay(1000);
P1=0xff;
delay(1000);
}
main ()
{
while (1)
{
sangdon();
delay(1000);
xenke();
delay(1000);
dongiua();
delay(1000);
}
}
#include <at89x52.h>
#define led P1
void delay (unsigned int ms)
{
unsigned int i ;
unsigned char j ;
for (i=0;i<ms;i++)
{
for (j=0;j<125;j++)
{}
}
}
void sangdon(void)
{
P1=00000001;
delay(1000);
P1=00000010;
delay(1000);
P1=00000100;
delay(1000);
P1=00001000;
delay(1000);
P1=00010000;
delay(1000);
P1=00100000;
delay(1000);
P1=01000000;
delay(1000);
P1=10000000;
delay(1000);
P1=10000001;
delay(1000);
P1=10000010;
delay(1000);
P1=10000100;
delay(1000);
P1=10001000;
delay(1000);
P1=10010000;
delay(1000);
P1=10100000;
delay(1000);
P1=11000000;
delay(1000);
P1=11000001;
delay(1000);
P1=11000010;
delay(1000);
P1=11000100;
delay(1000);
P1=11001000;
delay(1000);
P1=11010000;
delay(1000);
P1=11100000;
delay(1000);
P1=11100001;
delay(1000);
P1=11100010;
delay(1000);
P1=11100100;
delay(1000);
P1=11101000;
delay(1000);
P1=11110000;
delay(1000);
P1=11110001;
delay(1000);
P1=11110010;
delay(1000);
P1=11110100;
delay(1000);
P1=11111000;
delay(1000);
P1=11111001;
delay(1000);
P1=11111010;
delay(1000);
P1=11111100;
delay(1000);
P1=11111101;
delay(1000);
P1=11111110;
delay(1000);
P1=0xff;
delay(1000);
}
void xenke(void)
{
P1=0x85;
delay(1000);
P1=0x170;
delay(1000);
}
void dongiua(void)
{
P1=0x00;
delay(1000);
P1=0x66;
delay(1000);
P1=0x36;
delay(1000);
P1=0x24;
delay(1000);
P1=0x153;
delay(1000);
P1=0x90;
delay(1000);
P1=0x60;
delay(1000);
P1=0x189;
delay(1000);
P1=0x126;
delay(1000);
P1=0xff;
delay(1000);
}
main ()
{
while (1)
{
sangdon();
delay(1000);
xenke();
delay(1000);
dongiua();
delay(1000);
}
}
Comment