/* Main - a simple test program*/
void main( void )
{
	InitUART( 11 );   /* Set the baudrate to 19,200 bps using a 3.6864MHz crystal */

	_SEI();           /* Enable interrupts => enable UART interrupts */

	for( ; ; )        /* Forever */
	{
		TransmitByte( ReceiveByte() ); /* Echo the received character */
	}
}
示例#2
0
文件: main.c 项目: shkodina/for-quest
int main( void ) {
    Setup();  //настройка регистров МК
    _SEI(); //разрешение прерываний
    StartUART0();

    while(1) {
        if (bModBus) {
            cNumTrByte0=ModBus(cNumRcByte0); //обработка принятого соообщения ModBus
            if (cNumTrByte0!=0) StartTrans0();
            bModBus=false;
        }//end if (bModBus)
    }//end while(1)
}//end main()
示例#3
0
int main(void)
{
	DDRA=0xff;


	DDRB=0xb1;
	PORTB |= 0xff;// Control UAB

	DDRC=0xfc;
	PORTC |=0xff;/*VT3=off*/

	DDRD=0xbf;
	PORTD=0xff;/*imp=off,Reset=off*/

	//  INIT SPI
	SPSR=0;//f/64
	SPCR=0x70;

	InitIndStart();
	TIFR |=0x40;//reset flag
	TIMSK |=0x40;
	TCCR2=0x3;

	TCCR0=5;// /1024
	TIMSK |=0x1;//enable int overlow T0


	//INIT TWI;
	TWBR=0x7f;//F TWI
	TWAR=(NumberLink<<1)+4;   
	TWCR =(1<<TWEA)|(1<<TWEN);

	CtStart=200;
	while(CtStart--)	_WDR();




	CtErrorLink[0]=CtErrorLink0[0];
	CtErrorLink[1]=CtErrorLink0[1];
	Error=0;
	NumberIndicator=2;
	_SEI();

	CtBegin=250;    
	/*Work program*/ 
	RomReceive[1]=2; 
	RomReceive[2]=16;//3;  
	RomReceive[3]=0; 
	RomReceive[4]=0;    
	RomReceive[5]=0; 
	RomReceive[6]=0;  
	RomReceive[7]=0; 
	RomReceive[8]=0;  
	RomReceive[9]=0; 
	RomReceive[10]=0;  
	
	CtInd=50;     	 
	while(1)
	{
		_WDR();




		ReadKn();
		if(Error & 0x80)
		{
			if(!CtInd)
			{
				IndOtkazSHSN();
				CtInd=50;
			}
		}
		else if(!RomReceive[1])
		{
			if(!CtInd)
			{
				IndicatorTest();
				CtInd=50;
			}
		}
		else if(!CtInd)//800 ms
		{

			CtInd=50;


			switch(RomReceive[NumberIndicator])
			{
			case 1:
				IndOtkazLuk1();

				break;
			case 2:
				IndOtkazLuk2();

				break;

			case 3:
				IndGotovDU();
				break;
			case 4:
				IndRabota();
				break;
			case 5:
				IndOtkazLuk3();
				break;

			case 6:
				IndNoLinkSHU();
				break;
			case 7:
				IndNoLinkMSHU();
				break;
			case 8:
				IndOtkazSHSN();
				break;
			case 9:
				IndRegimMSHU();
				break;

			case 10:
				IndOtkazLuk4();

				break;
			case 11:
				IndOtkazLuk5();

				break;

			case 12:
				IndOtkazLukDG1();

				break;
			case 13:
				IndOtkazLukDG2();

				break;
			case 14:
				IndOtkazLukLR1();

				break;
			case 15:
				IndOtkazLukLR2();

				break;
			case 16:
				IndGotovMU();
				break;
			case 17:
				IndGotovSystem();
				break;
			case 18:
				IndOtkazFVU();
				break;
			case 19:
				IndOtkazLukPCH1();

				break;
			case 20:
				IndOtkazLukPCH2();

				break;
			case 21:
				IndOtkazDT();
				break;

			default:
				break;


			}
		}
		if(EnableLoad)
		{
			LoadRegTransmit();
			LoadControlSum();
		}
		if(TWCR & 0x80)
		{
			++TestTWI;
			ReceiveTransmitSlave();
		}

		if(!CtErrorLink[0])//ErrorLink;
		{
			//	++TestTwi;
			//INIT TWI;
			TWBR=0;//F TWI
			TWAR=0;
			TWCR =0;
			TWSR=0xf8;
			CtStart=50;
			while(CtStart--)	_WDR();
			TWBR=0x7f;//F TWI
			TWAR=(NumberLink<<1)+4;
			TWCR =(1<<TWEA)|(1<<TWEN);
			//   TWCR |=(1<<TWINT);
			CtErrorLink[0]=CtErrorLink0[0];

			CtStart=200;
			while(CtStart--)	_WDR();
		}
	}
}
示例#4
0
    int main(void)
    {
	unsigned char Arg0;
 



//if DDRX,X=1 PORTX,X=OUT
    DDRA=0x61;
	PORTA = 0xff;//0xc0 prov

    DDRB=0x68;
	PORTB = 0xff;

    DDRC=0xfc;
    PORTC =0xff;

    DDRD=0xfe;
    PORTD=0xf7;
	TCCR2=0;
	TCCR1A=0;
	TCCR0=0;
//INIT TWI;
    TWBR=0x7f;//F TWI


    TCCR1B=0x2;//0.5mkc
    TIMSK=TIMSK | 0x4;//enable Int overlowT1
    TWAR=(NumberLink<<1)+4;   
   TWCR =(1<<TWEA)|(1<<TWEN);

   _SEI();



		
	for(Arg0=1;Arg0<=10;++Arg0)
	RomReceive[Arg0]=0;


	CtEeprom=1;

	RegimWork=0x10;//avt vent
	CtErrorLink=CtErrorLink0;
	CtKn=5;

			
	ResetError();	
//WORK	
	           
      while(1)
    {
	_WDR();
	if(RomReceive[3] & 0x1)
	ResetError();
	SetError();
	SetRegimError();


	ControlRegim();
	ControlPech();
	if(RomReceive[1] & 1)
	OpenLuk1();
	else if(RomReceive[2] & 1)
	CloseLuk1();
	else
	PORTC |=0xc;
	if(RomReceive[1] & 2)
	OpenLuk2();
	else	if(RomReceive[2] & 2)
	CloseLuk2();
	else
			{
	PORTC |=0x10;
	PORTB |=0x8;
			}



	ControlLed();
	ControlRevun();
	if(EnableLoad)
		{
    LoadRegTransmit();
    LoadControlSum();
		}
	if(TWCR & 0x80)
			{
    ReceiveTransmitSlave();
	++TestTransmit;
			}
	if(!CtErrorLink)//ErrorLink;
		{

//INIT TWI;
    TWBR=0;//F TWI
   TWAR=0;
   TWCR =0;
	TWSR=0xf8;
    CtStart=50;
	while(CtStart--)	_WDR();
    TWBR=0x7f;//F TWI
    TWAR=(NumberLink<<1)+4;
   TWCR =(1<<TWEA)|(1<<TWEN);
 //   TWCR |=(1<<TWINT);
	CtErrorLink=CtErrorLink0;

    CtStart=200;
	while(CtStart--)	_WDR();
		}



				

    }
  
}
示例#5
0
    void ControlReika(void)
    {

	unsigned int R0;




	R0=DPNom;
	R0 >>=6;

	if(RegimStop)
		{
	PORTD &=0xf7;
	Alfa=0xff;
	DPNom=DPNomMax;
		}
	else 
		{




	PORTD &=0xf7;


	if(DP<=(DPNom-50))
				{

	Alfa=180;
//	CtAlfa=5;
				}
	else if(DP>=(DPNom+50))
				{

	Alfa=125;

				}		
	else if(DP>=(DPNom))
				{

	Alfa=TabMinAlfa[R0];
//	Alfa=R1;//200;
//	CtAlfa=20;
				}
	else	if(DP<(DPNom))
				{

	Alfa=TabMaxAlfa[R0];
//	Alfa=R1;//254;

//	CtAlfa=30;
				}


		}

//	Alfa=150;
	_CLI();

	OCR0=Alfa;
	_SEI();
    }
示例#6
0
void main(void)
{
    // настройка таймера
    init_timer0();
    // настройка LCD
    InitLcd();
    // настройка индикации
    indicator_init();
    // глобальная настройка портов входных/выходных развязок
    {
        // выходная развязка - выход, на выход=1
        DDRF = 255;
        PORTF = 255;
        DDRE |= 1<<2;
        DDRE |= 1<<3;
        PORTE |= 1<<2;
        PORTE |= 1<<3;
        // верхняя входная развязка, вход
        DDRD &= ~(1<<5);
        DDRD &= ~(1<<4);
        DDRB &= ~(1<<7);
        DDRB &= ~(1<<6);
        DDRB &= ~(1<<5);
        DDRB &= ~(1<<4);
        DDRE &= ~(1<<7);
        DDRE &= ~(1<<6);
        DDRE &= ~(1<<5);
        DDRE &= ~(1<<4);
        PORTD |= 1<<5;
        PORTD |= 1<<4;
        PORTB |= 1<<7;
        PORTB |= 1<<6;
        PORTB |= 1<<5;
        PORTB |= 1<<4;
        PORTE |= 1<<7;
        PORTE |= 1<<6;
        PORTE |= 1<<5;
        PORTE |= 1<<4;
        // нижняя входная развязка, вход
        DDRC = 0;
        DDRD &= ~(1<<7);
        DDRD &= ~(1<<6);
        PORTC = 255;
        PORTD |= 1<<7;
        PORTD |= 1<<6;
    }
    // зануление сбора дефектов на линии реза
    {
        unsigned char i;
        for (i=0; i<16; i++)
            def_rez_m[i]=0;
    }
    // зануление сопровождения на станке
    rez_init();
    def_rez=0;
    // зануление работы упора и сопровождения по датчикам
    upor_init();
    // разрешение прерываний
    _SEI();
    //------------
    {
        extern unsigned int timeout_key;
        unsigned char err;
        ClearDisplay1();
        Show_m2( 0,"Т2,стан№1");
        Show_m2(16,"29.01.2013");
        for (timeout_key=5000;;)
        {
            if ( timeout_key<5 )
                break;
        }
        err=PING & 0x08;
        // стереть память
        if ( err==0 )
            ep_zero();
    }

    //--------------
    // настройка цифрового фильтра датчиков дефектов
    defect_init();
    // начальная настройка kk
    pulsar_init();
    //-------------
    ClearDisplay1();
#ifdef RSPC
    rspc_init();
#endif
    // сброс кол-ва циклов сработки колеса
    koleso_cicle=0;
    for(;;)
    {
        //
        OutPC_FromMainCycle();
        // выбор экрана
        // indicator_next();
        // индикация
        indicator_cicle();
        //==========================
        if ( koleso_cicle>2 )
        {
            DDRF |= (1<<6);
            PORTF &= ~(1<<6);
        }
        //=========================================
        // Сигнал рез, разделение на трубы
        if ( rez_fg==255 )
        {
            // сброс флага рез
            rez_fg=0;
            // новая труба, длина=1, сброс дефектов
            rez_ms_def[0]=0;
            rez_ms_ind[0]=1;
            // перенос дефекта и трубы в следущую позитцию
            // 1-4 - сопровождение на станке от 1 до 4 труб
            // 1 - еще неотрезаная труба
            // перенос дефекта
            rez_ms_def[4]=rez_ms_def[3];
            rez_ms_def[3]=rez_ms_def[2];
            rez_ms_def[2]=rez_ms_def[1];
            rez_ms_def[1]=rez_ms_def[0];
            // перенос длины от линии реза
            rez_ms_ind[4]=rez_ms_ind[3];
            rez_ms_ind[3]=rez_ms_ind[2];
            rez_ms_ind[2]=rez_ms_ind[1];
            rez_ms_ind[1]=rez_ms_ind[0];
            rez_ms_ind[1]=1;
            // длина отрезаной трубы
            tube_len=rez_ms_ind[2];
            // сброс флага дефекта очередной трубы
            def_rez_out=0;
            // подсчет труб дефектных и общее количество
            tube_count++;
            {
                unsigned char maska;
                maska = ((1<<0) | (1<<1) | (1<<3));
                if ( (rez_ms_def[2] & maska)>0 )
                    tube_count_def++;
            }
        }



        // сработало колесо
        if ( koleso_cicle>0 )
        {
            //=========================================
            {
                // анализ сигнала с кельвина и укладка маркировки ограниченой длины
                void kelv_analiz(void);
                kelv_analiz();
            }
            //=========================================

            // протяжка дефектов
            {
                unsigned int i;
                for ( i=1; i<8; i++)
                {
                    if ( ind_def8[i]>0 )
                    {
                        ind_def8[i]=0;
                        ind_def12[ d_def_sm[i]/ind_def_k ]=ind_def_k;
                    }
                }


                // отображение на 12
                if ( ind_def12[0]>0 ) ind_def12[0]--;
                for (i=1; i<12; i++)
                {
                    if ( ind_def12[i]>0 ) ind_def12[i]--;
                    if ( d_def[indx_norm(i*ind_def_k)]>0 )  ind_def12[i-1]=ind_def_k;
                }
                //===============================================
                d_def[indx_norm(0)]=0;
                indx_inc();
            }

//=========================================
            // сопровождение от краско отметчиков до линии реза
            {
                unsigned char i;
                for (i=152; i>0; i--) s_def[i]=s_def[i-1];
                s_def[0]=d_def[indx_norm(1)];
            }
            //----------------------------
            // индикация дефекта от кк до реза
            if ( ind_d_korez>0 ) ind_d_korez--;
            if ( s_def[0]>0 ) ind_d_korez=d_rez_sm;
//=========================================
            // "пятно" дефектов в р-не линии реза
            /*
            {
              unsigned char i;
              //
              for (i=0;i<10;i++)
              {
                // def_rez_m[i]=def_rez_m[i-1];
                // 105 -5 = 100
                // def_rez |= s_def[i+100];
                def_rez |= s_def[i+d_rez_sm-5];
                // def_rez |= def_rez_m[i];
              }
              // def_rez_m[1]=s_def[105-5];
            }
            */
            def_rez |= s_def[d_rez_sm];
            // ShowDigitZ(13,3,s_def[110]);
//==========================================

            // сопровождение на станке до 4 труб
            {
                unsigned char i;
                for (i=1; i<5; i++)
                {
                    if ( rez_ms_ind[i]>0 )rez_ms_ind[i]++;
                    if ( rez_ms_ind[i]>=rez_end )
                    {
                        // конец станка
                        def_rez_out|=rez_ms_def[i];
                        // сброс сопровождения на станке
                        rez_ms_ind[i]=0;
                        rez_ms_def[i]=0;
                    }
                }
            }
//==============================================
            // 1 - накопление дефекта на неотрезаной трубе
            rez_ms_def[1]|=def_rez;
            // сброс флага дефектов
            def_rez=0;
//================================================
// сигнализация работы датчиков
            sign_flag=0;
            if ( sign_count_d1<sign_dl ) sign_count_d1++;
            else sign_flag|=(1<<0);
            if ( sign_count_d2<sign_dl ) sign_count_d2++;
            else sign_flag|=(1<<1);
            if ( sign_count_d3<sign_dl ) sign_count_d3++;
            else sign_flag|=(1<<2);
            if ( sign_count_d4<sign_dl ) sign_count_d4++;
            else sign_flag|=(1<<3);
            if ( sign_count_d5<sign_dl ) sign_count_d5++;
            else sign_flag|=(1<<4);
            if ( sign_flag>0 )
            {
                DDRF |= (1<<4);
                PORTF &= ~(1<<4);
            }
            else
            {
                DDRF |= (1<<4);
                PORTF |=  (1<<4);
            }
//==============================================
            // Работа с краскопультом
            pulsar_cicle();
            // конец цикла колесо
            koleso_cicle--;
        }
// ===== конец работы "внутри срабатывания колеса" =======
//--------------------
        // сопровождение по датчикам
        // датчик 1 ( фрсу )
        if ( trub_fg_1==255 )
        {
            trub_fg_1=128;
            // чтение дефекта
            defect1=def_rez_out;
            defect1r=defect1;
            // сброс флага дефекта очередной трубы
            // def_rez_out=0;
            // запуск краскоотметчика на толщиномер
            pusk_kr3( defect1r );
        }
        if ( trub_fg_1==0 )
        {
            trub_fg_1=128;
            defect1=0;
        }
//----------------------------------------
        // датчик 2
        if ( trub_fg_2==255 )
        {
            trub_fg_2=128;
            defect2=defect1r;
            defect2r=defect2;
        }
        if ( trub_fg_2==0 )
        {
            trub_fg_2=128;
            defect2=0;
        }
//---------------------------------------
        // датчик 3
        if ( trub_fg_3==255 )
        {
            trub_fg_3=128;
            if ( (sign_flag & (1<<1) ) == 0 )
            {
                defect3=defect2r;
                defect3r=defect3;
            }
            else
            {
                defect3=defect1r;
                defect3r=defect3;
            }
        }
        if ( trub_fg_3==0 )
        {
            trub_fg_3=128;
            defect3=0;
        }
//----------------------------------------
        // датчик 4
        if ( trub_fg_4==255 )
        {
            trub_fg_4=128;
            defect4=defect3r;
            defect4r=defect4;
        }
        if ( trub_fg_4==0 )
        {
            trub_fg_4=128;
            defect4=0;
        }
//----------------------------------------------
        {
            unsigned char mask_d;
            mask_d = ((1<<0) | (1<<1) | (1<<2) | (1<<3));
            // датчик 5
            if ( trub_fg_5==255 )
            {
                trub_fg_5=128;
                defect5=defect4r;
                // упор верх
                if ( (defect5 & mask_d)>0 )
                {
                    upor_up();
                    upor_flag=255;
                }
            }
            if ( trub_fg_5==0 )
            {
                trub_fg_5=128;
                // упор вниз
                if ( (defect5 & mask_d)>0 )
                {
                    upor_dn();
                    upor_flag=0;
                }
                defect5=0;
            }
        }
//===============================================
// Сигнализация
        if ( trub_fg_1i != 128 )
        {
            trub_fg_1i=128;
            sign_count_d1=0;
        }
        if ( trub_fg_2i != 128 )
        {
            trub_fg_2i=128;
            sign_count_d2=0;
        }
        if ( trub_fg_3i != 128 )
        {
            trub_fg_3i=128;
            sign_count_d3=0;
        }
        if ( trub_fg_4i != 128 )
        {
            trub_fg_4i=128;
            sign_count_d4=0;
        }
        if ( trub_fg_5i != 128 )
        {
            trub_fg_5i=128;
            sign_count_d5=0;
        }
//===============================================
    }
}
示例#7
0
文件: M19U6PKD.c 项目: maxk9/etro_new
	int main(void)
    {
	unsigned char Arg0;


//if DDRX,X=1 PORTX,X=OUT
    DDRA=0xff;


    DDRB=0x1f;
	PORTB = 0xff;

    DDRC=0xfc;
    PORTC =0xff;

    DDRD=0xea;

    PORTD=0xff;
	RegTransmitRS[7]=ReadEeprom(4);
//INIT TWI;
    TWBR=0x7f;//F TWI


    TCCR1B=0x2;//0.5mkc
    TIMSK=TIMSK | 0x4;//enable Int overlowT1
    TWAR=(NumberLink<<1)+4;   
   TWCR =(1<<TWEA)|(1<<TWEN);

   _SEI();
    RegimTime =0;

		
	for(Arg0=1;Arg0<=10;++Arg0)
		RomReceive[Arg0]=0;




	RegimWork=0;
	CtErrorLink=CtErrorLink0;

	CtKn=5;

	Regim=1;//Gashenie=on;

	InitUsart();  
			
	CtUsart=1;	
	CtEnableKn=3;
	InitStarter();

	CtErrorRS=9;
	NumberRegim=1;// hand MShU
	NNom=1500;
	CtBegin=50;
	RegS=0x1200;
	RegSTemp=0x1200;
	RegS1=0;
	RegSTemp1=0;
	CtErrorRSMin=255;
	NumberRegim=2;
	ClearPZA=0;
	CtPZA=CtPZA0;
	ErrorPZA=0;
	RezervDiz2=0;
//WORK	
	           
      while(1)
    {


	_WDR();

	ControlNU();
	PORTB &=0xef;
	if(RegimWork<=2)
		{
		ReadEeprom(4);
		if(ReadEeprom(4)!=RegTransmitRS[7])
			WriteEeprom(4,RegTransmitRS[7]);
		}






	if((!RegimWork)||(RegimWork & 0x8))
	PORTD |=0x60;
	else if((RegimWork & 1)||(RegimWork & 0x80))
		{
	PORTD &=0xbf;

		}
	else
		{
	PORTD &=0xdf;
	PORTD |=0x40;
		}


	ControlZapravkaTopliva();
	ControlZapravkaMasla();
	ControlPodogrev();
//	ControlAvarStop();
	ControlLampError();
	TOG=RomReceiveRS[6][(NumberBlok-1)];


	if(CtBegin)
		
	ClearError();
	else if(RegS1 & 8)
		{
	ClearError();


		}
	if(!(RegTransmit[1] & 6))
	ClearPZA=0;
	if(RegS1 & 0x20)
		{
	ClearPZA=0;

		}
	if(RomReceive[3] & 1) 
	NumberBlok=6;//SHU 2
	else
	NumberBlok=3;//SHU 1



		


	if(PORTC & 8)
	ChangeNumberRegim();

	ChangeNNom();
	AccountNDiz();
	LoadRegTransmitRS();

	SetRegimError();
	SetError();
	ControlRegimWork();


     _WDR();
	if(EndAd)
		{

	EndAd=0;
		}
	if(EnableLoad)
		{
    LoadRegTransmit();
    LoadControlSum();
		}
	if(TWCR & 0x80)
			{
    ReceiveTransmitSlave();

			}
	if(!CtErrorLink)//ErrorLink;
		{

//INIT TWI;
    TWBR=0;//F TWI
   TWAR=0;
   TWCR =0;
	TWSR=0xf8;
    CtStart=50;
	while(CtStart--)	_WDR();
    TWBR=0x7f;//F TWI
    TWAR=(NumberLink<<1)+4;
   TWCR =(1<<TWEA)|(1<<TWEN);

	CtErrorLink=CtErrorLink0;

    CtStart=200;
	while(CtStart--)	_WDR();
		}



				

    }
  
}
示例#8
0
    int main(void)
    {
	unsigned int R0;
	unsigned int R2;
	DDRA=0;
	PORTA=0;
 
    DDRB=0xa0;
	PORTB |= 0xff;

    DDRC=0xfc;
    PORTC |=0xff;

    DDRD=0x2a;
    PORTD=0xf7;

//INIT TWI;
    TWBR=0x7f;//F TWI
    CtStart=65000;
	while(CtStart--)	_WDR();
//Init capture1
    TCCR1B=0x82;//0.5mkc,falling edge
    TIMSK=TIMSK | 0x4;//enable Int overlowT1
//    TIMSK=TIMSK | 0x20;//enable Int capture1 prov

//INIT USART
	InitUsart();

//  INIT SPI
    SPCR=0x70;//f/64
    SPSR=0;//f/64

    InitIndStart();


    InitAd();
    TCCR1B=0xc2;//0.5mkc
    TIMSK=TIMSK | 0x4;//enable Int overlowT1




 
    ResetAvaria();
	LoadFromEeprom();
	RomReceive[3]=1;
	RomReceive[4]=0;
	RomReceive[6]=0;

	RegSPCH2=0;
	RegSPCH2Old=0;
	CtKn=5;
	RegimWork=0;
	U50=0;
	I50=200;
	UKvadro=0;
	U400Out=0;
	IA=0;
	IB=0;
	IC=0;
	CtUsart=NumberBlok;
	RegTransmitRS[1]=0;
	CtLuk=200;
    _SEI();
	CtBegin=50;
	RomReceiveRS[3][1]=0;//denablePusk
	RomReceiveRS[3][4]=0;//denablePusk
	RegTransmitRS[3]=0;	
	RegTransmitRS[1]=0;
	ClearErrorFar();
	CtIMax=80;
	CtUError=160;
	AvariaI=0;
	RegStop=0;								             
     while(1)
    {

     _WDR();
	 if(CtBegin)
	 	{
	if(RomReceive[3] & 2)
	NumberBlok=4;
	else
	NumberBlok=1;
		}

//	UMin=220;
//	UMax=600;
	if(RegimWork>=6)
		{
	if((UKvadro>=UMin) && (UKvadro<=UMax))
	CtUError=160;
		}
	else
	CtUError=80;
	if(RomReceiveRS[5][3] & 4)
		{
	ResetAvaria();
	ClearErrorFar();
		}
	if((RomReceiveRS[5][6] & 4)||(RomReceive[4] & 0x80))
		{
	ResetAvaria();
	ClearErrorFar();
		}
	if((Avaria)||(AvariaI))
	RegTransmitRS[1] |=1;
	else
	RegTransmitRS[1] &=0xfe;
	if(!(RegS & 0x60))
	RegTransmitRS[1] |=2;
	else
	RegTransmitRS[1] &=0xfd;
	if(RegS & 0x10)
	RegTransmitRS[1] |=4;
	else
	RegTransmitRS[1] &=0xfb;
	if((RegimWork)&&(!CtLuk))
	RegTransmitRS[1] |=8;//Open Luk
	else
	RegTransmitRS[1] &=0xf7;//Close Luk

	if((RomReceive[5] & 1)&&(RegS & 0x10))
	RegTransmitRS[1] |=0x10;
	else
	RegTransmitRS[1] &=0xef;
	if(RegS & 0x10)//nagr=on
	RegTransmitRS[1] |=0x20;
	else
	RegTransmitRS[1] &=0xdf;

	RegTransmitRS[2]=RomReceiveRS[3][0];//Avaria;//RegS;//RegimError;//NumberBlok;//45;//U50;

	RegTransmitRS[4]=U400In>>2;//RomReceive[2];//UNom
	RegTransmitRS[5]=Avaria;//46;//AdResult[1];
	RegTransmitRS[6]=TestTimeAd;//16;

	RegSPCH2=RomReceive[3]<<8;
	RegSPCH2 |=RomReceive[4];
	AccountU50();
	AccountI50();
	CalcI50();

	AccountUKvadro();
	AccountU400Out();
	AccountIA();
	AccountIB();
	AccountIC();
	AccountIMax();
	if(IMax<IMaxDop)
	CtIMax=80;


	ControlRegimError();
	if(RomReceive[3] & 1)
		{
	ControlRegimWork();
	ControlK();
		}
	else
		{
	ControlRegimWorkDU();
	ControlKDU();
		}
	SetAvaria();		




	 if(!CtErrorLink)
		{
//INIT TWI;
    TWBR=0;//F TWI
   TWAR=0;
   TWCR =0;
	TWSR=0xf8;

    TWBR=0x7f;//F TWI

	CtErrorLink=CtErrorLink0;
		}
  
	if(CtLinkTWI)
	--CtLinkTWI;
	else
	{
	CtLinkTWI=30;

	_WDR();
    LoadRegTransmit();//++RegTransmit
    ReceiveTransmitMaster();
	}
  ReadKn();






     DecSegm(U400In);
    SetCursor(0,0);
    IndPar();
	R0=400;
    while(R0--)         _WDR();	
    SPDR=0x20;
	R2=900;
    while(R2--)         _WDR();
     DecSegm(UKvadro);
    SetCursor(40,0);
    IndPar();
	R0=400;
    while(R0--)         _WDR();	
    SPDR=0x20;
	R2=900;
    while(R2--)         _WDR();
    DecSegm(IMax);
    SetCursor(80,0);
    IndPar();
	R0=400;
    while(R0--)         _WDR();	
    SPDR=0x20;
	R2=900;
    while(R2--)         _WDR();
     DecSegm(RegSPCH2);
    SetCursor(0,1);
    IndPar();
	R0=400;
    while(R0--)         _WDR();	
    SPDR=0x20;
	R2=900;
    while(R2--)         _WDR();
     DecSegm(RegStop);
    SetCursor(40,1);
    IndPar();
	R0=400;
    while(R0--)         _WDR();	
    SPDR=0x20;
	R2=900;
    while(R2--)         _WDR();
    DecSegm(Avaria);
    SetCursor(80,1);
    IndPar();
	R0=400;
    while(R0--)         _WDR();	
    SPDR=0x20;
	R2=900;
    while(R2--)         _WDR();
    Reg0=600;
    while(Reg0)
    --Reg0;

    }
  
}
示例#9
0
    int main(void)
    {
	unsigned char Arg0;
 



//if DDRX,X=1 PORTX,X=OUT
    DDRA=0xbf;
	PORTA = 0xff;//0xc0 prov

    DDRB=1;
	PORTB = 0xff;

    DDRC=0xd4;
    PORTC =0xff;

    DDRD=0x12;
    PORTD=0xff;

//INIT TWI;
    TWBR=0x7f;//F TWI


    TCCR1B=0xc2;//0.5mkc
    TIMSK=TIMSK | 0x4;//enable Int overlowT1
	TWAR=4;
    TWCR =(1<<TWEA)|(1<<TWEN);
    ReadKn();
    CtStart=200;
	while(CtStart--)	_WDR();
    ReadKn();
   _SEI();
    RegimTime &=0xc0;

    CtUst=CtUst0;
		
	for(Arg0=1;Arg0<=10;++Arg0)
	RomReceive[Arg0]=0;


	CtEeprom=1;

	RegimWork=0;
	CtErrorLink=CtErrorLink0;

	InitUSART();
	Gashenie=0;//Gashenie=off;
	UNom=ReadEeprom(1);
	if(UNom>260)
	UNom=220;
	if(UNom<90)
	UNom=220;
	UMin=80;//95;//95B
	CtReceiveUsart=0;			
	Gashenie =4;//vozb=on	
//WORK	
	           
      while(1)
    {
	_WDR();
	if(!CtTransmitUsart)
		{
	if(NumberLinkUsart)
	--NumberLinkUsart;
	else
	NumberLinkUsart=2;



	CtReceiveUsart=0;
	LoadRegTransmitUsart(NumberLinkUsart);
	CtTransmitUsart=15;
	RCHReceive=0xff;
	RCLReceive=0xff;

		}


	if(RegS & 2)
	RegimWork &=0xfe;
	else if(RegSWork & 0x40)
		{
	if(RegimWork & 1)
	RegimWork &=0xfe;
	else
	RegimWork |=1;
	RegSWork &=0xbf;
		}


	if((RomReceive[1]& 0xe)&&(!(RomReceive[1]& 0x10)))
	PORTA &=0xdf;
	else
	PORTA |=0x20;
	if(RegS & 2)
	PORTA &=0x7f;
	else
	PORTA |=0x80;

	if(RegS & 4)
	PORTC &=0xef;
	else
	PORTC |=0x10;
	if(RegS & 8)
	PORTC &=0xfb;
	else
	PORTC |=0x4;

	ChangeUNom();







	IndicatorLed();
	++TestLink;
     _WDR();
	if(EndAd)
		{

	EndAd=0;
		}
	if(EnableLoad)
		{
    LoadRegTransmit();
    LoadControlSum();
		}
	if(TWCR & 0x80)
			{
    ReceiveTransmitSlave();
//	++TestTransmit;
			}
	if(!CtErrorLink)//ErrorLink;
		{

//INIT TWI;
    TWBR=0;//F TWI
   TWAR=0;
   TWCR =0;
	TWSR=0xf8;
    CtStart=50;
	while(CtStart--)	_WDR();
    TWBR=0x7f;//F TWI
   TWAR=4;
   TWCR =(1<<TWEA)|(1<<TWEN);
	CtErrorLink=CtErrorLink0;

    CtStart=200;
	while(CtStart--)	_WDR();
		}

    ReadKn();

				

    }
  
}
示例#10
0
    int main(void)
    {
	DDRA=0;
	PORTA=0;
 
    DDRB=0xbc;
	PORTB |= 0xff;

    DDRC=0x1c;
 //   PORTC |=0xff;

    DDRD=0xba;
    PORTD=0xff;

//INIT TWI;
    TWBR=0x7f;//F TWI
    CtStart=65000;
	while(CtStart--)	_WDR();
//Init capture1
    TCCR1B=0x82;//0.5mkc,falling edge
    TIMSK=TIMSK | 0x4;//enable Int overlowT1





//  INIT SPI
    SPCR=0x72;//f/64
    SPSR=0;//f/64



    InitAd();


    MCUCR=0;


	TCCR0=5;// /1024

	ASSR=0;

	TCCR2=2;// T=0,5 mkc

	ASSR=0;





	NumberLink=1;

	CtUsart=NumberBlok;
	ResetError();
	URef=ReadEepromWord(8);
	if(URef>275)
	URef=256;
	if(URef<230)
	URef=256;

    _SEI();

					             
     while(1)
    {

     _WDR();
	 ChangeRegimTest();
	 ControlOut();
	CalcTM();
	LoadIndicator();
	SetRegimErrorLuk();
	SetErrorLuk();


	if(RomReceiveRS[5][3] & 4)
	ResetError();
	else if(RomReceiveRS[5][6] & 4)
	ResetError();
	else
		{
	RegTransmit[3][1] &=0xdf;
	RegTransmit[3][2] &=0xfe;
		}
	SetError();

	if(RomReceiveRS[6][3] & 0x80)
		{
	RegTransmit[1][2]=0;
	RegTransmit[2][2] &=0xfe;
		}
	else
	ControlLuk();







	 if(!CtErrorLink[0])
		{
//INIT TWI;
    TWBR=0;//F TWI
   TWAR=0;
   TWCR =0;
	TWSR=0xf8;

    TWBR=0x7f;//F TWI

    CtStart=65000;
	while(CtStart--)	_WDR();
	CtErrorLink[0]=CtErrorLink0;
	CtErrorLink[1]=CtErrorLink0;
	CtErrorLink[2]=CtErrorLink0;
		}
	 if(!CtErrorLink[1])
		{
//INIT TWI;
    TWBR=0;//F TWI
   TWAR=0;
   TWCR =0;
	TWSR=0xf8;

    TWBR=0x7f;//F TWI
    CtStart=65000;
	while(CtStart--)	_WDR();

	CtErrorLink[0]=CtErrorLink0;
	CtErrorLink[1]=CtErrorLink0;
	CtErrorLink[2]=CtErrorLink0;
		}
	 if(!CtErrorLink[2])
		{
//INIT TWI;
    TWBR=0;//F TWI
   TWAR=0;
   TWCR =0;
	TWSR=0xf8;

    TWBR=0x7f;//F TWI
    CtStart=65000;
	while(CtStart--)	_WDR();
	CtErrorLink[0]=CtErrorLink0;
	CtErrorLink[1]=CtErrorLink0;
	CtErrorLink[2]=CtErrorLink0;
		}
    ReadKn();

   if(NumberLink)
    --NumberLink;
    else
    NumberLink=2;






    LoadRegTransmit();

   ReceiveTransmitMaster();






    }
  
}
示例#11
0
    int main(void)
    {
    DDRA=0xff;


    DDRB=0xb3;
	PORTB |= 0xff;// Control UAB

    DDRC=0xfc;
    PORTC |=0xff;/*VT3=off*/

    DDRD=0xbf;
    PORTD=0xff;/*imp=off,Reset=off*/
//    PORTD=0xef;/*Reset=on*/
	ICR1=200;//20KH
    TCCR1A=0xb2;
    TCCR1B=0x11;
	Alfa=(ICR1>>1)-80;//-24;

	LoadAlfaStart();

 	/*InitCpi*/

	TCCR0=5;// /1024
 	TIMSK |=0x1;//enable int overlow T0
	ASSR=0;
	SPCR=0x70;//0x73;
//SPDR=0x55;
    Test=1;
	SPCR |=0x80;


 	SPDR=0;//RegSPI;

        //INIT TWI;
        TWBR=0x7f;//F TWI
    TWAR=(NumberLink<<1)+4;   
   TWCR =(1<<TWEA)|(1<<TWEN);

    CtStart=200;
	while(CtStart--)	_WDR();

	LoadRegInd(); 
	CtSetka=0;
	CtByteAnod=0;
	LoadRegSPI(CtSetka,CtByteAnod);
	CtErrorLink[0]=CtErrorLink0[0];
	CtErrorLink[1]=CtErrorLink0[1];
	Error=0;
	NumberIndicator=2;
    _SEI();

 	ClearDisplay();
	RomReceive[1]=2;    
  /*Work program*/     	 
    while(1)
	    {
    _WDR();
	ReadKn();
	if(!RomReceive[1])
			{
	IndicatorTest();

			}
	else
			{



//	if(RomReceive[NumberIndicator] !=19)
//	ClearDisplay2();
	switch(RomReceive[NumberIndicator])
				{


	case 1:
	IndOtkazLuk();

	RegInd[15]=0x31;
	break;
	case 2:
	IndOtkazLuk();

	RegInd[15]=0x32;
	break;

	case 3:
	IndGotovDU();
	break;
	case 4:
	IndRabota();
	break;
	case 5:
	IndOtkazLuk();
	RegInd[15]=0x33;
	break;

	case 6:
	IndNoLinkSHU();
	break;
	case 7:
	IndNoLinkMSHU();
	break;
	case 8:
	IndOtkazSHSN();
	break;
	case 9:
	IndRegimMSHU();
	break;

	case 10:
	IndOtkazLuk();

	RegInd[15]=0x34;
	break;
	case 11:
	IndOtkazLuk();

	RegInd[15]=0x35;
	break;

	case 12:
	IndOtkazLukDG();

	RegInd[14]=0x31;
	break;
	case 13:
	IndOtkazLukDG();

	RegInd[14]=0x32;
	break;
	case 14:
	IndOtkazLukLR();

	RegInd[14]=0x31;
	break;
	case 15:
	IndOtkazLukLR();

	RegInd[14]=0x32;
	break;
	case 16:
	IndGotovMU();
	break;
	case 17:
	IndGotovSystem();
	break;
	case 18:
	IndOtkazFVU();
	break;
	case 19:
	IndOtkazLukPCH();
	RegInd[14]=0x31;
	break;
	case 20:
	IndOtkazLukPCH();
	RegInd[14]=0x32;
	break;
	case 21:
	IndOtkazDT();
	break;
	default:
	break;
				}
			}
	if(EnableLoad)
		{
    LoadRegTransmit();
    LoadControlSum();
		}
	if(TWCR & 0x80)
			{

  ReceiveTransmitSlave();

		}

	if(!CtErrorLink[0])//ErrorLink;
			{

//INIT TWI;
    TWBR=0;//F TWI
   TWAR=0;
   TWCR =0;
	TWSR=0xf8;
    CtStart=50;
	while(CtStart--)	_WDR();
    TWBR=0x7f;//F TWI
    TWAR=(NumberLink<<1)+4;
   TWCR =(1<<TWEA)|(1<<TWEN);
 //   TWCR |=(1<<TWINT);
	CtErrorLink[0]=CtErrorLink0[0];

    CtStart=200;
	while(CtStart--)	_WDR();
			}


        }

 
 }
示例#12
0
    int main(void)
    {
	DDRA=0;
	PORTA=0;
    DDRB=0xb2;
	PORTB |= 0xf3;// Control UAB

    DDRC=0x2a;
    PORTC |=0x2a;
    DDRD=0xc7;
    PORTD=0xff;/*Reset=on*/

//  INIT SPI
    SPSR=0;//f/64
	SPCR=0x72;
	SPCR |=0x80;//enable Int SPI

    InitAd();

    TCCR1A=0;//0x82;
    TCCR1B=0x2;//0.5mks


 //   TIMSK=TIMSK | 0x20;//enable Int capture1 

   TIMSK=TIMSK | 0x4;//enable Int overlowT1 

		
    /*Interrupt1*/
//    MCUCR=0x8;// Log1>0 Int1

 
//    GICR |=(1<<INT1);/*Enable INT1*/

 
   	/*Timer0*/
 	TCCR0=0x61;//0x61;//1;//1;
	OCR0=0xe0;
//    TIMSK |=1;/*Enable Int Overlow Timer0*/

   	/*Timer2*/
 	TCCR2=0x4;
    TIMSK |=(1<<TOIE2);/*Enable Int Overlow Timer2*/

	CtSetka=0;

    _SEI();

 	RegimWork=0;

	ResetError();
	CtStart=50;
	RevunOff=0;
//	ClearRomReceive();

  /*Work program*/     	 
    while(1)
    {
    _WDR();
	if(!CtIndAd)
		{
//	IndicatorAd(2);
	CtIndAd=30;
		}
	ReadKn();
	if(RegS & 0x10)
	ResetError();

	ChangeRegim();
 	ControlRevun();
	ControlMPP();
	ControlPogar();
 	ControlNorma();
	Indicator();
	IndicatorAll();

	SetRegimError();
	SetError();
//	DecSegm(RegS);
//	IndicatorSegment();	
	if(Error)
	PORTD |=0x40;//Error
	else
	PORTD &=0xbf;//Norma


	}

}
示例#13
0
文件: MSDAIND.c 项目: maxk9/etro_new
    int main(void)
    {
    DDRA=0xff;


    DDRB=0xb1;
	PORTB |= 0xff;// Control UAB

    DDRC=0xfc;
    PORTC |=0xff;/*VT3=off*/

    DDRD=0xbf;
    PORTD=0xff;/*imp=off,Reset=off*/
//    PORTD=0xef;/*Reset=on*/
	ICR1=200;//20KH
    TCCR1A=0xb2;
    TCCR1B=0x11;
	Alfa=(ICR1>>1)-80;//-24;

	LoadAlfaStart();

 	/*InitCpi*/

	TCCR0=5;// /1024
 	TIMSK |=0x1;//enable int overlow T0
	ASSR=0;
	SPCR=0x70;//0x73;
//SPDR=0x55;
    Test=1;
	SPCR |=0x80;


 	SPDR=0;//RegSPI;

        //INIT TWI;
        TWBR=0x7f;//F TWI
    TWAR=(NumberLink<<1)+4;   
   TWCR =(1<<TWEA)|(1<<TWEN);

    CtStart=200;
	while(CtStart--)	_WDR();

	LoadRegInd(); 
	CtSetka=0;
	CtByteAnod=0;
	LoadRegSPI(CtSetka,CtByteAnod);
	CtErrorLink[0]=CtErrorLink0[0];
	CtErrorLink[1]=CtErrorLink0[1];
	Error=0;
	NumberIndicator=2;
    _SEI();
 	ClearDisplay();
	CtBegin=250;    
  /*Work program*/ 
  RomReceive[1]=2;    	 
    while(1)
	    {
    _WDR();
	ReadKn();
	if(CtBegin)
	IndSDA();
//	else if(RegS !=2)
//	IndNiobij();
	else if(!RomReceive[1])
			{
	IndicatorTest();

			}
	else
			{



//	if(RomReceive[NumberIndicator] !=19)
//	ClearDisplay2();
	switch(RomReceive[NumberIndicator])
				{

	case 1:
	IndNoTopliva();
	break;
	case 2:
	IndT8Gr();
	break;
	case 3:
	IndT37Gr();
	break;

	case 4:
	IndZashitaOff();
	break;
	case 5:
	IndOtkazLuk();
	break;

	case 6:
	IndLowIzol();
	break;
	case 7:
	IndNoPusk();
	break;
	case 8:
	IndNoLinkMSHU();
	break;

	case 9:
	IndNoOborotov();
	break;
	case 10:
	IndNoVozb();
	break;
	case 11:
	IndErrorU();
	break;
	case 12:
	IndPeregruzKG();
	break;
	case 13:
	IndErrorKG();
	break;

	case 15:
	IndNoLinkRU();
	break;
	case 16:
	IndObratnajaP();
	break;

	case 17:
	IndPeregruzKG();
	break;
	case 18:


	case 19:
	IndPogar();
	break;

	case 20:
	IndErrorKS();
	break;

	case 21:
	IndUKorpus();
	break;
	case 22:
	IndErrorLuk();
	break;
	case 23:
	IndErrorSet();
	break;
	case 24:
	IndNoMasla();
	break;
	case 25:
	IndDozapravkaTopliva();
	break;
	case 26:
	IndDozapravkaMasla();
	break;
	case 27:
	IndOtkazFVU();
	break;
	case 28:
	IndAvarDvig();
	break;
	case 29:
	IndGotovSystem();
	break;


	case 31:
	IndRabota();
	break;


	case 32:
	IndNoLinkSN();
	break;



				}
			}
	if(EnableLoad)
		{
    LoadRegTransmit();
    LoadControlSum();
		}
	if(TWCR & 0x80)
			{

  ReceiveTransmitSlave();

		}

	if(!CtErrorLink[0])//ErrorLink;
			{

//INIT TWI;
    TWBR=0;//F TWI
   TWAR=0;
   TWCR =0;
	TWSR=0xf8;
    CtStart=50;
	while(CtStart--)	_WDR();
    TWBR=0x7f;//F TWI
    TWAR=(NumberLink<<1)+4;
   TWCR =(1<<TWEA)|(1<<TWEN);
 //   TWCR |=(1<<TWINT);
	CtErrorLink[0]=CtErrorLink0[0];

    CtStart=200;
	while(CtStart--)	_WDR();
			}


        }

 
 }
示例#14
0
文件: main.c 项目: vasik041/openlab
int main(void)
{
uint8_t dots,cnt,f;
uint8_t key,prev_key;
uint16_t dcnt;
	_WDR();
	WDTCR = 0x0f;

	DDRA = 0xff;	// porta 0-7 out
	PORTA = 0;
	DDRB = 0x0f;	// portb 0-3 out
	PORTB = 0x0f;

	ADCSRA = 0x87;	// ADC
        ADMUX = 9;
	i2c_init();
	clock_init();

	TCCR0B = 5;	// cpu clk / 1
	TIMSK = 2;
	ref_pos = 0;
	skip = 0;
	_SEI();
	bme_init();

//	wr_eeprom(11,0x55);

	prev_key = 0;
	timer = 0;
	timer_pos = 0;
	cnt = 0;
	f = 1;
	swcnt = sw = mode = 0;
	dcnt = 0;
	get_date();
	for(dots=0; ; ) {
		if(++cnt >= 10 || f) {
			if(!timer) {
				if(mode) setting(); else show();
			} else {
				uint8_t tm = timer/60;
				uint8_t ts = timer%60;
				putchr(0,tm/10);
				putchr(1,tm%10);
				putchr(2,ts/10);
				putchr(3,ts%10);
				timer--;
				if(timer == 300) beep(); //5min
				else if(!timer) beep();  //end
			}
			cnt = 0;
			f = 0;
			if(mode) {
				if(dots) {
					dsp_buf[0] = chrSP;
					dsp_buf[1] = chrSP;
					dsp_buf[2] = chrSP;
					dsp_buf[3] = chrSP;
				}
			} else {
				if(dots || sw == 1 || sw == 2) {
					dsp_buf[1] |= segDP;
				}
				if(sw == 3) {
					dsp_buf[1] &= ~segDP;
					dsp_buf[3] |= segDP;
				}
			}
			dots ^= 1;
		}
		
		delay(100);

		key = get_key();
		if(key == 0 && prev_key != 0) {
			tocnt = 0;
			switch(prev_key) {
				case KEY_1:
					if(timer) break;
					if(++mode > 5) mode = 0;
					f = 1;
					sw = swcnt = 0;
					break;

				case KEY_2:
					if(timer) break;
					inc();
					f = 1;
					sw = swcnt = 0;
					break;

				case KEY_3:
					if(timer_pos) {
						timer_pos--;
						timer = 60*pgm_read_byte(timer_vals+timer_pos);
					} else {
						timer = 0;
					}
					f = 1;
					break;

				case KEY_4:
					if(timer_pos < NELEM(timer_vals)-1) {
						if(timer != 0) timer_pos++;
						timer = 60*pgm_read_byte(timer_vals+timer_pos);
						f = 1;
					}
					break;

				default:;
			}
		}
		prev_key = key;

		if(++dcnt > 10*60) {
			dcnt = 0;
			get_date();
		}
	}

	return 0;
}
示例#15
0
    int main(void)
    {
	DDRA=0;
	PORTA=0xf4;
    DDRB=0xe6;
	PORTB |= 0xf3;// Control UAB

    DDRC=0xf;
    PORTC |=0xff;


    DDRD=0x1a;
    PORTD=0xff;/*Reset=on*/

//  INIT SPI
    SPSR=0;//f/64
	SPCR=0x72;
	SPCR |=0x80;//enable Int SPI
//INIT USART
	InitUsart();


    TCCR1A=0;//0x82;
    TCCR1B=0x2;//0.5mks


 //   TIMSK=TIMSK | 0x20;//enable Int capture1 

    TIMSK=TIMSK | 0x4;//enable Int overlowT1 

		
    /*Interrupt1*/
//    MCUCR=0x8;// Log1>0 Int1

 
//    GICR |=(1<<INT1);/*Enable INT1*/

 
   	/*Timer0*/
 	TCCR0=0x61;//0x61;//1;//1;
	OCR0=0xe0;
//    TIMSK |=1;/*Enable Int Overlow Timer0*/

   	/*Timer2*/
 	TCCR2=0x4;
    TIMSK |=(1<<TOIE2);/*Enable Int Overlow Timer2*/

	CtSetka=0;

    _SEI();

 	RegimWork=0;

	ResetError();
	CtStart=50;
//	ClearRomReceive();

  /*Work program*/     	 
    while(1)
    {

    _WDR();
	if(CtStart)
		{
	if(NumberBlok==1)
			{
	RegimWork=(RomReceiveRS[2][2]<<8) & 0xeff;
	RegimWork |=RomReceiveRS[1][2];
	if(RegSWork & 0x100)
	RegimWork |=0x100;
			}
	else
			{
	RegimWork=(RomReceiveRS[2][1]<<8) & 0xeff;
	RegimWork |=RomReceiveRS[1][1];
	if(RegSWork & 0x100)
	RegimWork |=0x100;
			}

	if(RegS1 & 1)
	NumberBlok=2;
	else
	NumberBlok=1;
		}
	else
		{

	if(NumberBlok==1)
			{
/*	if((RomReceiveRS[2][2] & 1)&&(!(Error & 4)))
				{
	RegimWork=(RomReceiveRS[2][2]<<8) & 0xeff;
	RegimWork |=RomReceiveRS[1][2];

				}
	else*/
	ChangeRegim();

			}
/*	else
			{
	if((RomReceiveRS[2][1] & 1)&&(!(Error & 2)))
				{
	RegimWork=(RomReceiveRS[2][1]<<8) & 0xeff;
	RegimWork |=RomReceiveRS[1][1];
				}
	else
	ChangeRegim();
			}*/
		}
	SetError();
	SetRegTransmitRS();



		{
	SetRegSegmentOn();
	SetRegSegmentMig();
		}
	IndicatorSegment();
	ControlRevun();

	}

}
示例#16
0
文件: MSDAPI18.c 项目: maxk9/etro_new
int main(void)
{
	DDRA=0xff;


	DDRB=0xb1;
	PORTB |= 0xff;// Control UAB

	DDRC=0xfc;
	PORTC |=0xff;/*VT3=off*/

	DDRD=0xbf;
	PORTD=0xff;/*imp=off,Reset=off*/

	//  INIT SPI
	SPSR=0;//f/64
	SPCR=0x70;

	InitIndStart();
	TIFR |=0x40;//reset flag
	TIMSK |=0x40;
	TCCR2=0x3;

	TCCR0=5;// /1024
	TIMSK |=0x1;//enable int overlow T0


	//INIT TWI;
	TWBR=0x7f;//F TWI
	TWAR=(NumberLink<<1)+4;   
	TWCR =(1<<TWEA)|(1<<TWEN);

	CtStart=200;
	while(CtStart--)	_WDR();




	CtErrorLink[0]=CtErrorLink0[0];
	CtErrorLink[1]=CtErrorLink0[1];
	Error=0;
	NumberIndicator=2;
	_SEI();

	CtBegin=250;    
	/*Work program*/ 
	RomReceive[1]=2; 
	RomReceive[2]=29;//3;  
	RomReceive[3]=0; 
	RomReceive[4]=0;    
	RomReceive[5]=0; 
	RomReceive[6]=0;  
	RomReceive[7]=0; 
	RomReceive[8]=0;  
	RomReceive[9]=0; 
	RomReceive[10]=0;  
	CtInd=50;
	CtInitInd=300;     	 
	while(1)
	{
		_WDR();

		if(!CtInitInd)
		{
			InitInd();
			CtInitInd=300;
		}


		ReadKn();
		if(CtBegin)
		{
			if(!CtInd)
			{
				IndSDA();
				CtInd=50;
			}
		}
		else if(!RomReceive[1])
		{
			if(!CtInd)
			{
				IndicatorTest();
				CtInd=50;
			}
		}
		else if(!CtInd)
		{

			CtInd=50;


			switch(RomReceive[NumberIndicator])
			{

			case 1:
				IndNoTopliva();
				break;
			case 2:
				IndT8Gr();
				break;
			case 3:
				IndT37Gr();
				break;

			case 4:
				IndZashitaOff();
				break;
			case 5:
				IndOtkazLuk();
				break;

			case 6:
				IndLowIzol();
				break;
			case 7:
				IndNoPusk();
				break;
			case 8:
				IndNoLinkMSHU();
				break;

			case 9:
				IndNoOborotov();
				break;
			case 11:
				IndErrorU();
				break;
			case 12:
				IndPeregruzKG();
				break;
			case 13:
				IndErrorKG();
				break;

			case 15:
				IndNoLinkRU();
				break;


			case 17:
				IndPeregruzKG();
				break;


			case 19:
				IndPogar();
				break;

			case 20:
				IndErrorKS();
				break;

			case 21:
				IndUKorpus();
				break;
			case 22:
				IndOtkazLuk();
				break;
			case 23:
				IndErrorSet();
				break;
			case 24:
				IndNoMasla();
				break;
			case 25:
				IndDozapravkaTopliva();
				break;
			case 26:
				IndDozapravkaMasla();
				break;
			case 27:
				IndOtkazFVU();
				break;
			case 28:
				IndAvarDvig();
				break;
			case 29:
				IndGotovSystem();
				break;


			case 31:
				IndRabota();
				break;


			case 32:
				IndNoLinkSN();
				break;
			case 33:
				IndOtkazPZA();
				break;
			default:break;

			}
		}
		if(EnableLoad)
		{
			LoadRegTransmit();
			LoadControlSum();
		}
		if(TWCR & 0x80)
		{
			++TestTWI;
			ReceiveTransmitSlave();

		}

		if(!CtErrorLink[0])//ErrorLink;
		{
			//	++TestTwi;
			//INIT TWI;
			TWBR=0;//F TWI
			TWAR=0;
			TWCR =0;
			TWSR=0xf8;
			CtStart=50;
			while(CtStart--)	_WDR();
			TWBR=0x7f;//F TWI
			TWAR=(NumberLink<<1)+4;
			TWCR =(1<<TWEA)|(1<<TWEN);
			//   TWCR |=(1<<TWINT);
			CtErrorLink[0]=CtErrorLink0[0];

			CtStart=200;
			while(CtStart--)	_WDR();
		}


	}


}