/*..........................................................................*/
void BSP_init(void) {
	SystemInit();         /* initialize STM32 system (clock, PLL and Flash) */

	/* initialize LEDs on Olimex P207 eval board */
	omxEval_led_init();

	/* initialize LCD on Olimex P207 eval board */
  InitLcd();

  /* initialize RS-232 serial port on Olimex P207 eval board */
  omxEval_rs232_init();

	/* initialize LEDs, Key Button, and LCD on STM322XX-EVAL board */
	// alu: TODO BSP_ButtonAndLED_Init();

	/* initialize the Serial for printfs to the serial port */
	// alu: TODO BSP_USART_Init();

	/* initialize the EXTI Line0 interrupt used for testing */
	// alu: TODO BSP_EXTI_Init();

	/* initialize the ETH GPIO */
	ETH_GPIO_Config();

	/* initialize the ETH MACDMA */
	ETH_MACDMA_Config();

	QS_OBJ_DICTIONARY(&l_SysTick_Handler);
}
Esempio n. 2
0
/*
*------------------------------------------------------------------------------
* void InitializeLcd(void)
*
* Summary	: Initialize LCD and setup LCD task to run.
*
* Input		: None
*
* Output	: None
*
*------------------------------------------------------------------------------
*/
void LCD_init(void)
{
	// Initialize LCD hardware
	InitLcd();
	// Clear the display at startup
	LCD_writeCommand(DISPLAY_CLEAR);
	lcd.NOofChar = 0;
}
Esempio n. 3
0
int main( int argc, char *argv[])
{
	// Imposto i valori iniziali della dimensione dell'LCD...
	rect.x=LCD_X_OFFSET;
	rect.y=LCD_Y_OFFSET;
	rect.w=LCD_WIDTH-1;
	rect.h=LCD_HEIGHT-1;
	rect.r=rect.g=rect.b=0;

	font.x=LCD_X_OFFSET;
	font.y=LCD_Y_OFFSET;
	font.size=SMALL;
	font.fr=font.fg=font.fb=250;	// foreground == WHITE
	font.br=font.bg=font.bb=0;	// background == BLACK

	parse_opts(argc, argv);
	
	// Inizializzo l'LCD della Nokia, controller compatibile al PCF8833
	InitLcd( PCF8833, device);
	
	if ( noreset==0) LCDReset();
	
	if ( clearcmd) {
		LCDDrawScreen( RGB( rect.r, rect.g, rect.b));
		usleep( 250000);
	}

	if ( isStringToDsiplay) {
		if ( strlen( StringToDsiplay)==1 && StringToDsiplay[0]=='-') {	// stdin
			StringToDsiplay=readLine( stdin );
		}

		LCDSetCurr_XY( rect.x, rect.y);
		LCDPutStr( StringToDsiplay, font.x, font.y, font.size, RGB(font.fr,font.fg, font.fb), RGB(font.br,font.bg, font.bb));
	}

	if ( (filename != (const char*)NULL) && isImage) LCDWritebmp( (const char*)filename, rect.x, rect.y, rect.w, rect.h);
	//if ( (FullScreenFilename != (const char*)NULL) && isFullScreen) LCDWriteRGB( (const char*)FullScreenFilename);
	if ( (FullScreenFilename != (const char*)NULL) && isFullScreen) LCDWriteFullScreenRGB_2( (const char*)FullScreenFilename);
	if ( (MoveFilename != (const char*)NULL) && isMovie) {
		if ( LoopFor == -1) {
			if (LCDMovieRGB( (const char*)MoveFilename)) {
				return 1;
			}
		} else {
			while( LoopFor--) {
				if (LCDMovieRGB( (const char*)MoveFilename)) {
					return 1;
				}
			}
		}
	}


	return 0;
}
Esempio n. 4
0
void LCD::PrintLine(INT32 line, const char *message, ...)
{
	DriverStationLCD::Line lcdLine;
	
	//consoleLog("printLine %d, %d", line, dsLcd);
	
	if (dsLcd == 0) InitLcd();
	
	ClearLine(line);

	switch (line)
	{
		case 1:
			lcdLine = DriverStationLCD::kUser_Line1;
			break;

		case 2:
			lcdLine = DriverStationLCD::kUser_Line2;
			break;

		case 3:
			lcdLine = DriverStationLCD::kUser_Line3;
			break;

		case 4:
			lcdLine = DriverStationLCD::kUser_Line4;
			break;

		case 5:
			lcdLine = DriverStationLCD::kUser_Line5;
			break;

		case 6:
			lcdLine = DriverStationLCD::kUser_Line6;
			break;
	}
		
	va_list vl;
	va_start(vl, message);
	
	//consoleLog("printLine %d, %d: %s", line, dsLcd, message);

	dsLcd->VPrintfLine(lcdLine, message, vl);
		
	dsLcd->UpdateLCD();
}
Esempio n. 5
0
void LCD::Print(INT32 line, INT32 column, const char *message, ...)
{
	DriverStationLCD::Line lcdLine;
		
	if (dsLcd == 0) InitLcd();
		
	switch (line)
	{
		case 1:
			lcdLine = DriverStationLCD::kUser_Line1;
			break;

		case 2:
			lcdLine = DriverStationLCD::kUser_Line2;
			break;

		case 3:
			lcdLine = DriverStationLCD::kUser_Line3;
			break;

		case 4:
			lcdLine = DriverStationLCD::kUser_Line4;
			break;

		case 5:
			lcdLine = DriverStationLCD::kUser_Line5;
			break;

		case 6:
			lcdLine = DriverStationLCD::kUser_Line6;
			break;
	}
	
	va_list vl;
	va_start(vl, message);
	
	dsLcd->VPrintf(lcdLine, column, message, vl);
		
	dsLcd->UpdateLCD();
}
Esempio n. 6
0
void LCD::ClearLine(INT32 line)
{
	const char *blankLine = "                                          ";
	DriverStationLCD::Line lcdLine;
	
	//consoleLog("clearLine %d, %d", line, dsLcd);
		
	if (dsLcd == 0) InitLcd();

	switch (line)
	{
	case 1:
		lcdLine = DriverStationLCD::kUser_Line1;
		break;

	case 2:
		lcdLine = DriverStationLCD::kUser_Line2;
		break;

	case 3:
		lcdLine = DriverStationLCD::kUser_Line3;
		break;

	case 4:
		lcdLine = DriverStationLCD::kUser_Line4;
		break;

	case 5:
		lcdLine = DriverStationLCD::kUser_Line5;
		break;

	case 6:
		lcdLine = DriverStationLCD::kUser_Line6;
		break;
	}
		
	dsLcd->PrintfLine(lcdLine, blankLine);		
		
	dsLcd->UpdateLCD();
}
Esempio n. 7
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;
        }
//===============================================
    }
}
Esempio n. 8
0
int main(void)
{
    communicationStatus = OpenCommunicationChannel(DEFAULT_CHANNEL, INPUT_BUFFER_SIZE);
    InitOutputPins();
    InitLcd();

    FireTextEvent("System", SYSTEM_NAME, DEFAULT_CHANNEL);
    FireTextEvent("Memory", PersistentMemoryType(), DEFAULT_CHANNEL);
    PutLcdLine(0, SYSTEM_NAME);
    UpdateLcd();

    InitPersistentDataManager();

    RegisterTableTypes();
    RegisterEngineType();
    
    memoryStatus = CheckPersistentMemory(&checkPersistentMemoryNotifyCallback);
    ShowStatus("Check memory", memoryStatus);

    if (memoryStatus == OK)
    {
        Status status = InitEngine();
        ShowStatus("Initialize engine", status);
        
        if (status == OK)
        {
            InitAnalogInput();
            ignitionStatus = InitIgnition();
            ShowStatus("Initialize ignition", ignitionStatus);
            injectionStatus = InitInjection();
            ShowStatus("Initialize injection", injectionStatus);
        }
    }

    if (FindMeasurement(RPM, &rpmMeasurement) != OK)
    {
        rpmMeasurement = NULL;
    }
    if (FindMeasurement(LOAD, &loadMeasurement) != OK)
    {
        loadMeasurement = NULL;
    }

    for (;;)
    {
        ShowIfError(communicationStatus);
        communicationStatus = ReadString(input);
        if ((communicationStatus == OK) && (strlen(input) > 0))
        {
            communicationStatus = HandleMessage(input, &motorManagementApi, DEFAULT_CHANNEL);
        }

        if (memoryStatus == OK)
        {
            Status status = UpdateIgnition();
            ShowIfError(status);
            if (status != ignitionStatus)
            {
                FireTextEvent(IGNITION, status, DEFAULT_CHANNEL);
                ignitionStatus = status;
            }

            status = UpdateInjection();
            ShowIfError(status);
            if (status != injectionStatus)
            {
                FireTextEvent(INJECTION, status, DEFAULT_CHANNEL);
                injectionStatus = status;
            }

            if ((ignitionStatus == OK) && (injectionStatus == OK))
            {
                UpdateDisplay();
            }
        }
    }

}
Esempio n. 9
0
int main(void)
{
    /* Configure the oscillator both devices */
    
    ConfigureOscillator();
    
    /* Initialize IO ports and peripherals for both devices */
   
    InitGPIO(); 
    InitUART();
    InitI2c();
    InitI2cCompass();
  
    /* Program for the bracelet */
    
#ifdef PROTECTED
    
    /* Initialize IO ports and peripherals */

      InitTimerUS();
 
    /* The values of the magnetic field will be save in x and y */
    s16 x = 0;
    s16 y = 0;   
    
    while(1)
    {
       I2cReadData(&x, &y);
       ComputeAngle(&angle, x, y);
       PutData16(angle);
       __delay_ms(500);
    }
    
#endif
    
    /* Program for the bodyguard*/
    
#ifdef BODY_GUARD
    

    /* Initialize IO ports and peripherals */
    InitADC();
    InitPWM();
    InitLcd();
    InitTimerServo();
    
    /* TODO <INSERT USER APPLICATION CODE HERE> */
    
    u16 ADC_values[NMB_SENSORS];
    u16 average[NMB_SENSORS];
    u8 i;
    u8 j;
    
    /* The values of the magnetic field will be save in x and y */
    s16 x = 0;
    s16 y = 0;
    
    u16 angle2=0;
    
    char T[5];
    
    
    memset(ADC_values,0x00,sizeof(ADC_values));
    memset(average, 0x00,sizeof(average));

    /*
    for(i=0; i<NMB_SENSORS; i++) 
    {
        ADC_values[i]=0;
    }*/
    LcdClear();
    
#if MAGNETIC_SENSOR    
    while(1)
    {
       I2cReadData(&x, &y);
       angle2=((-atan2(x,y)*180)/3.14)+180;
        /* Computes the angle using the arctan2 which provides an angle
        * between -180° and 180°, then converts the result that is in radian
        * into degree (*180/pi) and in the end add 180° so the angle is between
        * 0° and 360° */
       //LcdPutFloat(angle2,0);
       LcdPutFloat(angle2,0);
       LcdGoto(1,2);
       LcdPutFloat(angle,0);
       __delay_ms(500);
       LcdClear();
        
    }
#endif

#ifdef BODY_GUARD_MODE
   while(1)
    { 
        
        for(j=0; j<NMB_MEASURES; j++)
        {
            /* SENSORS SAMPLING */
            for(i=0; i<NMB_SENSORS; i++)
            {
                StartADC(ADC_values);
            }
            ObjectDetection(ADC_values, average);
        }
        LcdClear();
        
        LcdPutFloat(CCP2RB, 0);
       
        //__delay_ms(1000);
        
        LcdClear();
        
        /* Set Flags */       
        ObjectReaction(average);        
        DistanceFlag(average[US]);
        
        /* react */
        
        AutoBodyGuard();

    }
#endif
               
#ifdef AUTO_FLEE
    while(1)
    { 
        
        for(j=0; j<NMB_MEASURES; j++)
        {
            /* SENSORS SAMPLING */
            for(i=0; i<NMB_SENSORS; i++)
            {
                StartADC(ADC_values);
            }
            ObjectDetection(ADC_values, average);
        }
        LcdClear();
        
        /* Set Flags */       
        ObjectReaction(average);        
        //DistanceFlag(average[US]);
        AutoFLee();

    }
    
#endif
#endif
    return 0;
}