Nguyên văn bởi tdm
Xem bài viết
đã sửa cho bạn:
Code:
#include"reg52.h" #include"stdio.h" #include"intrins.h" char x,y,i,j,q,tong1; int tong2; char mu(char u,char v); char duoithuan(char vovan); char duoinguoc(); char sangdanthuan(char vovan); char sangdannguoc(char vovan); char nhicthuan(char vovan); char nhicnguoc(char vovan); void delay(unsigned long int t); void nhay(char t); void duoi0(); void duoi1(); void duoitren(); void duoiduoi(); void duoitrai(); void duoiphai(); void sangdan0(); void sangdan1(); void sangdantren(); void sangdanduoi(); void sangdantrai(); void sangdanphai(); void nhictren(); void nhicduoi(); void hay1(); void hay2(); void main() { while(1) { nhay(10); for(q=0;q<2;q++) { nhictren(); nhicduoi(); nhay(3); } for(q=0;q<2;q++) { sangdantren(); nhay(3); sangdanduoi(); nhay(3); } for(q=0;q<2;q++) { duoitren(); nhay(3); duoiduoi(); nhay(3); } for(q=0;q<2;q++) { sangdantrai(); nhay(3); sangdanphai(); nhay(3); } for(q=0;q<2;q++) { duoitrai(); nhay(3); duoiphai(); nhay(3); } for(q=0;q<2;q++) { sangdan0(); nhay(3); sangdan1(); nhay(3); } for(q=0;q<2;q++) { duoi0(); nhay(3); duoi1(); nhay(3); } hay1(); hay2(); hay1(); hay2(); nhictren(); nhicduoi(); for(q=0;q<100;q++) { P0=P1=P2=P3=0x00; delay(1000); P0=P1=P2=P3=0xff; delay(1000); } } } void delay(unsigned long int t) { unsigned long int l; for(l=0;l<t;l++); } char mu(char u,char v) { char s=1,q; for(q=1;q<=v;q++) s=s*u; return s; } void nhay(char t) { for(i=0;i<t;i++) { P0=P1=P2=P3=0x00; delay(4000); P0=P1=P2=P3=0xff; delay(4000); } } char duoithuan(char vovan) { if(vovan%2!=0) tong1=2*tong1+1; else tong1=2*tong1; return tong1; } char duoinguoc() { tong2=tong2>>1; return tong2; } char sangdanthuan(char vovan) { x=x-mu(2,vovan); return x; } char sangdannguoc(char vovan) { y=y-mu(2,7-vovan); return y; } char nhicthuan(char vovan) { x=mu(2,vovan); return x; } char nhicnguoc(char vovan) { y=mu(2,7-vovan); return y; } void duoi0() { P0=P1=P2=P3=0xff; tong1=0; for(j=1;j<=8;j++) { P0=~duoithuan(j); delay(2000); } tong2=21760; P0=0x55; for(j=1;j<=8;j++) { P0=~P0; P2=~duoithuan(j);// delay(2000); } tong2=21760; P0=0x55; P2=0xaa; for(j=1;j<=8;j++) { P0=~P0; P2=~P2; P3=~duoinguoc(); delay(2000); } tong2=21760; P0=0x55; P2=0xaa; for(j=1;j<=8;j++) { P0=~P0; P2=P3=~P2; P1=~duoinguoc(); delay(2000); } } void duoi1() { P0=P1=P2=P3=0xff; tong1=0; for(j=1;j<=8;j++) { P1=~duoithuan(j); delay(2000); } tong1=0; P1=0x55; for(j=1;j<=8;j++) { P1=~P1; P3=~duoithuan(j); delay(2000); } tong1=0; P1=P3=0x55; for(j=1;j<=8;j++) { P1=P3=~P1; P2=~duoinguoc();// delay(2000); } tong2=21760; P1=P3=P2=0x55; for(j=1;j<=8;j++) { P1=P2=P3=~P1; P0=~duoinguoc(); delay(2000); } } void duoitren() { P0=P1=P2=P3=0xff; tong1=0; for(j=1;j<=8;j++) { P1=P0=~duoithuan(j); delay(2000); } tong1=0; tong2=21760; P1=0x55; for(j=1;j<=8;j++) { P1=P0=~P1; P3=~duoithuan(j); P2=~duoithuan(j);// delay(2000); } } void duoiduoi() { P0=P1=P2=P3=0xff; tong1=0; tong2=21760; for(j=1;j<=8;j++) { P2=~duoinguoc();// P3=~duoinguoc(); delay(2000); } tong2=21760; P2=0x55; P3=0xaa; for(j=1;j<=8;j++) { P2=~P2; P3=~P3; P0=P1=~duoinguoc(); delay(2000); } } void duoitrai() { P0=P1=P2=P3=0xff; tong2=21760; for(j=1;j<=8;j++) { P0=~duoinguoc(); P2=~duoithuan(j);// delay(2000); } tong1=0; tong2=21760; P0=0xaa; for(j=1;j<=8;j++) { P0=P2=~P0; P3=~duoinguoc(); P1=~duoithuan(j); delay(2000); } } void duoiphai() { P0=P1=P2=P3=0xff; tong1=0; tong2=21760; for(j=1;j<=8;j++) { P3=~duoithuan(j); P1=~duoinguoc(); delay(2000); } tong1=0; P1=0xaa; P3=0x55; for(j=1;j<=8;j++) { P1=~P1; P3=~P3; P2= ~duoinguoc();// P0=~duoithuan(j); delay(2000); } } void sangdan0() { P0=P1=P2=P3=0xff; x=y=255; for(j=0;j<8;j++) { P0= sangdanthuan(j); delay(2000); } x=y=255; for(j=0;j<8;j++) { P2=sangdanthuan(j);// delay(2000); } x=y=255; for(j=0;j<8;j++) { P3=sangdannguoc(j); delay(2000); } x=y=255; for(j=0;j<8;j++) { P1=sangdannguoc(j); delay(2000); } } void sangdan1() { P0=P1=P2=P3=0xff; x=y=255; for(j=0;j<8;j++) { P1= sangdanthuan(j); delay(2000); } x=y=255; for(j=0;j<8;j++) { P3=sangdanthuan(j); delay(2000); } x=y=255; for(j=0;j<8;j++) { P2=sangdannguoc(j);// delay(2000); } x=y=255; for(j=0;j<8;j++) { P0=sangdannguoc(j); delay(2000); } } void sangdantren() { P0=P1=P2=P3=0xff; x=y=255; for(j=0;j<8;j++) { P1=P0= sangdanthuan(j); delay(2000); } x=y=255; for(j=0;j<8;j++) { P3=sangdanthuan(j); P2=sangdanthuan(j); // delay(2000); } x=y=255; } void sangdanduoi() { P0=P1=P2=P3=0xff; x=y=255; for(j=0;j<8;j++) { P2= sangdannguoc(j);// P3=sangdannguoc(j); delay(2000); } x=y=255; for(j=0;j<8;j++) { P1=P0=sangdannguoc(j); delay(2000); } x=y=255; } void sangdantrai() { P0=P1=P2=P3=0xff; x=y=255; for(j=0;j<8;j++) { P0=sangdannguoc(j); P2=sangdanthuan(j); // delay(2000); } x=y=255; for(j=0;j<8;j++) { P3=sangdannguoc(j); P1=sangdanthuan(j); delay(2000); } } void sangdanphai() { P0=P1=P2=P3=0xff; x=y=255; for(j=0;j<8;j++) { P1=sangdannguoc(j); P3=sangdanthuan(j); delay(2000); } x=y=255; for(j=0;j<8;j++) { P0=sangdanthuan(j); P2=sangdannguoc(j); // delay(2000); } } void nhictren() { P0=P1=P2=P3=0xff; for(j=0;j<8;j++) { P0=P1=~nhicthuan(j); delay(2000); } P1=P0=0xff; for(j=0;j<8;j++) { P3=~nhicthuan(j); P2=~nhicthuan(j);// delay(2000); } P3=0xff; } void nhicduoi() { P0=P1=P2=P3=0xff; for(j=0;j<8;j++) { P2=~nhicnguoc(j); // P3=~nhicnguoc(j); delay(2000); } P2=P3=0xff; for(j=0;j<8;j++) { P0=P1=~nhicnguoc(j); delay(2000); } P3=0xff; } void hay1() { P0=P1=P2=P3=0xff; x=y=255; for(j=0;j<8;j++) { P1=P3=sangdannguoc(j); P0=sangdanthuan(j); P2=sangdanthuan(j); // delay(2000); } } void hay2() { P0=P1=P2=P3=0xff; x=y=255; for(j=0;j<8;j++) { P0=sangdannguoc(j); P2=sangdannguoc(j); // P1=P3=sangdanthuan(j); delay(2000); } }
Comment