示例#1
0
void
vga_puts(const char *s)
{
    for (; *s != '\0'; s++)
        vga_putch(*s);

}
示例#2
0
/* cons_putc - print a single character @c to console devices */
void
cons_putc(int c) {
    bool intr_flag;
    local_intr_save(intr_flag);
    {
        serial_putc(c);
		vga_putch(c);
    }
    local_intr_restore(intr_flag);
}
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