Basic program operations [PICProgramm.cs]

This commit is contained in:
Mike Schwörer 2017-05-10 12:00:41 +02:00
parent fd747d6c87
commit 65864ecd4e
40 changed files with 3740 additions and 3545 deletions

View File

@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PIC_Simulator
{
class Befehlssatz
{
}
}

View File

@ -1,68 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace PIC_Simulator
{
public class Einlesen
{
//Globale Variablen der Klasse:
public int LengthArray = 0;
public string[] result;
public int writeToArray(StreamReader sr)
{
// StreamReader jede Zeile in Listenelement schreiben
var list = new List<string>();
string line;
while ((line = sr.ReadLine()) != null)
{ if (!line.StartsWith(" ") )
{
list.Add(line);
}
}
//Schreiben der Listenelemente in String Array
result = list.ToArray();
LengthArray = result.Length -1; //-1 Wegen Start des Arrays bei Index 0!
// MessageBox.Show("Zeilen des Programms:" + LengthArray );
//PCount Variable von Form1 holen und für readExec als Param nutzen
Form1 instForm1 = new Form1();
readExecCode(instForm1.PCounter);
return LengthArray;
}
//Ausführbarer Maschinencode aus Zeile des Arrays herausschneiden
public void readExecCode(int index) {
try
{
result[index] = result[index].Substring(5, 4);
// MessageBox.Show(result[index]);
execCode(index);
}
catch { }
}
public string execCode(int index) {
// MessageBox.Show("Index der Row welche ausgeführt werden soll" + index);
MessageBox.Show("Code der ausgeführt werden soll" + result[index]);
Register Ausführen = new Register();
Ausführen.findOrder(result[index].ToString());
return result[index];
// Hier ist der Start für die Befehlsausführung des PIC bzw. Übergabe an Befehlssatz
// Return übergibt Auszuführenden Code!!
}
}
}

View File

@ -46,7 +46,6 @@
this.hilfeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.cmdOpenDoc = new System.Windows.Forms.ToolStripMenuItem();
this.label4 = new System.Windows.Forms.Label();
this.cmdSetClock = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
@ -67,27 +66,29 @@
//
this.label1.AutoSize = true;
this.label1.BackColor = System.Drawing.SystemColors.Control;
this.label1.Location = new System.Drawing.Point(39, 96);
this.label1.Location = new System.Drawing.Point(29, 78);
this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(0, 17);
this.label1.Size = new System.Drawing.Size(0, 13);
this.label1.TabIndex = 1;
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(11, 577);
this.label2.Location = new System.Drawing.Point(8, 469);
this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(105, 17);
this.label2.Size = new System.Drawing.Size(78, 13);
this.label2.TabIndex = 2;
this.label2.Text = "Programmpfad:";
//
// box_CodeView
//
this.box_CodeView.Location = new System.Drawing.Point(11, 95);
this.box_CodeView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.box_CodeView.Location = new System.Drawing.Point(8, 77);
this.box_CodeView.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.box_CodeView.Name = "box_CodeView";
this.box_CodeView.Size = new System.Drawing.Size(833, 462);
this.box_CodeView.ReadOnly = true;
this.box_CodeView.Size = new System.Drawing.Size(626, 376);
this.box_CodeView.TabIndex = 3;
this.box_CodeView.Text = "";
this.box_CodeView.WordWrap = false;
@ -95,9 +96,10 @@
// lbl_path
//
this.lbl_path.AutoSize = true;
this.lbl_path.Location = new System.Drawing.Point(116, 577);
this.lbl_path.Location = new System.Drawing.Point(87, 469);
this.lbl_path.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_path.Name = "lbl_path";
this.lbl_path.Size = new System.Drawing.Size(0, 17);
this.lbl_path.Size = new System.Drawing.Size(0, 13);
this.lbl_path.TabIndex = 4;
//
// openFileDialog1
@ -106,10 +108,10 @@
//
// cmd_Start
//
this.cmd_Start.Location = new System.Drawing.Point(15, 36);
this.cmd_Start.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.cmd_Start.Location = new System.Drawing.Point(11, 29);
this.cmd_Start.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.cmd_Start.Name = "cmd_Start";
this.cmd_Start.Size = new System.Drawing.Size(67, 28);
this.cmd_Start.Size = new System.Drawing.Size(50, 23);
this.cmd_Start.TabIndex = 5;
this.cmd_Start.Text = "Start";
this.cmd_Start.UseVisualStyleBackColor = true;
@ -117,10 +119,10 @@
//
// cmd_next
//
this.cmd_next.Location = new System.Drawing.Point(168, 38);
this.cmd_next.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.cmd_next.Location = new System.Drawing.Point(126, 31);
this.cmd_next.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.cmd_next.Name = "cmd_next";
this.cmd_next.Size = new System.Drawing.Size(67, 26);
this.cmd_next.Size = new System.Drawing.Size(50, 21);
this.cmd_next.TabIndex = 6;
this.cmd_next.Text = "Schritt";
this.cmd_next.UseVisualStyleBackColor = true;
@ -128,10 +130,10 @@
//
// cmd_reset
//
this.cmd_reset.Location = new System.Drawing.Point(253, 38);
this.cmd_reset.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.cmd_reset.Location = new System.Drawing.Point(190, 31);
this.cmd_reset.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.cmd_reset.Name = "cmd_reset";
this.cmd_reset.Size = new System.Drawing.Size(67, 26);
this.cmd_reset.Size = new System.Drawing.Size(50, 21);
this.cmd_reset.TabIndex = 7;
this.cmd_reset.Text = "Reset";
this.cmd_reset.UseVisualStyleBackColor = true;
@ -140,9 +142,10 @@
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(331, 42);
this.label3.Location = new System.Drawing.Point(248, 34);
this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(112, 17);
this.label3.Size = new System.Drawing.Size(82, 13);
this.label3.TabIndex = 8;
this.label3.Text = "Programmzähler";
//
@ -154,8 +157,8 @@
this.hilfeToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2);
this.menuStrip1.Size = new System.Drawing.Size(1397, 28);
this.menuStrip1.Padding = new System.Windows.Forms.Padding(4, 2, 0, 2);
this.menuStrip1.Size = new System.Drawing.Size(1048, 24);
this.menuStrip1.TabIndex = 9;
this.menuStrip1.Text = "menuStrip1";
//
@ -165,20 +168,20 @@
this.programmÖffnenToolStripMenuItem,
this.beendenToolStripMenuItem});
this.cmdOpenFile.Name = "cmdOpenFile";
this.cmdOpenFile.Size = new System.Drawing.Size(57, 24);
this.cmdOpenFile.Size = new System.Drawing.Size(46, 20);
this.cmdOpenFile.Text = "Datei";
//
// programmÖffnenToolStripMenuItem
//
this.programmÖffnenToolStripMenuItem.Name = "programmÖffnenToolStripMenuItem";
this.programmÖffnenToolStripMenuItem.Size = new System.Drawing.Size(201, 26);
this.programmÖffnenToolStripMenuItem.Size = new System.Drawing.Size(169, 22);
this.programmÖffnenToolStripMenuItem.Text = "Programm öffnen";
this.programmÖffnenToolStripMenuItem.Click += new System.EventHandler(this.programmÖffnenToolStripMenuItem_Click);
//
// beendenToolStripMenuItem
//
this.beendenToolStripMenuItem.Name = "beendenToolStripMenuItem";
this.beendenToolStripMenuItem.Size = new System.Drawing.Size(201, 26);
this.beendenToolStripMenuItem.Size = new System.Drawing.Size(169, 22);
this.beendenToolStripMenuItem.Text = "Beenden";
this.beendenToolStripMenuItem.Click += new System.EventHandler(this.beendenToolStripMenuItem_Click);
//
@ -187,36 +190,26 @@
this.hilfeToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.cmdOpenDoc});
this.hilfeToolStripMenuItem.Name = "hilfeToolStripMenuItem";
this.hilfeToolStripMenuItem.Size = new System.Drawing.Size(53, 24);
this.hilfeToolStripMenuItem.Size = new System.Drawing.Size(44, 20);
this.hilfeToolStripMenuItem.Text = "Hilfe";
//
// cmdOpenDoc
//
this.cmdOpenDoc.Name = "cmdOpenDoc";
this.cmdOpenDoc.Size = new System.Drawing.Size(234, 26);
this.cmdOpenDoc.Size = new System.Drawing.Size(195, 22);
this.cmdOpenDoc.Text = "Dokumentation öffnen";
this.cmdOpenDoc.Click += new System.EventHandler(this.cmdOpenDoc_Click);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(1038, 36);
this.label4.Location = new System.Drawing.Point(778, 29);
this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(129, 17);
this.label4.Size = new System.Drawing.Size(95, 13);
this.label4.TabIndex = 10;
this.label4.Text = "Quarzfrequenz in s";
//
// cmdSetClock
//
this.cmdSetClock.Location = new System.Drawing.Point(1273, 34);
this.cmdSetClock.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.cmdSetClock.Name = "cmdSetClock";
this.cmdSetClock.Size = new System.Drawing.Size(67, 24);
this.cmdSetClock.TabIndex = 11;
this.cmdSetClock.Text = "setzen";
this.cmdSetClock.UseVisualStyleBackColor = true;
this.cmdSetClock.Click += new System.EventHandler(this.cmdSetClock_Click);
//
// timer1
//
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
@ -234,10 +227,10 @@
this.columnHeader8});
this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
listViewItem2});
this.listView1.Location = new System.Drawing.Point(906, 95);
this.listView1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.listView1.Location = new System.Drawing.Point(680, 77);
this.listView1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(434, 350);
this.listView1.Size = new System.Drawing.Size(326, 285);
this.listView1.TabIndex = 14;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details;
@ -277,10 +270,10 @@
//
// cmd_Stop
//
this.cmd_Stop.Location = new System.Drawing.Point(85, 37);
this.cmd_Stop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.cmd_Stop.Location = new System.Drawing.Point(64, 30);
this.cmd_Stop.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.cmd_Stop.Name = "cmd_Stop";
this.cmd_Stop.Size = new System.Drawing.Size(67, 27);
this.cmd_Stop.Size = new System.Drawing.Size(50, 22);
this.cmd_Stop.TabIndex = 15;
this.cmd_Stop.Text = "Stop";
this.cmd_Stop.UseVisualStyleBackColor = true;
@ -289,30 +282,31 @@
// lbl_Timer
//
this.lbl_Timer.AutoSize = true;
this.lbl_Timer.Location = new System.Drawing.Point(940, 34);
this.lbl_Timer.Location = new System.Drawing.Point(705, 28);
this.lbl_Timer.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lbl_Timer.Name = "lbl_Timer";
this.lbl_Timer.Size = new System.Drawing.Size(44, 17);
this.lbl_Timer.Size = new System.Drawing.Size(33, 13);
this.lbl_Timer.TabIndex = 16;
this.lbl_Timer.Text = "Timer";
//
// insertTime
//
this.insertTime.Location = new System.Drawing.Point(1192, 38);
this.insertTime.Location = new System.Drawing.Point(894, 31);
this.insertTime.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.insertTime.Name = "insertTime";
this.insertTime.Size = new System.Drawing.Size(61, 22);
this.insertTime.Size = new System.Drawing.Size(47, 20);
this.insertTime.TabIndex = 17;
this.insertTime.Text = "100";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1397, 600);
this.ClientSize = new System.Drawing.Size(1048, 488);
this.Controls.Add(this.insertTime);
this.Controls.Add(this.lbl_Timer);
this.Controls.Add(this.cmd_Stop);
this.Controls.Add(this.listView1);
this.Controls.Add(this.cmdSetClock);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.cmd_reset);
@ -324,7 +318,7 @@
this.Controls.Add(this.label1);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "PIC Simulator";
@ -352,7 +346,6 @@
private System.Windows.Forms.ToolStripMenuItem hilfeToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem cmdOpenDoc;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button cmdSetClock;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;

View File

@ -1,152 +1,86 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using PIC_Simulator.PIC;
using PIC_Simulator.Properties;
using System;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using PIC_Simulator;
using System.Windows.Forms;
namespace PIC_Simulator
{
public partial class Form1 : Form
{
private PICProgramm programm;
private Timer quartztimer = new Timer();
public Form1()
{
InitializeComponent();
}
// Globale Variablen
public int ArrayLaenge =0;
public int PCounter = -1;
public int time;
public int timeIntervall;
Einlesen instEinlesen = new Einlesen();
private void label1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
box_CodeView.Font = new Font("Consolas", 8);
timeIntervall = 1000;
box_CodeView.Text = Resources.TPicSim1;
programm = new PICProgramm();
programm.Laden(Resources.TPicSim1);
}
private void cmd_Start_Click(object sender, EventArgs e)
{
timer1.Interval = timeIntervall; // 1 Sekunde
timer1.Enabled = true;
quartztimer.Stop();
quartztimer.Interval = int.Parse(insertTime.Text);
quartztimer.Start();
}
private void cmd_next_Click(object sender, EventArgs e)
{
// MessageBox.Show("Array laenge übergeben:" + ArrayLaenge);
if (PCounter == ArrayLaenge) { MessageBox.Show("Programm ist komplett durchlaufen!"); }
else {
PCounter = PCounter + 1;
try
{
//Zeilenmarkierung aufheben
highLightALine(box_CodeView, PCounter - 1, Color.White);
}
catch { }
//Counter im Label inkrementieren
int shownCounter = PCounter;
shownCounter++;
label3.Text = shownCounter.ToString();
}
//Aktuelle Zeile markieren
highLightALine(box_CodeView, PCounter, Color.Green);
instEinlesen.readExecCode(PCounter);
}
private int getPCounter() {
return PCounter;
StepProgramm();
}
private void programmÖffnenToolStripMenuItem_Click(object sender, EventArgs e)
{
// Datei über openFileDialog1 Auswählen und in Anzeige öffnen
FileStream fs;
StreamReader sr;
string zeile;
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
sr = new
StreamReader(openFileDialog1.FileName);
DialogResult = MessageBox.Show(sr.ReadToEnd(), "Programm Vorschau", MessageBoxButtons.OKCancel);
sr.Close();
// Abfrage von Ergebnis des Dialogs, wenn ja Datei laden
if (DialogResult == DialogResult.OK)
{
fs = new FileStream(openFileDialog1.FileName, FileMode.Open);
sr = new StreamReader(fs);
string datei = File.ReadAllText(openFileDialog1.FileName);
while (sr.Peek() != -1)
{
zeile = sr.ReadLine();
box_CodeView.Text += zeile + "\n";
}
sr.Close();
lbl_path.Text = openFileDialog1.FileName;
// StreamReader jede Zeile in Listenelement schreiben über Funktionsaufruf in der Klasse Einlesen
ArrayLaenge = instEinlesen.writeToArray(sr = new StreamReader(openFileDialog1.FileName));
}
box_CodeView.Text = datei;
programm = new PICProgramm();
programm.Laden(datei);
}
}
private void cmdOpenDoc_Click(object sender, EventArgs e)
{
string path = Application.StartupPath;
MessageBox.Show( path);
System.Diagnostics.Process.Start(@"C:\Users\nicol\Desktop\Projekte\PIC_Simulator\Projektinformationen\DataSheet.pdf");
string path = Path.GetTempFileName() + ".pdf";
File.WriteAllBytes(path, Resources.DataSheet);
System.Diagnostics.Process.Start(path);
}
//Funktion um Zeile aktuell ausgeführte Zeile zu markieren
void highLightALine(RichTextBox rtb, int line, Color hiLight)
void Highlight(int line)
{
int i1 = rtb.GetFirstCharIndexFromLine(line);
int i2 = rtb.GetFirstCharIndexFromLine(line + 1);
if (i2 < 0) i2 = rtb.Text.Length;
rtb.SelectionStart = i1;
rtb.SelectionLength = i2 - i1;
rtb.SelectionBackColor = hiLight;
int i1 = box_CodeView.GetFirstCharIndexFromLine(line);
int i2 = box_CodeView.GetFirstCharIndexFromLine(line + 1);
if (i2 < 0 || i1 < 0)
{
box_CodeView.SelectionColor = Color.Transparent;
}
private void cmdSetClock_Click(object sender, EventArgs e)
else
{
timeIntervall = Convert.ToInt32(insertTime.Text);
box_CodeView.SelectionStart = i1;
box_CodeView.SelectionLength = i2 - i1;
box_CodeView.SelectionBackColor = Color.SteelBlue;
}
}
private void cmd_reset_Click(object sender, EventArgs e)
{ //######################### Muss ergänzt und getestet werden !!!
// Hier müssen alle Werte wieder auf den Standard gesetzt werden!
highLightALine(box_CodeView, PCounter, Color.White);
PCounter = -1;
label3.Text = PCounter.ToString();
//######################### Muss ergänzt und getestet werden !!!
}
private void buildtbl_Register() {
{
//TODO
}
private void beendenToolStripMenuItem_Click(object sender, EventArgs e)
@ -156,18 +90,22 @@ namespace PIC_Simulator
private void timer1_Tick(object sender, EventArgs e)
{
Einlesen QuarzExec = new Einlesen();
PCounter = PCounter + 1;
label3.Text = PCounter.ToString();
StepProgramm();
}
private void cmd_Stop_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
quartztimer.Stop();
}
private void StepProgramm()
{
bool finished = programm.Step();
if (finished) { quartztimer.Stop(); return; }
Highlight(programm.befehle[programm.PCCounter].zeilennummer);
}
}
}

View File

@ -0,0 +1,646 @@

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace PIC_Simulator.PIC
{
class PICBefehl
{
public string befehl;
public uint parameter_d;
public uint parameter_f;
public uint parameter_x;
public uint parameter_k;
public uint parameter_b;
public int zeilennummer;
}
class PICProgramm
{
public const uint ADDR_INDF = 0x00;
public const uint ADDR_TMR0 = 0x01;
public const uint ADDR_PCL = 0x02;
public const uint ADDR_STATUS = 0x03;
public const uint ADDR_FSR = 0x04;
public const uint ADDR_PORT_A = 0x05;
public const uint ADDR_PORT_B = 0x06;
public const uint ADDR_UNIMPL_A = 0x07;
public const uint ADDR_PCLATH = 0x0A;
public const uint ADDR_INTCON = 0x0B;
public const uint ADDR_OPTION = 0x81;
public const uint ADDR_TRIS_A = 0x85;
public const uint ADDR_TRIS_B = 0x86;
public const uint ADDR_UNIMPL_B = 0x87;
public const uint ADDR_EECON1 = 0x88;
public const uint ADDR_EECON2 = 0x89;
public const uint STATUS_BIT_IRP = 7; // Unused in PIC16C84
public const uint STATUS_BIT_RP1 = 6; // Register Bank Selection Bit [1] (Unused in PIC16C84)
public const uint STATUS_BIT_RP0 = 5; // Register Bank Selection Bit [0]
public const uint STATUS_BIT_TO = 4; // Time Out Bit
public const uint STATUS_BIT_PD = 3; // Power Down Bit
public const uint STATUS_BIT_Z = 2; // Zero Bit
public const uint STATUS_BIT_DC = 1; // Digit Carry Bit
public const uint STATUS_BIT_C = 0; // Carry Bit
public const uint OPTION_BIT_RBPU = 7; // PORT-B Pull-Up Enable Bit
public const uint OPTION_BIT_INTEDG = 6; // Interrupt Edge Select Bit
public const uint OPTION_BIT_T0CS = 5; // TMR0 Clock Source Select Bit
public const uint OPTION_BIT_T0SE = 4; // TMR0 Source Edge Select Bit
public const uint OPTION_BIT_PSA = 3; // Prescaler Alignment Bit
public const uint OPTION_BIT_PS2 = 2; // Prescaler Rate Select Bit [2]
public const uint OPTION_BIT_PS1 = 1; // Prescaler Rate Select Bit [1]
public const uint OPTION_BIT_PS0 = 0; // Prescaler Rate Select Bit [0]
public const uint INTCON_BIT_GIE = 7; // Global Interrupt Enable Bit
public const uint INTCON_BIT_EEIE = 6; // EE Write Complete Interrupt Enable Bit
public const uint INTCON_BIT_T0IE = 5; // TMR0 Overflow Interrupt Enable Bit
public const uint INTCON_BIT_INTE = 4; // RB0/INT Interrupt Bit
public const uint INTCON_BIT_RBIE = 3; // RB Port Change Interrupt Enable Bit
public const uint INTCON_BIT_T0IF = 2; // TMR0 Overflow Interrupt Flag Bit
public const uint INTCON_BIT_INTF = 1; // RB0/INT Interrupt Flag Bit
public const uint INTCON_BIT_RBIF = 0; // RB Port Change Interrupt Flag Bit
public const string ADDWF = "000111dfffffff";
public const string ANDWF = "000101dfffffff";
public const string CLRF = "0000011fffffff";
public const string CLRW = "0000010xxxxxxx";
public const string COMF = "001001dfffffff";
public const string DECF = "000011dfffffff";
public const string DECFSZ = "001011dfffffff";
public const string INCF = "001010dfffffff";
public const string INCFSZ = "001111dfffffff";
public const string IORWF = "000100dfffffff";
public const string MOVF = "001000dfffffff";
public const string MOVWF = "0000001fffffff";
public const string NOP = "0000000xx00000";
public const string RLF = "001101dfffffff";
public const string RRF = "001100dfffffff";
public const string SUBWF = "000010dfffffff";
public const string SWAPF = "001110dfffffff";
public const string XORWF = "000110dfffffff";
public const string BCF = "0100bbbfffffff";
public const string BSF = "0101bbbfffffff";
public const string BTFSC = "0110bbbfffffff";
public const string BTFSS = "0111bbbfffffff";
public const string ADDLW = "11111xkkkkkkkk";
public const string ANDLW = "111001kkkkkkkk";
public const string CALL = "100kkkkkkkkkkk";
public const string CLRWDT = "00000001100100";
public const string GOTO = "101kkkkkkkkkkk";
public const string IORLW = "111000kkkkkkkk";
public const string MOVLW = "1100xxkkkkkkkk";
public const string RETFIE = "00000000001001";
public const string RETLW = "1101xxkkkkkkkk";
public const string RETURN = "00000000001000";
public const string SLEEP = "00000001100011";
public const string SUBLW = "11110xkkkkkkkk";
public const string XORLW = "111010kkkkkkkk";
public string[] ALL_COMMANDS = {ADDWF, ANDWF, CLRF, CLRW, COMF, DECF, DECFSZ, INCF, INCFSZ, IORWF, MOVF, MOVWF, NOP, RLF, RRF, SUBWF, SWAPF, XORWF, BCF, BSF, BTFSC, BTFSS, ADDLW, ANDLW, CALL, CLRWDT, GOTO, IORLW, MOVLW, RETFIE, RETLW, RETURN, SLEEP, SUBLW, XORLW };
public List<PICBefehl> befehle;
public int PCCounter = 0; // -> nächster befehl
public uint Register_W = 0;
public uint[] Register = new uint[0x100];
public PICProgramm()
{
}
public void Laden(string code)
{
befehle = new List<PICBefehl>();
int zn = 0;
foreach (var zeile in Regex.Split(code, @"\r?\n"))
{
zn++;
if (zeile.StartsWith(" ")) continue;
if (zeile.Length < 10) continue;
befehle.Add(FindeBefehl(zeile, zn));
}
}
private PICBefehl FindeBefehl(string zeile, int zeilennummer)
{
foreach (var cmd in ALL_COMMANDS)
{
string bin = hex2binary(zeile.Substring(5, 4));
uint p_d = 0;
uint p_f = 0;
uint p_x = 0;
uint p_k = 0;
uint p_b = 0;
bool ok = true;
for (int i = 0; i < 14; i++)
{
if (cmd[i] == '0' && bin[i] == '0') continue;
if (cmd[i] == '1' && bin[i] == '1') continue;
if (cmd[i] == 'd' && bin[i] == '0') { p_d <<= 1; p_d |= 0; continue; }
if (cmd[i] == 'd' && bin[i] == '1') { p_d <<= 1; p_d |= 1; continue; }
if (cmd[i] == 'f' && bin[i] == '0') { p_f <<= 1; p_f |= 0; continue; }
if (cmd[i] == 'f' && bin[i] == '1') { p_f <<= 1; p_f |= 1; continue; }
if (cmd[i] == 'x' && bin[i] == '0') { p_x <<= 1; p_x |= 0; continue; }
if (cmd[i] == 'x' && bin[i] == '1') { p_x <<= 1; p_x |= 1; continue; }
if (cmd[i] == 'k' && bin[i] == '0') { p_k <<= 1; p_k |= 0; continue; }
if (cmd[i] == 'k' && bin[i] == '1') { p_k <<= 1; p_k |= 1; continue; }
if (cmd[i] == 'b' && bin[i] == '0') { p_b <<= 1; p_b |= 0; continue; }
if (cmd[i] == 'b' && bin[i] == '1') { p_b <<= 1; p_b |= 1; continue; }
if (cmd[i] == '0' && bin[i] == '1') { ok = false; break; }
if (cmd[i] == '1' && bin[i] == '0') { ok = false; continue; }
throw new Exception("Falscher wert in cmd");
}
if (ok)
{
PICBefehl b = new PICBefehl();
b.befehl = cmd;
b.parameter_d = p_d;
b.parameter_f = p_f;
b.parameter_k = p_k;
b.parameter_x = p_x;
b.parameter_b = p_b;
b.zeilennummer = zeilennummer;
return b;
}
}
throw new Exception("konnte befehl nicht finden: " + zeile);
}
private string hex2binary(string hexvalue)
{
string binaryval = "";
binaryval = Convert.ToString(Convert.ToInt32(hexvalue, 16), 2).PadLeft(14, '0');
return binaryval;
}
public bool Step()
{
if (PCCounter >= befehle.Count) return true;
PICBefehl aktueller_befehl = befehle[PCCounter];
if (aktueller_befehl.befehl == ADDWF)
{
uint a = GetRegister(aktueller_befehl.parameter_f);
uint b = Register_W;
uint Result = a + b;
bool dc = AdditionDigitCarry(a, b);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, (Result % 0x100) == 0);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_DC, dc);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_C, Result > 0xFF);
Result %= 0x100;
if (aktueller_befehl.parameter_d != 0)
SetRegister(aktueller_befehl.parameter_f, Result);
else
Register_W = Result;
}
else if (aktueller_befehl.befehl == ANDWF)
{
uint Result = Register_W & GetRegister(aktueller_befehl.parameter_f);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, Result == 0);
if (aktueller_befehl.parameter_d != 0)
SetRegister(aktueller_befehl.parameter_f, Result);
else
Register_W = Result;
}
else if (aktueller_befehl.befehl == CLRF)
{
SetRegister(aktueller_befehl.parameter_f, 0x00);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, true);
}
else if (aktueller_befehl.befehl == CLRW)
{
Register_W = 0;
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, true);
}
else if (aktueller_befehl.befehl == COMF)
{
uint Result = ~GetRegister(aktueller_befehl.parameter_f);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, Result == 0);
if (aktueller_befehl.parameter_d != 0)
SetRegister(aktueller_befehl.parameter_f, Result);
else
Register_W = Result;
}
else if (aktueller_befehl.befehl == DECF)
{
uint Result = GetRegister(aktueller_befehl.parameter_f);
if (Result == 0)
Result = 0xFF;
else
Result -= 1;
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, Result == 0);
if (aktueller_befehl.parameter_d != 0)
SetRegister(aktueller_befehl.parameter_f, Result);
else
Register_W = Result;
}
else if (aktueller_befehl.befehl == DECFSZ)
{
bool Cond = GetRegister(aktueller_befehl.parameter_f) == 1;
uint Result = GetRegister(aktueller_befehl.parameter_f);
if (Result == 0)
Result = 0xFF;
else
Result -= 1;
if (aktueller_befehl.parameter_d != 0)
SetRegister(aktueller_befehl.parameter_f, Result);
else
Register_W = Result;
if (Cond)
{
PCCounter++; // skip next
}
}
else if (aktueller_befehl.befehl == INCF)
{
uint Result = GetRegister(aktueller_befehl.parameter_f);
Result += 1;
Result %= 0x100;
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, Result == 0);
if (aktueller_befehl.parameter_d != 0)
SetRegister(aktueller_befehl.parameter_f, Result);
else
Register_W = Result;
}
else if (aktueller_befehl.befehl == INCFSZ)
{
bool Cond = GetRegister(aktueller_befehl.parameter_f) == 0xFF;
uint Result = GetRegister(aktueller_befehl.parameter_f);
Result += 1;
Result %= 0x100;
if (aktueller_befehl.parameter_d != 0)
SetRegister(aktueller_befehl.parameter_f, Result);
else
Register_W = Result;
if (Cond)
{
PCCounter++; // skip next
}
}
else if (aktueller_befehl.befehl == IORWF)
{
uint Result = Register_W | GetRegister(aktueller_befehl.parameter_f);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, Result == 0);
if (aktueller_befehl.parameter_d != 0)
SetRegister(aktueller_befehl.parameter_f, Result);
else
Register_W = Result;
}
else if (aktueller_befehl.befehl == MOVF)
{
uint Result = GetRegister(aktueller_befehl.parameter_f);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, Result == 0);
if (aktueller_befehl.parameter_d != 0)
SetRegister(aktueller_befehl.parameter_f, Result);
else
Register_W = Result;
}
else if (aktueller_befehl.befehl == MOVWF)
{
SetRegister(aktueller_befehl.parameter_f, Register_W);
}
else if (aktueller_befehl.befehl == NOP)
{
// ~~~~~
}
else if (aktueller_befehl.befehl == RLF)
{
uint Result = GetRegister(aktueller_befehl.parameter_f);
uint Carry_Old = GetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_C) ? 1u : 0u;
uint Carry_New = (Result & 0x80) >> 7;
Result = Result << 1;
Result &= 0xFF;
Result |= Carry_Old;
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_C, Carry_New != 0);
if (aktueller_befehl.parameter_d != 0)
SetRegister(aktueller_befehl.parameter_f, Result);
else
Register_W = Result;
}
else if (aktueller_befehl.befehl == RRF)
{
uint Result = GetRegister(aktueller_befehl.parameter_f);
uint Carry_Old = GetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_C) ? 0x80u : 0x00u;
uint Carry_New = Result & 0x01;
Result = Result >> 1;
Result &= 0xFF;
Result |= Carry_Old;
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_C, Carry_New != 0);
if (aktueller_befehl.parameter_d != 0)
SetRegister(aktueller_befehl.parameter_f, Result);
else
Register_W = Result;
}
else if (aktueller_befehl.befehl == SUBWF)
{
uint a = GetRegister(aktueller_befehl.parameter_f);
uint b = Register_W;
bool carry;
bool dc = SubtractionDigitCarry(a, b);
if (carry = a < b)
{
a += 0x100;
}
uint Result = a - b;
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, (Result % 0x100) == 0);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_DC, dc);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_C, !carry);
Result %= 0x100;
if (aktueller_befehl.parameter_d != 0)
SetRegister(aktueller_befehl.parameter_f, Result);
else
Register_W = Result;
}
else if (aktueller_befehl.befehl == SWAPF)
{
uint Result = GetRegister(aktueller_befehl.parameter_f);
uint Low = Result & 0x0F;
uint High = Result & 0xF0;
Result = (Low << 4) | (High >> 4);
if (aktueller_befehl.parameter_d != 0)
SetRegister(aktueller_befehl.parameter_f, Result);
else
Register_W = Result;
}
else if (aktueller_befehl.befehl == XORWF)
{
uint Result = Register_W ^ GetRegister(aktueller_befehl.parameter_f);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, Result == 0);
if (aktueller_befehl.parameter_d != 0)
SetRegister(aktueller_befehl.parameter_f, Result);
else
Register_W = Result;
}
else if (aktueller_befehl.befehl == BCF)
{
SetRegister(aktueller_befehl.parameter_f, aktueller_befehl.parameter_b, false);
}
else if (aktueller_befehl.befehl == BSF)
{
SetRegister(aktueller_befehl.parameter_f, aktueller_befehl.parameter_b, true);
}
else if (aktueller_befehl.befehl == BTFSC)
{
if (!GetBit(GetRegister(aktueller_befehl.parameter_f), aktueller_befehl.parameter_b))
{
PCCounter++;
}
}
else if (aktueller_befehl.befehl == BTFSS)
{
if (GetBit(GetRegister(aktueller_befehl.parameter_f), aktueller_befehl.parameter_b))
{
PCCounter++;
}
}
else if (aktueller_befehl.befehl == ADDLW)
{
uint a = Register_W;
uint b = aktueller_befehl.parameter_k;
uint Result = a + b;
bool dc = AdditionDigitCarry(a, b);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, (Result % 0x100) == 0);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_DC, dc);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_C, Result > 0xFF);
Result %= 0x100;
Register_W = Result;
}
else if (aktueller_befehl.befehl == ANDLW)
{
uint Result = Register_W & aktueller_befehl.parameter_k;
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, Result == 0);
Register_W = Result;
}
else if (aktueller_befehl.befehl == CALL)
{
//TODO
}
else if (aktueller_befehl.befehl == CLRWDT)
{
//TODO
}
else if (aktueller_befehl.befehl == GOTO)
{
//TODO
}
else if (aktueller_befehl.befehl == IORLW)
{
uint Result = Register_W | aktueller_befehl.parameter_k;
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, Result == 0);
Register_W = Result;
}
else if (aktueller_befehl.befehl == MOVLW)
{
Register_W = aktueller_befehl.parameter_k;
}
else if (aktueller_befehl.befehl == RETFIE)
{
//TODO
}
else if (aktueller_befehl.befehl == RETLW)
{
//TODO
}
else if (aktueller_befehl.befehl == RETURN)
{
//TODO
}
else if (aktueller_befehl.befehl == SLEEP)
{
//TODO
}
else if (aktueller_befehl.befehl == SUBLW)
{
uint a = aktueller_befehl.parameter_k;
uint b = Register_W;
bool carry;
bool dc = SubtractionDigitCarry(a, b);
if (carry = a < b)
{
a += 0x100;
}
uint Result = a - b;
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, (Result % 0x100) == 0);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_DC, dc);
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_C, !carry);
Result %= 0x100;
Register_W = Result;
}
else if (aktueller_befehl.befehl == XORLW)
{
uint Result = Register_W ^ aktueller_befehl.parameter_k;
SetRegisterOhneBank(ADDR_STATUS, STATUS_BIT_Z, Result == 0);
Register_W = Result; ;
}
}
private uint GetRegister(uint index)
{
if ((Register[ADDR_STATUS] & STATUS_BIT_RP0) == STATUS_BIT_RP0)
{
return Register[0x80 + index];
}
else
{
return Register[index];
}
}
private void SetRegister(uint index, uint wert)
{
if ((Register[ADDR_STATUS] & STATUS_BIT_RP0) == STATUS_BIT_RP0)
{
Register[0x80 + index] = wert;
}
else
{
Register[index] = wert;
}
}
private void SetRegister(uint index, uint bit, bool wert)
{
if ((Register[ADDR_STATUS] & STATUS_BIT_RP0) == STATUS_BIT_RP0)
{
Register[0x80 + index] = SetBit(Register[index], bit, wert);
}
else
{
Register[index] = SetBit(Register[index], bit, wert);
}
}
private void SetRegisterOhneBank(uint index, uint bit, bool wert)
{
Register[index] = SetBit(Register[index], bit, wert);
}
private bool GetRegisterOhneBank(uint index, uint bit)
{
return GetBit(Register[index], bit);
}
public static bool AdditionDigitCarry(uint a, uint b)
{
a &= 0x0F;
b &= 0x0F;
return (a + b) > 0x0F;
}
public static bool SubtractionDigitCarry(uint a, uint b)
{
b = (~b) + 1;
return AdditionDigitCarry(a, b);
}
public static bool GetBit(uint val, uint pos)
{
return (val & SHL(1, pos)) != 0;
}
public static uint SHL(uint val, uint steps)
{
return (uint)((val) << ((int)steps));
}
public static uint SHR(uint val, uint steps)
{
return (uint)((val) >> ((int)steps));
}
public static uint SetBit(uint val, uint pos, bool bit)
{
return bit ? (val | SHL(1, pos)) : (val & ~SHL(1, pos));
}
}
}

View File

@ -45,17 +45,15 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Befehlssatz.cs" />
<Compile Include="Einlesen.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="PIC\PICProgramm.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Register.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
@ -67,6 +65,7 @@
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
@ -77,9 +76,14 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<None Include="Resources\DataSheet.pdf" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\TPicSim1.LST" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -1,27 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace PIC_Simulator
{
static class Program
{
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

View File

@ -1,49 +1,44 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
// Laufzeitversion: 4.0.30319.42000
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Änderungen an dieser Datei können fehlerhaftes Verhalten verursachen und gehen verloren, wenn
// der Code neu generiert wird.
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace PIC_Simulator.Properties
{
namespace PIC_Simulator.Properties {
using System;
/// <summary>
/// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// Diese Klasse wurde von der StronglyTypedResourceBuilder-Klasse
// über ein Tool wie ResGen oder Visual Studio automatisch generiert.
// Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen
// mit der Option /str erneut aus, oder erstellen Sie Ihr VS-Projekt neu.
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
internal Resources() {
}
/// <summary>
/// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PIC_Simulator.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
@ -52,20 +47,44 @@ namespace PIC_Simulator.Properties
}
/// <summary>
/// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
/// Ressourcenlookups, die diese stark typisierte Ressourcenklasse verwenden.
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set
{
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] DataSheet {
get {
object obj = ResourceManager.GetObject("DataSheet", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized string similar to 00001 ;TPicSim1
/// 00002 ;Programm zum Test des 16F84-Simulators.
/// 00003 ;Es werden alle Literal-Befehle geprüft
/// 00004 ;(c) St. Lehmann
/// 00005 ;Ersterstellung: 23.03.2016
/// 00006 ;
/// 00007 list c=132 ;Zeilenlänge im LST auf 132 Zeichen setzen
/// 00008
/// [rest of string was truncated]&quot;;.
/// </summary>
internal static string TPicSim1 {
get {
return ResourceManager.GetString("TPicSim1", resourceCulture);
}
}
}
}

View File

@ -46,7 +46,7 @@
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
@ -60,6 +60,7 @@
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
@ -68,9 +69,10 @@
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
@ -85,9 +87,10 @@
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
@ -109,9 +112,16 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="DataSheet" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\DataSheet.pdf;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="TPicSim1" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\TPicSim1.LST;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
</root>

View File

@ -1,357 +0,0 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Forms;
namespace PIC_Simulator
{
class Register
{
// Speicherarray anlegen:
List<int[]> arrMemList = new List<int[]>();
// BANK 0 definieren
byte BANK0_INDF = 0x0; //0000 0000
byte BANK0_TMR0 = 0x0; //0000 0000
byte BANK0_PCL = 0x0; //0000 0000
byte BANK0_STATUS = 0x18; //0001 1000
byte BANK0_FSR = 0x0; //0000 0000
byte BANK0_PORTA = 0x0; //0000 0000
byte BANK0_PORTB = 0x0; //0000 0000
byte BANK0_EEDATA = 0x0; //0000 0000
byte BANK0_EEADR = 0x0; //0000 0000
// BANK 1 definieren
byte BANK1_INDF = 0x0; //0000 0000
byte BANK1_OPTION_REG = 0xFF; //1111 1111
byte BANK1_PCL = 0x0; //0000 0000
byte BANK1_STATUS = 0x18; //0001 1000
byte BANK1_FSR = 0x0; //0000 0000
byte BANK1_TRISA = 0x1F; //0001 1111
byte BANK1_TRISB = 0xFF; //1111 1111
byte BANK1_EECON1 = 0x0; //0000 0000
byte BANK1_EECON2 = 0x0; //0000 0000
// Gemeinsam genutzte Register
byte BANK_PCLATH = 0x0; //0000 0000
byte BANK_INTCON = 0x0; //0000 0000
//############## PIC COMMANDS BINARY #############################
// --- Bit-Oriented File Register Operations ---
public string BCF = "0100"; // 4 Stellen zum Vergleichen
public string BSF = "0101";
public string BTFSC = "0110";
public string BTFSS = "0111";
//--- Byte-Oriented File Register Operations ---
public string ADDWF = "000111"; //6 Stellen zum Vergleichen
public string ANDWF = "000101"; //6
public string COMF = "001001"; //6
public string DECF = "000011"; //6
public string DECFSZ = "001011"; //6
public string INCF = "001010"; //6
public string INCFSZ = "001111"; //6
public string IORWF = "000100"; //6
public string MOVF = "001000"; //6
public string RLF = "001101"; //6
public string RRF = "001100"; //6
public string SUBWF = "000010"; //6
public string SWAPF = "001110"; //6
public string XORWF = "000110"; //6
public string CLRF = "0000011"; //7 Stellen zum Vergleichen
public string CLRW = "0000010"; //7
public string MOVWF = "0000001"; //7
public string NOP1 = "00000000000000"; //14 Stellen zum Vergleichen
public string NOP2 = "00000000100000"; //14
public string NOP3 = "00000001000000"; //14
public string NOP4 = "00000001100000"; //14
// --- Literal and Control Operations ---
public string CALL = "100"; //3 Stellen zum Vergleichen
public string GOTO = "101"; //3
public string MOVLW = "1100"; //4 Stellen zum Vergleichen
public string RETLW = "1101"; //4
public string SUBLW = "11110"; //5 Stellen zum Vergleichen
public string ADDLW = "11111"; //5
public string ANDLW = "111001"; //6 Stellen zum Vergleichen
public string IORLW = "111000"; //6
public string XORLW = "111010"; //6
public string CLRWDT = "00000001100100"; //14
public string RETFIE = "00000000001001"; //14
public string RETURN = "00000000001000"; //14
public string SLEEP = "00000001100011"; //14
//############## PIC COMMANDS BINARY #############################
// Findet den auszuführenden Befehl
public void findOrder(string Order)
{
string OrderBinary;
string Reduced;
// Hex to Int Umrechnung Funktionsaufruf
OrderBinary = hex2binary(Order);
// 14 Zeichen
Reduced = OrderBinary;
if (Reduced.Equals(NOP1))
{
MessageBox.Show("Erfolgreich NOP1" + Reduced);
}
else if (Reduced.Equals(NOP2))
{
MessageBox.Show("Erfolgreich NOP2" + Reduced);
}
else if (Reduced.Equals(NOP3))
{
MessageBox.Show("Erfolgreich NOP3" + Reduced);
}
else if (Reduced.Equals(NOP4))
{
MessageBox.Show("Erfolgreich NOP4" + Reduced);
}
else if (Reduced.Equals(CLRWDT))
{
MessageBox.Show("Erfolgreich CLRWDT" + Reduced);
}
else if (Reduced.Equals(RETFIE))
{
MessageBox.Show("Erfolgreich RETFIE" + Reduced);
}
else if (Reduced.Equals(RETURN))
{
MessageBox.Show("Erfolgreich RETURN" + Reduced);
}
else if (Reduced.Equals(SLEEP))
{
MessageBox.Show("Erfolgreich SLEEP" + Reduced);
}
else
{ // Reduzieren und Vergleich mit 7 Zeichen
Reduced = OrderBinary.Substring(0, 7);
}
//7 Zeichen
if (Reduced.Equals(CLRF))
{
MessageBox.Show("Erfolgreich CLRF" + Reduced);
}
else if (Reduced.Equals(CLRW))
{
MessageBox.Show("Erfolgreich CLRW" + Reduced);
}
else if (Reduced.Equals(MOVWF))
{
MessageBox.Show("Erfolgreich MOVWF" + Reduced);
}
else {
// Reduzieren und Vergleich mit 6 Zeichen
Reduced = OrderBinary.Substring(0, 6);
}
// 6 Zeichen
if (Reduced.Equals(ANDWF))
{
MessageBox.Show("Erfolgreich ANDWF " + Reduced);
}
else if (Reduced.Equals(COMF))
{
MessageBox.Show("Erfolgreich COMF " + Reduced);
}
else if (Reduced.Equals(DECF))
{
MessageBox.Show("Erfolgreich DECF " + Reduced);
}
else if (Reduced.Equals(DECFSZ))
{
MessageBox.Show("Erfolgreich DECFSZ " + Reduced);
}
else if (Reduced.Equals(INCF))
{
MessageBox.Show("Erfolgreich INCF " + Reduced);
}
else if (Reduced.Equals(INCFSZ))
{
MessageBox.Show("Erfolgreich INCFSZ " + Reduced);
}
else if (Reduced.Equals(IORWF))
{
MessageBox.Show("Erfolgreich IORWF " + Reduced);
}
else if (Reduced.Equals(MOVF))
{
MessageBox.Show("Erfolgreich MOVF " + Reduced);
}
else if (Reduced.Equals(RLF))
{
MessageBox.Show("Erfolgreich RLF " + Reduced);
}
else if (Reduced.Equals(RRF))
{
MessageBox.Show("Erfolgreich RRF " + Reduced);
}
else if (Reduced.Equals(SUBWF))
{
MessageBox.Show("Erfolgreich SUBWF " + Reduced);
}
else if (Reduced.Equals(SWAPF))
{
MessageBox.Show("Erfolgreich SWAPF " + Reduced);
}
else if (Reduced.Equals(XORWF))
{
MessageBox.Show("Erfolgreich XORWF " + Reduced);
}
else if (Reduced.Equals(ANDLW))
{
MessageBox.Show("Erfolgreich ANDLW " + Reduced);
}
else if (Reduced.Equals(IORLW))
{
MessageBox.Show("Erfolgreich IORLW " + Reduced);
}
else if (Reduced.Equals(XORLW))
{
MessageBox.Show("Erfolgreich XORLW " + Reduced);
}
else
{ // Reduzieren und Vergleich mit 5 Zeichen
Reduced = OrderBinary.Substring(0, 5);
}
// 5 Zeichen
if (Reduced.Equals(SUBLW))
{
MessageBox.Show("Erfolgreich SUBLW " + Reduced);
}
else if (Reduced.Equals(ADDLW))
{
MessageBox.Show("Erfolgreich ADDLW " + Reduced);
}
else
{ // Reduzieren und Vergleich mit 4 Zeichen
Reduced = OrderBinary.Substring(0, 4);
}
//4 Zeichen
if (Reduced.Equals(BCF))
{
MessageBox.Show("Erfolgreich BCF " + Reduced);
}
else if (Reduced.Equals(BSF))
{
MessageBox.Show("Erfolgreich BSF " + Reduced);
}
else if (Reduced.Equals(BTFSC))
{
MessageBox.Show("Erfolgreich DBTFSC " + Reduced);
}
else if (Reduced.Equals(BTFSS))
{
MessageBox.Show("Erfolgreich BTFSS " + Reduced);
}
else if (Reduced.Equals(MOVLW))
{
MessageBox.Show("Erfolgreich MOVLW " + Reduced);
}
else if (Reduced.Equals(RETLW))
{
MessageBox.Show("Erfolgreich RETLW " + Reduced);
}
else
{// Reduzieren und Vergleich mit 3 Zeichen
Reduced = OrderBinary.Substring(0, 3);
}
if (Reduced.Equals(CALL))
{
MessageBox.Show("Erfolgreich CALL " + Reduced);
}
else if (Reduced.Equals(GOTO))
{
MessageBox.Show("Erfolgreich GOTO " + Reduced);
}
else { }
}
private string hex2binary(string hexvalue)
{
string binaryval = "";
binaryval = Convert.ToString(Convert.ToInt32(hexvalue, 16), 2).PadLeft(14,'0');
return binaryval;
}
private void fillpicmemory()
{
int[] line1 = new int[8];
int[] line2 = new int[8];
int[] line3 = new int[8];
int[] line4 = new int[8];
int[] line5 = new int[8];
int[] line6 = new int[8];
int[] line7 = new int[8];
int[] line8 = new int[8];
int[] line9 = new int[8];
int[] line10 = new int[8];
int[] line11 = new int[8];
int[] line12 = new int[8];
int[] line13 = new int[8];
int[] line14 = new int[8];
int[] line15 = new int[8];
int[] line16 = new int[8];
int[] line17 = new int[8];
int[] line18 = new int[8];
int[] line19 = new int[8];
int[] line20 = new int[8];
int[] line21 = new int[8];
int[] line22 = new int[8];
int[] line23 = new int[8];
int[] line24 = new int[8];
int[] line25 = new int[8];
int[] line26 = new int[8];
int[] line27 = new int[8];
int[] line28 = new int[8];
int[] line29 = new int[8];
int[] line30 = new int[8];
int[] line31 = new int[8];
}
}
}

Binary file not shown.

View File

@ -0,0 +1,35 @@
00001 ;TPicSim1
00002 ;Programm zum Test des 16F84-Simulators.
00003 ;Es werden alle Literal-Befehle geprüft
00004 ;(c) St. Lehmann
00005 ;Ersterstellung: 23.03.2016
00006 ;
00007 list c=132 ;Zeilenlänge im LST auf 132 Zeichen setzen
00008
00009 ;Definition einiger Symbole
00010 ;zuerst Hardware-Register
00011 status equ 03h
00012 ra equ 05h
00013 rb equ 06h
00014
00015 ;für den Benutzer frei verwendbare Register
00016 count equ 0ch
00017
00018 ;Definition des Prozessors
00019 device 16F84
00020
00021 ;Festlegen des Codebeginns
00022 org 0
00023 start
0000 3011 00024 movlw 11h ;in W steht nun 11h, Statusreg. unverändert
0001 3930 00025 andlw 30h ;W = 10h, C=x, DC=x, Z=0
0002 380D 00026 iorlw 0Dh ;W = 1Dh, C=x, DC=x, Z=0
0003 3C3D 00027 sublw 3Dh ;W = 20h, C=1, DC=1, Z=0
0004 3A20 00028 xorlw 20h ;W = 00h, C=1, DC=1, Z=1
0005 3E25 00029 addlw 25h ;W = 25h, C=0, DC=0, Z=0
00030
00031
00032 ende
0006 2806 00033 goto ende ;Endlosschleife, verhindert Nirwana
00034
00035

View File

@ -1,43 +1,42 @@
--- Byte-Oriented File Register Operations ---
ADDWF | 6 | 00 0111 dfff ffff
ANDWF | 6 | 00 0101 dfff ffff
CLRF | 7 | 00 0001 1fff ffff
CLRW | 7 | 00 0001 0xxx xxxx
COMF | 6 | 00 1001 dfff ffff
DECF | 6 | 00 0011 dfff ffff
DECFSZ | 6 | 00 1011 dfff ffff
INCF | 6 | 00 1010 dfff ffff
INCFSZ | 6 | 00 1111 dfff ffff
IORWF | 6 | 00 0100 dfff ffff
MOVF | 6 | 00 1000 dfff ffff
MOVWF | 7 | 00 0000 1fff ffff
NOP1 | 14 | 00 0000 0000 0000
NOP2 | 14 | 00 0000 0010 0000
NOP3 | 14 | 00 0000 0100 0000
NOP4 | 14 | 00 0000 0110 0000
RLF | 6 | 00 1101 dfff ffff
RRF | 6 | 00 1100 dfff ffff
SUBWF | 6 | 00 0010 dfff ffff
SWAPF | 6 | 00 1110 dfff ffff
XORWF | 6 | 00 0110 dfff ffff
--- Bit-Oriented File Register Operations ---
BCF | 4 | 01 00bb bfff ffff
BSF | 4 | 01 01bb bfff ffff
BTFSC | 4 | 01 10bb bfff ffff
BTFSS | 4 | 01 11bb bfff ffff
public string ADDWF = "000111dfffffff";
public string ANDWF = "000101dfffffff";
public string CLRF = "0000011fffffff";
public string CLRW = "0000010xxxxxxx";
public string COMF = "001001dfffffff";
public string DECF = "000011dfffffff";
public string DECFSZ = "001011dfffffff";
public string INCF = "001010dfffffff";
public string INCFSZ = "001111dfffffff";
public string IORWF = "000100dfffffff";
public string MOVF = "001000dfffffff";
public string MOVWF = "0000001fffffff";
public string NOP1 = "00000000000000";
public string NOP2 = "00000000100000";
public string NOP3 = "00000001000000";
public string NOP4 = "00000001100000";
public string RLF = "001101dfffffff";
public string RRF = "001100dfffffff";
public string SUBWF = "000010dfffffff";
public string SWAPF = "001110dfffffff";
public string XORWF = "000110dfffffff";
public string BCF = "0100bbbfffffff";
public string BSF = "0101bbbfffffff";
public string BTFSC = "0110bbbfffffff";
public string BTFSS = "0111bbbfffffff";
public string ADDLW = "11111xkkkkkkkk";
public string ANDLW = "111001kkkkkkkk";
public string CALL = "100kkkkkkkkkkk";
public string CLRWDT = "00000001100100";
public string GOTO = "101kkkkkkkkkkk";
public string IORLW = "111000kkkkkkkk";
public string MOVLW = "1100xxkkkkkkkk";
public string RETFIE = "00000000001001";
public string RETLW = "1101xxkkkkkkkk";
public string RETURN = "00000000001000";
public string SLEEP = "00000001100011";
public string SUBLW = "11110xkkkkkkkk";
public string XORLW = "111010kkkkkkkk";
--- Literal and Control Operations ---
ADDLW | 5 | 11 111x kkkk kkkk
ANDLW | 6 | 11 1001 kkkk kkkk
CALL | 3 | 10 0kkk kkkk kkkk
CLRWDT | 14 | 00 0000 0110 0100
GOTO | 3 | 10 1kkk kkkk kkkk
IORLW | 6 | 11 1000 kkkk kkkk
MOVLW | 4 | 11 00xx kkkk kkkk
RETFIE | 14 | 00 0000 0000 1001
RETLW | 4 | 11 01xx kkkk kkkk
RETURN | 14 | 00 0000 0000 1000
SLEEP | 14 | 00 0000 0110 0011
SUBLW | 5 | 11 110x kkkk kkkk
XORLW | 6 | 11 1010 kkkk kkkk