资源描述:
《实验三 流水灯控制实验.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、实验三功能:使用查询和中断方式编写程序,每按动一次K1键,演示不同流水效果*一、中断式/*功能:使用查询方式编写程序,每按动一次K1键,演示不同流水效果*KEY=1:全亮KEY=2:单管点亮;KEY=3:依次点亮;KEY=4依次熄灭;KEY=5:整体闪烁;KEY=6:双管点亮;*/#include#defineucharunsignedcharucharkey=0;voiddelay(charc);voidINT_1();voidxiaoguo1();voidxiaoguo2();voidxiaoguo3();
2、voidxiaoguo4();voidxiaoguo5();voidxiaoguo6();voidmain()//主函数{EA=1;EX1=1;IT1=1;P1=0x00;while(1){switch(key){case1:xiaoguo1();break;case2:xiaoguo2();break;case3:xiaoguo3();break;case4:xiaoguo4();break;case5:xiaoguo5();break;case6:xiaoguo6();}}}/*************************
3、***********延时函数***********************************/voiddelay(charc)//延时函数{unsignedinti,j;for(;c>0;c--){for(j=142;j>0;j--){for(i=2;i>0;i--);}}}/************************************中断函数***********************************/voidINT_1()interrupt2//中断函数{EX1=0;delay(20);EX1=1
4、;key++;if(key>6)key=1;}/************************************效果1***********************************/voidxiaoguo1()//效果全亮{P1=0xff;delay(300);}/************************************效果2***********************************/voidxiaoguo2()//效果先全灭然后单管点亮{uchara;ucharcodetable1[]
5、={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};P1=0x00;for(a=0;a<8;a++){P1=table1[a];delay(300);}}/************************************效果3***********************************/voidxiaoguo3()//效果先全灭,然后依次点亮{ucharb;ucharcodetable2[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};P1
6、=0x00;for(b=0;b<8;b++){P1=table2[b];delay(300);}}/************************************效果4***********************************/voidxiaoguo4()//效果全亮,依次熄灭{ucharc;ucharcodetable3[]={0xff,0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01};P1=0xff;for(c=0;c<8;c++){P1=table3[c];delay(300);}
7、}/************************************效果5***********************************/voidxiaoguo5()//效果全灭,整体闪烁{uchard;ucharcodetable4[]={0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff};P1=0x00;for(d=0;d<8;d++){P1=table4[d];delay(300);}}/************************************效果6*******
8、****************************/voidxiaoguo6()//效果.自定义双管循环{uchare;ucharcodetable5[]={0xcc,0x33,0xcc,0x33,0xcc,0x33,0xcc,0x33};P