From d4a95696937f6b04406bba40f20324b475dd879c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Tue, 16 May 2017 17:52:02 +0200 Subject: [PATCH] [X] Testprogramm 11 (Watchdog, Vorteiler) --- PIC_Simulator/Form1.Designer.cs | 57 +++++++++++++++++----------- PIC_Simulator/Form1.cs | 24 +++++++++--- PIC_Simulator/PIC/PICProgramm.cs | 16 +++++--- PIC_Simulator/PIC/PICTimer.cs | 2 +- PIC_Simulator/PIC/PICWatchDog.cs | 25 ++++++------ PIC_Simulator/PIC/RS232Verbindung.cs | 2 +- Projektinformationen/Tabelle.txt | 2 +- 7 files changed, 78 insertions(+), 50 deletions(-) diff --git a/PIC_Simulator/Form1.Designer.cs b/PIC_Simulator/Form1.Designer.cs index 222761c..13ef0e6 100644 --- a/PIC_Simulator/Form1.Designer.cs +++ b/PIC_Simulator/Form1.Designer.cs @@ -110,8 +110,9 @@ this.btnClockStart = new System.Windows.Forms.Button(); this.edCLockFreq = new System.Windows.Forms.TextBox(); this.WakeUpButton = new System.Windows.Forms.Button(); - this.button1 = new System.Windows.Forms.Button(); - this.button2 = new System.Windows.Forms.Button(); + this.btnWD1 = new System.Windows.Forms.Button(); + this.btnWD0 = new System.Windows.Forms.Button(); + this.tbWD = new System.Windows.Forms.TextBox(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -835,33 +836,42 @@ this.WakeUpButton.UseVisualStyleBackColor = true; this.WakeUpButton.Click += new System.EventHandler(this.button1_Click); // - // button1 + // btnWD1 // - this.button1.Location = new System.Drawing.Point(341, 18); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(126, 23); - this.button1.TabIndex = 64; - this.button1.Text = "Watchdog An"; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.button1_Click_1); + this.btnWD1.Location = new System.Drawing.Point(341, 18); + this.btnWD1.Name = "btnWD1"; + this.btnWD1.Size = new System.Drawing.Size(126, 23); + this.btnWD1.TabIndex = 64; + this.btnWD1.Text = "Watchdog An"; + this.btnWD1.UseVisualStyleBackColor = true; + this.btnWD1.Click += new System.EventHandler(this.button1_Click_1); // - // button2 + // btnWD0 // - this.button2.Location = new System.Drawing.Point(341, 48); - this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(126, 23); - this.button2.TabIndex = 65; - this.button2.Text = "Watchdog Aus"; - this.button2.UseVisualStyleBackColor = true; - this.button2.Click += new System.EventHandler(this.button2_Click); + this.btnWD0.Location = new System.Drawing.Point(341, 48); + this.btnWD0.Name = "btnWD0"; + this.btnWD0.Size = new System.Drawing.Size(126, 23); + this.btnWD0.TabIndex = 65; + this.btnWD0.Text = "Watchdog Aus"; + this.btnWD0.UseVisualStyleBackColor = true; + this.btnWD0.Click += new System.EventHandler(this.button2_Click); + // + // tbWD + // + this.tbWD.Location = new System.Drawing.Point(474, 18); + this.tbWD.Name = "tbWD"; + this.tbWD.Size = new System.Drawing.Size(58, 20); + this.tbWD.TabIndex = 66; + this.tbWD.Text = "18.0"; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1298, 692); - this.Controls.Add(this.button2); - this.Controls.Add(this.button1); + this.Controls.Add(this.tbWD); + this.Controls.Add(this.btnWD0); + this.Controls.Add(this.btnWD1); this.Controls.Add(this.WakeUpButton); this.Controls.Add(this.edCLockFreq); this.Controls.Add(this.btnClockStart); @@ -1015,8 +1025,9 @@ private System.Windows.Forms.Button btnClockStart; private System.Windows.Forms.TextBox edCLockFreq; private System.Windows.Forms.Button WakeUpButton; - private System.Windows.Forms.Button button1; - private System.Windows.Forms.Button button2; - } + private System.Windows.Forms.Button btnWD1; + private System.Windows.Forms.Button btnWD0; + private System.Windows.Forms.TextBox tbWD; + } } diff --git a/PIC_Simulator/Form1.cs b/PIC_Simulator/Form1.cs index b52a66e..dff2531 100644 --- a/PIC_Simulator/Form1.cs +++ b/PIC_Simulator/Form1.cs @@ -2,6 +2,7 @@ using PIC_Simulator.Properties; using System; using System.Drawing; +using System.Globalization; using System.IO; using System.Linq; using System.Windows.Forms; @@ -12,8 +13,8 @@ namespace PIC_Simulator { private PICProgramm programm; - private Timer quartztimer; - private RS232Verbindung rs232 = new RS232Verbindung(); + public Timer quartztimer; + public RS232Verbindung rs232 = new RS232Verbindung(); public Form1() { @@ -41,6 +42,7 @@ namespace PIC_Simulator lvSpecial.Items.Add(new ListViewItem(new[] { "Status[DC]", "0" })); lvSpecial.Items.Add(new ListViewItem(new[] { "Status[C]", "0" })); lvSpecial.Items.Add(new ListViewItem(new[] { "Status[Z]", "0" })); + lvSpecial.Items.Add(new ListViewItem(new[] { "Watchdog timer", "0ms" })); } private void Form1_Load(object sender, EventArgs e) @@ -49,7 +51,7 @@ namespace PIC_Simulator box_CodeView.Text = Resources.TPicSim1; - programm = new PICProgramm(); + programm = new PICProgramm(this); programm.Laden(Resources.TPicSim1); OberflaecheAktualisieren(); @@ -76,7 +78,7 @@ namespace PIC_Simulator box_CodeView.Text = datei; - programm = new PICProgramm(); + programm = new PICProgramm(this); programm.Laden(datei); OberflaecheAktualisieren(); @@ -125,7 +127,7 @@ namespace PIC_Simulator { quartztimer.Stop(); - programm = new PICProgramm(); + programm = new PICProgramm(this); programm.Laden(box_CodeView.Text); rs232.Disconnect(); @@ -204,6 +206,7 @@ namespace PIC_Simulator lvSpecial.Items[7].SubItems[1].Text = programm.GetRegisterOhneBank(PICProgramm.ADDR_STATUS, PICProgramm.STATUS_BIT_C) ? "1" : "0"; lvSpecial.Items[8].SubItems[1].Text = programm.GetRegisterOhneBank(PICProgramm.ADDR_STATUS, PICProgramm.STATUS_BIT_DC) ? "1" : "0"; lvSpecial.Items[9].SubItems[1].Text = programm.GetRegisterOhneBank(PICProgramm.ADDR_STATUS, PICProgramm.STATUS_BIT_Z) ? "1" : "0"; + lvSpecial.Items[10].SubItems[1].Text = string.Format("{0:0.000}ms", programm.WatchDog.time * 1000); lbStack.Items.Clear(); foreach (var u in programm.Stack) lbStack.Items.Add(u.ToString()); @@ -246,6 +249,8 @@ namespace PIC_Simulator btn_RB_Tris_6.Text = (programm.GetRegisterOhneBank(PICProgramm.ADDR_TRIS_B, 6) ? "i" : "o"); btn_RB_Tris_7.Text = (programm.GetRegisterOhneBank(PICProgramm.ADDR_TRIS_B, 7) ? "i" : "o"); + if (btnWD1.Font.Bold != programm.WatchDog.Aktiviert) btnWD1.Font = new Font(btnWD1.Font, programm.WatchDog.Aktiviert ? FontStyle.Bold : FontStyle.Regular); + if (btnWD0.Font.Bold == programm.WatchDog.Aktiviert) btnWD0.Font = new Font(btnWD0.Font, programm.WatchDog.Aktiviert ? FontStyle.Regular : FontStyle.Bold); } private void box_CodeView_DoubleClick(object sender, EventArgs e) @@ -508,11 +513,13 @@ namespace PIC_Simulator private void btnRSConnect_Click(object sender, EventArgs e) { rs232.Connect(cbxComPorts.SelectedItem.ToString(), edRS232Log, programm, this); + OberflaecheAktualisieren(); } private void btnRSDisconnect_Click(object sender, EventArgs e) { rs232.Disconnect(); + OberflaecheAktualisieren(); } private void btnClockStart_Click(object sender, EventArgs e) @@ -522,21 +529,26 @@ namespace PIC_Simulator programm.TaktgeberZahler = 0; programm.TaktgeberAdresse = Convert.ToUInt32(edClockAddr.Text.Substring(2), 16); programm.TaktgeberBitnummer = uint.Parse(edClockBit.Text); + OberflaecheAktualisieren(); } private void button1_Click(object sender, EventArgs e) { programm.IsSleeping = false; //Kein WatchdogTimer implementiert, Sleep durch button deaktiviert - } + OberflaecheAktualisieren(); + } private void button1_Click_1(object sender, EventArgs e) { + programm.WatchDog.TimeOut = double.Parse(tbWD.Text, CultureInfo.InvariantCulture) / 1000d; programm.WatchDog.Aktiviert = true; + OberflaecheAktualisieren(); } private void button2_Click(object sender, EventArgs e) { programm.WatchDog.Aktiviert = false; + OberflaecheAktualisieren(); } } } diff --git a/PIC_Simulator/PIC/PICProgramm.cs b/PIC_Simulator/PIC/PICProgramm.cs index 7933865..2a30667 100644 --- a/PIC_Simulator/PIC/PICProgramm.cs +++ b/PIC_Simulator/PIC/PICProgramm.cs @@ -5,7 +5,7 @@ using System.Text.RegularExpressions; namespace PIC_Simulator.PIC { - class PICBefehl + public class PICBefehl { public string befehl; public uint parameter_d; @@ -19,7 +19,7 @@ namespace PIC_Simulator.PIC public int zeilennummer; } - class PICProgramm + public class PICProgramm { public const uint ADDR_INDF = 0x00; public const uint ADDR_TMR0 = 0x01; @@ -132,10 +132,10 @@ namespace PIC_Simulator.PIC public PICTimer Zaehler; public PICWatchDog WatchDog; - public PICProgramm() + public PICProgramm(Form1 f) { Zaehler = new PICTimer(this); - WatchDog = new PICWatchDog(this); + WatchDog = new PICWatchDog(this, f); // Anfangswerte @@ -233,7 +233,7 @@ namespace PIC_Simulator.PIC } } - if (IsSleeping) { WatchDog.Aktualisieren(1, frequenz); return false;} + if (IsSleeping) { WatchDog.Aktualisieren(1); return false;} uint cycleCount = 1; @@ -357,6 +357,7 @@ namespace PIC_Simulator.PIC if (Cond) { PCCounter++; // skip next + cycleCount = 2; } } else if (aktueller_befehl.befehl == INCF) @@ -406,6 +407,7 @@ namespace PIC_Simulator.PIC if (Cond) { PCCounter++; // skip next + cycleCount = 2; } } else if (aktueller_befehl.befehl == IORWF) @@ -594,6 +596,7 @@ namespace PIC_Simulator.PIC if (!GetBit(GetRegister(aktueller_befehl.parameter_f), aktueller_befehl.parameter_b)) { PCCounter++; + cycleCount = 2; } } else if (aktueller_befehl.befehl == BTFSS) @@ -607,6 +610,7 @@ namespace PIC_Simulator.PIC if (GetBit(GetRegister(aktueller_befehl.parameter_f), aktueller_befehl.parameter_b)) { PCCounter++; + cycleCount = 2; } } else if (aktueller_befehl.befehl == ADDLW) @@ -806,7 +810,7 @@ namespace PIC_Simulator.PIC Zaehler.TimerBerechnen(cycleCount); - WatchDog.Aktualisieren(cycleCount, frequenz); + WatchDog.Aktualisieren(cycleCount); return PCCounter >= befehle.Count; } diff --git a/PIC_Simulator/PIC/PICTimer.cs b/PIC_Simulator/PIC/PICTimer.cs index e2105d0..c9213e8 100644 --- a/PIC_Simulator/PIC/PICTimer.cs +++ b/PIC_Simulator/PIC/PICTimer.cs @@ -1,7 +1,7 @@  namespace PIC_Simulator.PIC { - class PICTimer + public class PICTimer { private PICProgramm programm; diff --git a/PIC_Simulator/PIC/PICWatchDog.cs b/PIC_Simulator/PIC/PICWatchDog.cs index 694e273..dfba0cd 100644 --- a/PIC_Simulator/PIC/PICWatchDog.cs +++ b/PIC_Simulator/PIC/PICWatchDog.cs @@ -1,31 +1,36 @@  namespace PIC_Simulator.PIC { - class PICWatchDog + public class PICWatchDog { private PICProgramm programm; - private const double TIME_OUT = 0.018; // 18ms; + public double TimeOut = 0.018; // ms; + + private const double FREQUENCY = 4000000d; // 4 MHz public uint Prescale = 1; - private double time; // in s + public double time; // in s public bool Aktiviert = false; - public PICWatchDog(PICProgramm p) + private Form1 form; + + public PICWatchDog(PICProgramm p, Form1 frm) { programm = p; time = 0; + form = frm; } - public void Aktualisieren(uint cycles, float frequenz) + public void Aktualisieren(uint cycles) { if (Aktiviert) { - time += (1.0 / frequenz) * cycles; + time += (1.0 / FREQUENCY) * cycles; - if (time > TIME_OUT * GetPreScale()) + if (time > TimeOut * GetPreScale()) { WDReset(); } @@ -46,6 +51,7 @@ namespace PIC_Simulator.PIC programm.Reset(); programm.SetRegisterOhneBank(PICProgramm.ADDR_STATUS, PICProgramm.STATUS_BIT_TO, false); + form.quartztimer.Stop(); } else { @@ -77,10 +83,5 @@ namespace PIC_Simulator.PIC { time = 0; } - - public double GetPerc() - { - return time / (TIME_OUT * Prescale); - } } } diff --git a/PIC_Simulator/PIC/RS232Verbindung.cs b/PIC_Simulator/PIC/RS232Verbindung.cs index 02fc258..68f463f 100644 --- a/PIC_Simulator/PIC/RS232Verbindung.cs +++ b/PIC_Simulator/PIC/RS232Verbindung.cs @@ -6,7 +6,7 @@ using System.Windows.Forms; namespace PIC_Simulator.PIC { - class RS232Verbindung + public class RS232Verbindung { private SerialPort ComPort; private PICProgramm Programm; diff --git a/Projektinformationen/Tabelle.txt b/Projektinformationen/Tabelle.txt index 1cf3800..289bccf 100644 --- a/Projektinformationen/Tabelle.txt +++ b/Projektinformationen/Tabelle.txt @@ -23,7 +23,7 @@ [ ] Testprogramm 7 (Interrupts) [ ] Testprogramm 9 (Sleep-Befehl) [X] Testprogramm 10 (PCL und PCLATH) -[ ] Testprogramm 11 (Watchdog, Vorteiler) +[X] Testprogramm 11 (Watchdog, Vorteiler) [ ] Testprogramm 12 (EEPROM) [ ] Zusätzliche eignene Features [ ] Vorzeitige Abgabe \ No newline at end of file