Ejemplo n.º 1
0
Archivo: main.c Proyecto: lysy1033/sfp
void lcd_start_screen()
{
	lcd_cls();
	lcd_locate(0,0);
	lcd_str(" SFP PROGRAMMER ");
	lcd_locate(1,0);
	lcd_str(" ALPHA 0.1 2014 ");
}
int main (void)
{
	board_init();
	
	// Insert application code here, after the board has been initialized.
	lcd_init();
	lcd_cls();
	lcd_locate(0,0);
	lcd_set_font(Lcd_Font_5x7);
	lcd_write_s(c_GreetingMsg);

	/* Initialize the PWM driver and set proper frequency */
	pwm_init();
	pwm_set_duty(0);
	pwm_set_frequency(Pwm_31250Hz);

	/* Initialize the encoder and register a callback function */
	encoder_init();
	encoder_register_event(OnEncoderEvent);
	
	while(1)
	{
		encoder_cyclic();
		
		switch(CurrentState)
		{
			case State_Info:
			//				info_cyclic(&CurrentEventMask);
			CurrentState = State_MainMenu;
			break;
			
			case State_MainMenu:
			CurrentState = main_menu_cyclic(MainMessagePump);
			break;
			
			case State_Reflow:
			//				refow_cyclic();
			CurrentState = State_MainMenu;
			break;
			
			case State_Learn:
			//				learn_cyclic();
			CurrentState = State_MainMenu;
			break;
			
			case State_Parameterize:
			//				parameterize_cyclic();
			CurrentState = State_MainMenu;
			break;
			
			default:
			CurrentState = State_MainMenu;
			break;
		}
	}
}
Ejemplo n.º 3
0
int
main ()
{
  DDRD = 0x00;
  PORTD = 0xff;

  lcd_init ();

  /*display on, cursor & blink off */
  lcd_control (1, 0, 0);
  timer1_init ();
  lcd_cls ();
  lcd_clear_CRGAM ();
  //az elso sorba irunk
  lcd_putstr ("Vertical", LCD_FIRST_LN_ADDR);
  
/* main -loop */
  for (;;)
    {
      if (cnt1 == CNT1_THRESHOLD)
	{
	  cnt1 = 0;
	  cnt3_flag = 1;
	  //clear second line
	  for (ch = 0; ch < 20; ch++)
	    {
	      lcd_set_DDRAM_addr (LCD_SECND_LN_ADDR + ch);
	      lcd_putch (' ');
	    }
	  /* 
	   * array2d: custom chars array
	   * ROWS: number of chars
	   * 30: vertical delay in ms
	   * 0: horiz. delay
	   * LCD_FIRST_LN_ADDR + 9 : ddram addr.
	   * 1: set CGRAM clear mode; 0: no CGRAM clear 
	   */
	   
	  //nem clear modban erdekes hatast kelt ;-)
	  lcd_vertical_scroll (array2d, ROWS, 40, 0 /* delay ms */ ,
			       LCD_FIRST_LN_ADDR + 9, 0);
	}

      if (cnt3 == CNT3_THRESHOLD)
	{
	  cnt3 = 0;
	  cnt3_flag = 0;
	  
	  lcd_putstr ("Is COOL!", LCD_SECND_LN_ADDR + 5);
	}
    }
  return 0;
}
Ejemplo n.º 4
0
static void next_level(bool init_game)
{
	if(init_game){
		g_level = 1;
		g_hp = 20;
		lcd_byte(0x08+4, 0);//Normal mode
		lcd_cls();
	} else {
		g_level++;
		g_seed += g_counter0;
	}
	make_current_dungeon();
}
Ejemplo n.º 5
0
void initAll(){
	SysTick_Config(SystemCoreClock / 1000);
	lcd_init();
    lcd_home();
	lcd_cls();
	initPWM(PWM_TIME_PERIOD);
	setServoAngle(0,0);
	UARTInit(BAUD_RATE);
	ds1307Init();
	eeprom_24aaInit();
	eeprom24aaMemoryCheck();
	initButtons();
}
Ejemplo n.º 6
0
//Prüfung ob zu weit links oder rechts und reagieren mit Kurskorrektur ->Folgen der Linie
void followLine(void){
	updateSensorsWhite();
	if (kurven == 7 && count == 1 && setting == 0){
		if (sensor[MID_MID] == 0){	
			if(start == 'l'){ //zu weit rechts
				motPowRight = motPowRight + 2; //nach links lenken
				lcd_cls();
				lcd_puts("links");
			// }else{//zu weit links
				// motPowLeft = motPowLeft + 2; //nach rechts lenken
				// motPowRight = motPowRight -2;
				// lcd_cls();
				// lcd_puts("rechts");
				}
			setMotPow(motPowLeft,motPowRight);
		}else{
			if(start == 'l'){//zu weit links
				//motPowLeft = motPowLeft + 1; //nach rechts lenken
				//lcd_cls();
				//lcd_puts("rechts");
			}else{//zu weit rechts
				motPowRight = motPowRight + 1;//nach links lenken
				lcd_cls();
				lcd_puts("links");
			}
			setMotPow(motPowLeft,motPowRight);
		}
		setting = 1;
	}else if (muchLeft()){
		setMotPow(motPowLeft,0);
	}else if (muchRight()){
		setMotPow(0,motPowRight);
	}else{
		setMotPow(motPowLeft,motPowRight);
	}	
}
Ejemplo n.º 7
0
/*-----------------27.5.99 20:30--------------------
 *  Display initialization
 *--------------------------------------------------*/
void lcd_init(void)
{
  outp(0xFF,DDRA);
  lcd_delay(10000);
  outp(0x03,PORTA); toggle_E(); lcd_delay(500);
  outp(0x03,PORTA); toggle_E(); lcd_delay(100);
  outp(0x03,PORTA); toggle_E(); lcd_delay(100);
  outp(0x02,PORTA); toggle_E(); lcd_delay(100);
  outp(0x02,PORTA); toggle_E();
  outp(0x08,PORTA); toggle_E(); lcd_delay(100);
  outp(0x00,PORTA); toggle_E();
  outp(0x0F,PORTA); toggle_E(); lcd_delay(100);
  outp(0x00,PORTA); toggle_E();
  outp(0x06,PORTA); toggle_E(); lcd_delay(100);
  lcd_cls();
}
Ejemplo n.º 8
0
//----------------------------------------------------------------------------------------
//
//		 ******* INICJALIZACJA WY�WIETLACZA LCD ********
//
//----------------------------------------------------------------------------------------
void lcd_init(void)
{
	// inicjowanie pin�w port�w ustalonych do pod��czenia z wy�wietlaczem LCD
	// ustawienie wszystkich jako wyj�cia
	data_dir_out();
	DDR(LCD_RSPORT) |= (1<<LCD_RS);
	DDR(LCD_EPORT) |= (1<<LCD_E);
	DDR(LCD_BACKGROUNDPORT) |= (1<<LCD_BL);
	#if USE_RW == 1
		DDR(LCD_RWPORT) |= (1<<LCD_RW);
	#endif

	// wyzerowanie wszystkich linii steruj�cych
	PORT(LCD_RSPORT) &= ~(1<<LCD_RS);
	PORT(LCD_EPORT) &= ~(1<<LCD_E);
	#if USE_RW == 1
		PORT(LCD_RWPORT) &= ~(1<<LCD_RW);
	#endif

	_delay_ms(15);
	PORT(LCD_RSPORT) &= ~(1<<LCD_RS);
	PORT(LCD_RWPORT) &= ~(1<<LCD_RW);

	// jeszcze nie mo�na u�ywa� Busy Flag
	lcd_sendHalf(LCDC_FUNC|LCDC_FUNC8B);
	_delay_ms(4.1);
	lcd_sendHalf(LCDC_FUNC|LCDC_FUNC8B);
	_delay_us(100);
	lcd_sendHalf(LCDC_FUNC|LCDC_FUNC4B);
	_delay_us(100);

	// ju� mo�na u�ywa� Busy Flag
	// tryb 4-bitowy, 2 wiersze, znak 5x7
	lcd_write_cmd( LCDC_FUNC|LCDC_FUNC4B|LCDC_FUNC2L|LCDC_FUNC5x7 );
	// wy��czenie kursora
	lcd_write_cmd( LCDC_ONOFF|LCDC_CURSOROFF );
	// w��czenie wy�wietlacza
	lcd_write_cmd( LCDC_ONOFF|LCDC_DISPLAYON );
	// przesuwanie kursora w prawo bez przesuwania zawarto�ci ekranu
	lcd_write_cmd( LCDC_ENTRY|LCDC_ENTRYR );

	// kasowanie ekranu
	lcd_cls();

	lcd_backgroundLedOn();

}
Ejemplo n.º 9
0
static void wavePlayEventHandler(uint8_t evt)
{
	static uint8_t prevEvt=0;

	if (evt && evt < 15)
		if (prevEvt!=evt) {
			prevEvt=evt;
			codec_sendBeep();
		}

	switch (evt)
	{
		case BTN_RIGHT:
			lcd_cls();
			ui_displayPreviousMenu();
			break;

		case BTN_LEFT:
			chThdTerminate(playerThread);
			chThdWait(playerThread);
			playerThread=NULL;
			break;

		case BTN_MID_DOWN:
			vol--;
			if (vol < 150) vol=150;
			codec_volCtl(vol);
			break;

		case BTN_MID_UP:
			vol++;
			if (vol > 220) vol=220;
			codec_volCtl(vol);
			break;

		case BTN_MID_SEL:
			if (!pause) {
				pause=1;
				ui_drawBottomBar("Stop", "Play", "Exit");
			} else {
				pause=0;
				ui_drawBottomBar("Stop", "Pause", "Exit");
			}
			codec_pauseResumePlayback(pause);
			break;
	}
}
Ejemplo n.º 10
0
void lcd_init(void)
{
/*
*  初始化LCD
*
* 调用:lcd_cls()、lcd_cmd()、lcd_position
*/
	lcd_cls();
	lcd_cmd(LCD_CURSOR);
	lcd_cmd(LCD_AC_AUTO_INCREMENT);
	lcd_cmd(LCD_DISPLAY_ON);

	lcd_cmd(LCD_LINES);	//工作方式(行数)

	lcd_position(2,0);		//定位到第一行第一列

}
Ejemplo n.º 11
0
int main (void)
{


	// enable pull ups for the 4 keys
	PORTA |= (1<<PORTA4)|(1<<PORTA5)|(1<<PORTA6)|(1<<PORTA7);

	
	// set LED Pins to output

	DDRC |= (1<<DDC2); // BL-LED1
	DDRD |= (1<<DDD6); // BL-LED2
	DDRD |= (1<<DDD7); // BL-LED3
	DDRC |= (1<<DDC6); // buzzer


	// disable bootloader LED
	DDRC |= (1<<DDC3);
	PORTC |= (1<<PORTC3);




	LCD_Init ();
	USART_Init ();
	USART1_Init ();
	TWIM_Init (200000);
	
	TIMER0_Init ();
	
	sei ();


	lcd_cls ();
	lcd_printp (PSTR("Hallo"), 0);
	
	
	
	for (;;)
	{
	}
}
Ejemplo n.º 12
0
void refresh(void)
{
/*
	液晶显示刷新函数
*/
	lcd_cls();
	switch(State){
		case 0:
			switch(Signal.w){
				case 0:lcd_printsxy("Sine    A=   Vol",0,0);	break;
				case 1:lcd_printsxy("Rect    A=   Vol",0,0);	break;
				case 2:lcd_printsxy("Tria    A=   Vol",0,0);	break;
			}
			lcd_printnxy(Signal.a,12,0);
			lcd_printsxy("C=        uS",0,1);
			lcd_printnxy(Signal.c,8,1);
			break;
		case 1:
			lcd_printsxy("Wave Select",0,0);
			switch(KeyCache){
				case 1: lcd_printsxy("Sine Wave",0,1);break;
				case 2: lcd_printsxy("Rect Wave",0,1);break;
				case 3: lcd_printsxy("Tria Wave",0,1);break;
				default: lcd_printsxy("1.Sin 2.Rec 3.Tri",0,1);break;
			}
			break;
		case 2:
			lcd_printsxy("Cycle  Setting",0,0);
			lcd_printsxy(" uS",13,1);
			lcd_printnxy(KeyCache,12,1);
			break;
		case 3:
			lcd_printsxy("Ample  Setting",0,0);
			lcd_printsxy("Vol",13,1);
			lcd_printnxy(KeyCache,12,1);
			break;
	}
	delay(1);
}
Ejemplo n.º 13
0
Archivo: main.c Proyecto: lysy1033/sfp
int main(void) {


	// LCD INIT
	lcd_init();
	lcd_start_screen();

	_delay_ms(500);

	while(1)
	{
		lcd_backlight(1);
		//sfp_read_vendor_name(sfp_vendor_name);
		EI2C_read_buf(0xa0,0x14,15,sfp_vendor_name);
		EI2C_read_buf(0xa0,56,4,sfp_vendor_rev);
		lcd_cls();
		lcd_locate(0,0);
		lcd_str((char*)sfp_vendor_name);
		lcd_locate(1,0);
		lcd_str((char*)sfp_vendor_rev);
		_delay_ms(1000);

	}
}
Ejemplo n.º 14
0
int main (void)
{
    /* INITIALIZE */
//	LCD_DDR |=(1<<LCD_RSDS_PIN);
//	LCD_DDR |=(1<<LCD_ENABLE_PIN);
//	LCD_DDR |=(1<<LCD_CLOCK_PIN);



    slaveinit();

    lcd_initialize(LCD_FUNCTION_8x2, LCD_CMD_ENTRY_INC, LCD_CMD_ON);
    lcd_puts("Guten Tag\0");
    delay_ms(1000);

    //lcd_cls();
    //lcd_puts("READY\0");
    delay_ms(1000);
    // DS1820 init-stuff begin

    uart_init();

    InitSPI_Slave();

    uint8_t linecounter=0;

    uint8_t SPI_Call_count0=0;
    lcd_cls();
    lcd_puts("UART\0");

#pragma mark while
    // OSZIA_HI;
    //char teststring[] = {"p,10,12"};


    initADC(TASTATURKANAL);

//  vga_start();

    setHomeCentral();
    vga_command("f,1");
    startcounter = 0;
    linecounter=0;
    uint8_t lastrand=rand();
    //srand(1);
    sei();
    uint8_t incounter=0;
    //uint8_t x=0;
    while (1)
    {
        loopCount0 ++;

        if (loopCount0 >=0x00FF)
        {
            //readSR();
            loopCount1++;

            if ((loopCount1 >0x01FF) )//&& (!(Programmstatus & (1<<MANUELL))))
            {
                LOOPLED_PORT ^= (1<<LOOPLED_PIN);
                if ((uartstatus & (1<< SUCCESS_BIT))&& (SPI_CONTROL_PORTPIN & (1<<SPI_CONTROL_CS_HC)))
                {
                    incounter++;
                    lcd_gotoxy(0,0);
                    lcd_puts("OK\0");
                    //lcd_puthex(in_startdaten);
                    lcd_putc(' ');
                    lcd_putint(incounter);
                    cli();
                    delay_ms(100);
                    //vga_command("f,2");
                    //vga_putch('*');
                    //putint(254);


                    uartstatus &= ~(1<< SUCCESS_BIT);


                    sei();

                }
                else
                {
                    //lcd_gotoxy(0,0);
                    //lcd_puts("  \0");

                }
                {
                    //lcd_gotoxy(15,3);
                    //lcd_putint(BitCounter);
                    /*
                    loopCount2++;
                    vga_command("f,2");
                    //puts("HomeCentral ");
                    vga_puts("Tastenwert ");
                    putint(Tastenwert);
                    vga_putch(' ');
                    newline();
                     */
                    /*
                    if (loopCount2 > 2)
                    {
                      newline();
                      linecounter++;
                      if (linecounter>50)
                      {
                         linecounter=0;
                         vga_command("e");
                      }
                      if (linecounter %3==0)
                      {
                         //linecounter =0;
                         linecounter+=1;
                         gotoxy(8,linecounter);
                         vga_command("f,2");
                         vga_puts("Stop");
                         putint_right(linecounter);
                         vga_putch(' ');
                         putint(Tastenwert);
                         //newline();
                         vga_command("f,1");
                         vga_command("e");
                         vga_puts("Daten");
                         putint_right(linecounter);
                         vga_command("f,2");
                         //vga_command("e");

                         gotoxy(0,linecounter);
                         vga_command("f,2");
                         newline();
                      }
                      loopCount2=0;
                    }
                    */
                    loopCount1=0;

                } // if startcounter

            }

            loopCount0 =0;
            //

            goto NEXT;
            {
                cli();

                {
                    Tastenwert=(uint8_t)(readKanal(TASTATURKANAL)>>2);

                    //lcd_gotoxy(12,1);
                    //lcd_puts("TW:\0");
                    //lcd_putint(Tastenwert);
                    if (Tastenwert>5) // ca Minimalwert der Matrix
                    {
                        tastaturstatus |= (1<<1);
                        //			wdt_reset();
                        /*
                         0: Wochenplaninit
                         1: IOW 8* 2 Bytes auf Bus laden
                         2: Menu der aktuellen Ebene nach oben
                         3: IOW 2 Bytes vom Bus in Reg laden
                         4: Auf aktueller Ebene nach rechts (Heizung: Vortag lesen und anzeigen)
                         5: Ebene tiefer
                         6: Auf aktueller Ebene nach links (Heizung: Folgetag lesen und anzeigen)
                         7:
                         8: Menu der aktuellen Ebene nach unten
                         9: DCF77 lesen

                         12: Ebene höher
                         */
                        TastaturCount++;
                        if (tastaturstatus & (1<<1))
                        {

                        }

                        if (TastaturCount>=80)	//	Prellen
                        {
                            tastaturstatus &= ~(1<<1);
                            Taste=Tastenwahl(Tastenwert);
                            lcd_gotoxy(0,1);
                            lcd_puts("T:\0");
                            //
                            lcd_putc(' ');
                            lcd_putint(Tastenwert);
                            lcd_putc(' ');
                            if (Taste >=0)
                            {
                                lcd_putint2(Taste);
                            }
                            else
                            {
                                lcd_putc('*');
                            }

                            //lcd_gotoxy(14,1);


                            //lcd_putint(linecounter);
                            //lcd_putc(' ');
                            //lcd_putint((uint8_t)rand()%40);

                            switch (Taste)
                            {
                            case 1:
                            {
                                vga_command("f,2");
                                gotoxy(0,2);
                                vga_command("f,2");
                                vga_puts("Brenner: ");
                            }
                            break;
                            case 2:
                            {
                                vga_command("f,3");
                                gotoxy(cursorx,cursory);
                                vga_command("f,3");
                                vga_putch(' ');

                                cursory--;
                                gotoxy(cursorx,cursory);
                                vga_command("f,3");
                                vga_putch('>');

                            }
                            break;
                            case 3:
                            {

                            } break;
                            case 4:
                            {
                                if (menuebene)
                                {
                                    menuebene--;
                                    if (cursorx>10)
                                    {
                                        vga_command("f,3");
                                        gotoxy(cursorx,cursory);
                                        vga_command("f,3");
                                        vga_putch(' ');
                                        cursorx-=10;
                                        gotoxy(cursorx,cursory);
                                        vga_command("f,3");
                                        vga_putch('>');
                                    }
                                }

                            }
                            break;
                            case 5:
                            {
                                vga_command("f,3");
                                gotoxy(cursorx,cursory);
                                vga_command("f,3");
                                vga_putch('>');

                            }
                            break;
                            case 6:
                            {
                                if (menuebene<MAXMENUEBENE)
                                {
                                    menuebene++;
                                    if (cursorx<40)
                                    {
                                        vga_command("f,3");
                                        gotoxy(cursorx,cursory);
                                        vga_command("f,3");
                                        vga_putch(' ');

                                        cursorx+=10;
                                        gotoxy(cursorx,cursory);
                                        vga_command("f,3");
                                        vga_putch('>');
                                    }
                                }
                            }
                            break;
                            case 7:
                            {

                                setFeld(3,70,3,30,32,1,"");
                                vga_command("f,3");
                                //vga_putch('x');
                                //lcd_putc('+');

                            }
                            break;
                            case 8:
                            {
                                vga_command("f,3");
                                gotoxy(cursorx,cursory);
                                vga_command("f,3");
                                vga_putch(' ');

                                cursory++;
                                gotoxy(cursorx,cursory);
                                vga_command("f,3");
                                vga_putch('>');

                            }
                            break;
                            case 9:
                            {

                            } break;
                            case 10:
                            {
                                setHomeCentral();
                            }
                            break;
                            case 12:
                            {
                                vga_command("f,3");
                                vga_command("e");
                                gotoxy(cursorx,cursory);
                                vga_command("f,3");
                                vga_putch(' ');
                                cursorx = CURSORX;
                                cursory = CURSORY;
                                gotoxy(CURSORX+1,CURSORY);
                                vga_command("f,3");
                                vga_puts("Alpha");
                                gotoxy(CURSORX+1,CURSORY+1);
                                vga_command("f,3");
                                vga_puts("Beta");
                                gotoxy(CURSORX+1,CURSORY+2);
                                vga_command("f,3");
                                vga_puts("Gamma");
                                gotoxy(CURSORX+1,CURSORY+3);
                                vga_command("f,3");
                                vga_puts("Delta");
                                gotoxy(cursorx,cursory);
                                vga_command("f,3");
                                vga_putch('>');

                            }
                            break;


                            } // switch Taste



                            lastrand = rand();
                            vga_command("f,2");
                            //vga_putch(' ');

                            //gotoxy(4,linecounter);
                            //lcd_gotoxy(16,1);
                            //lcd_putint(erg);
                            /*
                            putint(linecounter);
                            vga_putch(' ');
                            putint_right(Tastenwert);
                            vga_putch(' ');
                            putint_right(Taste);
                            */
                            //newline();
                            linecounter++;
                            TastaturCount=0;

                        }

                    } // if Tastenwert

                }

            }
NEXT:
            //x=0;
            sei();
            //
        }

        /* *** SPI begin **************************************************************/

        //lcd_gotoxy(19,0);
        //lcd_putc('-');

        // ***********************
        //goto ENDSPI;
        if (SPI_CONTROL_PORTPIN & (1<< SPI_CONTROL_CS_HC)) // PIN ist Hi, SPI ist Passiv
        {
            // lcd_gotoxy(19,1);
            //  lcd_putc('*');

            // ***********************
            /*
             Eine Uebertragung hat stattgefunden.
             (Die out-Daten sind auf dem Webserver.)
             Die in-Daten vom Webserver sind geladen.
             Sie muessen noch je nach in_startdaten ausgewertet werden.
             */

            // ***********************
//			SPI_CONTROL_PORT |= (1<<SPI_CONTROL_MISO); // MISO ist HI in Pausen

#pragma mark PASSIVE

            if (spistatus &(1<<ACTIVE_BIT)) // Slave ist neu passiv geworden. Aufraeumen, Daten uebernehmen
            {

                wdt_reset();
                SPI_Call_count0++;
                // Eingang von Interrupt-Routine, Daten von Webserver
                //lcd_gotoxy(19,0);
                //lcd_putc(' ');

                // in lcd verschoben
                lcd_clr_line(2);
                lcd_gotoxy(0,2);

                // Eingang anzeigen
                lcd_puts("iW \0");
                lcd_puthex(in_startdaten);
                lcd_putc(' ');
                lcd_puthex(in_hbdaten);
                lcd_puthex(in_lbdaten);
                lcd_putc(' ');
                uint8_t j=0;
                for (j=0; j<2; j++)
                {
                    //lcd_putc(' ');
                    lcd_puthex(inbuffer[j]);
                    //lcd_putc(inbuffer[j]);
                }
                OutCounter++;

                // Uebertragung pruefen

                //lcd_gotoxy(6,0);
                //lcd_puts("bc:\0");
                //lcd_puthex(ByteCounter);

                //lcd_gotoxy(0,0);
                //lcd_puts("      \0");


                lcd_gotoxy(19,0);
                lcd_putc(' ');

                if (ByteCounter == SPI_BUFSIZE-1) // Uebertragung war vollstaendig
                {
                    if (out_startdaten + in_enddaten==0xFF)
                    {
                        lcd_gotoxy(19,2);
                        lcd_putc('+');
                        spistatus |= (1<<SUCCESS_BIT); // Bit fuer vollstaendige und korrekte  Uebertragung setzen
                        lcd_gotoxy(19,0);
                        lcd_putc(' ');
                        //lcd_clr_line(3);
                        //lcd_gotoxy(0,1);
                        //lcd_puthex(loopCounterSPI++);
                        //lcd_puts("OK \0");

                        //lcd_puthex(out_startdaten + in_enddaten);
                        //					if (out_startdaten==0xB1)
                        {
                            SendOKCounter++;
                        }
                        spistatus |= (1<<SPI_SHIFT_IN_OK_BIT);
                    }

                    else
                    {
                        spistatus &= ~(1<<SUCCESS_BIT); // Uebertragung fehlerhaft, Bit loeschen
                        lcd_putc('-');
                        lcd_clr_line(1);
                        lcd_gotoxy(0,1);
                        lcd_puts("ER1\0");
                        lcd_putc(' ');
                        lcd_puthex(out_startdaten);
                        lcd_puthex(in_enddaten);
                        lcd_putc(' ');
                        lcd_puthex(out_startdaten + in_enddaten);

                        spistatus &= ~(1<<SPI_SHIFT_IN_OK_BIT);
                        {
                            SendErrCounter++;
                        }
                        //errCounter++;
                    }

                }
                else
                {
                    spistatus &= ~(1<<SUCCESS_BIT); //  Uebertragung unvollstaendig, Bit loeschen
                    lcd_clr_line(0);
                    lcd_gotoxy(0,0);
                    lcd_puts("ER2\0");
                    lcd_putc(' ');
                    lcd_puthex(ByteCounter);
                    //lcd_putc(' ');
                    //lcd_puthex(BitCounter);

                    /*
                    	lcd_putc(' ');
                    lcd_puthex(out_startdaten);
                    lcd_puthex(in_enddaten);
                    lcd_putc(' ');
                    lcd_puthex(out_startdaten + in_enddaten);
                    */
                    //delay_ms(100);
                    //errCounter++;
                    IncompleteCounter++;
                    spistatus &= ~(1<<SPI_SHIFT_IN_OK_BIT);
                }

                //lcd_gotoxy(11, 1);							// Events zahelen
                //lcd_puthex(OutCounter);
                /*
                 lcd_puthex(SendOKCounter);
                 lcd_puthex(SendErrCounter);
                 lcd_puthex(IncompleteCounter);
                 */
                /*
                 lcd_gotoxy(0,0);
                 lcd_putc('i');
                 lcd_puthex(in_startdaten);
                 lcd_puthex(complement);
                 lcd_putc(' ');
                 lcd_putc('a');
                 lcd_puthex(out_startdaten);
                 lcd_puthex(in_enddaten);
                 lcd_putc(' ');
                 lcd_putc('l');
                 lcd_puthex(in_lbdaten);
                 lcd_putc(' ');
                 lcd_putc('h');
                 lcd_puthex(in_hbdaten);
                 out_hbdaten++;
                 out_lbdaten--;

                 lcd_putc(out_startdaten);
                 */
                /*
                 lcd_gotoxy(0,0);
                 lcd_puthex(inbuffer[9]);
                 lcd_puthex(inbuffer[10]);
                 lcd_puthex(inbuffer[11]);
                 lcd_puthex(inbuffer[12]);
                 lcd_puthex(inbuffer[13]);
                 */
                //lcd_gotoxy(13,0);								// SPI - Fehler zaehlen
                //lcd_puts("ERR    \0");
                //lcd_gotoxy(17,0);
                //lcd_puthex(errCounter);

                // Bits im Zusammenhang mit der Uebertragung zuruecksetzen. Wurden in ISR gesetzt
                spistatus &= ~(1<<ACTIVE_BIT);		// Bit 0 loeschen
                spistatus &= ~(1<<STARTDATEN_BIT);	// Bit 1 loeschen
                spistatus &= ~(1<<ENDDATEN_BIT);		// Bit 2 loeschen
                spistatus &= ~(1<<SUCCESS_BIT);		// Bit 3 loeschen
                spistatus &= ~(1<<LB_BIT);				// Bit 4 loeschen
                spistatus &= ~(1<<HB_BIT);				// Bit 5 loeschen

                // aufraeumen
                out_startdaten=0x00;
                out_hbdaten=0;
                out_lbdaten=0;
                for (int i=0; i<SPI_BUFSIZE; i++)
                {
                    outbuffer[i]=0;
                }

                /*
                lcd_gotoxy(0,0);				// Fehler zaehlen
                lcd_puts("IC   \0");
                lcd_gotoxy(2,0);
                lcd_puthex(IncompleteCounter);
                lcd_gotoxy(5,0);
                lcd_puts("TW   \0");
                lcd_gotoxy(7,0);
                lcd_puthex(TWI_errCounter);

                lcd_gotoxy(5,1);
                lcd_puts("SE   \0");
                lcd_gotoxy(7,1);
                lcd_puthex(SendErrCounter);
                */
            } // if Active-Bit

#pragma mark HomeCentral-Tasks

        } // neu Passiv

        // letzte Daten vom Webserver sind in inbuffer und in in_startdaten, in_lbdaten, in_hbdaten


        else						// (IS_CS_HC_ACTIVE)
        {
            if (!(spistatus & (1<<ACTIVE_BIT))) // CS ist neu aktiv geworden, Daten werden gesendet, Active-Bit 0 ist noch nicht gesetzt
            {
                // Aufnahme der Daten vom Webserver vorbereiten

                uint8_t j=0;
                in_startdaten=0;
                in_enddaten=0;
                in_lbdaten=0;
                in_hbdaten=0;
                for (j=0; j<SPI_BUFSIZE; j++)
                {
                    inbuffer[j]=0;
                }

                spistatus |=(1<<ACTIVE_BIT); // Bit 0 setzen: neue Datenserie
                spistatus |=(1<<STARTDATEN_BIT); // Bit 1 setzen: erster Wert ergibt StartDaten

                bitpos=0;
                ByteCounter=0;
                //timer0(); // Ueberwachung der Zeit zwischen zwei Bytes. ISR setzt bitpos und ByteCounter zurueck, loescht Bit 0 in spistatus

                // Anzeige, das  rxdata vorhanden ist
                lcd_gotoxy(19,0);
                lcd_putc('$');
                lcd_gotoxy(19,1);
                lcd_putc(' ');




            }//										if (!(spistatus & (1<<ACTIVE_BIT)))
        }//											(IS_CS_HC_ACTIVE)
ENDSPI:
        /* *** SPI end **************************************************************/

# pragma mark Tasten

        if (!(PINB & (1<<PORTB0))) // Taste 0
        {
            //lcd_gotoxy(12,0);
            //lcd_puts("P0 Down\0");
            //wdt_reset();
            if (! (TastenStatus & (1<<PORTB0))) //Taste 0 war nicht nicht gedrueckt
            {
                TastenStatus |= (1<<PORTB0);
                Tastencount=0;
                //lcd_gotoxy(12,0);
                //lcd_puts("P0\0");
                //lcd_putint(TastenStatus);
                //delay_ms(800);
            }
            else
            {

                Tastencount ++;
                //lcd_gotoxy(7,1);
                //lcd_puts("TC \0");
                //lcd_putint(Tastencount);
                wdt_reset();
                if (Tastencount >= Tastenprellen)
                {
                    //lcd_gotoxy(18,0);
                    //lcd_puts("ON\0");
                    //lcd_putint(TastenStatus);

                    Tastencount=0;
                    TastenStatus &= ~(1<<PORTB0);

                }
            }//else

        }


#pragma mark Tastatur

    } // while
Ejemplo n.º 15
0
int
main ()
{
  DDRD = 0x00;
  PORTD = 0xff;

  lcd_init ();
  /*display on, cursor & blink off */
  lcd_control (1, 0, 0);
  lcd_cls ();
  lcd_putstr ("Animate is cool !", LCD_FIRST_LN_ADDR + 2);

  timer1_init ();

/* main -loop */
  for (;;)
    {
      // 2*0.065 Sec-kent vegrehajtodik az 1. es 3. animacio egy reszlete

      if (cnt1 == CNT1_THRESHOLD)
	{
	  cnt1 = 0;
	  //1. animacio 
	  if (i > 3)
	    {
	      i = 0;
	    }
	  uint8_t buf[8];

	  for (n = 0; n < 8; n++)
	    {
	      buf[n] = pgm_read_byte_near (&anim[i][n]);
	    }
	    i++;
	  lcd_put_custom_char (0x00, buf);	//CGRAM 0x00 cimre beirjuk a sajat karaktert.
	  lcd_set_DDRAM_addr (LCD_FIRST_LN_ADDR);	//vissza DDRAMhoz, elso sor 1 karakterehez
	  lcd_putch (0x00);	//megjelenitjuk a CGRAM 0x00 cimen levo karaktert.

	  //2. animacio
	  lcd_set_DDRAM_addr (LCD_FIRST_LN_ADDR + 19);	//masodik sor 8. karakterehez
	  lcd_putch (0x00);	//megjelenitjuk a CGRAM 0x00 cimen levo karaktert.
	}

      // 7 * 0.065 Sec(OVF) -kent vegrehajtodik a 3. animacio egy reszlete

      if (cnt2 == CNT2_THRESHOLD)
	{
	  cnt2 = 0;
	  //3. animacio
	  if (j > 1)
	    {
	      j = 0;
	    }
	  uint8_t buf[8];

	  //read 8byte(one char) from FLASH
	  for (n = 0; n < 8; n++)
	    {
	      buf[n] = pgm_read_byte_near (&man[j][n]);
	    }
	    j++;
	  lcd_put_custom_char (0x02, buf);
	  lcd_set_DDRAM_addr (LCD_SECND_LN_ADDR);
	  lcd_putch (0x02);
	}
    }
  return 0;
}
Ejemplo n.º 16
0
int main(void)
{
#if !SDL
	//wdt_enable(WDTO_1S);

	// I/O ports

	DDRB = 0x17;
	PORTB = 0x00 | (1<<5);
	//input logic disable on adc3
	DIDR0 = (1<<ADC3D);

	//timer0
	
	//set clock divider to 1024
	TCCR0B |= (1<<CS02) | (1<<CS00);
	//compare value 49 -> 20Hz
	//OCR0B = 49;
	OCR0B = 3;
	//enable compare match B interrupt
	TIMSK |= (1<<OCIE0B);

	//timer1

	//      CK/64
	//TCCR1 = (1<<CS12) | (1<<CS11) | (1<<CS10);
	//overflow interrupt
	//TIMSK |= (1<<TOIE1);

	//external interrupts
	
	//enable pin change interrupt
	//GIMSK = (1<<PCIE);
	//enable only on PB3
	//PCMSK = (1<<3);
	
	//adc
	
	//       enable      clk/16
	//ADCSRA = (1<<ADEN) | (1<<ADPS2);
	//       enable      clk/2
	ADCSRA = (1<<ADEN) | (1<<ADPS0);

	/*//if it's a watchdog reset
	if(mcusr_mirror & (1<<WDRF)){
		if(getkey() == DIR_NONE){
			set_sleep_mode(SLEEP_MODE_PWR_DOWN);
			sleep_mode();
		}
	}*/

	//wdt_enable(WDTO_4S);

#else

	SDL_Init(SDL_INIT_VIDEO);
	if (!(screen = SDL_SetVideoMode(80, 48, 32, SDL_SWSURFACE)))
		return EXIT_FAILURE;

	SDL_WM_SetCaption("elladunkku", NULL);

#endif

	/*g_highscore = eeprom_read_byte(0);
	if(g_highscore == 0xff) g_highscore = 0;*/
	/*g_highscore = eeprom_read_word(0);
	if(g_highscore == 0xffff) g_highscore = 0;*/

start:

	lcd_init();

	//lcd_locate(10,2);
	//lcd_locate8((2<<4)+1);
	//lcd_printstrP(PSTR("C55 PRESENTS"));
	//_delay_ms(1000);

	sei();

	for(;;){

		next_level(true);
		draw_game();

		//main loop

		g_counter0 = 0;
		//TCNT0 = 0;
		for(;;){
#if SDL
			++g_counter0;
			SDL_WaitEvent(&g_event);
			if (g_event.type == SDL_QUIT)
				goto quit;
#endif

			// TODO: If nothing happens for a long time, go to sleep

			int8_t key = getkey();
			if(key == DIR_NONE)
				continue;

			uint8_t num_enemy_moves = move_player(key);
			switch(num_enemy_moves){
			case 2:
				step_enemies();
				draw_game();
			case 1:
				step_enemies();
			}
			draw_game();

			if(g_hp <= 0){
				_delay_ms(5000);
				while(getkey() == DIR_NONE);
				next_level(true); // Reset game
				draw_game();
			}

			/*int8_t lastdir_inv = -g_next_dir;
			while(g_counter0 < 6){
			//while(TCNT0 < 6*3){
				int8_t key = getkey();
				if(key == DIR_NONE) continue;
				if(key == lastdir_inv) continue;
				g_next_dir = key;
				g_random += g_counter0;
			}
			TCNT0 = 0;
			g_counter0 = 0;
			uint8_t ret = snake_move_and_draw();
			if(ret == 1){
				snake_draw(0xaa);
				draw_block(g_snake[g_snake_end], 0xff);
				//lcd_locate(83,5);
				lcd_locate8((0<<4)+4);
				if(g_points > g_highscore){
					g_highscore = g_points;
					//eeprom_write_byte(0, g_highscore);
					eeprom_write_word(0, g_highscore);
				}
				_delay_ms(200);
				break;
			}*/
		}

#if !SDL
		while(getkey() != DIR_NONE);
		//TCNT0 = 0;
		g_counter0 = 0;
		while(getkey() == DIR_NONE){
			if(g_counter0 >= 200){
				cli();

				/*lcd_cls();
				lcd_locate8((1<<4)+0);
				lcd_printstrP(PSTR("GREETINGS  ELLA  TEJEEZ  3210"));
				_delay_ms(2000);*/
				/*lcd_locate8((1<<4)+1);
				lcd_printstrP(PSTR("GREETINGS ELLA TEJEEZ"));
				lcd_locate8((2<<4)+1);
				lcd_printstrP(PSTR("ELLA"));
				lcd_locate8((3<<4)+1);
				lcd_printstrP(PSTR("TEJEEZ"));*/
				/*lcd_cls();
				lcd_locate8((1<<4)+3);
				lcd_put5digit(2048);
				lcd_locate8((2<<4)+3);
				lcd_put5digit(128);
				lcd_locate8((3<<4)+3);
				lcd_put5digit(55);
				_delay_ms(2000);*/
				
				lcd_cls();
				lcd_powerdown();

				ADCSRA = 0 | (1<<ADPS0);
				DIDR0 = 0;
				CLKPR = 0x80;
				CLKPR = (1<<CLKPS3); //256
				while(PINB & (1<<3));
				//while(getkey() == DIR_NONE);
				CLKPR = 0x80;
				CLKPR = 0;
				DIDR0 = (1<<ADC3D);
				ADCSRA = (1<<ADEN) | (1<<ADPS0);

				goto start;
			}
		}
#endif
	}

#if SDL
quit:
	SDL_Quit();
#endif
	return 0;
}
Ejemplo n.º 17
0
void
menu_handle_joystick(uint8_t key)
{
    uint8_t menu_line[MLINESIZE+1];

    ////////////////////////////////////////
    // Scrolling up/down.
    if(key == KEY_DOWN || key == KEY_UP) {
        menu_setbg(menu_curitem);
        lcd_putchar(menu_curitem-menu_topitem+1,  ' ');

        uint8_t insert_line = 0;

        if(key == KEY_DOWN) {

            if(menu_curitem == menu_nitems-1)
                menu_curitem = 0;
            else
                menu_curitem++;

            if(menu_curitem - menu_topitem >= BODY_LINES) {
                menu_topitem++;
                insert_line = 9;
            }
        }

        if(key == KEY_UP) {

            if(menu_curitem == 0)
                menu_curitem = menu_nitems-1;
            else
                menu_curitem--;

            if(menu_topitem > menu_curitem) {
                menu_topitem--;
                insert_line = 10;
            }
        }

        menu_setbg(menu_curitem);
        if(insert_line) {
            uint8_t dpybuf[17];
            menu_get_line(menu_item_offset[menu_curitem],
                          menu_line, sizeof(menu_line));
            menu_getlineword(1, menu_line, dpybuf+1, sizeof(dpybuf)-1);
            dpybuf[0] = ' ';

            lcd_putline(insert_line, (char *)dpybuf);
        }
        lcd_putchar(menu_curitem-menu_topitem+1, '>');
    }

    ////////////////////////////////////////
    // Exec current command
    if(key == KEY_RIGHT) {

        // Save the current position
        menu_lastsel[menu_stack[menu_stackidx-1]] = menu_curitem;

        menu_get_line(menu_item_offset[menu_curitem],
                      menu_line, sizeof(menu_line));

        uint8_t arg[MLINESIZE];
        menu_getlineword(2, menu_line, arg, sizeof(arg));

        if(menu_line[0] == 'S') {   // submenu
            uint8_t sm;
            fromhex((char *)arg, &sm, 1);
            menu_push(sm);
        }

        if(menu_line[0] == 'C') {   // Command
            lcd_invon();
            callfn((char *)arg);
            lcd_invoff();
        }

        if(menu_line[0] == 'm') {   // Macro
            uint8_t idx;
            uint16_t off;

            lcd_invon();
            fromhex((char *)arg, &idx, 1);

            off = menu_get_line(menu_offset[idx], menu_line, sizeof(menu_line));
            while(off && menu_line[0]) {
                off = menu_get_line(off, menu_line, sizeof(menu_line));
                if(off == 0 || !menu_line[0])
                    break;
                callfn((char *)menu_line);
            }

            lcd_invoff();

        }

    }

    if(key == KEY_LEFT) {         // pop menu stack
        // Save the current position
        menu_lastsel[menu_stack[menu_stackidx-1]] = menu_curitem;
        menu_pop();
    }


    ////////////////////////////////////////
    // Switch display on / off
    if(key == KEY_ENTER) {
        if(lcd_on) {
            if(lcd_on == 0xff) {

                lcd_switch(1);
                lcd_cls();
                lcd_contrast(0xfc);
                menu_stackidx = 0;
                menu_push(0);

            } else {

                dosleep();

            }

        } else {

            lcd_switch(1);

        }
        bat_drawstate();
    }
}
Ejemplo n.º 18
0
int main(void) {
	//programowy pwm
	DDRC |= (1<<PC0)|(1<<PC1);
	PORTC |= (1<<PC0);
	PORTC |= (1<<PC1);

	TCCR2B |= (1<<WGM21);	// tryb  CTC
	TCCR2B |= (1<<CS20);		// preskaler = 1
	OCR2B = 199;				// dodatkowy podzia³ czêsttotliwoœci przez 200
	TIMSK2 |= (1<<OCIE2B);

	/*TCCR2 |= (1<<WGM21);	// tryb  CTC
	TCCR2 |= (1<<CS20);		// preskaler = 1
	OCR2 = 199;				// dodatkowy podzia³ czêsttotliwoœci przez 200
	TIMSK |= (1<<OCIE2);*/

	#if MPU6050_GETATTITUDE == 0
    int16_t ax = 0;
    int16_t ay = 0;
    int16_t az = 0;
    int16_t gx = 0;
    int16_t gy = 0;
    int16_t gz = 0;
    double axg = 0;
    double ayg = 0;
    double azg = 0;
    double gxds = 0;
    double gyds = 0;
    double gzds = 0;
	#endif

	#if MPU6050_GETATTITUDE == 1 || MPU6050_GETATTITUDE == 2
    //long *ptr = 0;
    double qw = 1.0f;
	double qx = 0.0f;
	double qy = 0.0f;
	double qz = 0.0f;
	double roll = 0.0f;
	double pitch = 0.0f;
	double yaw = 0.0f;
	#endif

	//uart_init(UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU));
	sei();

	mpu6050_init();
	_delay_ms(50);


	int maxa=0,maxg=0,aax,pom;

	//init mpu6050 dmp processor
	#if MPU6050_GETATTITUDE == 2
	mpu6050_dmpInitialize();
	mpu6050_dmpEnable();
	_delay_ms(10);
	#endif
	DDRD |= (1<<PD0);
	PORTD |= (1<<PD0);
	lcd_init();
	int licz=1,suma=0,_ax,fi,bak;
	int i;
	int ii,jj;
	int sprawdz;

	//pid
			/*float wzmocnienieP=10;		//Wzmocnienie
			float stalaI=0.4;		//Sta³a czasowa ca³kowania
			float stalaD=12;		//Sta³a czasowa ró¿niczkowania
			*/
			float wzmocnienieP=14;		//Wzmocnienie
			float stalaI=0;		//Sta³a czasowa ca³kowania
			float stalaD=0;
			float czas=0.15;	//Czas zmian wielkoœci
			int predkosc=127;		//Prêdkoœæ silników
			int predkosc_k=127;
			int sterowanie,uchyb,uchyb_pop=0;
			int calka=0;
			int lqr;

			//KF
			/*Matrix *x_post = matrix_alloc(4,1);
			for(ii=0;ii<4;ii++) {
				for(jj=0;jj<1;jj++) {
					x_post->matrix_entry[ii][jj]=0;
				}
			}
			Matrix *P_post = matrix_alloc(4,4);
			for(ii=0;ii<4;ii++) {
				for(jj=0;jj<4;jj++) {
					P_post->matrix_entry[ii][jj]=1;
				}
			}
			Matrix *V = matrix_alloc(4,4);
			for(ii=0;ii<4;ii++) {
				for(jj=0;jj<4;jj++) {
					if(ii==jj) V->matrix_entry[ii][ii]=0.8;
					else V->matrix_entry[ii][jj]=0;
				}
			}

			Matrix *W = matrix_alloc(2,2);
			W->matrix_entry[0][0]=0.02;
			W->matrix_entry[0][1]=0;
			W->matrix_entry[1][0]=0;
			W->matrix_entry[1][1]=4;

			//LQR

			Matrix *K_C = matrix_alloc(1,4);
			K_C->matrix_entry[0][0]=80;
			K_C->matrix_entry[0][1]=28.6388;
			K_C->matrix_entry[0][2]=-63.7184;
			K_C->matrix_entry[0][3]=-5.6401;

*/
	for(;;) {
		lcd_cls();
		#if MPU6050_GETATTITUDE == 0
		mpu6050_getRawData(&ax, &ay, &az, &gx, &gy, &gz);
		mpu6050_getConvData(&axg, &ayg, &azg, &gxds, &gyds, &gzds);
		#endif

		#if MPU6050_GETATTITUDE == 1
		mpu6050_getQuaternion(&qw, &qx, &qy, &qz);
		mpu6050_getRollPitchYaw(&roll, &pitch, &yaw);
		_delay_ms(10);
		#endif

		#if MPU6050_GETATTITUDE == 2
		if(mpu6050_getQuaternionWait(&qw, &qx, &qy, &qz)) {
			mpu6050_getRollPitchYaw(qw, qx, qy, qz, &roll, &pitch, &yaw);
		}
		_delay_ms(10);
		#endif

		#if MPU6050_GETATTITUDE == 0
		//char itmp[10];
		/*ltoa(ax, itmp, 10); uart_putc(' '); uart_puts(itmp); uart_putc(' ');
		ltoa(ay, itmp, 10); uart_putc(' '); uart_puts(itmp); uart_putc(' ');
		ltoa(az, itmp, 10); uart_putc(' '); uart_puts(itmp); uart_putc(' ');
		ltoa(gx, itmp, 10); uart_putc(' '); uart_puts(itmp); uart_putc(' ');
		ltoa(gy, itmp, 10); uart_putc(' '); uart_puts(itmp); uart_putc(' ');
		ltoa(gz, itmp, 10); uart_putc(' '); uart_puts(itmp); uart_putc(' ');
		uart_puts("\r\n");

		dtostrf(axg, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
		dtostrf(ayg, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
		dtostrf(azg, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
		dtostrf(gxds, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
		dtostrf(gyds, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
		dtostrf(gzds, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
		uart_puts("\r\n");

		uart_puts("\r\n");*/
		/*lcd_cls();
		lcd_str("a=(");
		lcd_locate(0,3);
		lcd_int(axg);
		lcd_locate(0,6);
		lcd_str(",");
		lcd_locate(0,7);
		lcd_int(ayg);
		lcd_locate(0,10);
		lcd_str(",");
		lcd_locate(0,11);
		lcd_int(azg);
		lcd_locate(0,14);
		lcd_str(")");

		lcd_locate(1,0);
		lcd_str("g=(");
		lcd_locate(1,3);
		lcd_int(gxds);
		lcd_locate(1,6);
		lcd_str(",");
		lcd_locate(1,7);
		lcd_int(gyds);
		lcd_locate(1,10);
		lcd_str(",");
		lcd_locate(1,11);
		lcd_int(gzds);
		lcd_locate(1,14);
		lcd_str(")");
		_delay_ms(100);*/

		/*if(ax<0) ax*=-1;
		if(gx<0) gx*=-1;
		if(ax>maxa) maxa=ax;
		if(gx>maxg) maxg=gx;
		lcd_int(maxa);
		lcd_locate(1,0);
		lcd_int(maxg);
		_delay_ms(100);*/

		/*
		lcd_int(ax);
		lcd_locate(1,0);
		lcd_int(gx);
		_delay_ms(100);*/

		//REGULATOR PROPORCJONALNY
		/*int K=26;
		ax/=100;
		if(ax<0) ax *= -1;
		pom=-K*ax+255;
		if(pom<0) pom = 0;
		pwm1=pom;
		if(ax>=0) PORTC &= ~(1<<PC1);
		else PORTC |= (1<<PC1);
		licz++;*/
		//if((licz%10000)==0)
		//{
			/*lcd_cls();
			lcd_int(pwm1);
			_delay_ms(1000);
		//}
		 *

		*/
//############################33
		ax /= 100;
		suma+=ax;
		licz++;
		if(licz == 20) {
			suma /= 20;
			fi=suma;
			//lcd_cls();
			//lcd_int(fi);
			//_delay_ms(500);

			//
			if(fi>=0) {
				PORTC &= ~(1<<PC1);
			}
			if(fi<0) {
				PORTC |= (1<<PC1);
				fi *= -1;
			}
			//REGULATOR PROPORCJONALNY
			//int K=80;
			//pom=K*fi;
			//if(pom>255) pom = 255;
			//pwm1=pom;


		//PID

		if(fi<0) {
			uchyb = -1*fi;
		} else {
			uchyb = fi;
		}
		calka += stalaI*fi;
		sterowanie = (int)(wzmocnienieP*fi)/* - (int)(stalaD*((fi - uchyb_pop)))*/ + (int)(calka);
		sprawdz = predkosc - sterowanie;
		if(sterowanie>255) sterowanie = 255;
		if(sterowanie<0) sterowanie = 0-sterowanie;
		if(sterowanie<-255) sterowanie = 255;

		//lcd_int(sterowanie);
		//_delay_ms(1000);

		pwm1=sterowanie;
		uchyb_pop=fi;

		suma=0;
		licz=1;

		}

		//LQR
		//Wypelnianie macierzy A
		/*Matrix *A;
		A = matrix_alloc(4,4);

		for(ii=0;ii<4;ii++) {
			for(jj=0;jj<4;jj++) {
				A->matrix_entry[ii][jj]=0;
			}
		}
		A->matrix_entry[0][1]=1; 		A->matrix_entry[2][3]=1;
		A->matrix_entry[1][1]=-0.1192; 	A->matrix_entry[1][2]=6.7359;
		A->matrix_entry[3][1]=-1.2764; 	A->matrix_entry[3][2]=177.1575;

		//Wypelnianie macierzy B
		Matrix *B;
		B = matrix_alloc(4,1);

		for(ii=0;ii<4;ii++) {
			B->matrix_entry[ii][0]=0;
		}
		B->matrix_entry[1][0]=1.1923; 		B->matrix_entry[3][0]=12.7640;

		//Wypelnianie macierzy C
		Matrix *C;
		C = matrix_alloc(2,4);

		for(ii=0;ii<2;ii++) {
			for(jj=0;jj<4;jj++) {
				C->matrix_entry[ii][jj]=0;
			}
		}
		C->matrix_entry[0][0]=1; 		C->matrix_entry[1][2]=1;

		//u=pwm1

		Matrix *x;
		x = matrix_alloc(4,1);
		x->matrix_entry[0][0]=0.000628*licznik; //m #################################
		//x->matrix_entry[1][0]=6.28/(-0.0588*pwm1+20); //m/s
		x->matrix_entry[1][0]=3.1416/(5000*pwm1); //m/s
		x->matrix_entry[2][0]=(ax*9)/1600; //16000 - 90 stopni
		x->matrix_entry[3][0]=gy; //

		Matrix *y = matrix_alloc(2,1);
		y->matrix_entry[0][0]=x->matrix_entry[0][0];
		y->matrix_entry[1][0]=x->matrix_entry[2][0];

		//lcd_cls();
		//lcd_int((int)x->matrix_entry[2][0]);
		//_delay_ms(500);

		//FILTR KALMANA



		Matrix *Ax = matrix_alloc(4,1);
		Matrix *Bu = matrix_alloc(4,1);
		Matrix *x_pri = matrix_alloc(4,1);
		Matrix *AP = matrix_alloc(4,4);
		Matrix *AT = matrix_alloc(4,4);
		Matrix *APAT = matrix_alloc(4,4);
		Matrix *P_pri = matrix_alloc(4,4);
		Matrix *eps = matrix_alloc(2,1);
		Matrix *CX = matrix_alloc(2,1);

		      // x(t+1|t) = Ax(t|t) + Bu(t)
		      Ax=matrix_multiply(A, x_post);
		      Bu->matrix_entry[0][0]=0;
		      Bu->matrix_entry[1][0]=pwm1*B->matrix_entry[1][0];
		      Bu->matrix_entry[2][0]=0;
		      Bu->matrix_entry[3][0]=pwm1*B->matrix_entry[3][0];
		      matrix_add(x_pri, Ax, Bu);

		      // P(t+1|t) = AP(t|t)A^T + V
		      AP=matrix_multiply(A, P_post);
		      AT=matrix_transpose(A);
		      APAT=matrix_multiply(AP, AT);
		      matrix_add(P_pri, APAT, V);

		      // eps(t) = y(t) - Cx(t|t-1)
		      CX=matrix_multiply(C, x_pri);
		      matrix_subtract(eps,y,CX);

		  Matrix *CP = matrix_alloc(2,4);
		  Matrix *CPCT = matrix_alloc(2,2);
		  Matrix *CT = matrix_alloc(4,2);
		  Matrix *S = matrix_alloc(2,2);
		  Matrix *PCT = matrix_alloc(4,2);
		  //Matrix *S1 = matrix_alloc(2,2);
		  Matrix *K = matrix_alloc(4,2);
		  Matrix *Keps = matrix_alloc(4,1);
		  Matrix *KS = matrix_alloc(4,2);
		  Matrix *KT = matrix_alloc(2,4);
		  Matrix *KSKT = matrix_alloc(4,4);

		      // S(t) = CP(t|t-1)C^T + W
		      CP=matrix_multiply(C, P_pri);
		      CT=matrix_transpose(C);
		      CPCT=matrix_multiply(CP, CT);
		      matrix_add(S, CPCT, W);

		      // K(t) = P(t|t-1)C^TS(t)^-1
		      PCT=matrix_multiply(P_pri, CT);
		      matrix_invert(S);
		      K=matrix_multiply(PCT, S); //S^-1

		      // x(t|t) = x(t|t-1) + K(t)eps(t)
		      Keps=matrix_multiply(K, eps);
		      matrix_add(x_post, x_pri, Keps);

		      // P(t|t) = P(t|t-1) - K(t)S(t)K(t)^T
		      matrix_invert(S);
		      KS=matrix_multiply(K, S);//S
		      KT=matrix_transpose(K);
		      KSKT=matrix_multiply(KS, KT);
		      matrix_subtract(P_post, P_pri, KSKT);

		      //LQR

		Matrix *KX = matrix_alloc(1,1);
		KX=matrix_multiply(K, x_post);

		lqr=(int)(KX->matrix_entry[0][0]);
		sprawdz=predkosc + lqr;
		if(sprawdz>255) sprawdz = 255;
		if(sprawdz<0) sprawdz = 0;
		pwm1=sprawdz;


		pwm1 = predkosc
*/

		//############

		//matrix_t *A = make_matrix( 4, 4 );
		//put_entry_matrix( eqs, if1, if1, dx );


		/*lcd_cls();
		lcd_int(fi);
		lcd_locate(0,7);
		lcd_int(pwm1);
		_delay_ms(500);*/


//#################################
		/*for(i=255;i>=0;i--) {
			pwm1=i;
			_delay_ms(30);
			if((i%10)==0) {
				lcd_cls();
				lcd_int(pwm1);
			}
		}
		for(i=0;i<=255;i++) {
			pwm1=i;
			_delay_ms(30);
			if((i%10)==0) {
				lcd_cls();
				lcd_int(pwm1);
			}
		}*/

		#endif

		#if MPU6050_GETATTITUDE == 1 || MPU6050_GETATTITUDE == 2

		//quaternion
		/*ptr = (long *)(&qw);
		uart_putc(*ptr);
		uart_putc(*ptr>>8);
		uart_putc(*ptr>>16);
		uart_putc(*ptr>>24);
		ptr = (long *)(&qx);
		uart_putc(*ptr);
		uart_putc(*ptr>>8);
		uart_putc(*ptr>>16);
		uart_putc(*ptr>>24);
		ptr = (long *)(&qy);
		uart_putc(*ptr);
		uart_putc(*ptr>>8);
		uart_putc(*ptr>>16);
		uart_putc(*ptr>>24);
		ptr = (long *)(&qz);
		uart_putc(*ptr);
		uart_putc(*ptr>>8);
		uart_putc(*ptr>>16);
		uart_putc(*ptr>>24);

		//roll pitch yaw
		ptr = (long *)(&roll);
		uart_putc(*ptr);
		uart_putc(*ptr>>8);
		uart_putc(*ptr>>16);
		uart_putc(*ptr>>24);
		ptr = (long *)(&pitch);
		uart_putc(*ptr);
		uart_putc(*ptr>>8);
		uart_putc(*ptr>>16);
		uart_putc(*ptr>>24);
		ptr = (long *)(&yaw);
		uart_putc(*ptr);
		uart_putc(*ptr>>8);
		uart_putc(*ptr>>16);
		uart_putc(*ptr>>24);

		uart_putc('\n');*/
		//lcd_int((int)qw);
		//_delay_ms(1000);
		#endif

	}

}
int main (void)
{
	/* INITIALIZE */
//	LCD_DDR |=(1<<LCD_RSDS_PIN);
//	LCD_DDR |=(1<<LCD_ENABLE_PIN);
//	LCD_DDR |=(1<<LCD_CLOCK_PIN);
	
	slaveinit();
	
   SPI_Init();
   
	lcd_initialize(LCD_FUNCTION_8x2, LCD_CMD_ENTRY_INC, LCD_CMD_ON);
	lcd_puts("Guten Tag\0");
	delay_ms(1000);
   
	lcd_cls();
   lcd_gotoxy(0,0);
	lcd_puts("MASTER\0");
	
	// DS1820 init-stuff begin
	// DS1820 init-stuff end
   
   volatile char incoming=0;
   volatile uint8_t outcounter=0;
   
   sei();
#pragma mark while
	while (1) 
	{
		loopCount0 ++;
		//_delay_ms(2);
		//LOOPLED_PORT ^= (1<<LOOPLED_PIN);
      //incoming = SPDR;
		if (loopCount0 >=0x0F)
		{
			LOOPLED_PORT ^= (1<<LOOPLED_PIN);
			loopCount1++;
         //SPDR = loopCount2;
         
  			if ((loopCount1 >0x0002F) )//&& (!(Programmstatus & (1<<MANUELL))))
			{
            SPI_PORT &= ~(1<<SPI_CS); // SS LO, Start
            
            //_delay_us(100);
            uint8_t outindex=0;
            textpos=0;
            inbuffer[0] = '\0';
            //outbuffer[0] = '\0';
            
            text[0] = 0x30+(outcounter & 0x07);
            for (outindex=0;outindex < strlen(text);outindex++)
            {
               SPDR = text[outindex];
               while(!(SPSR & (1<<SPIF)) && spiwaitcounter<0xFFF)
               {
                  spiwaitcounter++;
               }
               spiwaitcounter=0;
               incoming = SPDR;
               inbuffer[outindex] = incoming;
               outbuffer[outindex] = text[outindex];
               
            }
            
            inbuffer[outindex] = '\0';
            //outbuffer[outindex] = '\0';
            //char rest = SPDR;
            SPI_PORT |= (1<<SPI_CS); // SS HI End

            
            lcd_gotoxy(8,0);
            lcd_putc('i');
            lcd_putc(' ');
            lcd_puts((char*)inbuffer);
            
            lcd_gotoxy(8,1);
            lcd_putc('o');
             lcd_putc(' ');
            lcd_puts((char*)outbuffer);
            
            outcounter++;
            if (outcounter > 9)
            {
               //outcounter =0;
            }
            
            /*
            if (textpos == 0)
            {
               
               SPI_PORT &= ~(1<<SPI_SS); // SS LO
            }
            
            SPDR = text[textpos];
            while(!(SPSR & (1<<SPIF)) && spiwaitcounter<0xFFF)
            {
               spiwaitcounter++;
            }
            incoming = SPDR;
            spiwaitcounter=0;
            
            textpos++;
            if (textpos >= strlen(text))
            {
               textpos=0;
               SPI_PORT |= (1<<SPI_SS); // SS HI
               //SPI_PORT &= ~(1<<SPI_SS); // SS LO
            }
            */
            loopCount2++;
            /*
            lcd_gotoxy(inpos,1);
            
            lcd_putc(incoming);
            inpos++;
            if (inpos >= 19)
            {
               inpos=0;
            }
            */
            
            
            //lcd_gotoxy(18,0);
            //lcd_puthex(loopCount2);
            //LOOPLED_PORT ^= (1<<LOOPLED_PIN);
				
            //LOOPLED_PORT ^= (1<<LOOPLED_PIN);
            loopCount1=0;
            /*
             if ((SPSR & (1<<SPIF)) > 0) // checks to see if the SPI bit is clear
             {
             
             data='a'; // send the data
             }
             */
            //char incoming = SPI_get_put_char('A');
            
            
            
            
				// DS1820 loop-stuff begin
            /*
             start_temp_meas();
             delay_ms(800);
             read_temp_meas();
             
             //Sensor 1
             lcd_gotoxy(0,1);
             lcd_puts("1:\0");
             if (gTempdata[0]/10>=100)
             {
             lcd_gotoxy(1,1);
             lcd_putint((gTempdata[0]/10));
             }
             else
             {
             lcd_gotoxy(2,1);
             lcd_putint2((gTempdata[0]/10));
             }
             
             lcd_putc('.');
             lcd_putint1(gTempdata[0]%10);
             
             // Sensor 2
             lcd_gotoxy(7,1);
             lcd_puts("2:\0");
             if (gTempdata[1]/10>=100)
             {
             lcd_gotoxy(8,1);
             lcd_putint((gTempdata[1]/10));
             }
             else
             {
             lcd_gotoxy(9,1);
             lcd_putint2((gTempdata[1]/10));
             }
             
             lcd_putc('.');
             lcd_putint1(gTempdata[1]%10);
             
             // Sensor 3
             lcd_gotoxy(14,1);
             lcd_puts("3:\0");
             if (gTempdata[2]/10>=100)
             {
             lcd_gotoxy(15,1);
             lcd_putint((gTempdata[2]/10));
             }
             else
             {
             lcd_gotoxy(16,1);
             lcd_putint2((gTempdata[2]/10));
             }
             
             lcd_putc('.');
             lcd_putint1(gTempdata[2]%10);
             
             
             
             lcd_gotoxy(15,0);
             lcd_puts("   \0");
             lcd_gotoxy(15,0);
             lcd_puthex(gTemp_measurementstatus);
             
             */
				
				// DS1820 loop-stuff end
				
				
				//lcd_putint(gTempdata[1]);
				//lcd_putint(gTempdata[2]);
				//delay_ms(1000);
			}
			
			loopCount0 =0;
		}
      
      
		if (!(PINB & (1<<PB0))) // Taste 0
		{
			lcd_gotoxy(10,1);
			lcd_puts("P0 Down\0");
         lcd_puthex(TastenStatus);
			
			if (! (TastenStatus & (1<<PB0))) //Taste 0 war nicht nicht gedrueckt
			{
            lcd_gotoxy(10,1);
            lcd_puts("P0 neu \0");
				TastenStatus |= (1<<PB0);
            delay_ms(1000);
				Tastencount=0;
				//lcd_gotoxy(3,1);
				//lcd_puts("P0 \0");
				//lcd_putint(Servoimpulsdauer);
				//delay_ms(800);
				SPDR = 'x';
            while(!(SPSR & (1<<SPIF)) && spiwaitcounter<0xFFF)
            {
               spiwaitcounter++;
            }
            spiwaitcounter=0;
            delay_ms(1000);
            //lcd_gotoxy(10,1);
				//lcd_puts("       \0");
            lcd_gotoxy(19,1);
            lcd_putc('+');
			}
			else
			{
				lcd_gotoxy(19,1);
            lcd_putc('$');
				//lcd_puts("*         *\0");
				
				Tastencount ++;
				if (Tastencount >= Tastenprellen)
				{
					Tastencount=0;
					TastenStatus &= ~(1<<PB0);
               lcd_gotoxy(10,1);
               lcd_puts("*         *\0");
               

               
				}
			}//	else
			
		} // Taste 0

		
#pragma mark Tastatur 
		/* ******************** */
		initADC(TASTATURPIN);
		Tastenwert=(readKanal(TASTATURPIN)>>2);
		
//		lcd_gotoxy(3,1);
//		lcd_putint(Tastenwert);
//		Tastenwert=0;
		if (Tastenwert>5)
		{
			/*
			 0:											1	2	3
			 1:											4	5	6
			 2:											7	8	9
			 3:											x	0	y
			 4: Schalterpos -
			 5: Manuell ein
			 6: Schalterpos +
			 7: 
			 8: 
			 9: 
			 
			 12: Manuell aus
			 */
			 
			TastaturCount++;
			if (TastaturCount>=200)
			{
				
				 
				 //lcd_gotoxy(17,1);
				 //lcd_puts("T:  \0");
				 //lcd_putint(Tastenwert);
				 
				uint8_t Taste=Tastenwahl(Tastenwert);
				//Taste=0;
				 //lcd_gotoxy(19,1);
				 //lcd_putint1(Taste);
				 //delay_ms(600);
				// lcd_clr_line(1);
				 

				TastaturCount=0;
				Tastenwert=0x00;
				uint8_t i=0;
				uint8_t pos=0;
//				lcd_gotoxy(18,1);
//				lcd_putint2(Taste);
				continue;
				switch (Taste)
				{
					case 0:// Schalter auf Null-Position
					{ 
						if (Programmstatus & (1<<MANUELL))
						{
							Manuellcounter=0;
							Programmstatus |= (1<<MANUELLNEU);
							/*
							lcd_gotoxy(13,0);
							lcd_puts("S\0");
							lcd_gotoxy(19,0);
							lcd_putint1(Schalterposition); // Schalterstellung
							lcd_gotoxy(0,1);
							lcd_puts("SI:\0");
							lcd_putint(ServoimpulsdauerSpeicher); // Servoimpulsdauer
							lcd_gotoxy(5,0);
							lcd_puts("SP\0");
							lcd_putint(Servoimpulsdauer); // Servoimpulsdauer
							*/
						}
						
					}break;
						
					case 1:	//	
					{ 
					if (Programmstatus & (1<<MANUELL))
						{
						uint8_t i=0;
						lcd_gotoxy(0,0);
						lcd_puts("Sens\0");
						lcd_putc('1');
						lcd_putc(' ');
						for (i=0;i<OW_ROMCODE_SIZE;i++)
						{
						lcd_puthex(gSensorIDs[0][i]);
						if (i==3)
						{
						lcd_gotoxy(0,1);
						}
						lcd_putc(' ');
						}
						Manuellcounter=0;
						
						}
					}break;
						
					case 2://
					{ 
					
						if (Programmstatus & (1<<MANUELL))
						{
						uint8_t i=0;
						lcd_gotoxy(0,0);
						lcd_puts("Sens\0");
						lcd_putc('1');
						lcd_putc(' ');
						for (i=0;i<OW_ROMCODE_SIZE;i++)
						{
						lcd_puthex(gSensorIDs[1][i]);
						if (i==3)
						{
						lcd_gotoxy(0,1);
						}
						lcd_putc(' ');
						}
						Manuellcounter=0;
						
						
						}
						
					}break;
						
					case 3: //	Uhr aus
					{ 
						if (Programmstatus & (1<<MANUELL))
						{
						uint8_t i=0;
						lcd_gotoxy(0,0);
						lcd_puts("Sens\0");
						lcd_putc('1');
						lcd_putc(' ');
						for (i=0;i<OW_ROMCODE_SIZE;i++)
						{
						lcd_puthex(gSensorIDs[2][i]);
						if (i==3)
						{
						lcd_gotoxy(0,1);
						}
						lcd_putc(' ');
						}
						Manuellcounter=0;
						

						}
					}break;
						
					case 4://
					{ 
						DS18X20_read_scratchpad(&gSensorIDs[0][0], gScratchPad );
												uint8_t i=0;
						lcd_gotoxy(0,0);
						lcd_puts("Sens\0");
						lcd_putc('0');
						lcd_putc(' ');
						for (i=0;i<OW_ROMCODE_SIZE;i++)
						{
						lcd_puthex(gScratchPad[i]);
						if (i==3)
						{
						lcd_gotoxy(0,1);
						}
						lcd_putc(' ');
						}

					}break;
						
					case 5://
					{ 
						Programmstatus |= (1<<MANUELL);	// MANUELL ON
						Manuellcounter=0;
						MANUELL_PORT |= (1<<MANUELLPIN);
						Programmstatus |= (1<<MANUELLNEU);
						lcd_clr_line(1);
						/*
							lcd_gotoxy(13,0);
							lcd_puts("S\0");
							lcd_putint1(Schalterposition); // Schalterstellung
							lcd_gotoxy(0,1);
							lcd_puts("SP:\0");
							lcd_putint(ServoimpulsdauerSpeicher); // Servoimpulsdauer
							lcd_gotoxy(5,0);
							lcd_puts("SI\0");
							lcd_putint(Servoimpulsdauer); // Servoimpulsdauer
						*/
					}break;
						
					case 6://
					{ 
					sensornummer=0xAF;
					Sensornummerlesen(0,&sensornummer);
						lcd_gotoxy(0,0);
						lcd_puts("Sens\0");
						lcd_putc('1');
						lcd_putc(' ');
						lcd_puthex(sensornummer);
					
					}break;
						
					case 7:// Schalter rückwaerts
					{ 
					sensornummer=0x00;
					Sensornummerlesen(0,&sensornummer);
						lcd_gotoxy(0,0);
						lcd_puts("Sens\0");
						lcd_putc('0');
						lcd_putc(' ');
						lcd_puthex(sensornummer);
					
					}break;
						
					case 8://
					{ 
					sensornummer=0x00;
					Sensornummerlesen(1,&sensornummer);
						lcd_gotoxy(0,0);
						lcd_puts("Sens\0");
						lcd_putc('1');
						lcd_putc(' ');
						lcd_puthex(sensornummer);
					

					}break;
						
					case 9:// Schalter vorwaerts
					{ 
					sensornummer=0x00;
					Sensornummerlesen(2,&sensornummer);
						lcd_gotoxy(0,0);
						lcd_puts("Sens\0");
						lcd_putc('2');
						lcd_putc(' ');
						lcd_puthex(sensornummer);
					
					}break;

					case 10:// *
					{ 
						
					}break;

					case 11://
					{ 
						
					}break;
						
					case 12: // # Normalbetrieb einschalten
					{
						Programmstatus &= ~(1<<MANUELL); // MANUELL OFF
						Programmstatus &= ~(1<<MANUELLNEU);
						MANUELL_PORT &= ~(1<<MANUELLPIN);
					}
						
				}//switch Tastatur
				
//				delay_ms(400);
//				lcd_gotoxy(18,1);
//				lcd_puts("  ");		// Tastenanzeige loeschen

			}//if TastaturCount	
			
		}
	}
	
	
	return 0;
}
Ejemplo n.º 20
0
int main(int argc, char *argv[]){
    int oldx, oldy;
    lcd_init();
    lcd_setcursor(1);

    if( argc != 2 ){
        lcd_printf("emin [filename]\n");
        return 0;
    }

    oldx = lcd_getcurx();
    oldy = lcd_getcury();
    lcd_setshowpage(2);
    lcd_setdrawpage(2);
    lcd_locate(0,0);
    init(argv[1]);

    uchar key;
    while(!quit){
        key = mpc_getchar();

        if(key != 0){
            if( !mpc_oncontrol() && !mpc_onalt() ){
                if(key == MKS_Enter){
                    emin_enter();

                }else if(key == MKS_BackSpace || key == MKS_Delete){
                    emin_backspace();

                }else if(0x20 <= key && key < 0x7f){
                    emin_type(key);
                }

            }else if( mpc_oncontrol() ){
                if(key == 'f'){
                    Cursor_move_right(&cursor);
                }else if(key == 'b'){
                    Cursor_move_left(&cursor);
                }else if(key == 'p'){
                    Cursor_move_up(&cursor);
                }else if(key == 'n'){
                    Cursor_move_down(&cursor);
                }else if(key == 'a'){
                    Cursor_move_head(&cursor);
                }else if(key == 'e'){
                    Cursor_move_end(&cursor);
                }else if(key == 'l'){
                    View_redraw(&cursor);
                }else if(key == 'h'){
                    emin_backspace();
                }else if(key == 'x'){
                    emin_command(key);
                }
                

            }else if( mpc_onalt() ){

            }
            
            //Cursor_on(&cursor);
            Cursor_set(&cursor);
        }
        
        mpc_usleep(1000);
    }

    lcd_cls();
    lcd_setshowpage(0);
    lcd_setdrawpage(0);
    lcd_locate(oldx, oldy);

    return 0;
}
Ejemplo n.º 21
0
void pong (void) {
	
ausrichtung = unten;
	
int16_t xcord = 5;
int16_t ycord = 0;
int16_t number = 23;

/* Koordinatensystem */

int16_t radius = 5;

int16_t xmin = 0;
int16_t xmax = 128 ;
int16_t ymin = 0;
int16_t ymax = 64;

int p1points = 10;
int cont = 1;

/* *******************************
 * Deklaration von zwei Kreisen k1 und k2
 * diese sollen wild durch die gegend bouncen
 * bei berührung -> invertierung
********************************/
int16_t k1xcord = 23;
int16_t k1ycord = 42;
int16_t k1xstep = 3;
int16_t k1ystep = 1;
int16_t k1xmaxcord;
int16_t k1xmincord;
int16_t k1ymaxcord;
int16_t k1ymincord;



int16_t r1xcord = 10;
int16_t r1ycord = 27;
int16_t r1widthx = 2;
int16_t r1widthy = 10;
int16_t r1step = 1;


int16_t r1xmaxcord;
int16_t r1xmincord;
int16_t r1ymaxcord;
int16_t r1ymincord;

r1xmaxcord = (r1xcord + r1widthx);
r1xmincord = r1xcord;

while(cont)	{
	
k1xmaxcord = (k1xcord + radius);
k1xmincord = (k1xcord - radius);
k1ymaxcord = (k1ycord + radius);
k1ymincord = (k1ycord - radius);

//STEUERUNG ***********************
	//hoch
		while (get_key_rpt (1 << KEY_MINUS)) {
			if (ymin < r1ymincord) {
			r1ycord = (r1ycord - r1step);
			//lcd_printp_at(3,0, PSTR("+\r"),0);
			 
			}
			r1ymincord = r1ycord;
			r1ymaxcord = r1ymincord + r1widthy;
			
		}
	//runter
		while (get_key_rpt (1 << KEY_PLUS)) {
			if (ymax > r1ymaxcord) {
				r1ycord = (r1ycord + r1step);
				//lcd_printp_at(3,0, PSTR("-\r"),0);
			}
			r1ymaxcord = (r1ycord + r1widthy);
			r1ymincord = r1ymaxcord - r1widthy;
			
		}
		if (debug) {
		lcd_write_number_u_at (3,0, r1ymincord);
		lcd_write_number_u_at (5,0, r1ymaxcord);
		}
		lcd_frect (r1xcord, r1ycord, r1widthx, r1widthy, 1);
// STEUERUNG ENDE ***********************

	
// BALL ABFRAGE **************************	
if (debug) {
lcd_write_number_u_at (7,0,	r1xmaxcord);
lcd_write_number_u_at (10,0, k1xmincord);
lcd_write_number_u_at (13, 0, k1ycord);
}
		if (((r1ymaxcord > k1ycord) && (r1ymincord < k1ycord)) && (r1xmaxcord >= k1xmincord)) {
			k1xstep = -(k1xstep);
		}
		if (xmax <= k1xmaxcord) {
			k1xstep = -(k1xstep);
		}
		if (xmin >= k1xmincord) {
			p1points--;
			if (p1points == 0) {
				cont = 0;
				lcd_printp_at (2, 3,PSTR("VERLOREN!\r\n"),0);
				wait_ms(5000);
				
			}
			k1xcord = 23;
			k1ycord = 42;
			k1xstep = 3;
			k1ystep = 1;
			
		}
		
		if ((k1ymaxcord >= ymax) || (k1ymincord <= ymin)) {
			k1ystep = -(k1ystep);
		}
		
		k1xcord += k1xstep;
		k1ycord += k1ystep;
		
		lcd_fcircle (k1xcord, k1ycord, radius);
		
// BALLABFRAGE ENDE *****************************

//Zeichnen		
		lcd_write_number_u_at (0,0, p1points);
		wait_ms (100);
		lcd_cls ();
		
		
		


	}



	lcd_write_number_u_at(xcord, ycord, number);
}