From 4eebfe825508861d2f847c6d6494a439a339ad6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Thu, 11 May 2017 11:58:44 +0200 Subject: [PATCH] externer taktgeber --- PIC_Simulator/Form1.Designer.cs | 57 ++++++++++++++++++++++++++++++++ PIC_Simulator/Form1.cs | 11 +++++- PIC_Simulator/PIC/PICProgramm.cs | 20 +++++++++-- Projektinformationen/Tabelle.txt | 2 +- 4 files changed, 86 insertions(+), 4 deletions(-) diff --git a/PIC_Simulator/Form1.Designer.cs b/PIC_Simulator/Form1.Designer.cs index 6c5d513..fcb7db6 100644 --- a/PIC_Simulator/Form1.Designer.cs +++ b/PIC_Simulator/Form1.Designer.cs @@ -106,6 +106,11 @@ this.cbxComPorts = new System.Windows.Forms.ComboBox(); this.btnRSConnect = new System.Windows.Forms.Button(); this.btnRSDisconnect = new System.Windows.Forms.Button(); + this.label6 = new System.Windows.Forms.Label(); + this.edClockAddr = new System.Windows.Forms.TextBox(); + this.edClockBit = new System.Windows.Forms.TextBox(); + this.btnClockStart = new System.Windows.Forms.Button(); + this.edCLockFreq = new System.Windows.Forms.TextBox(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -798,11 +803,58 @@ this.btnRSDisconnect.UseVisualStyleBackColor = true; this.btnRSDisconnect.Click += new System.EventHandler(this.btnRSDisconnect_Click); // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(915, 610); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(56, 13); + this.label6.TabIndex = 58; + this.label6.Text = "Taktgeber"; + // + // edClockAddr + // + this.edClockAddr.Location = new System.Drawing.Point(918, 626); + this.edClockAddr.Name = "edClockAddr"; + this.edClockAddr.Size = new System.Drawing.Size(64, 20); + this.edClockAddr.TabIndex = 59; + this.edClockAddr.Text = "0x20"; + // + // edClockBit + // + this.edClockBit.Location = new System.Drawing.Point(994, 626); + this.edClockBit.Name = "edClockBit"; + this.edClockBit.Size = new System.Drawing.Size(64, 20); + this.edClockBit.TabIndex = 60; + this.edClockBit.Text = "3"; + // + // btnClockStart + // + this.btnClockStart.Location = new System.Drawing.Point(1064, 626); + this.btnClockStart.Name = "btnClockStart"; + this.btnClockStart.Size = new System.Drawing.Size(49, 23); + this.btnClockStart.TabIndex = 61; + this.btnClockStart.Text = "Start"; + this.btnClockStart.UseVisualStyleBackColor = true; + this.btnClockStart.Click += new System.EventHandler(this.btnClockStart_Click); + // + // edCLockFreq + // + this.edCLockFreq.Location = new System.Drawing.Point(918, 652); + this.edCLockFreq.Name = "edCLockFreq"; + this.edCLockFreq.Size = new System.Drawing.Size(140, 20); + this.edCLockFreq.TabIndex = 62; + // // 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.edCLockFreq); + this.Controls.Add(this.btnClockStart); + this.Controls.Add(this.edClockBit); + this.Controls.Add(this.edClockAddr); + this.Controls.Add(this.label6); this.Controls.Add(this.btnRSDisconnect); this.Controls.Add(this.btnRSConnect); this.Controls.Add(this.cbxComPorts); @@ -948,6 +1000,11 @@ private System.Windows.Forms.ComboBox cbxComPorts; private System.Windows.Forms.Button btnRSConnect; private System.Windows.Forms.Button btnRSDisconnect; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.TextBox edClockAddr; + private System.Windows.Forms.TextBox edClockBit; + private System.Windows.Forms.Button btnClockStart; + private System.Windows.Forms.TextBox edCLockFreq; } } diff --git a/PIC_Simulator/Form1.cs b/PIC_Simulator/Form1.cs index 9c870a3..a57c591 100644 --- a/PIC_Simulator/Form1.cs +++ b/PIC_Simulator/Form1.cs @@ -142,7 +142,7 @@ namespace PIC_Simulator private void StepProgramm() { - bool finished = programm.Step(); + bool finished = programm.Step(int.Parse(insertTime.Text)); if (finished) { quartztimer.Stop(); MessageBox.Show("Finished"); return; } @@ -483,6 +483,15 @@ namespace PIC_Simulator { rs232.Disconnect(); } + + private void btnClockStart_Click(object sender, EventArgs e) + { + programm.TaktgeberAktiviert = !programm.TaktgeberAktiviert; + programm.TaktgeberFrequenz = int.Parse(edCLockFreq.Text); + programm.TaktgeberZahler = 0; + programm.TaktgeberAdresse = Convert.ToUInt32(edClockAddr.Text.Substring(2), 16); + programm.TaktgeberBitnummer = uint.Parse(edClockBit.Text); + } } } diff --git a/PIC_Simulator/PIC/PICProgramm.cs b/PIC_Simulator/PIC/PICProgramm.cs index a741479..ba0f1f8 100644 --- a/PIC_Simulator/PIC/PICProgramm.cs +++ b/PIC_Simulator/PIC/PICProgramm.cs @@ -116,7 +116,13 @@ namespace PIC_Simulator.PIC public Stack Stack = new Stack(); public bool IsSleeping = false; - public List Breakpoints = new List(); + public List Breakpoints = new List(); + + public int TaktgeberFrequenz = 100000; + public int TaktgeberZahler = 100000; + public bool TaktgeberAktiviert = false; + public uint TaktgeberAdresse = 0; + public uint TaktgeberBitnummer = 0; public PICProgramm() { @@ -210,12 +216,22 @@ namespace PIC_Simulator.PIC return binaryval; } - public bool Step() + public bool Step(int frequenz) { if (PCCounter >= befehle.Count) return true; PICBefehl aktueller_befehl = befehle[PCCounter]; + if (TaktgeberAktiviert) + { + TaktgeberZahler += frequenz; + if (TaktgeberZahler > TaktgeberFrequenz) + { + TaktgeberZahler = 0; + SetRegisterOhneBank(TaktgeberAdresse, TaktgeberBitnummer, !GetRegisterOhneBank(TaktgeberAdresse, TaktgeberBitnummer)); + } + } + if (IsSleeping) return false; if (aktueller_befehl.befehl == ADDWF) diff --git a/Projektinformationen/Tabelle.txt b/Projektinformationen/Tabelle.txt index e8f7fb8..46cc0cf 100644 --- a/Projektinformationen/Tabelle.txt +++ b/Projektinformationen/Tabelle.txt @@ -19,7 +19,7 @@ [ ] Testprogramm 5 (Bitbefehle) [ ] Testprogramm 6 (indirekte Adressierung) [ ] Testprogramm 7 (Timer 0 ) -[ ] Ext. Taktgeber an RA4 + IO-Pin +[X] Ext. Taktgeber an RA4 + IO-Pin [ ] Testprogramm 7 (Interrupts) [ ] Testprogramm 9 (Sleep-Befehl) [ ] Tetstprogramm 10 (PCL und PCLATH)