Esempio n. 1
0
 public void check_Konfiguration(Atmega Main)
 {
     OperationMode = Main.GetBitIOPort(UCSRC, UMSEL) ? 1 : 0;
     Parity        = Main.GetBitIOPort(UCSRC, UPM1) || Main.GetBitIOPort(UCSRC, UPM0) ? true : false;
     StopBits      = Main.GetBitIOPort(UCSRC, USBS) ? 2 : 1;
     int[] Data = { 5, 6, 7, 8, 0, 0, 0, 9 };
     DataBits    = Data[(Main.GetBitIOPort(Main.INC.UCSRC, Main.INC.UCSZ0) ? 1 : 0) + (Main.GetBitIOPort(UCSRC, UCSZ1) ? 2 : 0) + (Main.GetBitIOPort(UCSRC, UCSZ2) ? 4 : 0)];
     DoubleSpeed = Main.GetBitIOPort(UCSRA, U2X) ? true : false;
     BAUDRATE    = Main.Frequenz / (((Main.LowHigh(Main.Ports[UBRRL].get(), Main.Ports[UBRRH].get()) << 1) >> 1) + 1) * 16;
 }
Esempio n. 2
0
        public void update(Atmega Main, Def INC)
        {
            if (Sleep > 0)
            {
                Sleep--;
                if (Sleep == 0)
                {
                    Main.SetBitIOPort(INC.EECR, INC.EEWE, false);
                    if (Main.GetBitIOPort(INC.EECR, INC.EERIE) && Main.GetBitIOPort(INC.SREG, INC.I))
                    {
                        if (Main.ExecuteInterrupt("ERDYaddr"))
                        {
                            Main.SetBitIOPort(INC.SREG, INC.I, false);
                        }
                    }
                }
            }

            // Schreiben
            if (Main.GetBitIOPort(INC.EECR, INC.EEMWE) && Main.GetBitIOPort(INC.EECR, INC.EEWE))
            {
                Main.SetBitIOPort(INC.EECR, INC.EEMWE, false);
                SPEICHER[Main.LowHigh(Main.Ports[INC.EEARL].get(), Main.Ports[INC.EEARH].get())] = Main.Ports[INC.EEDR].get();
                Sleep       = 8448 * (Main.Frequenz / 1000000);
                Main.Sleep += 2;
                Anz_Write++;
            }

            // Lesen
            if (Main.GetBitIOPort(INC.EECR, INC.EERE) && !(Main.GetBitIOPort(INC.EECR, INC.EEMWE) || Main.GetBitIOPort(INC.EECR, INC.EEWE)))
            {
                Main.Ports[INC.EEDR].set(SPEICHER[Main.LowHigh(Main.Ports[INC.EEARL].get(), Main.Ports[INC.EEARH].get())]);
                Main.Sleep += 4;
                Main.SetBitIOPort(INC.EECR, INC.EERE, false);
                Anz_Read++;
            }
        }
Esempio n. 3
0
        public void update(Atmega Main, Def INC)
        {
            if (Sleep > 0)
            {
                Sleep--; return;
            }
            if (Typ == 0)
            {
                if ((Main.Ports[TCCR].get() & PRESC_MASKE) == 0)
                {
                    return;
                }
                int a = TCNT;
                // Overflow prüfen
                if (Main.GetBitIOPort(INC.TIFR, TOV) && Main.GetBitIOPort(INC.TIMSK, TOIE) && (Main.SREG & SREGI) > 0)
                {
                    if (Main.ExecuteInterrupt("OVF" + ID + "addr"))
                    {
                        Main.SetBitIOPort(INC.TIFR, TOV, false);
                        //Main.SetBitIOPort(INC.SREG, INC.I, false);
                        Main.SREG = (Byte)(Main.SREG & SREGNOI);
                    }
                }

                // Compare Prüfen
                if (Main.GetBitIOPort(INC.TIFR, OCF) && Main.GetBitIOPort(INC.TIMSK, OCIE) && (Main.SREG & SREGI) > 0)
                {
                    if (Main.ExecuteInterrupt("OC" + ID + "Aaddr"))
                    {
                        Main.SetBitIOPort(INC.TIFR, OCF, false);
                        //Main.SetBitIOPort(INC.SREG, INC.I, false);
                        Main.SREG = (Byte)(Main.SREG & SREGNOI);
                        Main.Ports[a].set(0);
                    }
                }

                // Test ob Aktiv
                int presc = Prescaler[Main.Ports[TCCR].get() & PRESC_MASKE];
                // Counter erhöhen
                int  res  = Main.Ports[a].get();
                bool Over = false;
                res++;
                Main.Ports[a].set(Help.Low(res));
                if (Main.Ports[a].get() == 0)
                {
                    Over = true;                           // Overflow eingetreten
                }
                Sleep = presc - 1;
                // Compare prüfen
                int c = OCR;

                if (Over)
                {// Overflow Treffer
                    Main.SetBitIOPort(INC.TIFR, TOV, true);
                }

                // Compare
                if (res == Main.Ports[c].get())
                {// Treffer
                    Main.SetBitIOPort(INC.TIFR, OCF, true);
                }
            }
            else
            if (Typ == 1)
            {
                if ((Main.Ports[TCCRB].get() & PRESC_MASKE) == 0)
                {
                    return;
                }
                int a = TCNTL;
                int b = TCNTH;

                // Overflow prüfen
                if (Main.GetBitIOPort(INC.TIFR, TOV) && Main.GetBitIOPort(INC.TIMSK, TOIE) && (Main.SREG & SREGI) > 0)
                {
                    if (Main.ExecuteInterrupt("OVF" + ID + "addr"))
                    {
                        Main.SetBitIOPort(INC.TIFR, TOV, false);
                        //Main.SetBitIOPort(INC.SREG, INC.I, false);
                        Main.SREG = (Byte)(Main.SREG & SREGNOI);
                    }
                }

                // Compare A Prüfen
                if (Main.GetBitIOPort(INC.TIFR, OCFA) && Main.GetBitIOPort(INC.TIMSK, OCIEA) && (Main.SREG & SREGI) > 0)
                {
                    if (Main.ExecuteInterrupt("OC" + ID + "Aaddr"))
                    {
                        Main.SetBitIOPort(INC.TIFR, OCFA, false);
                        //Main.SetBitIOPort(INC.SREG, INC.I, false);
                        Main.SREG = (Byte)(Main.SREG & SREGNOI);
                        Main.Ports[a].set(0);
                        Main.Ports[b].set(0);
                    }
                }

                // Compare B Prüfen
                if (Main.GetBitIOPort(INC.TIFR, OCFB) && Main.GetBitIOPort(INC.TIMSK, OCIEB) && (Main.SREG & SREGI) > 0)
                {
                    if (Main.ExecuteInterrupt("OC1Baddr"))
                    {
                        Main.SetBitIOPort(INC.TIFR, OCFB, false);
                        // Main.SetBitIOPort(INC.SREG, INC.I, false);
                        Main.SREG = (Byte)(Main.SREG & SREGNOI);
                        Main.Ports[a].set(0);
                        Main.Ports[b].set(0);
                    }
                }

                // Test ob Aktiv
                int presc = Prescaler[Main.Ports[TCCRB].get() & PRESC_MASKE];
                // Counter erhöhen
                int  res  = Main.LowHigh(Main.Ports[a].get(), Main.Ports[b].get());
                bool Over = false;
                res++;
                Main.Ports[a].set(Help.Low(res));
                Main.Ports[b].set(Help.High(res));
                if (Main.Ports[a].get() == 0 && Main.Ports[b].get() == 0)
                {
                    Over = true;                                                           // Overflow eingetreten
                }
                Sleep = presc - 1;

                // Compare prüfen

                if (Over)
                {    // Overflow Treffer
                    Main.SetBitIOPort(INC.TIFR, TOV, true);
                }

                // A Compare
                if (res == Main.LowHigh(Main.Ports[OCRAL].get(), Main.Ports[OCRAH].get()))
                {    // A Treffer
                    Main.SetBitIOPort(INC.TIFR, OCFA, true);
                }

                // B Compare
                if (res == Main.LowHigh(Main.Ports[OCRBL].get(), Main.Ports[OCRBH].get()))
                {    // B Treffer
                    Main.SetBitIOPort(INC.TIFR, OCFB, true);
                }
            }
        }