欢迎来到天天文库
浏览记录
ID:40813640
大小:312.50 KB
页数:7页
时间:2019-08-08
《加热炉送料系统的单片机实现》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、加热炉送料系统的单片机实现程序清单:#include#include#defineV_UP0#defineV_DOWN1#defineV_STOP2#defineH_RIGHT3#defineH_LEFT4#defineH_STOP5#defineFosc19.2sbitDOWN=P2^2;sbitUP=P2^3;sbitRIGHT=P2^4;sbitLEFT=P2^5;sbitDOWN_LIM=P1^0;sbitUP_LIM=P1^1;sbitRIGHT_LIM=P1^2;sbitLEFT_LIM=P1^3;sbitTIME_PLUS=P1^4;s
2、bitTIME_MINUS=P1^5;sbitCONFIRME=P1^6;sbitSEL1=P2^0;sbitSEL2=P2^1;externunsignedcharcount=1;unsignedchardbuf[2]={0,0};unsignedcharcodesegtab[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,//0,1,2,3,4,5,6,70x7f,0x6f};//8,9voiddelay(unsignedintcount)//延时函数{unsignedinti;for(i=0;i3、void)interrupt1//定时器T0中断服务函数{unsignedchartemp=0xfe;TL0=(65536-(unsignedint)(1000.0*Fosc/12)+16)%256;TH0=(65536-(unsignedint)(1000.0*Fosc/12)+16)/256;dbuf[0]=count/10;dbuf[1]=count%10;SEL2=0;SEL1=1;P0=segtab[dbuf[1]];delay(300);P0=0xff;SEL1=0;SEL2=1;P0=segtab[dbuf[0]];delay(300);P0=0xff;}voidsys_in4、itial()//单片机初始化函数{TMOD=0x01;//计时器方式设定为模式1TL0=(65536-(unsignedint)(1000.0*Fosc/12)+16)%256;TH0=(65536-(unsignedint)(1000.0*Fosc/12)+16)/256;TR0=1;//开启T0中断ET0=1;//允许T0中断EA=1;//CPU开中断}voiddriver(unsignedcharmode)//电机驱动函数{switch(mode){case0:UP=1;DOWN=0;break;case1:UP=0;DOWN=1;break;case2:UP=0;DOWN=0;b5、reak;case3:RIGHT=1;LEFT=0;break;case4:RIGHT=0;LEFT=1;break;case5:RIGHT=0;LEFT=0;break;}}voiddisp()//闪烁显示函数{staticbitflash_signal=0;staticbitnumber=1;staticunsignedintflash_count=1;staticunsignedcharp0_temp;dbuf[0]=count/10;dbuf[1]=count%10;if(++flash_count>=400){flash_signal=~flash_signal;flash_co6、unt=0;}if(flash_signal==1)p0_temp=0x00;elsep0_temp=segtab[dbuf[number]];SEL2=~number;SEL1=number;P0=p0_temp;delay(30);P0=0x00;number=~number;}voidSET_TIME()//送料次数设定函数{while(1){disp();if(TIME_PLUS==0){count++;P0=0x00;delay(10000);}if(TIME_MINUS==0){if(count==1);else{count--;P0=0x00;delay(10000);}}i7、f(CONFIRME==0)break;}}voidreset()//系统复位函数{if(DOWN_LIM==1&&RIGHT_LIM==1)while(1){if(DOWN_LIM==1)driver(V_DOWN);if(RIGHT_LIM==1)driver(H_RIGHT);if(DOWN_LIM==0)driver(V_STOP);if(RIGHT_LIM==0)driver(H_STOP);if(RIGHT_
3、void)interrupt1//定时器T0中断服务函数{unsignedchartemp=0xfe;TL0=(65536-(unsignedint)(1000.0*Fosc/12)+16)%256;TH0=(65536-(unsignedint)(1000.0*Fosc/12)+16)/256;dbuf[0]=count/10;dbuf[1]=count%10;SEL2=0;SEL1=1;P0=segtab[dbuf[1]];delay(300);P0=0xff;SEL1=0;SEL2=1;P0=segtab[dbuf[0]];delay(300);P0=0xff;}voidsys_in
4、itial()//单片机初始化函数{TMOD=0x01;//计时器方式设定为模式1TL0=(65536-(unsignedint)(1000.0*Fosc/12)+16)%256;TH0=(65536-(unsignedint)(1000.0*Fosc/12)+16)/256;TR0=1;//开启T0中断ET0=1;//允许T0中断EA=1;//CPU开中断}voiddriver(unsignedcharmode)//电机驱动函数{switch(mode){case0:UP=1;DOWN=0;break;case1:UP=0;DOWN=1;break;case2:UP=0;DOWN=0;b
5、reak;case3:RIGHT=1;LEFT=0;break;case4:RIGHT=0;LEFT=1;break;case5:RIGHT=0;LEFT=0;break;}}voiddisp()//闪烁显示函数{staticbitflash_signal=0;staticbitnumber=1;staticunsignedintflash_count=1;staticunsignedcharp0_temp;dbuf[0]=count/10;dbuf[1]=count%10;if(++flash_count>=400){flash_signal=~flash_signal;flash_co
6、unt=0;}if(flash_signal==1)p0_temp=0x00;elsep0_temp=segtab[dbuf[number]];SEL2=~number;SEL1=number;P0=p0_temp;delay(30);P0=0x00;number=~number;}voidSET_TIME()//送料次数设定函数{while(1){disp();if(TIME_PLUS==0){count++;P0=0x00;delay(10000);}if(TIME_MINUS==0){if(count==1);else{count--;P0=0x00;delay(10000);}}i
7、f(CONFIRME==0)break;}}voidreset()//系统复位函数{if(DOWN_LIM==1&&RIGHT_LIM==1)while(1){if(DOWN_LIM==1)driver(V_DOWN);if(RIGHT_LIM==1)driver(H_RIGHT);if(DOWN_LIM==0)driver(V_STOP);if(RIGHT_LIM==0)driver(H_STOP);if(RIGHT_
此文档下载收益归作者所有