|
來回流水燈制作
0.png (23.16 KB, 下載次數(shù): 61)
下載附件
2017-1-1 15:35 上傳
- #include<reg51.h>
- #define uint unsigned int
- #define uchar unsigned char
- void delay(uint z)
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=125;y>0;y--);
- }
- uchar code tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd};
- void main()
- {
- uchar i;
- while(1)
- {
- for(i=0;i<14;i++)
- {
- P2=tab[i];
- delay(500);
- }
- }
- }
- /*#include <reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar zhancun;
- void delay(uint x)
- {
- uchar t;
- while(x--) for(t = 0; t<120; t++);
- }
- void main( )
- {
- uchar i;
- while(1)
- {
- zhancun = 0x01;
- for(i = 0; i < 8; i++)
- {
- P2 = ~zhancun;
- delay(200);
- zhancun <<= 1;
- }
- zhancun = 0x80;
- for( i = 0; i < 8;i++)
- {
- P2 = ~zhancun;
- delay(200);
- zhancun >>= 1;
- }
- }
- }
- #include <reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- //uchar k;
- uint a;
- void delay(uint x)
- {
- uchar t;
- while(x--) for(t = 0; t<120; t++);
- }
- void main()
- {uchar k;
- while(1)
- {
- a=0x7f;
- for(k=0;k<7;k++)
- {
- P2=a;
- delay(500);
- a=(a>>1)|0x80;
- // a=a|0x80;
-
- }
- a=0xfe;
- for(k=0;k<7;k++)
- {
- P2=a;
- delay(500);
- a=(a<<1)|0x01;
- // a=a|0x01;
-
- }
- }
- }
- #include<reg51.h>
- #include<intrins.h>
- #define uint unsigned int
- #define uchar unsigned char
- void delay(uint z)
- {
- uint x,y;
- for(x=100;x>0;x--)
- for(y=z;y>0;y--);
- }
- void main()
- {
- uchar i;
- for(;;)
- {
- P2=0xfe;
- for(i=0;i<7;i++)
- {
- delay(500);P2=_crol_(P2,1);
-
- }
- P2=0x7f;
- for(i=0;i<7;i++)
- {
- delay(500);P2=_cror_(P2,1);
-
- }
- }
- }*/
復(fù)制代碼
|
-
-
實驗4.zip
2016-12-25 19:08 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
34.82 KB, 下載次數(shù): 8, 下載積分: 黑幣 -5
流水燈
|