新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 劍桿織布機(jī)單片機(jī)C語言程序

劍桿織布機(jī)單片機(jī)C語言程序

作者: 時(shí)間:2016-11-30 來源:網(wǎng)絡(luò) 收藏
#include
#includesbit  P3_7=P0^6;   //   點(diǎn)動按鈕sbit  P3_6=P0^5; //   單梭按鈕sbit  P3_5=P0^4;   //   啟動按鈕sbit  P3_4=P0^3;   //   停止按鈕sbit  P3_3=P2^6;   //   經(jīng)停信號輸入sbit  P3_2=P2^7;   //   緯停信號輸入sbit  P3_1=P3^1;   //    “加”指示燈sbit  P3_0=P3^0;   //   “減”指示燈//sbit  P2_7=P2^7;   ////sbit  P2_6=P2^6; // sbit  P2_5=P2^5; //  “減”按鈕sbit P2_4=P2^4;    //   “加”按鈕//sbit  P2_4=P2^4; //  儲緯繼電器sbit  P2_3=P1^2 ;   //  保護(hù)輸出,至指示燈, 繼電器sbit  P2_2=P3^7 ;   //  高壓輸出sbit  P2_1=P3^6; //  離合輸出sbit  P2_0=P2^0; //  制動輸出sbit  P1_7=P0^7; //  儲緯停信號輸入sbit  P1_6=P0^2; //   H3信號輸入sbit  P1_5=P0^1; //   H2信號輸入sbit  P1_4=P0^0; //   H1信號輸入sbit  P1_3=P3^4; //    DIP2sbit  P1_2=P3^5; //   DIP3sbit  P1_1=P3^3; //   DIP4// sbit  P1_0=P1^0; //  // sbit  P0_7=P0^7; //sbit  P0_6=P3^2; //  過載保護(hù)輸入sbit  P0_5=P2^1; //  保護(hù)輸入,高壓檢測sbit  P0_4=P2^2; //  保護(hù)輸入,離合檢測sbit  P0_3=P2^3; //  保護(hù)輸入,制動檢測sbit  P0_2=P1^3; //  儲緯停輸出,至指示燈,繼電器。 sbit  P0_1=P1^0; //  緯停輸出sbit  P0_0=P1^1; //  經(jīng)停輸出#define uchar unsigned  char# define uint unsigned   int  //注意 無冒號static unsigned char flag,flag1,flag2,flag3,flag4,flag5,flag6,flag7;bit testflag,testflag1,testflag2,testflag3;static unsigned char   temp=0,temp1=0,temp2=0,temp3=0,tag=0,tag1=0,tag2=0,tag3=0,count=0;static unsigned char   tag4=0,tag5=0,tag6=0,tag7=0;static unsigned char   temp4=0,temp5=0,temp6=0,temp7=0,temp8=0,temp9=0, xx=0,count1=0,enable=0,mean=0;static unsigned char x,x1,x2,x3;static  unsigned  int  i,j,k,i1,j1,k1;sfr T2MOD = 0xC9;void delay(uchar ms);//sfr  WDT_CONTR=0xe1;  //看門狗地址sfr ISP_DATA  = 0xE2;  /* Flash Data Register */sfr ISP_ADDRH = 0xE3;  /* flash address high */sfr ISP_ADDRL = 0xE4;  /* flash address low */sfr ISP_CMD   = 0xE5;  /* flash command register */sfr ISP_TRIG  = 0xE6;  /* flash command trigger */sfr ISP_CONTR = 0xE7;  /* isp/iap control register */#define ISP_IAP_BYTE_READ 1;  /* 讀字節(jié) */#define ISP_IAP_BYTE_PROGRAM 2; /* 字節(jié)編程 */#define ISP_IAP_SECTOR_ERASE 3; /* 扇區(qū)擦除 */#define ISP_IAP_ENABLE 0x81; /* 系統(tǒng)工作時(shí)鐘<12M,對ISP_CONTR寄存器設(shè)置此值 ,0x81*/unsigned char byte_read(unsigned int addr);void byte_write(unsigned int addr,unsigned char program_data);void Sector_Erase(unsigned int addr);void IAP_Disable();unsigned int  eeprom_address;unsigned  char  read_eeprom;unsigned char value_buf[22];void main  (void){ P2_0=0; xx=0;TMOD=0x11;EA=1;ET0=1;ET1=1;TH0=(65536-10000)/256;TL0=(65536-10000)%256;  TR0=0;TH1=(65536-10000)/256;TL1=(65536-10000)%256;  TR1=0;ET2=1;   //T2中斷允許T2MOD=0x00; //如果T2MOD=0X02,則從P1_0輸出T2CON=0x00;//CP_RL2=1;EXEN2=1;TH2=(65536-50000)/256;TL2=(65536-50000)%256;RCAP2H=(65536-50000)/256;   //重裝載計(jì)數(shù)器賦初值RCAP2L=(65536-50000)%256;read_eeprom=byte_read(0x2000);x=read_eeprom;if (x<5) x=5;if(x>25) x=25;x1=byte_read(0x2200);if (x1<35) x1=35;if(x1>45) x1=45;while(1){if ((P3_7==1) &&(temp1==1) || (P3_6==1)&&(temp1==1) )  temp2=1;  // temp2點(diǎn)動單梭終止運(yùn)行標(biāo)志while (temp2==1){//if (!((P1_6==1) && (P1_4==1)&&(P1_5==0)) )   continue;// elseif((P1_6==1)&&(P1_5==0)&&(P1_4==1)){P2_1=1;P2_0=0;temp=0;temp1=0;temp2=0;enable=0;}}if  ((P3_3==1)&&(temp1==1) &&(xx==0)) {temp3=1;P0_0=0;}        // temp3經(jīng)停標(biāo)志while((temp3==1) && (temp1==1)&&(xx==0)){// if(!((P1_6==1) && (P1_4==1)&&(P1_5==0))) continue;// elseif((P1_6==1)&&(P1_5==0)&&(P1_4==1)){P2_1=1;temp1=0;P2_0=0; P0_0=0;enable=0;temp3=0;} }if ((P1_7==1)&&(temp1==1) &&(xx==0) ) {temp4=1;P0_2=0;}        //temp4儲緯停標(biāo)志while((temp4==1) &&(temp1==1)&&(xx==0)){//if(!((P1_6==1) && (P1_4==1)&&(P1_5==0)) ) continue;// elseif((P1_6==1)&&(P1_5==0)&&(P1_4==1)){P2_1=1;temp1=0;P0_2=0;P2_0=0;enable=0;}}if  ((temp4==1) && (temp1==0) && (P3_4==1)) {P0_2=1; temp4=0;} //解除儲緯停標(biāo)志if ((P3_2==0)&&(temp1==1) && (enable==1)&&(xx==0))          //緯停負(fù)輸入{delay(10);                                            if ((temp1==1) && (enable==1)&&(P3_2==0) &&(xx==0)){//count1數(shù)字濾波計(jì)數(shù) 略{}if (mean==5)                                               //mean 采樣值 之和 略{                 //enable=1 緯停允許while   ((temp1==1) && (enable==1)&&(P3_2==0)&&(xx==0)&&(P0_5==0)&&(P0_3==0)&&(P0_6==1)){/*if(!((P1_6==1) && (P1_5==1))) continue;    //斷緯時(shí)  仍可保護(hù)else  {delay(2); P2_1=1;P2_0=0;temp1=0;temp5=1;enable=0;P0_1=0;} */  //temp5 緯停標(biāo)志if((P1_6==1)&&(P1_4==0)&&(P1_5==1)&&(P3_2==0))    //傳感器正輸入flag=1;                                        //flag 斷緯,傳感器后沿停機(jī)記憶while ((flag==1)&&(P3_2==0)&&(xx==0)&&(P0_5==0)&&(P0_3==0)&&(P0_6==1) ){if ((P1_6==0)&&(P1_5==0)){temp5=1;flag=0;enable=0;}        //temp5 緯停標(biāo)志}}                                     }}}if(P3_2==1){flag=0;                    //松開按鈕 flag=0;for (count1=0;count1<5;count1++)         //count1數(shù)字濾波計(jì)數(shù){value_buf[count1]=0;}mean=0;}  if (temp5==1){delay(2); P2_1=1;delay(1);P2_0=0;temp1=0;enable=0;P0_1=0;_nop_(); for (count1=0;count1<5;count1++){value_buf[count1]=0;}mean=0;temp5=0;}if ((P3_6==1) && (temp1==0) &&(temp==0)&&(temp4==0)&&(xx==0))   //單梭  ,temp 單梭標(biāo)志{P2_0=1;P2_1=0;temp=1;}while (temp==1){//if  (!(( P1_5==1)&&(P1_6==0)&&(P1_4==0)|| (P3_4==1))  ) continue;     //P1_5 ,H2信號 單梭停止// elseif((P1_6==0)&&(P1_5==1)&&(P1_4==0) ||(P3_4==1)){P2_1=1;temp=0;P2_0=0;   }    }if ((P3_5==1) && (temp4==0)&&(P3_4==0)&&(xx==0))    //無儲緯停,無保護(hù) ,啟動{P2_0=1;P2_1=0;_nop_();  temp=0;temp1=1;temp3=0;temp5=0;_nop_();P0_0=1;P0_1=1;}//temp1 啟動標(biāo)志 ,temp8==1,開機(jī)瞬間緯停無效//while ( (temp3==0)&&(temp4==0)&& (temp5==0)&&(xx==0)&&(temp1==1))if ((temp3==0)&&(temp4==0)&& (temp5==0)&&(xx==0))         //停止{if (P3_4==1){ P2_1=1; P2_0=0;_nop_();temp=0;temp1=0;enable=0;}}    if ((temp==0) && (temp1==0) &&(temp4==0)&& (P3_7==1) &&(xx==0) && (tag==0))   //tag 切斷點(diǎn)動動作按鈕{//delay(1);temp9=1;                                        //temp9 點(diǎn)動狀態(tài)運(yùn)行中P2_0=1; tag=1;  tag1=0; count=1;      //開機(jī)瞬間無高壓,count==0;delay(1);    //間隔P2_1=0; P2_2=0;delay(20);P2_2=1;    //高壓1時(shí)間delay(x1);     //離合時(shí)間if (P3_7==0)     //松開點(diǎn)動按鈕{P2_1=1;}}
				
            
                
			
							
上一頁 1 2 下一頁

評論


技術(shù)專區(qū)

關(guān)閉