资源描述:
《河南理工大学微机原理课设--悄艽傲河南理工大学微机原理课设--智能窗aspan class=》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#defineucharunsignedcharunsignedcharcodedofly[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x00,0x6d,0x78,0x5c,0x73};uchartable_num[4]={0};sbitk1=P0^5;sbitk2=P0^6;sbitk3=P0^7;sbitA=P3^2;sbitb=P3^3;sbitC=P3^4;sbitD=P3^5;sbitout1=P2^0;sbitout2=P2^1;sbit
2、huoerA=P2^2;sbithuoerb=P2^3;sbitP3_6=P3^6;sbitP3_7=P3^7;intpwm=50,a,pwmout;charflag;voiddelay2(unsignedintcnt){unsignedchari;for(;cnt>0;cnt--)for(i=0;i<250;i++);}voiddelay1(ucharmm){ucharnn;for(;mm>0;mm--)for(nn=110;nn>0;nn--);}voiddisplay(void){chari;for(i=0;i<4;i++){P0=~(1<
3、um[i]];delay1(90);P1=0x00;}}voidinitime(void){P1M0=0x00;P1M1=0xff;TMOD=0x02;//dingshiqi0fangshi2TH0=TL0=0x06;TR0=1;ET0=1;EA=1;out1=out2=0;}voidkeyscan(void){P0=0xff;P3_6=0;P3_7=1;if(k1==0){delay1(3);if(k1==0){pwm++;while(!k1);}}if(k2==0){delay1(3);if(k2==0){pwm+=5;while(!k2);}}if(k3==0){delay1(3
4、);if(k3==0){pwm+=10;while(!k3);}}P0=0xff;P3_7=0;P3_6=1;if(k1==0){delay1(3);if(k1==0){pwm--;while(!k1);}}if(k2==0){delay1(3);if(k2==0){pwm-=5;while(!k2);}}if(k3==0){delay1(3);if(k3==0){pwm-=10;while(!k3);}}if(pwm<0)pwm=0;if(pwm>100)pwm=100;P0=0xff;}main(){initime();for(;;)//主函数循环体while(1){display
5、();//显示函数调用keyscan();//按键扫描函数调用table_num[1]=pwm/100;table_num[2]=pwm%100/10;table_num[3]=pwm%10;if(D==1)//按键D按下调整PWM控制电机速度{table_num[0]=18;out2=out1=0;}elseif(A==1&&huoerA==1){out1=pwmout;out2=0;flag=1;table_num[0]=10;}//按键A按下且A端霍尔传感器为不靠近磁钢A方向旋转elseif(b==1&&huoerb==1){out2=pwmout;out1=0;flag=2;t
6、able_num[0]=11;}//按键b按下且b端霍尔传感器为不靠近磁钢b方向旋转else{//按键C按下或磁钢靠近对应方向磁钢即窗帘到头if(flag==1){out2=1;out1=0;delay2(1000);}//短时间反方向旋转电机急停if(flag==2){out2=0;out1=1;delay2(1000);}//短时间反方向旋转电机急停out2=out1=0;flag=0;table_num[0]=15;//数码管显示当前状态stoptable_num[1]=16;table_num[2]=17;table_num[3]=18;}}}voidtime0()interr
7、upt1{a++;//控制单位时间内高低电平持续时间if(a==100)a=0;if(a=pwm){pwmout=0;}}