效果图和程序不是特别吻合,但也太差不差,是我用PS做的gif动画,灯的颜色可以按照个人偏好自行选择
中间的笑脸我没有用程序实现,所以出来是静止的程序如下:
#include#include#define uint unsigned int#define uchar unsigned char***it key = P3^2;unsigned int mode = 0;uint code stars[16][2] = {{1,4},{0,5},{1,6},{2,7},{3,7},{4,6},{5,5},{6,4},{6,3},{5,2},{4,1},{3,0},{2,0},{1,1},{0,2},{1,3}};uchar code v[8]= {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//p2->vuchar code h[8]= {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//p0->hvoid delay(uint x,uint y)//单步执行7*E-4{ int i,j; for(i = 0;i); delay(10,142); } } return 0;}int mod1()//从中间向两边,两边向中间{ int laps = 5; while(laps--) { int i; for(i=7;i>=0;i--) { dpoint(stars); delay(10,142); dpoint(stars[15-i]); delay(10,142); } for(i=0;i<=7;i++) { dpoint(stars); delay(10,142); dpoint(stars[15-i]); delay(10,142); } } return 1;}int mod2()//奇偶变换{ int laps = 5; while(laps--) { int time = 10; while(time--) { int i; for(i=0;i<16;i++){ if(i%2 == 0) dpoint(stars); delay(5,14); } } time = 10; while(time--) { int i; for(i=0;i<16;i++){ if(i%2 != 0) dpoint(stars); delay(5,14); } } } return 2;}int mod3()//全亮{ int laps = 500; int i; while(laps--) { int temp; for(i=0;i<=15;i++) { dpoint(stars); for(temp=80;temp>=0;temp--); //时间应当足够让电平稳定 } for(temp=80;temp>=0;temp--); } return 3;}int mod4()//闪烁{ int laps = 50; while(laps--) { int time = 5; while(time--) { int i; for(i=0;i<16;i++){ dpoint(stars); delay(5,14); P0 = 0x00; } } delay(50,142); } return 4;}/********************************/int main(){IE = 0X81;//EA = 1; EX0 = 1;TCON = 0X01; mod0(); delay(10,500); mod1(); delay(10,500); mod2(); delay(10,500); mod3(); delay(10,500); mod4();return 0;}void mode_change() interrupt 0{ if(key==0) { delay(20,20); if(key==0) { if(mode<4) mode++; else mode = 0; while(!key); } }}
|