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; }
public void Reload_INC(Atmega Main) { string ADD = ANZ > 1 ? ID.ToString() : ""; string ADD2 = ANZ > 1 ? ID.ToString() + "_" : ""; UDR = Main.getIORegister("UDR" + ADD); UBRRH = Main.getIORegister("UBRR" + ADD + "H"); UCSRC = Main.getIORegister("UCSR" + ADD + "C"); UCSRA = Main.getIORegister("UCSR" + ADD + "A"); UCSRB = Main.getIORegister("UCSR" + ADD + "B"); UBRRL = Main.getIORegister("UBRR" + ADD + "L"); UDR0 = (Byte)Main.getVar("UDR" + ADD2 + "0"); UDR1 = (Byte)Main.getVar("UDR" + ADD2 + "1"); UDR2 = (Byte)Main.getVar("UDR" + ADD2 + "2"); UDR3 = (Byte)Main.getVar("UDR" + ADD2 + "3"); UDR4 = (Byte)Main.getVar("UDR" + ADD2 + "4"); UDR5 = (Byte)Main.getVar("UDR" + ADD2 + "5"); UDR6 = (Byte)Main.getVar("UDR" + ADD2 + "6"); UDR7 = (Byte)Main.getVar("UDR" + ADD2 + "7"); USR = (Byte)Main.getVar("USR" + ADD); MPCM = (Byte)Main.getVar("MPCM" + ADD); U2X = (Byte)Main.getVar("U2X" + ADD); UPE = (Byte)Main.getVar("UPE" + ADD); PE = (Byte)Main.getVar("PE" + ADD); DOR = (Byte)Main.getVar("DOR" + ADD); FE = (Byte)Main.getVar("FE" + ADD); UDRE = (Byte)Main.getVar("UDRE" + ADD); TXC = (Byte)Main.getVar("TXC" + ADD); RXC = (Byte)Main.getVar("RXC" + ADD); UCR = (Byte)Main.getVar("UCR" + ADD); TXB8 = (Byte)Main.getVar("TXB8" + ADD); RXB8 = (Byte)Main.getVar("RXB8" + ADD); UCSZ2 = (Byte)Main.getVar("UCSZ" + ADD + "2"); CHR9 = (Byte)Main.getVar("CHR9" + ADD); TXEN = (Byte)Main.getVar("TXEN" + ADD); RXEN = (Byte)Main.getVar("RXEN" + ADD); UDRIE = (Byte)Main.getVar("UDRIE" + ADD); TXCIE = (Byte)Main.getVar("TXCIE" + ADD); RXCIE = (Byte)Main.getVar("RXCIE" + ADD); UCPOL = (Byte)Main.getVar("UCPOL" + ADD); UCSZ0 = (Byte)Main.getVar("UCSZ" + ADD + "0"); UCSZ1 = (Byte)Main.getVar("UCSZ" + ADD + "1"); USBS = (Byte)Main.getVar("USBS" + ADD); UPM0 = (Byte)Main.getVar("UPM" + ADD + "0"); UPM1 = (Byte)Main.getVar("UPM" + ADD + "1"); UMSEL = (Byte)Main.getVar("UMSEL" + ADD); URSEL = (Byte)Main.getVar("URSEL" + ADD); }
public void update(Atmega Main) { // if (UDR == -1) Reload_INC(Main); if (Sleep > 0) { Sleep--; if (Sleep == 0) { } return; } string ADD = ANZ > 1 ? ID.ToString() : ""; // Receiver if (Main.GetBitIOPort(UCSRB, RXEN)) { PIN a = null; // Main.GetTypPin("RXD" + ADD); if (a == null) { goto trans; } // if (Main.Ports[a.PORT].Typ[a.ID][0] != "RXD"+ADD) // { // for (int i = 1; i < Main.Ports[a.PORT].Typ[a.ID].Count; i++) // if (Main.Ports[a.PORT].Typ[a.ID][i] == "RXD"+ADD) // { Main.Ports[a.PORT].Typ[a.ID][i] = Main.Ports[a.PORT].Typ[a.ID][0]; Main.Ports[a.PORT].Typ[a.ID][0] = "RXD"+ADD; break; } //} } trans: // Transmitter if (Main.GetBitIOPort(UCSRB, TXEN)) { PIN a = null; // Main.GetTypPin("TXD" + ADD); if (a == null) { return; } int Bits = DataBits + StopBits + 1 + (Parity ? 1 : 0); Sleep = BAUDRATE == 0 ? 0 : Main.Frequenz / BAUDRATE * Bits; Sleep = DoubleSpeed ? Sleep / 2 : Sleep; } }
public void update(Atmega Main, Def INC) { if (Main.GetBitIOPort(INC.WDTCR, INC.WDE)) { if (Sleep < Max) { Sleep++; } if (Sleep >= Max) { // Zuende Reset(Main); Main.ExecuteInterrupt("RESET"); } } else { Sleep = 0; } }
public void Receive(Atmega Main, int Text) { if (Main.GetBitIOPort(UCSRB, RXEN)) { Main.SetBitIOPort(UCSRA, RXC, true); Main.Ports[Main.INC.UDR].set((Byte)Text); // in UDR laden if (DataBits == 9) { Main.SetBitIOPort(UCSRB, RXB8, true); // 9tes bit setzen } // Event abfragen if (Main.GetBitIOPort(UCSRB, RXCIE) && Main.GetBitIOPort(Main.INC.SREG, Main.INC.I) && Main.GetBitIOPort(UCSRA, RXC)) { if (Main.ExecuteInterrupt("URXCaddr")) { Main.SetBitIOPort(Main.INC.SREG, Main.INC.I, false); Main.SetBitIOPort(UCSRA, RXC, false); } } } }
public void Reload_INC(Atmega Main) { if (TCNT != -1) { return; } TCNT = Main.getIORegister("TCNT" + ID); TCNTL = Main.getIORegister("TCNT" + ID + "L"); TCNTH = Main.getIORegister("TCNT" + ID + "H"); TCCR = Main.getIORegister("TCCR" + ID); TCCRA = Main.getIORegister("TCCR" + ID + "A"); TCCRB = Main.getIORegister("TCCR" + ID + "B"); OCRAL = Main.getIORegister("OCR" + ID + "AL"); OCRAH = Main.getIORegister("OCR" + ID + "AH"); OCRBL = Main.getIORegister("OCR" + ID + "BL"); OCRBH = Main.getIORegister("OCR" + ID + "BH"); OCR = Main.getIORegister("OCR" + ID); TOIE = (Byte)Main.INT("TOIE" + ID); TOV = (Byte)Main.INT("TOV" + ID); OCF = (Byte)Main.INT("OCF" + ID); CS0 = (Byte)Main.INT("CS" + ID + "0"); CS1 = (Byte)Main.INT("CS" + ID + "1"); CS2 = (Byte)Main.INT("CS" + ID + "2"); WGM1 = (Byte)Main.INT("WGM" + ID + "1"); CTC = (Byte)Main.INT("CTC" + ID); COM0 = (Byte)Main.INT("COM" + ID + "0"); COM1 = (Byte)Main.INT("COM" + ID + "1"); WGM0 = (Byte)Main.INT("WGM" + ID + "0"); PWM = (Byte)Main.INT("PWM" + ID); FOC = (Byte)Main.INT("FOC" + ID); OCIE = (Byte)Main.INT("OCIE" + ID); OCIEA = (Byte)Main.INT("OCIE" + ID + "A"); OCIEB = (Byte)Main.INT("OCIE" + ID + "B"); OCFA = (Byte)Main.INT("OCF" + ID + "A"); PRESC_MASKE = (((0 | (1 << CS0)) | (1 << CS1)) | (1 << CS2)); OCFB = (Byte)Main.INT("OCF" + ID + "B"); }
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++; } }
public SZENARIEN(Atmega Besitzer) { Name = "[None]"; Vater = Besitzer; }
public void Reset(Atmega Main) { int[] Prescaler = { 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152 }; Max = Prescaler[(Main.GetBitIOPort(Main.INC.WDTCR, Main.INC.WDP0) ? 1 : 0) + (Main.GetBitIOPort(Main.INC.WDTCR, Main.INC.WDP1) ? 2 : 0) + (Main.GetBitIOPort(Main.INC.WDTCR, Main.INC.WDP2) ? 4 : 0)] * (Main.Frequenz / 1000000); }
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); } } }
public static String Arithmetic(Atmega Main, String Text, bool check_klammern) // Führt die Berechnung durch { int begin_klammer = -1; int anz_in = 0; int end_klammer = -1; if (IsNumber(Text)) { return(Text); } if (check_klammern == true) { for (int i = 0; i < Text.Length; i++) // check ob noch klammern existieren { if (Text[i] == '(' && begin_klammer == -1) { begin_klammer = i; } if (Text[i] == '(') { anz_in++; } if (Text[i] == ')' && anz_in > 1) { anz_in--; } else if (Text[i] == ')') { end_klammer = i; break; } } } if (begin_klammer != -1 && end_klammer != -1) { String p = Text.Substring(0, begin_klammer); String p2 = Text.Substring(end_klammer + 1, Text.Length - end_klammer - 1); String p3 = Text.Substring(begin_klammer + 1, end_klammer - begin_klammer - 1); Text = Arithmetic(Main, p + Arithmetic(Main, p3, true) + p2, true); } else { // operationen checken, da keine klammern mehr char[] sep = "<<".ToCharArray(); String[] temp = Text.Split(sep); int res; if (temp.Count() >= 2) { res = Main.INT(Arithmetic(Main, temp[0], false)); for (int i = 1; i < temp.Count(); i++) { if (temp[i] == ",") { continue; } res = res << Main.INT(Arithmetic(Main, temp[i], false)); } return(res.ToString()); } sep = ">>".ToCharArray(); temp = Text.Split(sep); if (temp.Count() >= 2) { res = Main.INT(Arithmetic(Main, temp[0], false)); for (int i = 1; i < temp.Count(); i++) { if (temp[i] == ",") { continue; } res = res >> Main.INT(Arithmetic(Main, temp[i], false)); } return(res.ToString()); } sep = "|".ToCharArray(); temp = Text.Split(sep); if (temp.Count() >= 2) { Text = ","; res = Main.INT(Arithmetic(Main, temp[0], false)); for (int i = 1; i < temp.Count(); i++) { res = res | Main.INT(Arithmetic(Main, temp[i], false)); } return(res.ToString()); } sep = "&".ToCharArray(); temp = Text.Split(sep); if (temp.Count() >= 2) { Text = ","; res = Main.INT(Arithmetic(Main, temp[0], false)); for (int i = 1; i < temp.Count(); i++) { res = res & Main.INT(Arithmetic(Main, temp[i], false)); } return(res.ToString()); } temp = Text.Split('+'); if (temp.Count() >= 2) { Text = ","; res = 0; for (int i = 0; i < temp.Count(); i++) { res += Main.INT(Arithmetic(Main, temp[i], false)); } return(res.ToString()); } temp = Text.Split('-'); if (temp.Count() >= 2) { res = Main.INT(Arithmetic(Main, temp[0], false)); for (int i = 1; i < temp.Count(); i++) { res -= Main.INT(Arithmetic(Main, temp[i], false)); } return(res.ToString()); } temp = Text.Split('*'); if (temp.Count() >= 2) { res = 1; Text = ","; for (int i = 0; i < temp.Count(); i++) { res *= Main.INT(Arithmetic(Main, temp[i], false)); } return(res.ToString()); } temp = Text.Split('/'); if (temp.Count() >= 2) { Text = ","; res = Main.INT(Arithmetic(Main, temp[0], false)); for (int i = 1; i < temp.Count(); i++) { int reb = Main.INT(Arithmetic(Main, temp[i], false)); if (reb != 0) { res /= reb; } } return(res.ToString()); } } return(Text); }
public void Reload(Atmega Main) { SREG = Main.getIORegister("SREG"); SPH = Main.getIORegister("SPH"); SPL = Main.getIORegister("SPL"); TIMSK = Main.getIORegister("TIMSK"); TIFR = Main.getIORegister("TIFR"); WDTCR = Main.getIORegister("WDTCR"); UBRRH = Main.getIORegister("UBRRH"); UBRRL = Main.getIORegister("UBRRL"); EEARH = Main.getIORegister("EEARH"); EEARL = Main.getIORegister("EEARL"); EEDR = Main.getIORegister("EEDR"); EECR = Main.getIORegister("EECR"); UDR = Main.getIORegister("UDR"); UCSRA = Main.getIORegister("UCSRA"); UCSRB = Main.getIORegister("UCSRB"); UCSRC = Main.getIORegister("UCSRC"); MCUCR = Main.getIORegister("MCUCR"); WDTCSR = (Byte)Main.getVar("WDTCSR"); WDP0 = (Byte)Main.getVar("WDP0"); WDP1 = (Byte)Main.getVar("WDP1"); WDP2 = (Byte)Main.getVar("WDP2"); WDCE = (Byte)Main.getVar("WDCE"); WDTOE = (Byte)Main.getVar("WDTOE"); WDE = (Byte)Main.getVar("WDE"); I = (Byte)Main.getVar("SREG_I"); T = (Byte)Main.getVar("SREG_T"); H = (Byte)Main.getVar("SREG_H"); S = (Byte)Main.getVar("SREG_S"); V = (Byte)Main.getVar("SREG_V"); N = (Byte)Main.getVar("SREG_N"); Z = (Byte)Main.getVar("SREG_Z"); C = (Byte)Main.getVar("SREG_C"); SP10 = (Byte)Main.getVar("SP10"); SP9 = (Byte)Main.getVar("SP9"); SP8 = (Byte)Main.getVar("SP8"); SP7 = (Byte)Main.getVar("SP7"); SP6 = (Byte)Main.getVar("SP6"); SP5 = (Byte)Main.getVar("SP5"); SP4 = (Byte)Main.getVar("SP4"); SP3 = (Byte)Main.getVar("SP3"); SP2 = (Byte)Main.getVar("SP2"); SP1 = (Byte)Main.getVar("SP1"); SP0 = (Byte)Main.getVar("SP0"); EEDR0 = (Byte)Main.getVar("EEDR0"); EEDR1 = (Byte)Main.getVar("EEDR1"); EEDR2 = (Byte)Main.getVar("EEDR2"); EEDR3 = (Byte)Main.getVar("EEDR3"); EEDR4 = (Byte)Main.getVar("EEDR4"); EEDR5 = (Byte)Main.getVar("EEDR5"); EEDR6 = (Byte)Main.getVar("EEDR6"); EEDR7 = (Byte)Main.getVar("EEDR7"); EERE = (Byte)Main.getVar("EERE"); EEWE = (Byte)Main.getVar("EEWE"); EEMWE = (Byte)Main.getVar("EEMWE"); EEWEE = (Byte)Main.getVar("EEWEE"); EERIE = (Byte)Main.getVar("EERIE"); UDR0 = (Byte)Main.getVar("UDR0"); UDR1 = (Byte)Main.getVar("UDR1"); UDR2 = (Byte)Main.getVar("UDR2"); UDR3 = (Byte)Main.getVar("UDR3"); UDR4 = (Byte)Main.getVar("UDR4"); UDR5 = (Byte)Main.getVar("UDR5"); UDR6 = (Byte)Main.getVar("UDR6"); UDR7 = (Byte)Main.getVar("UDR7"); USR = (Byte)Main.getVar("USR"); MPCM = (Byte)Main.getVar("MPCM"); U2X = (Byte)Main.getVar("U2X"); UPE = (Byte)Main.getVar("UPE"); PE = (Byte)Main.getVar("PE"); DOR = (Byte)Main.getVar("DOR"); FE = (Byte)Main.getVar("FE"); UDRE = (Byte)Main.getVar("UDRE"); TXC = (Byte)Main.getVar("TXC"); RXC = (Byte)Main.getVar("RXC"); UCR = (Byte)Main.getVar("UCR"); TXB8 = (Byte)Main.getVar("TXB8"); RXB8 = (Byte)Main.getVar("RXB8"); UCSZ2 = (Byte)Main.getVar("UCSZ2"); CHR9 = (Byte)Main.getVar("CHR9"); TXEN = (Byte)Main.getVar("TXEN"); RXEN = (Byte)Main.getVar("RXEN"); UDRIE = (Byte)Main.getVar("UDRIE"); TXCIE = (Byte)Main.getVar("TXCIE"); RXCIE = (Byte)Main.getVar("RXCIE"); UCPOL = (Byte)Main.getVar("UCPOL"); UCSZ0 = (Byte)Main.getVar("UCSZ0"); UCSZ1 = (Byte)Main.getVar("UCSZ1"); USBS = (Byte)Main.getVar("USBS"); UPM0 = (Byte)Main.getVar("UPM0"); UPM1 = (Byte)Main.getVar("UPM1"); UMSEL = (Byte)Main.getVar("UMSEL"); URSEL = (Byte)Main.getVar("URSEL"); SM0 = (Byte)Main.getVar("SM0"); SM1 = (Byte)Main.getVar("SM1"); SM2 = (Byte)Main.getVar("SM2"); SE = (Byte)Main.getVar("SE"); XH = (Byte)Main.getRegister("XH"); XL = (Byte)Main.getRegister("XL"); YH = (Byte)Main.getRegister("YH"); YL = (Byte)Main.getRegister("YL"); ZH = (Byte)Main.getRegister("ZH"); ZL = (Byte)Main.getRegister("ZL"); }