logo资料库

炫彩流水灯程序 用P1 口作为控制端口,使8个LED 轮流亮。从0-7,0—7,从两端开始,中间开始,全闪烁,四个四个,全灭,全....doc

第1页 / 共11页
第2页 / 共11页
第3页 / 共11页
第4页 / 共11页
第5页 / 共11页
第6页 / 共11页
第7页 / 共11页
第8页 / 共11页
资料共11页,剩余部分请下载后查看
画出电路,编写一段程序,用 P1 口作为控制端口,使 8 个 LED 轮流亮。 #include "reg51.h" unsigned char code flash1[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; void delay() { } int i,j; for(i=1;i<1000;i++) for(j=1;j<100;j++); void main(void) { unsigned char temp; P1=0x00; //关闭发光二极管,防止发光二极管闪烁 while(1) //总循环 { for(temp=0;temp<8;temp++)
P1=flash1[temp]; delay(); { } } } #include //**********花样表**********/ unsigned char code flash1[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //从 0-7 1 unsigned char code flash2[]={0xfc,0xf3,0xcf,0x3f,0xfc,0xf3,0xcf,0x3f}; //从 0-7 2 unsigned char code flash3[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe}; //从 7-0 1 unsigned char code flash4[]={0x3f,0xcf,0xf3,0xfc,0x3f,0xcf,0xf3,0xfc}; //从 7-0 2 unsigned char code flash5[]={0x7e,0xbd,0xdb,0xe7,0xe7,0xdb,0xbd,0x7e}; //从两端开始 1 unsigned char code flash6[]={0xe7,0xdb,0xbd,0x7e,0x7e,0xbd,0xdb,0xe7}; //从中间开始 1 unsigned char code flash7[]={0x3c,0xc3,0x3c,0xc3,0x3c,0xc3,0x3c,0xc3}; //从两端开始 2 unsigned char code flash8[]={0xc3,0x3c,0xc3,0x3c,0xc3,0x3c,0xc3,0x3c}; //从中间开始 2 unsigned char code flash9[]={0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00}; //全闪烁 unsigned char code flash10[]={0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00}; //正拉幕 unsigned char code flash11[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00}; //反拉幕 unsigned char code flash12[]={0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55}; //单流水 unsigned char code flash13[]={0x33,0xcc,0x33,0xcc,0x33,0xcc,0x33,0xcc}; //双流水
unsigned char code flash14[]={0x0f,0xf0,0x0f,0xf0,0x0f,0xf0,0x0f,0xf0}; //四个四个 unsigned char code flash15[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //全亮 unsigned char code flash16[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; //全灭 unsigned char code flash18[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //累加 1 unsigned char code flash19[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; //累加 2 //*****************延时函数********************************/ void delay(unsigned int k) { unsigned int i,j; for(i=0;i
P2=flash2[temp]; P3=flash2[temp]; //查表 2 花样送端口 delay(100); } //*************第三组******************/ for(temp=0;temp<8;temp++) { P0=flash3[temp]; P1=flash3[temp]; P2=flash3[temp]; P3=flash3[temp]; //查表 3 花样送端口 delay(100); } //**************第四组*****************/ for(temp=0;temp<8;temp++) { P0=flash4[temp]; P1=flash4[temp]; P2=flash4[temp]; P3=flash4[temp]; //查表 4 花样送端口 delay(100); } //*************第五组******************/ for(temp=0;temp<8;temp++) { P0=flash5[temp]; P1=flash5[temp]; P2=flash5[temp]; P3=flash5[temp];//查表 5 花样送端口 delay(200); } //*************第六组******************/ for(temp=0;temp<8;temp++) { P0=flash6[temp]; P1=flash6[temp]; P2=flash6[temp]; P3=flash6[temp]; //查表 6 花样送端口 delay(200); } //*************第七组******************/ for(temp=0;temp<8;temp++) { P0=flash7[temp];
P1=flash7[temp]; P2=flash7[temp]; P3=flash7[temp];//查表 7 花样送端口 delay(200); } //*************第八组*****************/ for(temp=0;temp<8;temp++) { P0=flash8[temp]; P1=flash8[temp]; P2=flash8[temp]; P3=flash8[temp];//查表 8 花样送端口 delay(200); } //***************第九组***************/ for(temp=0;temp<8;temp++) { P0=flash9[temp]; P1=flash9[temp]; P2=flash9[temp]; P3=flash9[temp];//查表 9 花样送端口 delay(300);//因闪烁,加大延长时间 } //***************第十组********************* for(temp=0;temp<8;temp++) { P0=flash10[temp]; P1=flash10[temp]; P2=flash10[temp]; P3=flash10[temp];//查表 10 花样送端口? delay(100); } //****************第十一组******************* for(temp=0;temp<8;temp++) { P0=flash11[temp]; P1=flash11[temp]; P2=flash11[temp]; P3=flash11[temp];//查表 12 花样送端口 delay(100); } //******************第十二组********************* for(temp=0;temp<8;temp++)
{ P0=flash12[temp]; P1=flash12[temp]; P2=flash12[temp]; P3=flash12[temp];//查表 13 花样送端口 delay(300);//因闪烁,加大延长时间 } //******************第十三组******************* for(temp=0;temp<8;temp++) { P0=flash13[temp]; P1=flash13[temp]; P2=flash13[temp]; P3=flash13[temp];//查表 13 花样送端口 delay(300);//因闪烁,加大延长时间 } //*********************第十四组***************** for(temp=0;temp<8;temp++) { P0=flash14[temp]; P1=flash14[temp]; P2=flash14[temp]; P3=flash14[temp];//查表 14 花样送端口 delay(500); } //************************************* for(temp=0;temp<8;temp++) { P0=flash15[temp]; P1=flash16[temp]; P2=flash16[temp]; P3=flash15[temp]; delay(100); } //************************************ for(temp=0;temp<8;temp++) { P0=flash16[temp]; P1=flash15[temp]; P2=flash15[temp]; P3=flash16[temp]; delay(100); } //*************************************
for(temp=0;temp<8;temp++) { P0=flash15[temp]; P1=flash16[temp]; P2=flash16[temp]; P3=flash15[temp]; delay(100); } //************************************ for(temp=0;temp<8;temp++) { P0=flash16[temp]; P1=flash15[temp]; P2=flash15[temp]; P3=flash16[temp]; delay(100); } //*********************************************** for(temp=0;temp<8;temp++) { P0=flash15[temp]; P1=flash16[temp]; P2=flash16[temp]; P3=flash16[temp]; delay(100); } //********************************************** for(temp=0;temp<8;temp++) { P0=flash16[temp]; P1=flash15[temp]; P2=flash16[temp]; P3=flash16[temp]; delay(100); } //*********************************************** for(temp=0;temp<8;temp++) { P0=flash16[temp]; P1=flash16[temp]; P2=flash16[temp]; P3=flash15[temp]; delay(100); }
//************************************************** for(temp=0;temp<8;temp++) { P0=flash16[temp]; P1=flash16[temp]; P2=flash15[temp]; P3=flash16[temp]; delay(100); } //************************************************** for(temp=0;temp<8;temp++) { P0=flash5[temp]; P1=flash16[temp]; P2=flash16[temp]; P3=flash16[temp]; delay(200) ; } //************************************************** for(temp=0;temp<8;temp++) { P0=flash16[temp]; P1=flash1[temp]; P2=flash3[temp]; P3=flash16[temp]; delay(200) ; } //************************************************** for(temp=0;temp<8;temp++) { P0=flash16[temp]; P1=flash16[temp]; P2=flash16[temp]; P3=flash5[temp]; delay(200) ; } //************************************************** for(temp=0;temp<8;temp++) { P0=flash16[temp]; P1=flash3[temp];
分享到:
收藏