commit fa1aa07e8d60824479d4c9135da2970eb8233a57 Author: Meruemon Date: Tue Mar 1 20:09:42 2022 +0100 init diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e112a70 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..7c03a53 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/bin/Backend/BackendCommandProcessing/BackendInformationTransferThread.class b/bin/Backend/BackendCommandProcessing/BackendInformationTransferThread.class new file mode 100644 index 0000000..cca4b4f Binary files /dev/null and b/bin/Backend/BackendCommandProcessing/BackendInformationTransferThread.class differ diff --git a/bin/Backend/BackendCommandProcessing/InformationConnecter.class b/bin/Backend/BackendCommandProcessing/InformationConnecter.class new file mode 100644 index 0000000..29c710c Binary files /dev/null and b/bin/Backend/BackendCommandProcessing/InformationConnecter.class differ diff --git a/bin/Backend/EepromLoader/ReadEepromFile.class b/bin/Backend/EepromLoader/ReadEepromFile.class new file mode 100644 index 0000000..1b708dd Binary files /dev/null and b/bin/Backend/EepromLoader/ReadEepromFile.class differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$1.class b/bin/Backend/FrontendCommandProcessing/CommandAction$1.class new file mode 100644 index 0000000..2b9c01d Binary files /dev/null and b/bin/Backend/FrontendCommandProcessing/CommandAction$1.class differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$10.class b/bin/Backend/FrontendCommandProcessing/CommandAction$10.class new file mode 100644 index 0000000..d83a3f8 Binary files /dev/null and b/bin/Backend/FrontendCommandProcessing/CommandAction$10.class differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$11.class b/bin/Backend/FrontendCommandProcessing/CommandAction$11.class new file mode 100644 index 0000000..18c9660 Binary files /dev/null and b/bin/Backend/FrontendCommandProcessing/CommandAction$11.class differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$12.class b/bin/Backend/FrontendCommandProcessing/CommandAction$12.class new file mode 100644 index 0000000..6e0c5c5 Binary files /dev/null and b/bin/Backend/FrontendCommandProcessing/CommandAction$12.class differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$13.class b/bin/Backend/FrontendCommandProcessing/CommandAction$13.class new file mode 100644 index 0000000..932bdfa Binary files /dev/null and b/bin/Backend/FrontendCommandProcessing/CommandAction$13.class differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$14.class b/bin/Backend/FrontendCommandProcessing/CommandAction$14.class new file mode 100644 index 0000000..1321088 Binary files /dev/null and b/bin/Backend/FrontendCommandProcessing/CommandAction$14.class differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$15.class b/bin/Backend/FrontendCommandProcessing/CommandAction$15.class new file mode 100644 index 0000000..aacff16 Binary files /dev/null and b/bin/Backend/FrontendCommandProcessing/CommandAction$15.class differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$2.class b/bin/Backend/FrontendCommandProcessing/CommandAction$2.class new file mode 100644 index 0000000..2cc2b9f Binary files /dev/null and b/bin/Backend/FrontendCommandProcessing/CommandAction$2.class differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$3.class b/bin/Backend/FrontendCommandProcessing/CommandAction$3.class new file mode 100644 index 0000000..af718fa Binary files /dev/null and b/bin/Backend/FrontendCommandProcessing/CommandAction$3.class differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$4.class b/bin/Backend/FrontendCommandProcessing/CommandAction$4.class new file mode 100644 index 0000000..a164759 Binary files /dev/null and b/bin/Backend/FrontendCommandProcessing/CommandAction$4.class differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$5.class b/bin/Backend/FrontendCommandProcessing/CommandAction$5.class new file mode 100644 index 0000000..2b7ae1d Binary files /dev/null and b/bin/Backend/FrontendCommandProcessing/CommandAction$5.class differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$6.class b/bin/Backend/FrontendCommandProcessing/CommandAction$6.class new file mode 100644 index 0000000..e59faf6 Binary files /dev/null and b/bin/Backend/FrontendCommandProcessing/CommandAction$6.class differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$7.class b/bin/Backend/FrontendCommandProcessing/CommandAction$7.class new file mode 100644 index 0000000..0b1c699 Binary files /dev/null and b/bin/Backend/FrontendCommandProcessing/CommandAction$7.class differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$8.class b/bin/Backend/FrontendCommandProcessing/CommandAction$8.class new file mode 100644 index 0000000..8eb7f9d Binary files /dev/null and b/bin/Backend/FrontendCommandProcessing/CommandAction$8.class differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction$9.class b/bin/Backend/FrontendCommandProcessing/CommandAction$9.class new file mode 100644 index 0000000..1245beb Binary files /dev/null and b/bin/Backend/FrontendCommandProcessing/CommandAction$9.class differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandAction.class b/bin/Backend/FrontendCommandProcessing/CommandAction.class new file mode 100644 index 0000000..e319374 Binary files /dev/null and b/bin/Backend/FrontendCommandProcessing/CommandAction.class differ diff --git a/bin/Backend/FrontendCommandProcessing/CommandDecoder.class b/bin/Backend/FrontendCommandProcessing/CommandDecoder.class new file mode 100644 index 0000000..fec746e Binary files /dev/null and b/bin/Backend/FrontendCommandProcessing/CommandDecoder.class differ diff --git a/bin/Backend/FrontendCommandProcessing/FrontendCommandProcessingThread.class b/bin/Backend/FrontendCommandProcessing/FrontendCommandProcessingThread.class new file mode 100644 index 0000000..270965a Binary files /dev/null and b/bin/Backend/FrontendCommandProcessing/FrontendCommandProcessingThread.class differ diff --git a/bin/Backend/FrontendCommandProcessing/ReadFile.class b/bin/Backend/FrontendCommandProcessing/ReadFile.class new file mode 100644 index 0000000..29afeba Binary files /dev/null and b/bin/Backend/FrontendCommandProcessing/ReadFile.class differ diff --git a/bin/Backend/Microcontroller/Bitmask.class b/bin/Backend/Microcontroller/Bitmask.class new file mode 100644 index 0000000..f8962ce Binary files /dev/null and b/bin/Backend/Microcontroller/Bitmask.class differ diff --git a/bin/Backend/Microcontroller/EEPROM.class b/bin/Backend/Microcontroller/EEPROM.class new file mode 100644 index 0000000..f2dbbc3 Binary files /dev/null and b/bin/Backend/Microcontroller/EEPROM.class differ diff --git a/bin/Backend/Microcontroller/PIC.class b/bin/Backend/Microcontroller/PIC.class new file mode 100644 index 0000000..c3f45a1 Binary files /dev/null and b/bin/Backend/Microcontroller/PIC.class differ diff --git a/bin/Backend/Microcontroller/RAM.class b/bin/Backend/Microcontroller/RAM.class new file mode 100644 index 0000000..feca46a Binary files /dev/null and b/bin/Backend/Microcontroller/RAM.class differ diff --git a/bin/Backend/Microcontroller/STACK.class b/bin/Backend/Microcontroller/STACK.class new file mode 100644 index 0000000..c30f16a Binary files /dev/null and b/bin/Backend/Microcontroller/STACK.class differ diff --git a/bin/Backend/Microcontroller/WATCHDOG.class b/bin/Backend/Microcontroller/WATCHDOG.class new file mode 100644 index 0000000..f903c95 Binary files /dev/null and b/bin/Backend/Microcontroller/WATCHDOG.class differ diff --git a/bin/Backend/Runtime/Environment.class b/bin/Backend/Runtime/Environment.class new file mode 100644 index 0000000..3b00481 Binary files /dev/null and b/bin/Backend/Runtime/Environment.class differ diff --git a/bin/Backend/Runtime/Main.class b/bin/Backend/Runtime/Main.class new file mode 100644 index 0000000..929b2b6 Binary files /dev/null and b/bin/Backend/Runtime/Main.class differ diff --git a/bin/Backend/Runtime/ProgramStepInformation.class b/bin/Backend/Runtime/ProgramStepInformation.class new file mode 100644 index 0000000..59cbe12 Binary files /dev/null and b/bin/Backend/Runtime/ProgramStepInformation.class differ diff --git a/bin/Backend/Runtime/TODO.class b/bin/Backend/Runtime/TODO.class new file mode 100644 index 0000000..9a052bc Binary files /dev/null and b/bin/Backend/Runtime/TODO.class differ diff --git a/bin/Backend/Runtime/WATCHDOG.class b/bin/Backend/Runtime/WATCHDOG.class new file mode 100644 index 0000000..b734d55 Binary files /dev/null and b/bin/Backend/Runtime/WATCHDOG.class differ diff --git a/bin/Backend/Statistics/ErrorHandling/BackendErrorCounter.class b/bin/Backend/Statistics/ErrorHandling/BackendErrorCounter.class new file mode 100644 index 0000000..b6d8842 Binary files /dev/null and b/bin/Backend/Statistics/ErrorHandling/BackendErrorCounter.class differ diff --git a/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMainFrame.class b/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMainFrame.class new file mode 100644 index 0000000..e32f089 Binary files /dev/null and b/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMainFrame.class differ diff --git a/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/Main.class b/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/Main.class new file mode 100644 index 0000000..a8d8a85 Binary files /dev/null and b/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/Main.class differ diff --git a/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/ReadBackendToFrontendFile.class b/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/ReadBackendToFrontendFile.class new file mode 100644 index 0000000..f5a2643 Binary files /dev/null and b/bin/Frontend/PIC_SIMULATOR_GUI_JAVA/ReadBackendToFrontendFile.class differ diff --git a/bin/In.class b/bin/In.class new file mode 100644 index 0000000..6d4bd51 Binary files /dev/null and b/bin/In.class differ diff --git a/bin/simulator_additional_functions.class b/bin/simulator_additional_functions.class new file mode 100644 index 0000000..9608605 Binary files /dev/null and b/bin/simulator_additional_functions.class differ diff --git a/documentation/EXCEL/Bitmask done masks.xlsx b/documentation/EXCEL/Bitmask done masks.xlsx new file mode 100755 index 0000000..175bc6e Binary files /dev/null and b/documentation/EXCEL/Bitmask done masks.xlsx differ diff --git a/documentation/EXCEL/Frontend an Backend.xlsx b/documentation/EXCEL/Frontend an Backend.xlsx new file mode 100755 index 0000000..fbdc209 Binary files /dev/null and b/documentation/EXCEL/Frontend an Backend.xlsx differ diff --git a/documentation/EXCEL/Mappe1.xlsx b/documentation/EXCEL/Mappe1.xlsx new file mode 100755 index 0000000..dc73a7f Binary files /dev/null and b/documentation/EXCEL/Mappe1.xlsx differ diff --git a/documentation/PDF/Datenblatt_Mikroprozessor.pdf b/documentation/PDF/Datenblatt_Mikroprozessor.pdf new file mode 100755 index 0000000..43556f5 Binary files /dev/null and b/documentation/PDF/Datenblatt_Mikroprozessor.pdf differ diff --git a/documentation/PDF/Foliensatz_Von_Neumann_Modell_P1.pdf b/documentation/PDF/Foliensatz_Von_Neumann_Modell_P1.pdf new file mode 100755 index 0000000..9e28c2c Binary files /dev/null and b/documentation/PDF/Foliensatz_Von_Neumann_Modell_P1.pdf differ diff --git a/documentation/PDF/Foliensatz_Von_Neumann_Modell_P2.pdf b/documentation/PDF/Foliensatz_Von_Neumann_Modell_P2.pdf new file mode 100755 index 0000000..2ed36b9 Binary files /dev/null and b/documentation/PDF/Foliensatz_Von_Neumann_Modell_P2.pdf differ diff --git a/documentation/PDF/Funktionsweise des PIC16F84.pdf b/documentation/PDF/Funktionsweise des PIC16F84.pdf new file mode 100755 index 0000000..da1c7c2 Binary files /dev/null and b/documentation/PDF/Funktionsweise des PIC16F84.pdf differ diff --git a/documentation/PDF/GUI_PicSim_Bedienungsanleitung.pdf b/documentation/PDF/GUI_PicSim_Bedienungsanleitung.pdf new file mode 100755 index 0000000..a0d0636 Binary files /dev/null and b/documentation/PDF/GUI_PicSim_Bedienungsanleitung.pdf differ diff --git a/documentation/PDF/Mitschrieb Rechnerarchitekturen 01.pdf b/documentation/PDF/Mitschrieb Rechnerarchitekturen 01.pdf new file mode 100755 index 0000000..6ea2ffc Binary files /dev/null and b/documentation/PDF/Mitschrieb Rechnerarchitekturen 01.pdf differ diff --git a/documentation/PDF/Operationsverstaerker.pdf b/documentation/PDF/Operationsverstaerker.pdf new file mode 100755 index 0000000..96534ec Binary files /dev/null and b/documentation/PDF/Operationsverstaerker.pdf differ diff --git a/documentation/PDF/Rechnerarchitektur 08.04.2021.pdf b/documentation/PDF/Rechnerarchitektur 08.04.2021.pdf new file mode 100755 index 0000000..7299ceb Binary files /dev/null and b/documentation/PDF/Rechnerarchitektur 08.04.2021.pdf differ diff --git a/documentation/PDF/Selbststudium_Skript_20210415.pdf b/documentation/PDF/Selbststudium_Skript_20210415.pdf new file mode 100755 index 0000000..11e5525 Binary files /dev/null and b/documentation/PDF/Selbststudium_Skript_20210415.pdf differ diff --git a/documentation/PDF/TODOS Simulator.pdf b/documentation/PDF/TODOS Simulator.pdf new file mode 100755 index 0000000..871f88a Binary files /dev/null and b/documentation/PDF/TODOS Simulator.pdf differ diff --git a/documentation/PDF/TestProg_PicSim_20210420.zip b/documentation/PDF/TestProg_PicSim_20210420.zip new file mode 100755 index 0000000..cdf5116 Binary files /dev/null and b/documentation/PDF/TestProg_PicSim_20210420.zip differ diff --git a/documentation/PDF/Themenblatt_PIC_programmieren.pdf b/documentation/PDF/Themenblatt_PIC_programmieren.pdf new file mode 100755 index 0000000..1342ab4 Binary files /dev/null and b/documentation/PDF/Themenblatt_PIC_programmieren.pdf differ diff --git a/documentation/PDF/Wichtige_Hinweise_zur_Vorlesung.pdf b/documentation/PDF/Wichtige_Hinweise_zur_Vorlesung.pdf new file mode 100755 index 0000000..3092676 Binary files /dev/null and b/documentation/PDF/Wichtige_Hinweise_zur_Vorlesung.pdf differ diff --git a/documentation/PDF/Wichtigste Datei evor.pdf b/documentation/PDF/Wichtigste Datei evor.pdf new file mode 100755 index 0000000..46dfdff Binary files /dev/null and b/documentation/PDF/Wichtigste Datei evor.pdf differ diff --git a/documentation/TXT/Rechnerarchitektur.txt b/documentation/TXT/Rechnerarchitektur.txt new file mode 100755 index 0000000..9f5f900 --- /dev/null +++ b/documentation/TXT/Rechnerarchitektur.txt @@ -0,0 +1,18 @@ +-Einlesen lst-Datei (15-16 Stck) (Anzahl von Befehlen) + : Am Ende ist ein carrieage return. + : int-Array Hex-Werte als int-Wert abspeichern + : 6 feste Befehlsbit (Maske 3f00), 4 feste Befehlsbit (Maske 3c00), 3bit-Befehle -> 3 Unterschiedliche Maskierungen (Maske 3800)Ergebnis 2000:Call; Ergebnis 2800:GOTO + : Codes in Excel-Tabelle und fest oder variabel einteilen + : 14 Tage ab 25.03.2021 + + -> Pflichtenheft erstellen, Vorgehen, Oberfläche, Variablen Organisation, Bennennung RAM & EPROM + + + +-Definieren der entsprechenden Arrays und globalen Variablen + +-Definieren der Funktionsköpfe und Anlegen der Funktionsrümpfe + +-Grundstruktur Switch Case + +-Grafik gestalten visuelle Komponenten Ein- und Ausgabe \ No newline at end of file diff --git a/documentation/TXT/Zeilen.txt b/documentation/TXT/Zeilen.txt new file mode 100755 index 0000000..1d6dbe6 --- /dev/null +++ b/documentation/TXT/Zeilen.txt @@ -0,0 +1,5 @@ +012345678 2021222324 + +0003 070C 0 0 0 3 8 + +11 Spaces \ No newline at end of file diff --git a/documentation/WORD/Konzept.docx b/documentation/WORD/Konzept.docx new file mode 100755 index 0000000..6f1cdd8 Binary files /dev/null and b/documentation/WORD/Konzept.docx differ diff --git a/documentation/WORD/Rechnerarchitektur Selbststudium Skript Verbesserungsvorschläge.docx b/documentation/WORD/Rechnerarchitektur Selbststudium Skript Verbesserungsvorschläge.docx new file mode 100755 index 0000000..c6cb2b7 Binary files /dev/null and b/documentation/WORD/Rechnerarchitektur Selbststudium Skript Verbesserungsvorschläge.docx differ diff --git a/documentation/actions.pdf b/documentation/actions.pdf new file mode 100755 index 0000000..f61f109 Binary files /dev/null and b/documentation/actions.pdf differ diff --git a/documentation/guilayout.pdf b/documentation/guilayout.pdf new file mode 100755 index 0000000..2679592 Binary files /dev/null and b/documentation/guilayout.pdf differ diff --git a/pictures/gui_logo.png b/pictures/gui_logo.png new file mode 100755 index 0000000..0857bca Binary files /dev/null and b/pictures/gui_logo.png differ diff --git a/src/Backend/BackendCommandProcessing/BackendInformationTransferThread.java b/src/Backend/BackendCommandProcessing/BackendInformationTransferThread.java new file mode 100755 index 0000000..872f0a8 --- /dev/null +++ b/src/Backend/BackendCommandProcessing/BackendInformationTransferThread.java @@ -0,0 +1,51 @@ +package Backend.BackendCommandProcessing; + +//package SIMULATOR; + +import java.util.concurrent.ConcurrentLinkedQueue; + +import java.io.*; + +public class BackendInformationTransferThread extends Thread { + + private static File fileBackendToFrontend = new File("../SIMULATOR_DAT/gui_set.dat"); + + private ConcurrentLinkedQueue queue; + + private int iSleepTime = 100; + + public BackendInformationTransferThread(ConcurrentLinkedQueue outputQueue) { + queue = outputQueue; + } + + private int writeOutputFile() { + int iSuccess = 0; + if(!queue.isEmpty()) { + String sPICInformation = queue.poll(); + FileWriter fw; + try { + fw = new FileWriter(fileBackendToFrontend); + BufferedWriter bw = new BufferedWriter(fw); + bw.write(sPICInformation); + bw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + iSuccess = 1; + } + return iSuccess; + } + + @Override + public void run() { + + while (true) { + try { + Thread.sleep(iSleepTime); + } catch (InterruptedException e) { + e.printStackTrace(); + } + writeOutputFile(); + } + } +} diff --git a/src/Backend/BackendCommandProcessing/InformationConnecter.java b/src/Backend/BackendCommandProcessing/InformationConnecter.java new file mode 100755 index 0000000..d3da198 --- /dev/null +++ b/src/Backend/BackendCommandProcessing/InformationConnecter.java @@ -0,0 +1,158 @@ +package Backend.BackendCommandProcessing; + +import Backend.Microcontroller.PIC; + +public class InformationConnecter { + + public String connectInformation (PIC oPic, int iActualLine, int iLastLine, int iSetBreakpoint, int iResetBreakpoint, long liRuntime, long liWatchdog) { + + String sConnectedInformation = ""; + + for (int i = 0; i < 128; i++) { + sConnectedInformation.concat("FREG " + i + "," + oPic.getRam().get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(false, i) + "\n"); + } + int j = 0; + for (int i = 128; i < 256; i++) { + sConnectedInformation.concat("FREG " + i + "," + oPic.getRam().get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(true, j) + "\n"); + j++; + } + sConnectedInformation.concat("SETLINE " + iActualLine + "\n"); + if (iLastLine != iActualLine) + { + sConnectedInformation.concat("RESLINE " + iLastLine + "\n"); + } + sConnectedInformation.concat("TIME " + (liRuntime / 100) + " µs\n"); + sConnectedInformation.concat("WReg " + oPic.get_WRegister() + "\n"); + sConnectedInformation.concat("PCL " + oPic.getRam().get_PCL() + "\n"); + sConnectedInformation.concat("PCLATH " + oPic.getRam().get_PCLATH() + "\n"); + sConnectedInformation.concat("PCINTERN " + oPic.getRam().get_Programcounter() + "\n"); + sConnectedInformation.concat("STATUS " + oPic.getRam().get_STATUS() + "\n"); + sConnectedInformation.concat("FSR " + oPic.getRam().get_FSR() + "\n"); + sConnectedInformation.concat("OPTION " + 1 + "\n"); + + //Statusbits + int sC = oPic.getRam().get_Carryflag()? 1:0; + int sDC = oPic.getRam().get_Digitcarryflag()? 1:0; + int sZ = oPic.getRam().get_Zeroflag()? 1:0; + int sPD = oPic.getRam().get_PowerDownFlag()? 1:0; + int sTO = oPic.getRam().get_TimeOutFlag()? 1:0; + int sRP0 = oPic.getRam().get_RP0Bit()? 1:0; + int sRP1 = oPic.getRam().get_RP1Bit()? 1:0; + int sIRP = oPic.getRam().get_Interruptflag()? 1:0; + + //Set Statusbits in frontend. + sConnectedInformation.concat("STATUSBIT " + 0 + ", " + sC + "\n"); + sConnectedInformation.concat("STATUSBIT " + 1 + ", " + sDC + "\n"); + sConnectedInformation.concat("STATUSBIT " + 2 + ", " + sZ + "\n"); + sConnectedInformation.concat("STATUSBIT " + 3 + ", " + sPD + "\n"); + sConnectedInformation.concat("STATUSBIT " + 4 + ", " + sTO + "\n"); + sConnectedInformation.concat("STATUSBIT " + 5 + ", " + sRP0 + "\n"); + sConnectedInformation.concat("STATUSBIT " + 6 + ", " + sRP1 + "\n"); + sConnectedInformation.concat("STATUSBIT " + 7 + ", " + sIRP + "\n"); + + //Optionbits + int oPS0 = oPic.getRam().get_PS0()? 1:0; + int oPS1 = oPic.getRam().get_PS1()? 1:0; + int oPS2 = oPic.getRam().get_PS2()? 1:0; + int oPSA = oPic.getRam().get_PSA()? 1:0; + int oTSE = oPic.getRam().get_T0SE()? 1:0; + int oTCS = oPic.getRam().get_T0CS()? 1:0; + int oIEG = oPic.getRam().get_INTEDG()? 1:0; + int oRPU = oPic.getRam().get_RBPU()? 1:0; + + //Set Optionbits in frontend. + sConnectedInformation.concat("OPTIONBIT " + 0 + ", " + oPS0 + "\n"); + sConnectedInformation.concat("OPTIONBIT " + 1 + ", " + oPS1 + "\n"); + sConnectedInformation.concat("OPTIONBIT " + 2 + ", " + oPS2 + "\n"); + sConnectedInformation.concat("OPTIONBIT " + 3 + ", " + oPSA + "\n"); + sConnectedInformation.concat("OPTIONBIT " + 4 + ", " + oTSE + "\n"); + sConnectedInformation.concat("OPTIONBIT " + 5 + ", " + oTCS + "\n"); + sConnectedInformation.concat("OPTIONBIT " + 6 + ", " + oIEG + "\n"); + sConnectedInformation.concat("OPTIONBIT " + 7 + ", " + oRPU + "\n"); + + //Intconbits + int iRIF = oPic.getRam().get_RBIF()? 1:0; + int iIF = oPic.getRam().get_INTF()? 1:0; + int iTIF = oPic.getRam().get_T0IF()? 1:0; + int iRIE = oPic.getRam().get_RBIE()? 1:0; + int iIE = oPic.getRam().get_INTE()? 1:0; + int iTIE = oPic.getRam().get_T0IE()? 1:0; + int iEIE = oPic.getRam().get_EEIE()? 1:0; + int iGIE = oPic.getRam().get_GIE()? 1:0; + + //Set Intconbits in frontend. + sConnectedInformation.concat("INTCONBIT " + 0 + ", " + iRIF + "\n"); + sConnectedInformation.concat("INTCONBIT " + 1 + ", " + iIF + "\n"); + sConnectedInformation.concat("INTCONBIT " + 2 + ", " + iTIF + "\n"); + sConnectedInformation.concat("INTCONBIT " + 3 + ", " + iRIE + "\n"); + sConnectedInformation.concat("INTCONBIT " + 4 + "," + iIE + "\n"); + sConnectedInformation.concat("INTCONBIT " + 5 + ", " + iTIE + "\n"); + sConnectedInformation.concat("INTCONBIT " + 6 + ", " + iEIE + "\n"); + sConnectedInformation.concat("INTCONBIT " + 7 + ", " + iGIE + "\n"); + + //TRISA in frontend is set. + sConnectedInformation.concat("TRISA " + 0 + "," + ((oPic.getRam().get_TRISA() & 0b00000001) >> 0) + "\n"); //For better understanding + sConnectedInformation.concat("TRISA " + 1 + "," + ((oPic.getRam().get_TRISA() & 0b00000010) >> 1) + "\n"); + sConnectedInformation.concat("TRISA " + 2 + "," + ((oPic.getRam().get_TRISA() & 0b00000100) >> 2) + "\n"); + sConnectedInformation.concat("TRISA " + 3 + "," + ((oPic.getRam().get_TRISA() & 0b00001000) >> 3) + "\n"); + sConnectedInformation.concat("TRISA " + 4 + "," + ((oPic.getRam().get_TRISA() & 0b00010000) >> 4) + "\n"); + sConnectedInformation.concat("TRISA " + 5 + "," + ((oPic.getRam().get_TRISA() & 0b00100000) >> 5) + "\n"); + sConnectedInformation.concat("TRISA " + 6 + "," + ((oPic.getRam().get_TRISA() & 0b01000000) >> 6) + "\n"); + sConnectedInformation.concat("TRISA " + 7 + "," + ((oPic.getRam().get_TRISA() & 0b10000000) >> 7) + "\n"); + + //PORTA in frontend is set. + sConnectedInformation.concat("PORTA " + 0 + "," + ((oPic.getRam().get_PORTA() & 0b00001) >> 0) + "\n"); //For better understanding + sConnectedInformation.concat("PORTA " + 1 + "," + ((oPic.getRam().get_PORTA() & 0b00010) >> 1) + "\n"); + sConnectedInformation.concat("PORTA " + 2 + "," + ((oPic.getRam().get_PORTA() & 0b00100) >> 2) + "\n"); + sConnectedInformation.concat("PORTA " + 3 + "," + ((oPic.getRam().get_PORTA() & 0b01000) >> 3) + "\n"); + sConnectedInformation.concat("PORTA " + 4 + "," + ((oPic.getRam().get_PORTA() & 0b10000) >> 4) + "\n"); + + //TRISB in frontend is set. + sConnectedInformation.concat("TRISB " + 0 + "," + ((oPic.getRam().get_TRISB() & 0b00000001) >> 0) + "\n"); //For better understanding + sConnectedInformation.concat("TRISB " + 1 + "," + ((oPic.getRam().get_TRISB() & 0b00000010) >> 1) + "\n"); + sConnectedInformation.concat("TRISB " + 2 + "," + ((oPic.getRam().get_TRISB() & 0b00000100) >> 2) + "\n"); + sConnectedInformation.concat("TRISB " + 3 + "," + ((oPic.getRam().get_TRISB() & 0b00001000) >> 3) + "\n"); + sConnectedInformation.concat("TRISB " + 4 + "," + ((oPic.getRam().get_TRISB() & 0b00010000) >> 4) + "\n"); + sConnectedInformation.concat("TRISB " + 5 + "," + ((oPic.getRam().get_TRISB() & 0b00100000) >> 5) + "\n"); + sConnectedInformation.concat("TRISB " + 6 + "," + ((oPic.getRam().get_TRISB() & 0b01000000) >> 6) + "\n"); + sConnectedInformation.concat("TRISB " + 7 + "," + ((oPic.getRam().get_TRISB() & 0b10000000) >> 7) + "\n"); + + //PORTB in frontend is set. + sConnectedInformation.concat("PORTB " + 0 + "," + ((oPic.getRam().get_PORTB() & 0b00000001) >> 0) + "\n"); //For better understandin + sConnectedInformation.concat("PORTB " + 1 + "," + ((oPic.getRam().get_PORTB() & 0b00000010) >> 1) + "\n"); + sConnectedInformation.concat("PORTB " + 2 + "," + ((oPic.getRam().get_PORTB() & 0b00000100) >> 2) + "\n"); + sConnectedInformation.concat("PORTB " + 3 + "," + ((oPic.getRam().get_PORTB() & 0b00001000) >> 3) + "\n"); + sConnectedInformation.concat("PORTB " + 4 + "," + ((oPic.getRam().get_PORTB() & 0b00010000) >> 4) + "\n"); + sConnectedInformation.concat("PORTB " + 5 + "," + ((oPic.getRam().get_PORTB() & 0b00100000) >> 5) + "\n"); + sConnectedInformation.concat("PORTB " + 6 + "," + ((oPic.getRam().get_PORTB() & 0b01000000) >> 6) + "\n"); + sConnectedInformation.concat("PORTB " + 7 + "," + ((oPic.getRam().get_PORTB() & 0b10000000) >> 7) + "\n"); + + //STACK in frontend is set. + sConnectedInformation.concat("STACK " + oPic.getStack().getSTACK()[0] + "," + + oPic.getStack().getSTACK()[1] + "," + + oPic.getStack().getSTACK()[2] + "," + + oPic.getStack().getSTACK()[3] + "," + + oPic.getStack().getSTACK()[4] + "," + + oPic.getStack().getSTACK()[5] + "," + + oPic.getStack().getSTACK()[6] + "," + + oPic.getStack().getSTACK()[7] + "\n"); + + //TIMER0 + sConnectedInformation.concat("TIMER0 " + oPic.getRam().get_TMR0() + "\n"); + + //Watchdog in frontend is set. (Doesn't work correctly since watchdog isn't implemented correctly) TODO + sConnectedInformation.concat("WATCHDOG " + liWatchdog + "\n"); + sConnectedInformation.concat("PRESCALER " + 1 + ":" + oPic.getRam().get_TMR0_PrescalerRate() + "\n"); + + if (iSetBreakpoint > -1) + sConnectedInformation.concat("SETBREAK " + iSetBreakpoint + "\n"); + + if (iResetBreakpoint > -1) + sConnectedInformation.concat("RESBREAK " + iResetBreakpoint + "\n"); + else if (iResetBreakpoint == -2) { + sConnectedInformation.concat("RESALLBREAK"); //TODO \n if new string concated + } + + return sConnectedInformation; + } +} diff --git a/src/Backend/EepromLoader/ReadEepromFile.java b/src/Backend/EepromLoader/ReadEepromFile.java new file mode 100755 index 0000000..2cf9159 --- /dev/null +++ b/src/Backend/EepromLoader/ReadEepromFile.java @@ -0,0 +1,220 @@ +package Backend.EepromLoader; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; + +import Backend.Microcontroller.PIC; + +public class ReadEepromFile { + + /** + * Get OP-Code out of String-data-array. + * @param dataArray String-array where OP-Code is. + * @return String-array with only OP-Code. + */ + public ArrayList getOPCode(ArrayList data) { + + ArrayList oPCode = new ArrayList(); + + for (int i = 0; i < data.size(); i++) { + //If element in dataArray at position i is null or a space, this element is not added into the new oPCode-Array. + if (data.get(i) != null && data.get(i).charAt(0) != 32) { + oPCode.add(data.get(i)); + } + } + + return oPCode; + } + + /** + * Gets whole data of the file. + * @param file + * @return ArrayList + * @throws IOException + */ + public ArrayList getData(File file) { + + ArrayList list = new ArrayList(); + try { + FileReader fR = new FileReader(file); + BufferedReader br = new BufferedReader(fR); + + String sLine; + while ((sLine = br.readLine()) != null) { + list.add(sLine); + } + + br.close(); + + } catch (IOException e) { + e.printStackTrace(); + } + return list; + } + + /** + * Turns hex-values of an overhanded String-array into an int-array with decimal-values. + * @param oPCode String-array + * @return int-array + */ + public int[][] getOPCodeArrayCommandAsInt(ArrayList oPCode) { + int[][] aiReturnArray = new int[oPCode.size()][2]; + + for (int indexRowOPCode = 0; indexRowOPCode < oPCode.size(); indexRowOPCode++) { + int indexOPCode = 0; + int commandAsInt = 0; + int memoryCount = 0; + + //Stops if second space is reached. (After command is read.) + while (indexOPCode < 9) { + switch (indexOPCode) { + case 0: { + memoryCount = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 0, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[0]); + }break; + + case 1: { + memoryCount = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 1, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[0]); + }break; + + case 2: { + memoryCount = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 2, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[0]); + }break; + + case 3: { + memoryCount = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 3, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[0]); + }break; + + case 5: { + commandAsInt = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 5, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[1]); + }break; + + case 6: { + commandAsInt = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 6, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[1]); + }break; + + case 7: { + commandAsInt = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 7, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[1]); + }break; + + case 8: { + commandAsInt = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 8, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[1]); + }break; + } + + //Increase location which will be checked by one. + indexOPCode++; + } + aiReturnArray[indexRowOPCode][0] = memoryCount; + aiReturnArray[indexRowOPCode][1] = commandAsInt; + } + return aiReturnArray; + } + + /** + * @param iCase Location of the actually checked character. + * @param iIndexRowOPCode Actual row of oPCode. + * @param iMemoryCount + * @param iCommandAsInt + * @return Int-Array with memoryCount [0] and commmandAsInt [1]. + */ + public int[] getOPCodeArrayCommandAsIntSubFunction(ArrayList oPCode, int iCase, int iIndexRowOPCode, int iIndexOPCode, int iMemoryCount, int iCommandAsInt) { + + int[] aiCaseArray = {4096, 256, 16, 1, 0, 4096, 256, 16, 1}; + int[] aiResultArray = new int[2]; + + int iMemoryCountReturn = iMemoryCount; + int iCommandAsIntReturn = iCommandAsInt; + + switch (iCase) { + //0123 0 == 4096 1 == 256 2 == 16 3 == 1 + //0(Ascii: 48) 1(49) ... 9(57) / A(Ascii: 65) B(66) ... F(70) + //Checks first four characters of one line of the simulation-file which are hex-represented-characters(0-F) + //These characters are converted into integer-representation to process further. + case 0: //Fallthrough is wanted + case 1: //Fallthrough is wanted + case 2: //Fallthrough is wanted + case 3: { + //0-9 + if (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) > 47 && oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) < 58) { + iMemoryCountReturn += (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) - 48) * aiCaseArray[iCase]; + } + + //A-F + else if (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) > 64 && oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) < 71) { + iMemoryCountReturn += (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) - 55) * aiCaseArray[iCase]; + } + + //Else + else { + System.out.println("Expected value between 48 and 57 or 65 and 70 but was " + oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode)); + } + }break; + + //Checks 5th, 6th, 7th, 8th character of one line of the simulation-file which are hex-represented-characters(0-F) + //These characters are converted into integer-representation to process further. + case 5: //Fallthrough is wanted + case 6: //Fallthrough is wanted + case 7: //Fallthrough is wanted + case 8: { + //0-9 + if (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) > 47 && oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) < 58) { + iCommandAsIntReturn += (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) - 48) * aiCaseArray[iCase]; + } + + //A-F + else if (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) > 64 && oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) < 71) { + iCommandAsIntReturn += (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) - 55) * aiCaseArray[iCase]; + } + + //Else + else { + System.out.println("Expected value between 48 and 57 or 65 and 70 but was " + oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode)); + } + }break; + } + + aiResultArray[0] = iMemoryCountReturn; + aiResultArray[1] = iCommandAsIntReturn; + + return aiResultArray; + } + + /** + * Reads file and writes instructions to EEPROM. + * @param files String-Array with paths of files. + * @param k index of file in String-Array "files". + * @param oPIC of the main-function. + */ + public void readFileAndWriteToEEPROM(File file, PIC oPIC) { + + //Creates String-arraylist with whole data. + ArrayList dataLines = getData(file); + + //Creates String-arraylist with oPCode. + ArrayList oPCode = getOPCode(dataLines); + + //Integer-array which will contain oPCode as int-values. + //Get an twodimensional array with int-values. + int[][] oPCodeAsInt = getOPCodeArrayCommandAsInt(oPCode); + + //Set length of eeprom for programend. + oPIC.getEeprom().setLengthEEPROM(oPCodeAsInt.length); + + //asCommands are written into EEPROM + for (int i = 0; i < oPCodeAsInt.length; i++) { + //The adress where the command will be written in the EEPROM + int memoryAdress = oPCodeAsInt[i][0]; + //System.out.println(memoryAdress); + + //Command that will be written into the EEPROM + int command = oPCodeAsInt[i][1]; + //System.out.println(command); + + //asCommands are written into EEPROM + oPIC.getEeprom().setElementXToValueY(memoryAdress, command); + } + } +} diff --git a/src/Backend/FrontendCommandProcessing/CommandAction.java b/src/Backend/FrontendCommandProcessing/CommandAction.java new file mode 100755 index 0000000..4b595bd --- /dev/null +++ b/src/Backend/FrontendCommandProcessing/CommandAction.java @@ -0,0 +1,393 @@ +package Backend.FrontendCommandProcessing; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; + +import Backend.BackendCommandProcessing.InformationConnecter; +import Backend.EepromLoader.ReadEepromFile; +import Backend.Runtime.Environment; +import Backend.Microcontroller.PIC; + +public class CommandAction { + + int iAction; + String sValue; + Environment env; + + //List with methods + private List actions = new ArrayList<>(); + + private InformationConnecter informationConnecter = new InformationConnecter(); + + public CommandAction(int iAction, String sValue, Environment env) { + this.iAction = iAction; + this.sValue = sValue; + this.env = env; + + actions.add(callLoadFile);//0 + actions.add(callSaveProgrammState);//1 + actions.add(callSetBreakpoint);//2 + actions.add(callTogglePortA);//3 + actions.add(callTogglePortB);//4 + actions.add(callChangeQuarz);//5 + actions.add(callToggleWatchdog);//6 + actions.add(callReset);//7 + actions.add(callStep);//8 + actions.add(callStartProgramm);//9 + actions.add(callStopProgramm);//10 + actions.add(callLoadProgrammState);//11 + actions.add(callRemoveBreakpoint);//12 + actions.add(callRemoveAllBreakpoints);//13 + + actions.add(callErrorReadFailed);//14 + } + + public int execute() { + int iReturn = 0; + if (iAction > -1) { + try { + iReturn = (int)actions.get(iAction).call(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return iReturn; + } + + Callable callLoadFile = new Callable() { + @Override + public Object call() { + return loadFile(); + } + }; + + Callable callSaveProgrammState = new Callable() { + @Override + public Object call() { + return saveProgrammState(); + } + }; + + Callable callSetBreakpoint = new Callable() { + @Override + public Object call() { + return setBreakpoint(); + } + }; + + Callable callTogglePortA = new Callable() { + @Override + public Object call() { + return togglePortA(); + } + }; + + Callable callTogglePortB = new Callable() { + @Override + public Object call() { + return togglePortB(); + } + }; + + Callable callChangeQuarz = new Callable() { + @Override + public Object call() { + return changeQuarz(); + } + }; + + Callable callToggleWatchdog = new Callable() { + @Override + public Object call() { + return toggleWatchdog(); + } + }; + + Callable callReset = new Callable() { + @Override + public Object call() { + return reset(); + } + }; + + Callable callStep = new Callable() { + @Override + public Object call() { + return step(); + } + }; + + Callable callStartProgramm = new Callable() { + @Override + public Object call() { + return startProgramm(); + } + }; + + Callable callStopProgramm = new Callable() { + @Override + public Object call() { + return stopProgramm(); + } + }; + + Callable callLoadProgrammState = new Callable() { + @Override + public Object call() { + return loadProgrammState(); + } + }; + + Callable callRemoveBreakpoint = new Callable() { + @Override + public Object call() { + return removeBreakpoint(); + } + }; + + Callable callRemoveAllBreakpoints = new Callable() { + @Override + public Object call() { + return removeAllBreakpoints(); + } + }; + + Callable callErrorReadFailed = new Callable() { + @Override + public Object call() { + return readFailed(); + } + }; + + //Read file out of filepath and write it to EEPROM of oPIC. + private int loadFile() { + ReadEepromFile readEepromFile = new ReadEepromFile(); + env.getPIC().resetPIC(); + readEepromFile.readFileAndWriteToEEPROM(new File(sValue), env.getPIC()); + env.getMainToFrontendQueue().add(informationConnecter.connectInformation(env.getPIC(), env.getActualLine(), env.getLastLine(), -2, -2, env.getRuntime(), env.getWatchdog().getTime())); + //TODO sent message to thread, to change value in file + return 0; + } + + private int saveProgrammState() { + //TODO Logic + //TODO sent message to thread, to change value in file + return 0; + } + + private int setBreakpoint() { + env.changeListBreakpoints(Integer.parseInt(sValue), true); + env.getMainToFrontendQueue().add(informationConnecter.connectInformation(env.getPIC(), env.getActualLine(), env.getLastLine(), Integer.parseInt(sValue), -2, env.getRuntime(), env.getWatchdog().getTime())); + //TODO sent message to thread, to change value in file + return 0; + } + + private int togglePortA() { + int iBit = Integer.parseInt(sValue.substring(0,1)); + int iValue = Integer.parseInt(sValue.substring(2, 3)); + env.getPIC().getRam().set_PORTA_Bit_X_To_Y(iBit, iValue); + //TODO sent message to thread, to change value in file + return 0; + } + + private int togglePortB() { + int iBit = Integer.parseInt(sValue.substring(0,1)); + int iValue = Integer.parseInt(sValue.substring(2, 3)); + env.getPIC().getRam().set_PORTB_Bit_X_To_Y(iBit, iValue); + //TODO sent message to thread, to change value in file + return 0; + } + + private int changeQuarz() { + //XTA(L) not implemented + //TODO sent message to thread, to change value in file + return 0; + } + + private int toggleWatchdog() { + /** + * //WAT(CHDOG) + if (sFileFrontendToBackendCommand.substring(9, 11).equals("ON")) + { + //ON + liWorkWithWatchdog(1, 5); + } + + else + { + //OFF + liWorkWithWatchdog(1, 4); + } + */ + //TODO sent message to thread, to change value in file + return 0; + } + + private int reset() { + /** + * //RES(ET) + liDifferenceTimeNano = 0; + oPIC.resetPIC(); + //oPIC.Ram.set_OPTION(255); + //resetLines(); + bCreateGUIFile = true; + */ + env.getPIC().resetPIC(); + env.getPIC().getRam().set_OPTION(255); + //TODO sent message to thread, to change value in file + return 0; + } + + private int step() { + /** + * //STE(P) + //System.out.println("STEP " + oPIC.Ram.get_Programcounter()); + if (oPIC.Ram.get_Programcounter() < (oPIC.Eeprom.getLengthEEPROM() - 1)) + { + final long liTimeStart = System.nanoTime(); + + //Makes one step through the eeprom. + bitMaskDecisionMaker(oPIC.Eeprom.getElement(oPIC.Ram.get_Programcounter()), oPIC); + + final long timeEnd = System.nanoTime(); + + liDifferenceTimeNano += (timeEnd - liTimeStart); + + if (!oPIC.Ram.get_T0CS()) + { + oPIC.Ram.increment_TMR0(); + } + + bCreateGUIFile = true; + */ + env.step();//step in env or set/gets + //TODO sent message to thread, to change value in file + return 0; + } + + private int startProgramm() { + /** + * //STA(RT) + + final long liTimeStart = System.nanoTime(); + + liWorkWithWatchdog(1, 1); + + if ((iAccessBreakpoint(3, 0) > (-1)) && (iAccessBreakpoint(3, 0) <= (oPIC.Eeprom.getLengthEEPROM() - 1))) + { + while ((oPIC.Ram.get_Programcounter() < iAccessBreakpoint(3, 0)) && (cMenueSelection != 'p')) + { + //System.out.println("STEP " + oPIC.Ram.get_Programcounter()); + bitMaskDecisionMaker(oPIC.Eeprom.getElement(oPIC.Ram.get_Programcounter()), oPIC); + + if (!oPIC.Ram.get_T0CS()) + { + oPIC.Ram.increment_TMR0(); + } + + bCreateGUIFile = true; + } + iAccessBreakpoint(2, 0); + bCreateGUIFile = true; + System.out.println(iAccessBreakpoint(3, 0)); + } + + else + { + while ((oPIC.Ram.get_Programcounter() < ((oPIC.Eeprom.getLengthEEPROM() - 1))) && (cMenueSelection != 'p')) + { + //System.out.println("STEP " + oPIC.Ram.get_Programcounter()); + bitMaskDecisionMaker(oPIC.Eeprom.getElement(oPIC.Ram.get_Programcounter()), oPIC); + + if (!oPIC.Ram.get_T0CS()) + { + oPIC.Ram.increment_TMR0(); + } + + bCreateGUIFile = true; + } + } + + liWorkWithWatchdog(1, 2); + final long timeEnd = System.nanoTime(); + + liDifferenceTimeNano = timeEnd - liTimeStart; + + bCreateGUIFile = true; + */ + //TODO sent message to thread, to change value in file + return 0; + } + + private int stopProgramm() { + /** + * //STO(PP) + //watchdogThread.setWatchdogStatus(3); + cMenueSelection = 'p'; + */ + //TODO sent message to thread, to change value in file + return 0; + } + + private int loadProgrammState() { + //TODO sent message to thread, to change value in file + return 0; + } + + private int removeBreakpoint() { + env.changeListBreakpoints(Integer.parseInt(sValue), false); + //TODO sent message to thread, to change value in file + return 0; + } + + private int removeAllBreakpoints() { + env.changeListBreakpoints(-1, false); + return 0; + } + + private int readFailed() { + System.out.println("Fehler: Lesen der Datei fehlgeschlagen."); + return 0; + } + + /** + * //PRT( Scale) ? Prescaler is set from additional frontend. + try + { + if (sFileFrontendToBackendCommand.substring(4, 5) != null) + { + oPIC.Ram.set_OPTION((oPIC.Ram.get_OPTION() & 11111000) | (Integer.parseInt(sFileFrontendToBackendCommand.substring(4, 5)))); + bCreateGUIFile = true; + } + } + catch (StringIndexOutOfBoundsException e) + {} + */ + + /** + * //PRW( Scale) ? Prescaler is set from additional frontend. + try + { + if (sFileFrontendToBackendCommand.substring(4, 5) != null) + { + oPIC.Ram.set_OPTION((oPIC.Ram.get_OPTION() & 11111000) | (Integer.parseInt(sFileFrontendToBackendCommand.substring(4, 5)))); + bCreateGUIFile = true; + } + if (sFileFrontendToBackendCommand.substring(5, 6) != null) + { + oPIC.Ram.set_OPTION((oPIC.Ram.get_OPTION() & 11111000) | (Integer.parseInt(sFileFrontendToBackendCommand.substring(4, 6)))); + bCreateGUIFile = true; + } + if (sFileFrontendToBackendCommand.substring(6, 7) != null) + { + oPIC.Ram.set_OPTION((oPIC.Ram.get_OPTION() & 11111000) | (Integer.parseInt(sFileFrontendToBackendCommand.substring(4, 7)))); + bCreateGUIFile = true; + } + } + catch (StringIndexOutOfBoundsException e) + {} + */ +} \ No newline at end of file diff --git a/src/Backend/FrontendCommandProcessing/CommandDecoder.java b/src/Backend/FrontendCommandProcessing/CommandDecoder.java new file mode 100755 index 0000000..0ea11f3 --- /dev/null +++ b/src/Backend/FrontendCommandProcessing/CommandDecoder.java @@ -0,0 +1,122 @@ +package Backend.FrontendCommandProcessing; + +import java.util.regex.*; + +import Backend.Runtime.Environment; + +//TODO Changes at patterns have to occur at all methods! + +/** + * Class to decode commandstring. + */ +public class CommandDecoder { + + private String sActualCommand = ""; + + public CommandDecoder(String sActualCommand) { + this.sActualCommand = sActualCommand; + } + + /** + * Get type of command. + * @return int representation of pattern, -1 if no pattern matches + */ + public int getCommandType() { + + int iPatternMatched = 0; + + //Read file and save line to string + //sActualCommand = input.getActualCommand(); + + //External oparations + Pattern loadFile = Pattern.compile("^F_\\S*$");//0 + Pattern saveProgrammState = Pattern.compile("^S_\\S*$");//1 + Pattern setBreakpoint = Pattern.compile("^BS_\\d*$");//2 + Pattern togglePortA = Pattern.compile("^PA_\\d\\s(1|0)$");//3 + Pattern togglePortB = Pattern.compile("^PB_\\d$");//4 + Pattern changeQuarz = Pattern.compile("^Q_[\\d]{1,2}$");//5 + Pattern toggleWatchdog = Pattern.compile("W_[tf]$");//6 + Pattern reset = Pattern.compile("^R_$");//7 + Pattern step = Pattern.compile("^S_$");//8 + Pattern startProgramm = Pattern.compile("^RP_$");//9 + Pattern stopProgramm = Pattern.compile("^SP_$");//10 + Pattern loadProgrammState = Pattern.compile("^L_\\S*$");//11 + Pattern removeBreakpoint = Pattern.compile("^BR_\\d*$");//12 + Pattern removeAllBreakpoint = Pattern.compile("^BRA$");//13 + + //Internal operations + Pattern errorFileRead = Pattern.compile("ERROR FILEREAD");//14 + + Pattern[] patterns = {loadFile, saveProgrammState, setBreakpoint, togglePortA, togglePortB, changeQuarz, toggleWatchdog, reset, step, + startProgramm, stopProgramm, loadProgrammState, removeBreakpoint, removeAllBreakpoint, errorFileRead}; + + int iNumberOfPatterns = patterns.length; + + //Iterate through patterns and check if pattern matches to command. + for (int i = 0; i < iNumberOfPatterns; i++) { + Matcher matcher = patterns[i].matcher(sActualCommand); + boolean bMatchFound = matcher.find(); + if (bMatchFound) { + iPatternMatched = i; + i = iNumberOfPatterns; // break loop for performance + } else { + iPatternMatched = -1; + } + } + + return iPatternMatched; + } + + /** + * Get value of command + * @return + */ + public String getCommandValue(int iCommandType) { + + int iStringLen = sActualCommand.length(); + + String sValue = ""; + + switch (iCommandType) { + //0 F_ + //1 S_ + //5 Q_ + //6 W_ + case 0: + case 1: + case 5: + case 6: + case 11: { + sValue = sActualCommand.substring(2, iStringLen); + }break; + + //2 BS_ + //3 PA_ + //4 PB_ + //12 BR_ + case 2: + case 3: + case 4: + case 12: { + sValue = sActualCommand.substring(3, iStringLen); + }break; + + case 13: { + //No Value needed + }break; + + default: { + sValue = "undefined"; + }break; + } + + return sValue; + } + + public int executeAction(Environment env) { + int iAction = getCommandType(); + String sValue = getCommandValue(iAction); + CommandAction action = new CommandAction(iAction, sValue, env); + return action.execute(); + } +} \ No newline at end of file diff --git a/src/Backend/FrontendCommandProcessing/FrontendCommandProcessingThread.java b/src/Backend/FrontendCommandProcessing/FrontendCommandProcessingThread.java new file mode 100755 index 0000000..f559b2a --- /dev/null +++ b/src/Backend/FrontendCommandProcessing/FrontendCommandProcessingThread.java @@ -0,0 +1,49 @@ +package Backend.FrontendCommandProcessing; + +import java.io.File; + +import java.util.concurrent.ConcurrentLinkedQueue; + +/** + * Thread-class responsibility is to check every few milliseconds if fileBackendToFrontend exists and if so, then read it and send string through queue to main-thread. + */ +public class FrontendCommandProcessingThread extends Thread { + + private static File fileBackendToFrontend = new File("../SIMULATOR_DAT/gui_set.dat"); + + private ConcurrentLinkedQueue queue; + + private int iSleepTime = 100; + + ReadFile readFile = new ReadFile(); + + /** + * + * @param inputQueue overhanded from main-method + */ + public FrontendCommandProcessingThread(ConcurrentLinkedQueue inputQueue) { + queue = inputQueue; + } + + /** + * FrontendCommandProcessingThread-class responsibility is to check every few milliseconds if fileBackendToFrontend exists and if so, then read it and send string through queue to main-thread. + */ + @Override + public void run() { + + String sActualCommand = ""; + + while (true) { + try { + //Sleeps iSleepTime milli seconds + Thread.sleep(iSleepTime); + } catch(InterruptedException e) { + System.out.println(e); + } + if (fileBackendToFrontend.isFile()) { + sActualCommand = readFile.getActualCommand(); + queue.add(sActualCommand); + } + } + } +} diff --git a/src/Backend/FrontendCommandProcessing/ReadFile.java b/src/Backend/FrontendCommandProcessing/ReadFile.java new file mode 100755 index 0000000..8749043 --- /dev/null +++ b/src/Backend/FrontendCommandProcessing/ReadFile.java @@ -0,0 +1,58 @@ +package Backend.FrontendCommandProcessing; +//package SIMULATOR; + +import java.io.*; + +/** + * Class reads line out of file. + */ +public class ReadFile { + + private File fileFrontendToBackend = new File("C:/Users/Windows 10/Desktop/Studium/SS_21/Rechnerarchitektur_Projekt/gui_change.dat"); + private String sActualCommand; + + public ReadFile() {} + + /** + * Resets file from where data is read to new overhanded path. + * @param fileFrontendToBackend + */ + public ReadFile(String fileFrontendToBackend) { + this.fileFrontendToBackend = new File(fileFrontendToBackend); + } + + /** + * Reads FrontendToBackend-file and updates (-)sActualCommand. + * @return 1 at success, -1 at error + */ + private int readInputFile() { + + int iReturn = 0; + try { + FileReader fileReader = new FileReader(fileFrontendToBackend); + BufferedReader bufferedReader = new BufferedReader(fileReader); + sActualCommand = bufferedReader.readLine(); + bufferedReader.close(); + fileFrontendToBackend.delete(); + iReturn = 1; // success + } catch (IOException e) { + iReturn = -1; // error + } + return iReturn; + } + + /** + * Reads file and returns actual command as string + * @return command as string at success, ERROR at error + */ + public String getActualCommand() { + String line = null; + int iReadInputFile = readInputFile(); + if (iReadInputFile == 1) { + line = sActualCommand; + } else if (iReadInputFile == -1) { + line = "ERROR FILEREAD"; + } + return line; + } +} diff --git a/src/Backend/Microcontroller/Bitmask.java b/src/Backend/Microcontroller/Bitmask.java new file mode 100755 index 0000000..0065fca --- /dev/null +++ b/src/Backend/Microcontroller/Bitmask.java @@ -0,0 +1,443 @@ +package Backend.Microcontroller; + +public class Bitmask { + /** + * Decides which PIC-command-method to call. + * @param iCommandAsIntToMask + * @param oPIC + */ + public int bitMaskDecoderAndExecuteCommand(int iCommandAsIntToMask, PIC oPIC) { + + //Return-value will be -1 if command can't be read. + int iDecodedCommand = -1; + + //Command that was overhanded is written into "command" + int iCommand = iCommandAsIntToMask; + + //Bitmask to get the destination-bit + int iDestinationBitBitmask = 0b00000010000000; + //Destination-bit + int iDestinationBit = (iDestinationBitBitmask & iCommand) >> 7; + + //Bitmask to get the register-file-adress + int iRegisterFileAddressBitmask = 0b00000001111111; + //Register-file-adress + int iRegisterFileAddress = (iRegisterFileAddressBitmask & iCommand); + + //Bitmask to get bitaddress + int iBitaddressBitmask = 0b00001110000000; + //Bitaddress + int iBitaddress = (iBitaddressBitmask & iCommand) >> 7; + + //Bitmask to get eight last k's + int iEightKBitmask = 0b00000011111111; + int iEightK = (iEightKBitmask & iCommand); + + //Bitmask to get eleven last k's + int iElevenKBitmask = 0b00011111111111; + int iElevenK = (iElevenKBitmask & iCommand); + + //Bitmask to get TRIS-register TRIS instruction not used + //int tRISRegisterBitmask = 0b000000000111; + //int tRISRegisterAddress = (tRISRegisterBitmask & command); + + if ((0b10000000000000 & iCommand) == 0b10000000000000) { + //1x xxxx xxxx xxxx + if ((0b01000000000000 & iCommand) == 0b01000000000000) { + //11 xxxx xxxx xxxx + if ((0b00100000000000 & iCommand) == 0b00100000000000) { + //11 1xxx xxxx xxxx + if ((0b00010000000000 & iCommand) == 0b00010000000000) { + //11 11xx xxxx xxxx + if ((0b00001000000000 & iCommand) == 0b00001000000000) { + //11 111x xxxx xxxx + iDecodedCommand = 22; //ADDLW + } else { + //11 110x xxxx xxxx + iDecodedCommand = 33; //SUBLW + } + } else { + //11 10xx xxxx xxxx + if ((0b00001000000000 & iCommand) == 0b00001000000000) { + //11 101x xxxx xxxx + if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //11 1011 xxxx xxxx + } else { + //11 1010 xxxx xxxx + iDecodedCommand = 34; //XORLW + } + } else { + //11 100x xxxx xxxx + if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //11 1001 xxxx xxxx + iDecodedCommand = 23; //ANDLW + } else { + //11 1000 xxxx xxxx + iDecodedCommand = 27; //IORLW + } + } + } + } else { + //11 0xxx xxxx xxxx + if ((0b00010000000000 & iCommand) == 0b00010000000000) { + //11 01xx xxxx xxxx + iDecodedCommand = 30; //RETLW + } else { + //11 00xx xxxx xxxx + iDecodedCommand = 28; //MOVLW + } + } + } else { + //10 xxxx xxxx xxxx + if ((0b00100000000000 & iCommand) == 0b00100000000000) { + //10 1xxx xxxx xxxx + iDecodedCommand = 26; //GOTO + } else { + //10 0xxx xxxx xxxx + iDecodedCommand = 24; //CALL + } + } + } else if ((0b01000000000000 & iCommand) == 0b01000000000000) { + //01 xxxx xxxx xxxx + if ((0b00100000000000 & iCommand) == 0b00100000000000) { + //01 1xxx xxxx xxxx + if ((0b00010000000000 & iCommand) == 0b00010000000000) { + //01 11xx xxxx xxxx + iDecodedCommand = 21; //BTFSS + } else { + //01 10xx xxxx xxxx + iDecodedCommand = 20; //BTFSC + } + } else { + //01 0xxx xxxx xxxx + if ((0b00010000000000 & iCommand) == 0b00010000000000) { + //01 01xx xxxx xxxx + iDecodedCommand = 19; //BSF + } else { + //01 00xx xxxx xxxx + iDecodedCommand = 18; //BCF + } + } + } else if ((0b00100000000000 & iCommand) == 0b00100000000000) { + //00 1xxx xxxx xxxx + if ((0b00010000000000 & iCommand) == 0b00010000000000) { + //00 11xx xxxx xxxx + if ((0b00001000000000 & iCommand) == 0b00001000000000) { + //00 111x xxxx xxxx + if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //00 1111 xxxx xxxx + iDecodedCommand = 8; //INCFSZ + } else { + //00 1110 xxxx xxxx + iDecodedCommand = 16; //SWAPF + } + } else { + //00 110x xxxx xxxx + if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //00 1101 xxxx xxxx + iDecodedCommand = 13; //RLF + } else { + //00 1100 xxxx xxxx + iDecodedCommand = 14; //RRF + } + } + } else { + //00 10xx xxxx xxxx + if ((0b00001000000000 & iCommand) == 0b00001000000000) { + //00 101x xxxx xxxx + if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //00 1011 xxxx xxxx + iDecodedCommand = 6; //DECFSZ + } else { + //00 1010 xxxx xxxx + iDecodedCommand = 7; //INCF + } + } else { + //00 100x xxxx xxxx + if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //00 1001 xxxx xxxx + iDecodedCommand = 4; //COMF + } else { + //00 1000 xxxx xxxx + iDecodedCommand = 10; //MOVF + } + } + } + } else if ((0b00010000000000 & iCommand) == 0b00010000000000) { + //00 01xx xxxx xxxx + if ((0b00001000000000 & iCommand) == 0b00001000000000) { + //00 011x xxxx xxxx + if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //00 0111 xxxx xxxx + iDecodedCommand = 0; //ADDWF + } else { + //00 0110 xxxx xxxx + iDecodedCommand = 17; //XORWF + } + } else { + //00 010x xxxx xxxx + if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //00 0101 xxxx xxxx + iDecodedCommand = 1; //ANDWF + } else { + //00 0100 xxxx xxxx + iDecodedCommand = 9; //IORWF + } + } + } else if ((0b00001000000000 & iCommand) == 0b00001000000000) { + //00 001x xxxx xxxx + if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //00 0011 xxxx xxxx + iDecodedCommand = 5; //DECF + } else { + //00 0010 xxxx xxxx + iDecodedCommand = 15; //SUBWF + } + } else if ((0b00000100000000 & iCommand) == 0b00000100000000) { + //00 0001 xxxx xxxx + if ((0b00000010000000 & iCommand) == 0b00000010000000) { + //00 0001 1xxx xxxx + iDecodedCommand = 2; //CLRF + } else { + //00 0001 0xxx xxxx + iDecodedCommand = 3; //CLRW + } + } else if ((0b00000001000000 & iCommand) == 0b00000001000000) { + //00 0000 01xx xxxx + if ((0b00000000100000 & iCommand) == 0b00000000100000) { + //00 0000 011x xxxx + if ((0b00000000010000 & iCommand) == 0b00000000010000) { + //00 0000 0111 xxxx + } else { + //00 0000 0110 xxxx + if ((0b00000000001000 & iCommand) == 0b00000000001000) { + //00 0000 0110 1xxx + } else { + //00 0000 0110 0xxx + if ((0b00000000000100 & iCommand) == 0b00000000000100) { + //00 0000 0110 01xx + if ((0b00000000000010 & iCommand) == 0b00000000000010) { + //00 0000 0110 011x + } else { + //00 0000 0110 010x + if ((0b00000000000001 & iCommand) == 0b00000000000001) { + //00 0000 0110 0101 + } else { + //00 0000 0110 0100 + iDecodedCommand = 25; //CLRWDT + } + } + } else { + //00 0000 0110 00xx + if ((0b00000000000010 & iCommand) == 0b00000000000010) { + //00 0000 0110 001x + if ((0b00000000000001 & iCommand) == 0b00000000000001) { + //00 0000 0110 0011 + iDecodedCommand = 32; //SLEEP + } else { + //00 0000 0110 0010 + iDecodedCommand = 35; //OPTION + } + } + } + } + } + } + } else if ((0b00000010000000 & iCommand) == 0b00000010000000) { + //00 0000 1xxx xxxx + iDecodedCommand = 11; //MOVWF + } else if ((0b00000000001000 & iCommand) == 0b00000000001000) { + //00 0000 0000 1xxx + if ((0b00000000000100 & iCommand) == 0b00000000000100) { + //00 0000 0000 11xx + } else { + //00 0000 0000 10xx + if ((0b00000000000010 & iCommand) == 0b00000000000010) { + //00 0000 0000 101x + } else { + //00 0000 0000 100x + if ((0b00000000000001 & iCommand) == 0b00000000000001) { + //00 0000 0000 1001 + iDecodedCommand = 29; //RETFIE + } else { + //00 0000 0000 1000 + iDecodedCommand = 31; //RETURN + } + } + } + } else if ((0b00000001100000 & iCommand) == iCommand) { + //00 0000 0xx0 0000 + iDecodedCommand = 12; //NOP + } + iDecodedCommandDecissionMaker(iDecodedCommand, oPIC, iDestinationBit, iRegisterFileAddress, iBitaddress, iEightK, iElevenK); + + return iDecodedCommand; + } + + public void iDecodedCommandDecissionMaker(int iDecodedCommand, PIC oPIC, int iDestinationBit, int iRegisterFileAddress, int iBitaddress, int iEightK, int iElevenK) { + switch (iDecodedCommand) { + case -1: { + System.out.println("Command doesn't exist."); + }break; + + case 0: { + oPIC.ADDWF(iDestinationBit, iRegisterFileAddress); + }break; + + case 1: { + oPIC.ANDWF(iDestinationBit, iRegisterFileAddress); + }break; + + case 2: { + oPIC.CLRF(iRegisterFileAddress); + }break; + + case 3: { + oPIC.CLRW(); + }break; + + case 4: { + oPIC.COMF(iDestinationBit, iRegisterFileAddress); + }break; + + case 5: { + oPIC.DECF(iDestinationBit, iRegisterFileAddress); + }break; + + case 6: { + oPIC.DECFSZ(iDestinationBit, iRegisterFileAddress); + }break; + + case 7: { + oPIC.INCF(iDestinationBit, iRegisterFileAddress); + }break; + + case 8: { + oPIC.INCFSZ(iDestinationBit, iRegisterFileAddress); + }break; + + case 9: { + oPIC.IORWF(iDestinationBit, iRegisterFileAddress); + }break; + + case 10: { + oPIC.MOVF(iDestinationBit, iRegisterFileAddress); + }break; + + case 11: { + oPIC.MOVWF(iRegisterFileAddress); + }break; + + case 12: { + oPIC.NOP(); + }break; + + case 13: { + oPIC.RLF(iDestinationBit, iRegisterFileAddress); + }break; + + case 14: { + oPIC.RRF(iDestinationBit, iRegisterFileAddress); + }break; + + case 15: { + oPIC.SUBWF(iDestinationBit, iRegisterFileAddress); + }break; + + case 16: { + oPIC.SWAPF(iDestinationBit, iRegisterFileAddress); + }break; + + case 17: { + oPIC.XORWF(iDestinationBit, iRegisterFileAddress); + }break; + + case 18: { + oPIC.BCF(iBitaddress, iRegisterFileAddress); + }break; + + case 19: { + oPIC.BSF(iBitaddress, iRegisterFileAddress); + }break; + + case 20: { + oPIC.BTFSC(iBitaddress, iRegisterFileAddress); + }break; + + case 21: { + oPIC.BTFSS(iBitaddress, iRegisterFileAddress); + }break; + + case 22: { + oPIC.ADDLW(iEightK); + }break; + + case 23: { + oPIC.ANDLW(iEightK); + }break; + + case 24: { + oPIC.CALL(iElevenK); + }break; + + case 25: { + //watchdogThread.setTime(0); + oPIC.CLRWDT(); + }break; + + case 26: { + oPIC.GOTO(iElevenK); + }break; + + case 27: { + oPIC.IORLW(iEightK); + }break; + + case 28: { + oPIC.MOVLW(iEightK); + }break; + + case 29: { + oPIC.RETFIE(); + }break; + + case 30: { + oPIC.RETLW(iEightK); + }break; + + case 31: { + oPIC.RETURN(); + }break; + + case 32: { + oPIC.SLEEP(); + }break; + + case 33: { + oPIC.SUBLW(iEightK); + }break; + + case 34: { + oPIC.XORLW(iEightK); + }break; + + case 35: { + /** + * To maintain upward compatibility + * with future PIC16CXX products, + * do not use this instruction. + */ + oPIC.OPTION(); + }break; + + case 36: { + /** + * To maintain upward compatibility + * with future PIC16CXX products, + * do not use this instruction. + */ + oPIC.TRIS(); + }break; + } + } +} \ No newline at end of file diff --git a/src/Backend/Microcontroller/EEPROM.java b/src/Backend/Microcontroller/EEPROM.java new file mode 100755 index 0000000..1f88cf8 --- /dev/null +++ b/src/Backend/Microcontroller/EEPROM.java @@ -0,0 +1,72 @@ +package Backend.Microcontroller; +/** + * @author Aaron Moser + * @date 23.06.2021 + */ + + /** + * Electrical Eraseable Programmable Read Only Memory of the PIC (Programmspeicher) + */ +public class EEPROM +{ + private int[] eeprom; + private int eepromLength = 0; + + public EEPROM() + { + eeprom = new int[1024]; + } + + /** + * Returns element of index element in eeprom-array. + * @param element index of array. + * @return element at index. + */ + public int getElement(int index) + { + int returnValue = -1; + + if (index >= 0 && index <= 1024) + { + returnValue = eeprom[index]; + } + + return returnValue; + } + + /** + * Returns length of EEPROM + */ + public int getLengthEEPROM() + { + return eepromLength; + } + + /** + * Set element to value. + * @param index of element. + * @param value of what the element is set to. + * @return true if set worked. + */ + public boolean setElementXToValueY(int index, int value) + { + boolean setWorked = false; + + if ((index >= 0) && (index <= 1024)) + { + eeprom[index] = value; + setWorked = true; + } + + return setWorked; + } + + /** + * Length of eeprom gets restricted. + * @param length is new length. + */ + public void setLengthEEPROM(int length) + { + eepromLength = length; + } +} diff --git a/src/Backend/Microcontroller/PIC.java b/src/Backend/Microcontroller/PIC.java new file mode 100755 index 0000000..3bbae2f --- /dev/null +++ b/src/Backend/Microcontroller/PIC.java @@ -0,0 +1,1483 @@ +package Backend.Microcontroller; + +/** + * @author Aaron Moser + * @date 23.06.2021 + */ + +/** + * Microcontrollerclass that contains all other partclasses + */ +public class PIC +{ + /** + * Parts of PIC. + * Objects are written with a large starting letter. + */ + private EEPROM Eeprom; + private RAM Ram; + private STACK Stack; + private int WRegister; + + public PIC() + { + //Initialising objects of PIC. + Eeprom = new EEPROM(); + Ram = new RAM(); + Stack = new STACK(); + WRegister = 0; + } + + public void resetPIC() + { + Ram = new RAM(); + Stack = new STACK(); + WRegister = 0; + } + + //Bitmasks to set or get bits (use OR for set and AND for get). + int bitMaskSetBit0 = 0b00000001; + int bitMaskSetBit1 = 0b00000010; + int bitMaskSetBit2 = 0b00000100; + int bitMaskSetBit3 = 0b00001000; + int bitMaskSetBit4 = 0b00010000; + int bitMaskSetBit5 = 0b00100000; + int bitMaskSetBit6 = 0b01000000; + int bitMaskSetBit7 = 0b10000000; + + int bitMaskSetBitArray[] = { bitMaskSetBit0, bitMaskSetBit1, bitMaskSetBit2, bitMaskSetBit3, bitMaskSetBit4, bitMaskSetBit5, + bitMaskSetBit6, bitMaskSetBit7 }; + + //Bitmasks to clear bits (use AND). + int bitMaskClearBit0 = 0b11111110; + int bitMaskClearBit1 = 0b11111101; + int bitMaskClearBit2 = 0b11111011; + int bitMaskClearBit3 = 0b11110111; + int bitMaskClearBit4 = 0b11101111; + int bitMaskClearBit5 = 0b11011111; + int bitMaskClearBit6 = 0b10111111; + int bitMaskClearBit7 = 0b01111111; + + int bitMaskClearBitArray[] = { bitMaskClearBit0, bitMaskClearBit1, bitMaskClearBit2, bitMaskClearBit3, bitMaskClearBit4, bitMaskClearBit5, + bitMaskClearBit6, bitMaskClearBit7}; + + public void setWRegister(int value) + { + WRegister = value; + } + + public int get_WRegister() + { + return WRegister; + } + + public RAM getRam() { + return Ram; + } + + public EEPROM getEeprom() { + return Eeprom; + } + + public STACK getStack() { + return Stack; + } + + /** + * Datasheet Page 57 + * + * The contents of the W register are + * added to the eight bit literal ’k’ and the + * result is placed in the W register. + */ + public void ADDLW(int eightK) + { + int wRegValue = get_WRegister(); + int result = wRegValue + eightK; + + //If result is zero. + if (result == 0) + { + Ram.set_Zeroflag(true); + } + + //If result is not zero. + else + { + Ram.set_Zeroflag(false); + } + + //If result is greater than 255. + if (result > 255) + { + result = result & 255; + Ram.set_Carryflag(true); + } + + //If result is smaller than 0. + else if (result < 0) + { + result = result & 255; + Ram.set_Carryflag(true); + } + + //If result is greater than or equal to 0 and smaller than or equal to 255. + else + { + Ram.set_Carryflag(false); + } + + //The lower four bits are bitwise and with 1111b (15d). + int dcResult = (wRegValue & 15) + (eightK & 15); + + //If the result is greater than 15, DC-Flag is set true. + if (dcResult > 15) + { + Ram.set_Digitcarryflag(true); + } + + //If the result is smaller or equal to 15, DC-Flag is set false. + else + { + Ram.set_Digitcarryflag(false); + } + + setWRegister(result); + Ram.inkrement_Programcounter(1, 0); //Kind of call + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 57 + * + * The contents of W register are + * AND’ed with the eight bit literal 'k'. The + * result is placed in the W register. + */ + public void ANDLW(int eightK) + { + int wRegValue = get_WRegister(); + int result = wRegValue & eightK; + + //If result is zero. + if (result == 0) + { + Ram.set_Zeroflag(true); + } + + //If result is not zero. + else + { + Ram.set_Zeroflag(false); + } + + //Write result into + setWRegister(result); + + //Increment programcounter + Ram.inkrement_Programcounter(1, 0); //Kind of call + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 57 + * + * Add the contents of the W register with the + * contents of register ’f’. If ’d’ is 0 the result is + * stored in the W register. If ’d’ is 1 the result is + * stored back in register ’f’. + */ + public void ADDWF(int destinationBit, int registerFileAddress) + { + //Get Value of + int wRegValue = get_WRegister(); + //Get Value of RAM-Bank-RP0Bit Address. + int regFileAddrValue = Ram.get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(Ram.get_RP0Bit(), registerFileAddress); + + //Calculate result. + int result = wRegValue + regFileAddrValue; + + //If result is zero. + if (result == 0) + { + Ram.set_Zeroflag(true); + } + + //If result is not zero. + else + { + Ram.set_Zeroflag(false); + } + + //If result is greater than 255. + if (result > 255) + { + result &= 255; + Ram.set_Carryflag(true); + } + + //If result is smaller than 0. + else if (result < 0) + { + result &= 255; + Ram.set_Carryflag(true); + } + + else + { + Ram.set_Carryflag(false); + } + + //The lower four bits are bitwise and with 1111boolean (15dezimal). + int dcResult = (wRegValue & 15) + (regFileAddrValue & 15); + + //If the result is greater than 15, DC-Flag is set true. + if (dcResult > 15) + { + Ram.set_Digitcarryflag(true); + } + + //If the result is smaller or equal to 15, DC-Flag is set false. + else + { + Ram.set_Digitcarryflag(false); + } + + //If the destinationbit is 0, the result is written into the + if (destinationBit == 0) + { + setWRegister(result); + } + + //If the destinationbit is 1, the result is written into the RAM. + else + { + Ram.set_Element_X_Of_Bank_Y_To_Z(registerFileAddress, Ram.get_RP0Bit(), result); + } + + //Increment programcounter + Ram.inkrement_Programcounter(1, 0); //Kind of call + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 57 + * + * AND the W register with contents of register 'f'. + * If 'd' is 0 the result is stored in the W regis- + * ter. If 'd' is 1 the result is stored back in + * register 'f'. + */ + public void ANDWF(int destinationBit, int registerFileAddress) + { + //Get Value of + int wRegValue = get_WRegister(); + //Get Value of RAM-Bank-RP0Bit Address. + int regFileAddrValue = Ram.get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(Ram.get_RP0Bit(), registerFileAddress); + + //Calculate result. + int result = wRegValue & regFileAddrValue; + + //If result is zero. + if (result == 0) + { + Ram.set_Zeroflag(true); + } + + //If result is not zero. + else + { + Ram.set_Zeroflag(false); + } + + //If the destinationbit is 0, the result is written into the + if (destinationBit == 0) + { + setWRegister(result); + } + + //If the destinationbit is 1, the result is written into the RAM. + else + { + Ram.set_Element_X_Of_Bank_Y_To_Z(registerFileAddress, Ram.get_RP0Bit(), result); + } + + //Increment programcounter + Ram.inkrement_Programcounter(1, 0); //Kind of call + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 58 + * + * Bit ’b’ in register ’f’ is cleared . + */ + public void BCF(int bitaddress, int registerFileAddress) + { + //Get bitmask to clear bit in fileaddress. + int bitMask = bitMaskClearBitArray[bitaddress]; + //Get Value of RAM-Bank-RP0Bit Address. + int regFileAddrValue = Ram.get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(Ram.get_RP0Bit(), registerFileAddress); + + //Result is bitMask AND value at fileaddress. + //(For example bit 0: 11111110 & 11111111 = 11111110). + int result = bitMask & regFileAddrValue; + + //Write result back into fileregister. + Ram.set_Element_X_Of_Bank_Y_To_Z(registerFileAddress, Ram.get_RP0Bit(), result); + + //Increment programcounter + Ram.inkrement_Programcounter(1, 0); //Kind of call + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 58 + * + * If bit ’b’ in register ’f’ is ’1’ then the next + * instruction is executed. + * If bit ’b’, in register ’f’, is ’0’ then the next + * instruction is discarded, and a NOP is + * executed instead, making this a 2TCY + * instruction. + */ + public void BTFSC(int bitaddress, int registerFileAddress) + { + //Get bitmask to AND with fileaddress to get bit. + int bitMask = bitMaskSetBitArray[bitaddress]; + //Get Value of RAM-Bank-RP0Bit Address. + int regFileAddrValue = Ram.get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(Ram.get_RP0Bit(), registerFileAddress); + + //If bit at bitaddress is 1, next instruction is executed. + if ((bitMask & regFileAddrValue) == bitMask) + { + //Increment programcounter by one. + Ram.inkrement_Programcounter(1, 0); //Kind of call + } + + //If bit at bitaddress is 0, next instruction will be replaced by a NOP. + else + { + //Increment programcounter by one. + Ram.inkrement_Programcounter(1, 0); //Kind of call + //Execute NOP. + NOP(); + } + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 58 + * + * Bit ’b’ in register ’f’ is set. + */ + public void BSF(int bitaddress, int registerFileAddress) + { + //Get bitmask to OR with fileaddress to set bit. + int bitMask = bitMaskSetBitArray[bitaddress]; + //Get Value of RAM-Bank-RP0Bit Address. + int regFileAddrValue = Ram.get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(Ram.get_RP0Bit(), registerFileAddress); + + //Result is bitMask OR file-register-value. + int result = bitMask | regFileAddrValue; + + //Write result into file-register. + Ram.set_Element_X_Of_Bank_Y_To_Z(registerFileAddress, Ram.get_RP0Bit(), result); + + //Increment programcounter + Ram.inkrement_Programcounter(1, 0); //Kind of call + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 59 + * + * If bit ’b’ in register ’f’ is ’0’ then the next + * instruction is executed. + * If bit ’b’ is ’1’, then the next instruction is + * discarded and a NOP is executed + * instead, making this a 2TCY instruction. + */ + public void BTFSS(int bitaddress, int registerFileAddress) + { + //Get bitmask to AND with fileaddress to get bit. + int bitMask = bitMaskSetBitArray[bitaddress]; + //Get Value of RAM-Bank-RP0Bit Address. + int regFileAddrValue = Ram.get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(Ram.get_RP0Bit(), registerFileAddress); + + //If bit at bitaddress is 0, next instruction is executed. + if ((bitMask & regFileAddrValue) != bitMask) + { + //Increment programcounter by one. + Ram.inkrement_Programcounter(1, 0); //Kind of call + } + + //If bit at bitaddress is 1, next instruction will be replaced by a NOP. + else + { + //Increment programcounter by one. + Ram.inkrement_Programcounter(1, 0); //Kind of call + //Execute NOP. + NOP(); + } + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 59 + * + * Call Subroutine. First, return address + * (PC+1) is pushed onto the stack. The + * eleven bit immediate address is loaded + * into PC bits <10:0>. The upper bits of + * the PC are loaded from PCLATH. CALL + * is a two cycle instruction. + */ + public void CALL(int elevenK) + { + //Push next instruction on STACK. + Stack.pushReturnAdressOnStack(Ram.get_Programcounter() + 1); + + //Get upper two bits of PCLATH and shift it by eight. + int shiftedPCLATH = (Ram.get_PCLATH() & 0b11000) << 8; + + //Create new address out of shifted PCLATH and elevenK. + int newPC = shiftedPCLATH | elevenK; + + //Set Programmcounter to new address. + Ram.set_Programcounter(newPC); + + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 60 + * + * The contents of register ’f’ are cleared + * and the Z bit is set. + */ + public void CLRF(int registerFileAddress) + { + //Value at fileregisteraddress is set to zero. + Ram.set_Element_X_Of_Bank_Y_To_Z(registerFileAddress, Ram.get_RP0Bit(), 0); + //Zeroflag is set. + Ram.set_Zeroflag(true); + //Increment programcounter by 1. + Ram.inkrement_Programcounter(1, 0); //Kind of call + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 60 + * + * W register is cleared. Zero bit (Z) is + * set. + */ + public void CLRW() + { + //Set to zero. + setWRegister(0); + //Zeroflag is set. + Ram.set_Zeroflag(true); + //Increment programcounter by 1. + Ram.inkrement_Programcounter(1, 0); //Kind of call + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 60 + * + * CLRWDT instruction resets the Watch- + * dog Timer. It also resets the prescaler + * of the WDT. Status bits TO and PD are + * set. + */ + public void CLRWDT() + { + Ram.set_TimeOutFlag(true); + Ram.set_PowerDownFlag(true); + Ram.set_PS0(false); + Ram.set_PS1(false); + Ram.set_PS2(false); + //Programcounter will be incremented by 1. + + //Increment programcounter by 1. + Ram.inkrement_Programcounter(1, 0); //Kind of call + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 61 + * + * The contents of register ’f’ are comple- + * mented. If ’d’ is 0 the result is stored in + * W. If ’d’ is 1 the result is stored back in + * register ’f’. + */ + public void COMF(int destinationBit, int registerFileAddress) + { + //Get value at registerFileAddress + int regFileAddrValue = Ram.get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(Ram.get_RP0Bit(), registerFileAddress); + + //Inverts the value. + int result = (~regFileAddrValue); + + //If result is zero, zeroflag is set true. + if (result == 0) + { + Ram.set_Zeroflag(true); + } + + //If result is not zero, zeroflag is set false. + else + { + Ram.set_Zeroflag(false); + } + + result &= 255; + + //If destinationbit is zero, result will be written into + if (destinationBit == 0) + { + setWRegister(result); + } + + //If destinationbit is one, result will be written into fileRegister. + else + { + Ram.set_Element_X_Of_Bank_Y_To_Z(registerFileAddress, Ram.get_RP0Bit(), result); + } + + //Increment programcounter by 1. + Ram.inkrement_Programcounter(1, 0); //Kind of call + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 61 + * + * The contents of register ’f’ are decre- + * mented. If ’d’ is 0 the result is placed in the + * W register. If ’d’ is 1 the result is placed + * back in register ’f’. + * If the result is not 0, the next instruction, is + * executed. If the result is 0, then a NOP is + * executed instead making it a 2T CY instruc- + * tion. + */ + public void DECFSZ(int destinationBit, int registerFileAddress) + { + //Get value of fileregisteraddress. + int regFileAddrValue = Ram.get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(Ram.get_RP0Bit(), registerFileAddress); + //Decrement value by one. + regFileAddrValue--; + + //If the destinationbit is 0, the decremented value is written into the + if (destinationBit == 0) + { + setWRegister(regFileAddrValue); + } + + //If the destinationbit is 1, the decremented value is written bach into the fileregister. + else + { + Ram.set_Element_X_Of_Bank_Y_To_Z(registerFileAddress, Ram.get_RP0Bit(), regFileAddrValue); + } + + //If the dekremented value doesn't equal zero, the next instruction is executed. + if (regFileAddrValue != 0) + { + Ram.inkrement_Programcounter(1, 0); + } + + //If the dekremented value equals zero, a NOP is executed and the other instruction will be dismissed. + else + { + Ram.inkrement_Programcounter(1, 0); + NOP(); + } + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 61 + * + * Decrement contents of register ’f’. If ’d’ is 0 the + * result is stored in the W register. If ’d’ is + * 1 the result is stored back in register ’f’ . + */ + public void DECF(int destinationBit, int registerFileAddress) + { + //Get value of fileregisteraddress. + int regFileAddrValue = Ram.get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(Ram.get_RP0Bit(), registerFileAddress); + //Decrement value by one. + regFileAddrValue--; + + //If dekremented value equals zero, zeroflag is set true. + if (regFileAddrValue == 0) + { + Ram.set_Zeroflag(true); + } + + //If dekremented value doesn't equal zero, zeroflag is set false. + else + { + Ram.set_Zeroflag(false); + } + + //If value gets smaller than zero it is AND with 255 to become positive, because only values between 0 and 255 are allowed. + if (regFileAddrValue < 0) + { + regFileAddrValue = regFileAddrValue & 255; + } + + //If destinationbit equals zero, value is written into + if (destinationBit == 0) + { + setWRegister(regFileAddrValue); + } + + //If destinationbit doesn't equal zero, value is written into fileregister. + else + { + Ram.set_Element_X_Of_Bank_Y_To_Z(registerFileAddress, Ram.get_RP0Bit(), regFileAddrValue); + } + + //Inkrement Ram by one. + Ram.inkrement_Programcounter(1, 0); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 62 + * + * GOTO is an unconditional branch. The + * eleven bit immediate value is loaded + * into PC bits <10:0>. The upper bits of + * PC are loaded from PCLATH<4:3>. + * GOTO is a two cycle instruction. + */ + public void GOTO(int elevenK) + { + //elevenK OR ((PCLATH AND 0b11000) << 8) + int result = elevenK | ((Ram.get_PCLATH() & 0b11000) << 8); + + Ram.set_Programcounter(result); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 62 + * + * The contents of register ’f’ are incre- + * mented. If ’d’ is 0 the result is placed in + * the W register. If ’d’ is 1 the result is + * placed back in register ’f’. + */ + public void INCF(int destinationBit, int registerFileAddress) + { + //Get value of fileregisteraddress. + int regFileAddrValue = Ram.get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(Ram.get_RP0Bit(), registerFileAddress); + //Increment value by one. + regFileAddrValue++; + + //If value becomes zero, zeroflag is set true. + if (regFileAddrValue == 0) + { + Ram.set_Zeroflag(true); + } + + //If value doesn't become zero, zeroflag is set false. + else + { + Ram.set_Zeroflag(false); + } + + //If value becomes greater than 255, it will be set to a value between 0 and 255. + if (regFileAddrValue > 255) + { + regFileAddrValue &= 255; + } + + //If destinationbit is set 0, value will be written into + if (destinationBit == 0) + { + setWRegister(regFileAddrValue); + } + + //If destinationbit is not 0, value will be written back to RAM. + else + { + Ram.set_Element_X_Of_Bank_Y_To_Z(registerFileAddress, Ram.get_RP0Bit(), regFileAddrValue); + } + + //Increment programcounter by one. + Ram.inkrement_Programcounter(1, 0); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 63 + * + * The contents of register ’f’ are incre- + * mented. If ’d’ is 0 the result is placed in + * the W register. If ’d’ is 1 the result is + * placed back in register ’f’. + * If the result is not 0, the next instruction is + * executed. If the result is 0, a NOP is exe- + * cuted instead making it a 2TCY instruc- + * tion . + */ + public void INCFSZ(int destinationBit, int registerFileAddress) + { + //Get value of fileregisteraddress. + int regFileAddrValue = Ram.get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(Ram.get_RP0Bit(), registerFileAddress); + //Increment value by one. + regFileAddrValue++; + + //If value increases over uper line, it is set to a value between 0 and 255. + if (regFileAddrValue > 255) + { + regFileAddrValue &= 255; + } + + //If destinationbit is zero, the value is written into + if (destinationBit == 0) + { + setWRegister(regFileAddrValue); + } + + //If destinationbit is one, the value is written into RAM. + else + { + Ram.set_Element_X_Of_Bank_Y_To_Z(registerFileAddress, Ram.get_RP0Bit(), regFileAddrValue); + } + + //If value is not zero, next instruction will be executed. + if (regFileAddrValue != 0) + { + //Increment programcounter by one. + Ram.inkrement_Programcounter(1, 0); + } + + //If value is zero, next instruction will not be executed and NOP is executed instead. + else + { + //Increment programcounter by one. + Ram.inkrement_Programcounter(1, 0); + + //Call NOP. + NOP(); + } + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 63 + * + * The contents of the W register is + * OR’ed with the eight bit literal 'k'. The + * result is placed in the W register . + */ + public void IORLW(int eightK) + { + //and eightK are OR'ed and result is written into result. + int result = get_WRegister() | eightK; + + //If result is zero, zeroflag is set true. + if (result == 0) + { + Ram.set_Zeroflag(true); + } + + //If result is not zero, zeroflag is set false. + else + { + Ram.set_Zeroflag(false); + } + + //Set to result. + setWRegister(result); + + //Increment programcounter. + Ram.inkrement_Programcounter(1, 0); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 64 + * + * Inclusive OR the W register with contents of + * register ’f’. If ’d’ is 0 the result is placed in the + * W register. If ’d’ is 1 the result is placed + * back in register ’f’. + */ + public void IORWF(int destinationBit, int registerFileAddress) + { + //Result is value OR fileregister-value. + int result = get_WRegister() | Ram.get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(Ram.get_RP0Bit(), + registerFileAddress); + //If result is zero, zeroflag is set true. + if (result == 0) + { + Ram.set_Zeroflag(true); + } + + //If result is not zero, zeroflag is set false. + else + { + Ram.set_Zeroflag(false); + } + + //If destinationbit is zero, result is written into + if (destinationBit == 0) + { + setWRegister(result); + } + + //If destinationbit is not zero, result is written into fileregister. + else + { + Ram.set_Element_X_Of_Bank_Y_To_Z(registerFileAddress, Ram.get_RP0Bit(), result); + } + + //Increment programcounter by one. + Ram.inkrement_Programcounter(1, 0); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 64 + * + * The eight bit literal ’k’ is loaded into W + * register . The don’t cares will assemble + * as 0’s. + */ + public void MOVLW(int eightK) + { + //is set to eightK bit literal. + setWRegister(eightK); + + //Increment programcounter by one. + Ram.inkrement_Programcounter(1, 0); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 64 + * + * Move does not mean delete at source! + * The contents of register f is moved to a + * destination dependant upon the status + * of d. If d = 0, destination is W register. If + * d = 1, the destination is file register f + * itself. d = 1 is useful to test a file regis- + * ter since status flag Z is affected. + */ + public void MOVF(int destinationBit, int registerFileAddress) + { + //If destinationbit is zero, the value from fileregister is written to + if (destinationBit == 0) + { + setWRegister(Ram.get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(Ram.get_RP0Bit(), registerFileAddress)); + } + + //If destinationbit is one, value will still be in fileregister. + + //If value in fileregister is zero, zeroflag is set true. + if (Ram.get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(Ram.get_RP0Bit(), registerFileAddress) == 0) + { + Ram.set_Zeroflag(true); + } + + //If value in fileregister is not zero, zeroflag is set false. + else + { + Ram.set_Zeroflag(false); + } + + //Increment programcounter by one. + Ram.inkrement_Programcounter(1, 0); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 64 + * + * Move data from W register to file register + */ + public void MOVWF(int registerFileAddress) + { + //Data from is moved to fileregister. + Ram.set_Element_X_Of_Bank_Y_To_Z(registerFileAddress, Ram.get_RP0Bit(), get_WRegister()); + + //Increment programcounter by one. + Ram.inkrement_Programcounter(1, 0); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 65 + * + * No operation + */ + public void NOP() + { + //Increment programcounter by one. + Ram.inkrement_Programcounter(1, 0); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 65 + * + * Return from Interrupt. Stack is POPed + * and Top of Stack (TOS) is loaded in the + * PC. Interrupts are enabled by setting + * Global Interrupt Enable bit, GIE + * (INTCON<7>). This is a two cycle + * instruction. + */ + public void RETFIE() + { + //Set Global Interrupt Enable Bit true. + Ram.set_GIE(true); + + //Pop address from STACK. + int returnAddress = Stack.popReturnAdressFromStack(); + + //Write returnAddress into programcounter. + Ram.set_Programcounter(returnAddress); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /**OPTION + * Datasheet Page 65 + */ + public void OPTION() + { + //Nothing happens, only programmcounter gets incremented by 1. + + Ram.inkrement_Programcounter(1, 0); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + + /** + * Datasheet Page 66 + * + * The W register is loaded with the eight + * bit literal ’k’. The program counter is + * loaded from the top of the stack (the + * return address). This is a two cycle + * instruction. + */ + public void RETLW(int eightK) + { + //Load with eight bit literal. + setWRegister(eightK); + + //Pop address from STACK. + int returnAddress = Stack.popReturnAdressFromStack(); + + //Write returnAddress into programcounter. + Ram.set_Programcounter(returnAddress); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 66 + * + * Return from subroutine. The stack is + * POPed and the top of the stack (TOS) + * is loaded into the program counter. This + * is a two cycle instruction. + */ + public void RETURN() + { + //Pop address from STACK. + int returnAddress = Stack.popReturnAdressFromStack(); + + //Write returnAddress into programcounter. + Ram.set_Programcounter(returnAddress); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 67 + * + * The contents of register ’f’ are rotated + * one bit to the left through the Carry + * Flag. If ’d’ is 0 the result is placed in the + * W register. If ’d’ is 1 the result is stored + * back in register ’f’. + */ + public void RLF(int destinationBit, int registerFileAddress) + { + //Get value at fileaddress. + int regFileAddrValue = Ram.get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(Ram.get_RP0Bit(), registerFileAddress); + //Shift result to left by one bit. + int result = regFileAddrValue << 1; + + boolean set_Carryflag = false; + + //If the first bit which will be shifted is 1, the Carryflag will be set at the end to true. + if ((0b10000000 & regFileAddrValue) == 0b10000000) + { + set_Carryflag = true; + } + + //If carryflag is true, last bit is set 1. + if (Ram.get_Carryflag() == true) + { + result |= 0b00000001; + } + + //If carryflag is false, last bit is set 0. + else + { + result &= 0b11111110; + } + + result &= 255; + + //If destinationbit is zero, result will be written into + if (destinationBit == 0) + { + setWRegister(result); + } + + //If destinationbit is one, result will be written into RAM. + else + { + Ram.set_Element_X_Of_Bank_Y_To_Z(registerFileAddress, Ram.get_RP0Bit(), result); + } + + //Set value of carryflag. + Ram.set_Carryflag(set_Carryflag); + + //Increment Ram by one. + Ram.inkrement_Programcounter(1, 0); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 67 + * + * The contents of register ’f’ are rotated + * one bit to the right through the Carry + * Flag. If ’d’ is 0 the result is placed in the + * W register. If ’d’ is 1 the result is placed + * back in register ’f’. + */ + public void RRF(int destinationBit, int registerFileAddress) + { + //Get value at fileaddress. + int regFileAddrValue = Ram.get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(Ram.get_RP0Bit(), registerFileAddress); + //Shift result to right by one bit. + int result = (regFileAddrValue >> 1) & 255; + + boolean set_Carryflag = false; + + //If the first bit which will be shifted is 1, the Carryflag will be set at the end to true. + if ((0b00000001 & regFileAddrValue) == 0b00000001) + { + set_Carryflag = true; + } + + //If carryflag is true, first bit is set 1. + if (Ram.get_Carryflag() == true) + { + result |= 0b10000000; + } + + //If carryflag is false, first bit is set 0. + else + { + result &= 0b01111111; + } + + //Set value of carryflag. + Ram.set_Carryflag(set_Carryflag); + + //If destinationbit is zero, result will be written into + if (destinationBit == 0) + { + setWRegister(result); + } + + //If destinationbit is one, result will be written into RAM. + else + { + Ram.set_Element_X_Of_Bank_Y_To_Z(registerFileAddress, Ram.get_RP0Bit(), result); + } + + //Increment Ram by one. + Ram.inkrement_Programcounter(1, 0); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 68 + * + * The power-down status bit, PD is + * cleared. Time-out status bit, TO is + * set. Watchdog Timer and its pres- + * caler are cleared. + * The processor is put into SLEEP + * mode with the oscillator stopped. See + * Section 14.8 for more details. + */ + public void SLEEP() + { + //Not implemented + Ram.inkrement_Programcounter(1, 0); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 68 + * + * The contents of W register is subtracted (2’s comple- + * ment method) from the eight bit literal 'k'. + * The result is placed in the W register. + */ + public void SUBLW(int eightK) + { + int wRegValue = get_WRegister(); + + //Build Two's complement + //eightK = (eightK ^ 0b11111111) + 1; + + //Build Two's complement + wRegValue = (wRegValue ^ 0b11111111) + 1; + + //Add both complemented values. + int result = eightK + wRegValue; + + int carry = (result & 0b100000000) >> 8; + + //The lower four bits are bitwise and with 1111b (15d). + int dcResult = (eightK & 15) + (wRegValue & 15) + 1; + + //If the result is greater than 15, DC-Flag is set true. + if (dcResult > 15) + { + Ram.set_Digitcarryflag(true); + } + + //If the result is smaller or equal to 15, DC-Flag is set false. + else + { + Ram.set_Digitcarryflag(false); + } + + if (result == 0) + { + Ram.set_Zeroflag(true); + } + + else + { + Ram.set_Zeroflag(false); + } + + if (carry == 1) + { + Ram.set_Carryflag(true); + } + + else + { + Ram.set_Carryflag(false); + } + + result &= 255; + + setWRegister(result); + + Ram.inkrement_Programcounter(1, 0); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 69 + * + * Subtract (2’s complement method) contents + * of W register from register 'f'. If 'd' is 0 the + * result is stored in the W register. If 'd' is 1 the + * result is stored back in register 'f'. + */ + public void SUBWF(int destinationBit, int registerFileAddress) + { + int wRegValue = get_WRegister(); + + //Get value at fileaddress. + int regFileAddrValue = Ram.get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(Ram.get_RP0Bit(), registerFileAddress); + + //Build Two's complement + //regFileAddrValue = (regFileAddrValue ^ 0b11111111) + 1; + + //Build Two's complement + wRegValue = (wRegValue ^ 0b11111111) + 1; + + //Add both complemented values. + int result = regFileAddrValue + wRegValue; + + int carry = (result & 0b100000000) >> 8; + + //The lower four bits are bitwise and with 1111b (15d). + int dcResult = (regFileAddrValue & 15) + (wRegValue & 15) + 1; + + //If the result is greater than 15, DC-Flag is set true. + if (dcResult > 15) + { + Ram.set_Digitcarryflag(true); + } + + //If the result is smaller or equal to 15, DC-Flag is set false. + else + { + Ram.set_Digitcarryflag(false); + } + + if (result == 0) + { + Ram.set_Zeroflag(true); + } + + else + { + Ram.set_Zeroflag(false); + } + + if (carry == 1) + { + Ram.set_Carryflag(true); + } + + else + { + Ram.set_Carryflag(false); + } + + result &= 255; + + //If destinationbit is zero, result will be written into + if (destinationBit == 0) + { + setWRegister(result); + } + + //If destinationbit is one, result will be written into RAM. + else + { + Ram.set_Element_X_Of_Bank_Y_To_Z(registerFileAddress, Ram.get_RP0Bit(), result); + } + + Ram.inkrement_Programcounter(1, 0); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 69 + * + * The upper and lower nibbles of contents of + * register 'f' are exchanged. If 'd' is 0 the result + * is placed in W register. If 'd' is 1 the result + * is placed in register 'f'. + */ + public void SWAPF(int destinationBit, int registerFileAddress) + { + //Get value at fileaddress. + int regFileAddrValue = Ram.get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(Ram.get_RP0Bit(), registerFileAddress); + + int lowerNibble = regFileAddrValue & 0b00001111; + + int higherNibble = (regFileAddrValue & 0b11110000) >> 4; + + int result = (lowerNibble << 4) | higherNibble; + + //If destinationbit is zero, result will be written into + if (destinationBit == 0) + { + setWRegister(result); + } + + //If destinationbit is one, result will be written into RAM. + else + { + Ram.set_Element_X_Of_Bank_Y_To_Z(registerFileAddress, Ram.get_RP0Bit(), result); + } + + Ram.inkrement_Programcounter(1, 0); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 69 + * + * The instruction is supported for code + * compatibility with the PIC16C5X prod- + * ucts. Since TRIS registers are read- + * able and writable, the user can directly + * address them. + * + * To maintain upward compatibility + * with future PIC16CXX products, + * do not use this instruction! + */ + public void TRIS() + { + //Nothing happens, only programcounter will be incremented by 1. + + Ram.inkrement_Programcounter(1, 0); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 70 + * + * The contents of the W register are + * XOR’ed with the eight bit literal 'k'. + * The result is placed in the W register. + */ + public void XORLW(int eightK) + { + int wRegValue = get_WRegister(); + + int result = wRegValue ^ eightK; + + if (result == 0) + { + Ram.set_Zeroflag(true); + } + + else + { + Ram.set_Zeroflag(false); + } + + setWRegister(result); + + Ram.inkrement_Programcounter(1, 0); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } + + /** + * Datasheet Page 70 + * + * Exclusive OR the contents of the W + * register with contents of register 'f'. If 'd' is + * 0 the result is stored in the W register. If 'd' is + * 1 the result is stored back in register 'f'. + */ + public void XORWF(int destinationBit, int registerFileAddress) + { + int wRegValue = get_WRegister(); + + //Get value at fileaddress. + int regFileAddrValue = Ram.get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(Ram.get_RP0Bit(), registerFileAddress); + + int result = wRegValue ^ regFileAddrValue; + + if (result == 0) + { + Ram.set_Zeroflag(true); + } + + else + { + Ram.set_Zeroflag(false); + } + + //If destinationbit is zero, result will be written into + if (destinationBit == 0) + { + setWRegister(result); + } + + //If destinationbit is one, result will be written into RAM. + else + { + Ram.set_Element_X_Of_Bank_Y_To_Z(registerFileAddress, Ram.get_RP0Bit(), result); + } + + Ram.inkrement_Programcounter(1, 0); + + //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. + Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + } +} \ No newline at end of file diff --git a/src/Backend/Microcontroller/RAM.java b/src/Backend/Microcontroller/RAM.java new file mode 100755 index 0000000..45031d3 --- /dev/null +++ b/src/Backend/Microcontroller/RAM.java @@ -0,0 +1,1738 @@ +package Backend.Microcontroller; + +/** + * @author Aaron Moser + * @date 23.06.2021 + */ + +/** + * Random Access Memory of the PIC (Datenspeicher) + * RAM has two banks. + * Each bank has 128 bytes. + * The first twelve locations of each bank are reserved for the special function registers. + * + * Page 13 datasheet parts of RAM. + */ +public class RAM { + //Bank0 of the PIC-RAM + private int[] bank0; + + //Bank1 of the PIC-RAM + private int[] bank1; + + //Last programmcounter for function getLastLine in main. + private int lastProgramcounter; + + //Prescaler counters Timer0. + private int Timer0Prescaled; + private int Timer0PrescaledRA4; + + /** + * Constructor of RAM + */ + public RAM() { + //Bank0 of the PIC-RAM + bank0 = new int[128]; + + //Bank1 of the PIC-RAM + bank1 = new int[128]; + } + + /** + * @param rP0Bit shows if data is at bank 0 or 1. + * @param adress represents the adress of where the data is stored. + * @return the value of the element at the adress of the bank. + * @throws Exception + */ + public int get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(boolean rP0Bit, int adress) { + int valueOfBankRP0BitOfElementAtAdress = 0; + + if (rP0Bit == false) { + if (adress >= 1 && adress < 128) { + valueOfBankRP0BitOfElementAtAdress = bank0[adress]; + } + + else { + valueOfBankRP0BitOfElementAtAdress = bank0[bank0[4]]; + } + } + + if (rP0Bit == true) { + if (adress >= 0 && adress < 128) { + valueOfBankRP0BitOfElementAtAdress = bank1[adress]; + } else { + valueOfBankRP0BitOfElementAtAdress = bank1[bank1[4]]; + } + } + + return valueOfBankRP0BitOfElementAtAdress; + } + + /** + * @param x shows if bank 0 or 1 will be set. + * @param array an array which will represent bank x. + */ + public void set_Bank_X(boolean rp0Bit, int[] array) { + if (rp0Bit == false) { + bank0 = array; + } + + if (rp0Bit == true) { + bank1 = array; + } + } + + /** + * @param element between 0 and 127. + * @param bank where the value will be changed. + * @param value that will be written into the element. + */ + public void set_Element_X_Of_Bank_Y_To_Z(int element, boolean rp0Bit, int value) { + if (element < 0 || element > 127) { + System.out.println("Wrong input, value from 0 to 127 expected!"); + } else { + + if (element >= 12 && element < 128) { + if (rp0Bit == false) { + bank0[element] = value; + } + + if (rp0Bit == true) { + bank1[element] = value; + } + } + + else { + //Bank0 Registers + if (rp0Bit == false) { + switch (element) { + case 0: { + bank0[bank0[4]] = value; + }break; + + case 1: { + set_TMR0(value); + }break; + + case 2: { + set_PCL(value); + }break; + + case 3: { + set_STATUS(value); + }break; + + case 4: { + set_FSR(value); + }break; + + case 5: { + set_PORTA(value); + }break; + + case 6: { + set_PORTB(value); + }break; + + case 7: { + bank0[7] = value; + }break; + + case 8: { + set_EEDATA(value); + }break; + + case 9: + { + set_EEADR(value); + }break; + + case 10: + { + set_PCLATH(value); + }break; + + case 11: + { + set_INTCON(value); + }break; + } + } + + //Bank1 Registers + else + { + switch (element) + { + case 0: + { + bank1[bank0[4]] = value; + }break; + + case 1: + { + set_OPTION(value); + }break; + + case 2: + { + bank1[2] = value; + }break; + + case 3: + { + bank1[3] = value; + }break; + + case 4: + { + bank1[4] = value; + }break; + + case 5: + { + set_TRISA(value); + }break; + + case 6: + { + set_TRISB(value); + }break; + + case 7: + { + set_EECON1(value); + }break; + + case 8: + { + set_EECON2(value); + }break; + + case 9: + { + bank1[9] = value; + }break; + + case 10: + { + bank1[10] = value; + }break; + + case 11: + { + bank1[11] = value; + }break; + } + } + } + } + } + + //Bank0 Registers + public void set_TMR0(int value) + { + value &= 255; + bank0[1] = value; + } + + public void increment_TMR0() + { + Timer0Prescaled++; + + if (Timer0Prescaled == get_TMR0_PrescalerRate()) + { + if (bank0[1] == 255) + { + set_T0IF(true); + bank0[1] = 0; + } + + else + { + set_T0IF(false); + bank0[1]++; + } + Timer0Prescaled = 0; + } + } + + public int get_TMR0() + { + return bank0[1]; + } + + public void set_PCL(int value) + { + bank0[2] = value; + bank1[2] = value; + } + + public int get_PCL() + { + return bank0[2]; + } + + public void set_STATUS(int value) + { + bank0[3] = value; + bank1[3] = value; + } + + public int get_STATUS() + { + return bank0[3]; + } + + public void set_FSR(int value) + { + bank0[4] = value; + bank1[4] = value; + } + + public int get_FSR() + { + return bank0[4]; + } + + public void set_PORTA(int value) + { + if (((value & 0b00010000) == 0b00010000) && get_T0CS()) + { + Timer0PrescaledRA4++; + if (Timer0PrescaledRA4 == get_TMR0_PrescalerRate()) + { + if (bank0[1] == 255) + { + set_T0IF(true); + bank0[1] = 0; + } + + else + { + set_T0IF(false); + bank0[1]++; + } + Timer0PrescaledRA4 = 0; + } + } + + bank0[5] = value; + } + + public void set_PORTA_Bit_X_To_Y(int x, int y) + { + if ((x == 4)) + { + if (y == 1) + { + if (get_T0CS()) + { + Timer0PrescaledRA4++; + if (Timer0PrescaledRA4 == get_TMR0_PrescalerRate()) + { + if (bank0[1] == 255) + { + set_T0IF(true); + bank0[1] = 0; + } + + else + { + set_T0IF(false); + bank0[1]++; + } + Timer0PrescaledRA4 = 0; + } + } + } + } + + if (y == 0) + { + int[] array = new int[8]; + array[0] = 0b11111110; + array[1] = 0b11111101; + array[2] = 0b11111011; + array[3] = 0b11110111; + array[4] = 0b11101111; + array[5] = 0b11011111; + array[6] = 0b10111111; + array[7] = 0b01111111; + + bank0[5] &= array[x]; + } + + //if (y == 1) + else + { + bank0[5] |= ((0b00000001) << x); + } + } + + public int get_PORTA() + { + return bank0[5]; + } + + public void set_PORTB(int value) + { + bank0[6] = value; + } + + public void set_PORTB_Bit_X_To_Y(int x, int y) + { + if (y == 0) + { + int[] array = new int[8]; + array[0] = 0b11111110; + array[1] = 0b11111101; + array[2] = 0b11111011; + array[3] = 0b11110111; + array[4] = 0b11101111; + array[5] = 0b11011111; + array[6] = 0b10111111; + array[7] = 0b01111111; + + bank0[6] &= array[x]; + } + + //if (y == 1) + else + { + bank0[6] |= ((0b00000001) << x); + } + } + + public int get_PORTB() + { + return bank0[6]; + } + + public void set_EEDATA(int value) + { + bank0[8] = value; + } + + public int get_EEDATA() + { + return bank0[8]; + } + + public void set_EEADR(int value) + { + bank0[9] = value; + } + + public int get_EEADR() + { + return bank0[9]; + } + + public void set_PCLATH(int value) + { + bank0[10] = value; + bank1[10] = value; + } + + public int get_PCLATH() + { + return bank0[10]; + } + + public void set_INTCON(int value) + { + bank0[11] = value; + bank1[11] = value; + } + + public int get_INTCON() + { + return bank0[11]; + } + + //Bank1 Registers + public void set_OPTION(int value) + { + bank1[1] = value; + } + + public int get_OPTION() + { + return bank1[1]; + } + + public void set_TRISA(int value) + { + bank1[5] = value; + } + + public int get_TRISA() + { + return bank1[5]; + } + + public void set_TRISB(int value) + { + bank1[6] = value; + } + + public int get_TRISB() + { + return bank1[6]; + } + + public void set_EECON1(int value) + { + bank1[7] = value; + } + + public int get_EECON1() + { + return bank1[7]; + } + + public void set_EECON2(int value) + { + bank1[8] = value; + } + + public int get_EECON2() + { + return bank1[8]; + } + + //Bank0 & Bank1 Statusflags + public void set_Carryflag(boolean value) + { + int status = get_STATUS(); + if (value) + { + status |= 0b00000001; + } + + else + { + status &= 0b11111110; + } + + set_STATUS(status); + } + + public boolean get_Carryflag() + { + return (get_STATUS() & 0b00000001) == 1; + } + + public void set_Digitcarryflag(boolean value) + { + int status = get_STATUS(); + if (value) + { + status |= 0b00000010; + } + + else + { + status &= 0b11111101; + } + + set_STATUS(status); + } + + public boolean get_Digitcarryflag() + { + return (get_STATUS() & 0b00000010) == 2; + } + + public void set_Zeroflag(boolean value) + { + int status = get_STATUS(); + if (value) + { + status |= 0b00000100; + } + + else + { + status &= 0b11111011; + } + + set_STATUS(status); + } + + public boolean get_Zeroflag() + { + return (get_STATUS() & 0b00000100) == 4; + } + + public void set_TimeOutFlag(boolean value) + { + int status = get_STATUS(); + if (value) + { + status |= 0b00001000; + } + + else + { + status &= 0b11110111; + } + + set_STATUS(status); + } + + public boolean get_TimeOutFlag() + { + return (get_STATUS() & 0b00001000) == 8; + } + + public void set_PowerDownFlag(boolean value) + { + int status = get_STATUS(); + if (value) + { + status |= 0b00010000; + } + + else + { + status &= 0b11101111; + } + + set_STATUS(status); + } + + public boolean get_PowerDownFlag() + { + return (get_STATUS() & 0b00010000) == 16; + } + + public void set_RP0Bit(boolean value) + { + int status = get_STATUS(); + if (value) + { + status |= 0b00100000; + } + + else + { + status &= 0b11011111; + } + + set_STATUS(status); + } + + public boolean get_RP0Bit() + { + return (get_STATUS() & 0b00100000) == 32; + } + + public void set_RP1Bit(boolean value) + { + int status = get_STATUS(); + if (value) + { + status |= 0b01000000; + } + + else + { + status &= 0b10111111; + } + + set_STATUS(status); + } + + public boolean get_RP1Bit() + { + return (get_STATUS() & 0b01000000) == 64; + } + + public void set_Interruptflag(boolean value) + { + int status = get_STATUS(); + if (value) + { + status |= 0b10000000; + } + + else + { + status &= 0b01111111; + } + + set_STATUS(status); + } + + public boolean get_Interruptflag() + { + return (get_STATUS() & 0b10000000) == 128; + } + + //Bank0 PCL + public int get_Programcounter() + { + return (bank0[2]); + } + + public int get_LastProgramcounter() + { + return lastProgramcounter; + } + + public void inkrement_Programcounter(int value, int kindOfCall) //0 at Fetchzycle, 1 at Jumpcommand, 2 at ... + { + if (bank0[2] >= 0 && bank0[2] <= 255) + { + lastProgramcounter = bank0[2]; + bank0[2] += value; + } + + else + { + if (kindOfCall == 0) + { + //Nothing happens + } + + if (kindOfCall == 1) + { + bank0[2] = 0; //Wrap-Around at fetchcycle + } + } + } + + public void dekrement_Programcounter(int value) + { + if (bank0[2] > 0 && bank0[2] <= 255) + { + lastProgramcounter = bank0[2]; + bank0[2] -= value; + } + + else + { + throw new IndexOutOfBoundsException(); + } + } + + public boolean set_Programcounter(int value) + { + boolean setWorked = false; + + if (value >= 0 && value <= 255) + { + lastProgramcounter = bank0[2]; + bank0[2] = value; + setWorked = true; + } + + else + { + throw new IndexOutOfBoundsException(); + } + + return setWorked; + } + + //Bank0 PORTA + public void set_RA0(boolean value) + { + int portA = get_PORTA(); + if (value) + { + portA |= 0b00000001; + } + + else + { + portA &= 0b11111110; + } + + set_PORTA(portA); + } + + public boolean get_RA0() + { + { + return (get_PORTA() & 0b00000001) == 1; + } + } + + public void set_RA1(boolean value) + { + int portA = get_PORTA(); + if (value) + { + portA |= 0b00000010; + } + + else + { + portA &= 0b11111101; + } + + set_PORTA(portA); + } + + public boolean get_RA1() + { + { + return (get_PORTA() & 0b00000010) == 2; + } + } + + public void set_RA2(boolean value) + { + int portA = get_PORTA(); + if (value) + { + portA |= 0b00000100; + } + + else + { + portA &= 0b11111011; + } + + set_PORTA(portA); + } + + public boolean get_RA2() + { + { + return (get_PORTA() & 0b00000100) == 4; + } + } + + public void set_RA3(boolean value) + { + int portA = get_PORTA(); + if (value) + { + portA |= 0b00001000; + } + + else + { + portA &= 0b11110111; + } + + set_PORTA(portA); + } + + public boolean get_RA3() + { + { + return (get_PORTA() & 0b00001000) == 8; + } + } + + //External Clockimpulse for Timer0 + public void set_RA4_T0CKI(boolean value) + { + int portA = get_PORTA(); + if (value) + { + portA |= 0b00010000; + } + + else + { + portA &= 0b11101111; + } + + set_PORTA(portA); + } + + public boolean get_RA4_T0CKI() + { + { + return (get_PORTA() & 0b00010000) == 16; + } + } + + //Bank0 PortB + public void set_RB0_INT(boolean value) + { + int portB = get_PORTB(); + if (value) + { + portB |= 0b00000001; + } + + else + { + portB &= 0b11111110; + } + + set_PORTB(portB); + } + + public boolean get_RB0_INT() + { + { + return (get_PORTB() & 0b00000001) == 1; + } + } + + public void set_RB1(boolean value) + { + int portB = get_PORTB(); + if (value) + { + portB |= 0b00000010; + } + + else + { + portB &= 0b11111101; + } + + set_PORTB(portB); + } + + public boolean get_RB1() + { + { + return (get_PORTB() & 0b00000010) == 2; + } + } + + public void set_RB2(boolean value) + { + int portB = get_PORTB(); + if (value) + { + portB |= 0b00000100; + } + + else + { + portB &= 0b11111011; + } + + set_PORTB(portB); + } + + public boolean get_RB2() + { + return (get_PORTB() & 0b00000100) == 4; + } + + public void set_RB3(boolean value) + { + int portB = get_PORTB(); + if (value) + { + portB |= 0b00001000; + } + + else + { + portB &= 0b11110111; + } + + set_PORTB(portB); + } + + public boolean get_RB3() + { + { + return (get_PORTB() & 0b00001000) == 8; + } + } + + public void set_RB4(boolean value) + { + int portB = get_PORTB(); + if (value) + { + portB |= 0b00010000; + } + + else + { + portB &= 0b11101111; + } + + set_PORTB(portB); + } + + public boolean get_RB4() + { + { + return (get_PORTB() & 0b00010000) == 16; + } + } + + public void set_RB5(boolean value) + { + int portB = get_PORTB(); + if (value) + { + portB |= 0b00100000; + } + + else + { + portB &= 0b11011111; + } + + set_PORTB(portB); + } + + public boolean get_RB5() + { + { + return (get_PORTB() & 0b00100000) == 32; + } + } + + public void set_RB6(boolean value) + { + int portB = get_PORTB(); + if (value) + { + portB |= 0b01000000; + } + + else + { + portB &= 0b10111111; + } + + set_PORTB(portB); + } + + public boolean get_RB6() + { + { + return (get_PORTB() & 0b01000000) == 64; + } + } + + public void set_RB7(boolean value) + { + int portB = get_PORTB(); + if (value) + { + portB |= 0b10000000; + } + + else + { + portB &= 0b01111111; + } + + set_PORTB(portB); + } + + public boolean get_RB7() + { + { + return (get_PORTB() & 0b10000000) == 128; + } + } + + //Bank0 INTCON + public void set_RBIF(boolean value) + { + int intcon = get_INTCON(); + if (value) + { + intcon |= 0b00000001; + } + + else + { + intcon &= 0b11111110; + } + + set_INTCON(intcon); + } + + public boolean get_RBIF() + { + { + return (get_INTCON() & 0b00000001) == 1; + } + } + + public void set_INTF(boolean value) + { + int intcon = get_INTCON(); + if (value) + { + intcon |= 0b00000010; + } + + else + { + intcon &= 0b11111101; + } + + set_INTCON(intcon); + } + + public boolean get_INTF() + { + { + return (get_INTCON() & 0b00000010) == 2; + } + } + + public void set_T0IF(boolean value) + { + int intcon = get_INTCON(); + if (value) + { + intcon |= 0b00000100; + } + + else + { + intcon &= 0b11111011; + } + + set_INTCON(intcon); + } + + public boolean get_T0IF() + { + { + return (get_INTCON() & 0b00000100) == 4; + } + } + + public void set_RBIE(boolean value) + { + int intcon = get_INTCON(); + if (value) + { + intcon |= 0b00001000; + } + + else + { + intcon &= 0b11110111; + } + + set_INTCON(intcon); + } + + public boolean get_RBIE() + { + { + return (get_INTCON() & 0b00001000) == 8; + } + } + + public void set_INTE(boolean value) + { + int intcon = get_INTCON(); + if (value) + { + intcon |= 0b00010000; + } + + else + { + intcon &= 0b11101111; + } + + set_INTCON(intcon); + } + + public boolean get_INTE() + { + { + return (get_INTCON() & 0b00010000) == 16; + } + } + + public void set_T0IE(boolean value) + { + int intcon = get_INTCON(); + if (value) + { + intcon |= 0b00100000; + } + + else + { + intcon &= 0b11011111; + } + + set_INTCON(intcon); + } + + public boolean get_T0IE() + { + { + return (get_INTCON() & 0b00100000) == 32; + } + } + + public void set_EEIE(boolean value) + { + int intcon = get_INTCON(); + if (value) + { + intcon |= 0b01000000; + } + + else + { + intcon &= 0b10111111; + } + + set_INTCON(intcon); + } + + public boolean get_EEIE() + { + { + return (get_INTCON() & 0b01000000) == 64; + } + } + + public void set_GIE(boolean value) + { + int intcon = get_INTCON(); + if (value) + { + intcon |= 0b10000000; + } + + else + { + intcon &= 0b01111111; + } + + set_INTCON(intcon); + } + + public boolean get_GIE() + { + { + return (get_INTCON() & 0b10000000) == 128; + } + } + + //Bank1 OPTION_REG + public void set_PS0(boolean value) + { + int option = get_OPTION(); + if (value) + { + option |= 0b00000001; + } + + else + { + option &= 0b11111110; + } + + set_OPTION(option); + } + + public boolean get_PS0() + { + { + return (get_OPTION() & 0b00000001) == 1; + } + } + + public void set_PS1(boolean value) + { + int option = get_OPTION(); + if (value) + { + option |= 0b00000010; + } + + else + { + option &= 0b11111101; + } + + set_OPTION(option); + } + + public boolean get_PS1() + { + { + return (get_OPTION() & 0b00000010) == 2; + } + } + + public void set_PS2(boolean value) + { + int option = get_OPTION(); + if (value) + { + option |= 0b00000100; + } + + else + { + option &= 0b11111011; + } + + set_OPTION(option); + } + + public boolean get_PS2() + { + { + return (get_OPTION() & 0b00000100) == 4; + } + } + + public int get_TMR0_PrescalerRate() + { + int returnValue = 0; + + if (get_PSA()) + { + returnValue = 1; + } + + else + { + switch (get_OPTION() & 0b00000111) + { + case 0: + { + returnValue = 2; + }break; + + case 1: + { + returnValue = 4; + }break; + + case 2: + { + returnValue = 8; + }break; + + case 3: + { + returnValue = 16; + }break; + + case 4: + { + returnValue = 32; + }break; + + case 5: + { + returnValue = 64; + }break; + + case 6: + { + returnValue = 128; + }break; + + case 7: + { + returnValue = 256; + }break; + } + } + return returnValue; + } + + public int get_WDT_PrescalerRate() + { + int returnValue = 0; + + switch (get_OPTION() & 0b00000111) + { + case 0: + { + returnValue = 1; + }break; + + case 1: + { + returnValue = 2; + }break; + + case 2: + { + returnValue = 4; + }break; + + case 3: + { + returnValue = 8; + }break; + + case 4: + { + returnValue = 16; + }break; + + case 5: + { + returnValue = 32; + }break; + + case 6: + { + returnValue = 64; + }break; + + case 7: + { + returnValue = 128; + }break; + } + + return returnValue; + } + + public void set_PSA(boolean value) + { + int option = get_OPTION(); + if (value) + { + option |= 0b00001000; + } + + else + { + option &= 0b11110111; + } + + set_OPTION(option); + } + + public boolean get_PSA() + { + { + return (get_OPTION() & 0b00001000) == 8; + } + } + + public void set_T0SE(boolean value) + { + int option = get_OPTION(); + if (value) + { + option |= 0b00010000; + } + + else + { + option &= 0b11101111; + } + + set_OPTION(option); + } + + public boolean get_T0SE() + { + { + return (get_OPTION() & 0b00010000) == 16; + } + } + + public void set_T0CS(boolean value) + { + int option = get_OPTION(); + if (value) + { + option |= 0b00100000; + } + + else + { + option &= 0b11011111; + } + + set_OPTION(option); + } + + public boolean get_T0CS() + { + { + return (get_OPTION() & 0b00100000) == 32; + } + } + + public void set_INTEDG(boolean value) + { + int option = get_OPTION(); + if (value) + { + option |= 0b01000000; + } + + else + { + option &= 0b10111111; + } + + set_OPTION(option); + } + + public boolean get_INTEDG() + { + { + return (get_OPTION() & 0b01000000) == 64; + } + } + + public void set_RBPU(boolean value) + { + int option = get_OPTION(); + if (value) + { + option |= 0b10000000; + } + + else + { + option &= 0b01111111; + } + + set_OPTION(option); + } + + public boolean get_RBPU() + { + { + return (get_OPTION() & 0b10000000) == 128; + } + } + + //Bank1 EECON1 + public void set_RD(boolean value) + { + int eecon = get_EECON1(); + if (value) + { + eecon |= 0b00000001; + } + + else + { + eecon &= 0b11111110; + } + + set_EECON1(eecon); + } + + public boolean get_RD() + { + { + return (get_EECON1() & 0b00000001) == 1; + } + } + + public void set_WR(boolean value) + { + int eecon = get_EECON1(); + if (value) + { + eecon |= 0b00000010; + } + + else + { + eecon &= 0b11111101; + } + + set_EECON1(eecon); + } + + public boolean get_WR() + { + { + return (get_EECON1() & 0b00000010) == 2; + } + } + + public void set_WREN(boolean value) + { + int eecon = get_EECON1(); + if (value) + { + eecon |= 0b00000100; + } + + else + { + eecon &= 0b11111011; + } + + set_EECON1(eecon); + } + + public boolean get_WREN() + { + { + return (get_EECON1() & 0b00000100) == 4; + } + } + + public void set_WRERR(boolean value) + { + int eecon = get_EECON1(); + if (value) + { + eecon |= 0b00001000; + } + + else + { + eecon &= 0b11110111; + } + + set_EECON1(eecon); + } + + public boolean get_WRERR() + { + { + return (get_EECON1() & 0b00001000) == 8; + } + } + + public void set_EEIF(boolean value) + { + int eecon = get_EECON1(); + if (value) + { + eecon |= 0b00010000; + } + + else + { + eecon &= 0b11101111; + } + + set_EECON1(eecon); + } + + public boolean get_EEIF() + { + { + return (get_EECON1() & 0b00010000) == 16; + } + } + + //Bank1 TRISA + public void set_TRISA0(boolean value) + { + int trisA = get_TRISA(); + if (value) + { + trisA |= 0b00000001; + } + + else + { + trisA &= 0b11111110; + } + + set_TRISA(trisA); + } + + public boolean get_TRISA0() + { + return (get_TRISA() & 0b00000001) == 1; + } + + public void set_TRISA1(boolean value) + { + int trisA = get_TRISA(); + if (value) + { + trisA |= 0b00000010; + } + + else + { + trisA &= 0b11111101; + } + + set_TRISA(trisA); + } + + public boolean get_TRISA1() + { + return (get_TRISA() & 0b00000010) == 2; + } + + public void set_TRISA2(boolean value) + { + int trisA = get_TRISA(); + if (value) + { + trisA |= 0b00000100; + } + + else + { + trisA &= 0b11111011; + } + + set_TRISA(trisA); + } + + public boolean get_TRISA2() + { + return (get_TRISA() & 0b00000100) == 4; + } + + public void set_TRISA3(boolean value) + { + int trisA = get_TRISA(); + if (value) + { + trisA |= 0b00001000; + } + + else + { + trisA &= 0b11110111; + } + + set_TRISA(trisA); + } + + public boolean get_TRISA3() + { + return (get_TRISA() & 0b00001000) == 8; + } + + public void set_TRISA4(boolean value) + { + int trisA = get_TRISA(); + if (value) + { + trisA |= 0b00010000; + } + + else + { + trisA &= 0b11101111; + } + + set_TRISA(trisA); + } + + public boolean get_TRISA4() + { + return (get_TRISA() & 0b00010000) == 16; + } +} \ No newline at end of file diff --git a/src/Backend/Microcontroller/STACK.java b/src/Backend/Microcontroller/STACK.java new file mode 100755 index 0000000..cc0816c --- /dev/null +++ b/src/Backend/Microcontroller/STACK.java @@ -0,0 +1,104 @@ +package Backend.Microcontroller; + +import java.util.EmptyStackException; + +/** + * @author Aaron Moser + * @date 31.03.2021 + */ + +/** + * Datasheet Page 18 + */ +public class STACK +{ + private int stackpointer; + private int[] stack; + + /** + * Constructor of STACK. + */ + public STACK() // + { + stackpointer = 0; + //Initialize stack with -1 to decide wether the stack is empty or not, because 0 could be a return address. + stack = new int[]{-1, -1, -1, -1, -1, -1, -1, -1}; + } + + /** + * Pushs returnAddress on stack. If stack is full, throws StackOverflowError. + * @param return_Adress + */ + public void pushReturnAdressOnStack(int return_Adress) + { + if (stackpointer < 7) + { + stack[stackpointer] = return_Adress; + stackpointer++; + } + + if (stackpointer == 7) + { + throw new StackOverflowError(); + } + } + + /** + * Pops returnAddress from stack. If stack is empty, throws EmptyStackException. + * @return + */ + public int popReturnAdressFromStack() + { + int adressToReturn = -1; + + if (noObjects(stack)) + { + throw new EmptyStackException(); + } + + else + { + stackpointer--; + adressToReturn = stack[stackpointer]; + stack[stackpointer] = -1; + } + + return adressToReturn; + } + + /** + * Returns stack-array. + */ + public int[] getSTACK() + { + return this.stack; + } + + /** + * Returns stackpointer. + */ + public int getStackpointer() + { + return stackpointer; + } + + /** + * Checks if there are any objects in stack. + * @param array to check. + * @return true if empty, false if not empty. + */ + private boolean noObjects(int[] array) + { + boolean noObjects = true; + + for (int i = 0; i < 8; i++) + { + if (stack[i] != (-1)) + { + noObjects = false; + } + } + + return noObjects; + } +} \ No newline at end of file diff --git a/src/Backend/Microcontroller/WATCHDOG.java b/src/Backend/Microcontroller/WATCHDOG.java new file mode 100755 index 0000000..4fb9bea --- /dev/null +++ b/src/Backend/Microcontroller/WATCHDOG.java @@ -0,0 +1,105 @@ +package Backend.Microcontroller; + +/** + * @author Aaron Moser + * @date 23.06.2021 + * @lastchange 23.06.2021 + */ + +//Doesn't work correctly, status is changed too fast. +public class WATCHDOG extends Thread +{ + private long time; + private int watchdogStatus; + private long timeStart; + private long timeEnd; + + /** + * Constructor of watchdog. + */ + public WATCHDOG() + { + time = 0; + watchdogStatus = 0; + timeStart = 0; + timeEnd = 0; + } + + /** + * @return time in microseconds of watchdog. + */ + public synchronized long getTime() + { + return this.time / 100; + } + + /** + * Sets time of watchdog. + * @param value of new time. + */ + public synchronized void setTime(long value) + { + this.time = value; + } + + /** + * @return Status of watchdog. + * 0: Waiting for start + * 1: Start Watchdog + * 2: GetTime Watchdog + * 3: End Watchdog + * 4: Stop Watchdog + */ + public synchronized int getWatchdogStatus() + { + return this.watchdogStatus; + } + + /** + * 0: Waiting for start + * 1: Start Watchdog + * 2: GetTime Watchdog + * 3: End Watchdog + * 4: Stop Watchdog + * @param value + */ + public synchronized void setWatchdogStatus(int value) + { + this.watchdogStatus = value; + } + + /** + * Makes it possible to create a thread of watchdog. + */ + @Override + public void run() + { + //If status is changed to 3, watchdog is stopped. + while (this.watchdogStatus != 3) + { + if (watchdogStatus != 4) + { + //If status changes to 1, starts to count time and sets status to 4. + if (this.watchdogStatus == 1) + { + this.timeStart = System.nanoTime(); + if (this.getWatchdogStatus() != 2) + { + this.setWatchdogStatus(4); + } + } + + //If status changes to 2, stops count time and sets time to new value, then sets status to 4. + if (this.watchdogStatus == 2) + { + this.timeEnd = System.nanoTime(); + if (this.getWatchdogStatus() != 1) + { + this.setWatchdogStatus(4); + } + this.setTime(this.timeEnd - this.timeStart); + } + } + } + } +} \ No newline at end of file diff --git a/src/Backend/Runtime/Environment.java b/src/Backend/Runtime/Environment.java new file mode 100755 index 0000000..6d6e5d9 --- /dev/null +++ b/src/Backend/Runtime/Environment.java @@ -0,0 +1,177 @@ +/** + * @author Aaron Moser + * @date 21.02.2022 + * @lastchange 21.02.2022 + */ + +package Backend.Runtime; + +import java.io.File; +import java.util.ArrayList; +import java.util.concurrent.ConcurrentLinkedQueue; + +import Backend.BackendCommandProcessing.BackendInformationTransferThread; +import Backend.BackendCommandProcessing.InformationConnecter; +import Backend.FrontendCommandProcessing.CommandDecoder; +import Backend.FrontendCommandProcessing.FrontendCommandProcessingThread; +import Backend.Microcontroller.PIC; +import Backend.Microcontroller.WATCHDOG; + +public class Environment { + + private PIC oPIC; + + private String sEepromDataFile; + private String sActualCommand; + + private int iEnvironmentState; + private int iActualLine; + private int iLastLine; + + private ArrayList listBreakpoints = new ArrayList(); + + private long liRuntime; + + private ConcurrentLinkedQueue frontendToMainQueue; + private ConcurrentLinkedQueue mainToFrontendQueue; + + private WATCHDOG watchdog; + + public Environment() { + + frontendToMainQueue = new ConcurrentLinkedQueue(); + mainToFrontendQueue = new ConcurrentLinkedQueue(); + + FrontendCommandProcessingThread frontendCommandProcessingThread = new FrontendCommandProcessingThread(frontendToMainQueue); + BackendInformationTransferThread backendInformationTransferThread = new BackendInformationTransferThread(mainToFrontendQueue); + + InformationConnecter informationConnecter = new InformationConnecter(); + + watchdog = new WATCHDOG(); + + CommandDecoder commandDecoder; + + oPIC = new PIC(); + + sEepromDataFile = ""; + sActualCommand = ""; + + //Start Threads + frontendCommandProcessingThread.start(); + backendInformationTransferThread.start(); + + iEnvironmentState = 0; + + while (iEnvironmentState > -1) { + //Check if frontend sent new command. + if (!frontendToMainQueue.isEmpty()) { + sActualCommand = frontendToMainQueue.poll(); + commandDecoder = new CommandDecoder(sActualCommand); + commandDecoder.executeAction(this); + } + + // loadfile command readEepromFile.readFileAndWriteToEEPROM(new File(sEepromDataFile), oPIC); + } + + //Stop Threads + try { + frontendCommandProcessingThread.join(); + backendInformationTransferThread.join(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public PIC getPIC() { + return oPIC; + } + + public ArrayList getBreakpoints() { + return listBreakpoints; + } + + public ConcurrentLinkedQueue getMainToFrontendQueue() { + return mainToFrontendQueue; + } + + public ConcurrentLinkedQueue getFrontendToMainQueue() { + return frontendToMainQueue; + } + + /** + * + * @param iBreakpoint + * @param bState + */ + public void changeListBreakpoints(int iBreakpoint, boolean bState) { + if (iBreakpoint > -1) { + if (bState) { + //add new breakpoint to list + boolean bExists = false; + for (int i = 0; i < listBreakpoints.size(); i++) { + if (listBreakpoints.get(i) == iBreakpoint) + bExists = true; + } + if (!bExists) { + listBreakpoints.add(iBreakpoint); + } + } else { + //remove breakpoint from list + int iIndex = -1; + for (int i = 0; i < listBreakpoints.size(); i++) { + if (listBreakpoints.get(i) == iBreakpoint) { + iIndex = i; + i = listBreakpoints.size(); + } + } + if (iIndex > -1) { + listBreakpoints.remove(iIndex); + } + } + } else { + //remove all breakpoints from list + while (listBreakpoints.size() > 0) { + listBreakpoints.remove(0); + } + } + + } + + /** + * + * @return + */ + public int getActualLine() { + return iActualLine; + } + + /** + * + * @return + */ + public int getLastLine() { + return iLastLine; + } + + /** + * + * @return + */ + public long getRuntime() { + return liRuntime; + } + + /** + * + * @return + */ + public WATCHDOG getWatchdog() { + return watchdog; + } + + public void step() { + + } +} + diff --git a/src/Backend/Runtime/Main.java b/src/Backend/Runtime/Main.java new file mode 100755 index 0000000..a022f94 --- /dev/null +++ b/src/Backend/Runtime/Main.java @@ -0,0 +1,7 @@ +package Backend.Runtime; + +public class Main { + public static void main(String[] args) { + Environment env = new Environment(); + } +} \ No newline at end of file diff --git a/src/Backend/Runtime/ProgramStepInformation.java b/src/Backend/Runtime/ProgramStepInformation.java new file mode 100755 index 0000000..e14e78d --- /dev/null +++ b/src/Backend/Runtime/ProgramStepInformation.java @@ -0,0 +1,7 @@ +package Backend.Runtime; + +import Backend.Microcontroller.PIC; + +public class ProgramStepInformation { + private PIC oPIC; +} diff --git a/src/Backend/Runtime/TODO.java b/src/Backend/Runtime/TODO.java new file mode 100755 index 0000000..dddb1cb --- /dev/null +++ b/src/Backend/Runtime/TODO.java @@ -0,0 +1,98 @@ +package Backend.Runtime; + +public class TODO { + + /** + * Returns the actual line which represents the actual programstep. + * @return + + public static int iGetLine() + { + int iActualLine = 1; + + if (sLoadedSimulationFile != ("Uninitialized")) + { + String[] asDataLines = {}; + try + { + //Filereader reads data out of destination. + FileReader fR = new FileReader(new File(sLoadedSimulationFile)); + + //Creates String-array with whole data. + asDataLines = getData(fR); + } + catch (Exception e) {} + + for (int i = 0; i < asDataLines.length; i++) + { + //Substring 0-4 from hex to dec. after that dec value has to be equal to progcounter minus 1 and at substring 20-25 is line. + + String substringHexStep = "0000"; + int hexStepAsInt = 0; + + try + { + if (!((asDataLines[i].substring(0, 4)).equals(" "))) + { + substringHexStep = asDataLines[i].substring(0, 4); + hexStepAsInt = Integer.parseInt(substringHexStep, 16); + } + }catch(NullPointerException npe){} + + if (hexStepAsInt == (oPIC.getRam().get_Programcounter())) + { + iActualLine = i+1; + } + } + } + + return iActualLine; + } + + + * Returns the last line which represents the last programstep. + * @return + + public static int getLastLine() + { + int actualLine = 1; + + if (sLoadedSimulationFile != ("Uninitialized")) + { + String[] dataLines = {}; + try + { + //Filereader reads data out of destination. + FileReader fR = new FileReader(new File(sLoadedSimulationFile)); + + //Creates String-array with whole data. + dataLines = getData(fR); + } + catch (Exception e) {} + + for (int i = 0; i < dataLines.length; i++) + { + //Substring 0-4 from hex to dec. after that dec value has to be equal to progcounter minus 1 and at substring 20-25 is line. + + String substringHexStep = "0000"; + int hexStepAsInt = 0; + + try + { + if (!((dataLines[i].substring(0, 4)).equals(" "))) + { + substringHexStep = dataLines[i].substring(0, 4); + hexStepAsInt = Integer.parseInt(substringHexStep, 16); + } + }catch(NullPointerException npe){} + + if (hexStepAsInt == (oPIC.getRam().get_LastProgramcounter())) + { + actualLine = i+1; + } + } + } + + return actualLine; + }*/ +} diff --git a/src/Backend/Runtime/WATCHDOG.java b/src/Backend/Runtime/WATCHDOG.java new file mode 100644 index 0000000..e25f1f1 --- /dev/null +++ b/src/Backend/Runtime/WATCHDOG.java @@ -0,0 +1,5 @@ +package Backend.Runtime; + +public enum WATCHDOG { + +} diff --git a/src/Backend/Statistics/ErrorHandling/BackendErrorCounter.java b/src/Backend/Statistics/ErrorHandling/BackendErrorCounter.java new file mode 100755 index 0000000..06c4991 --- /dev/null +++ b/src/Backend/Statistics/ErrorHandling/BackendErrorCounter.java @@ -0,0 +1,16 @@ +package Backend.Statistics.ErrorHandling; + +public class BackendErrorCounter { + private int iErrorCounter = 0; + private int [] aiErrors; + + public void incrementErrorCounter() { + iErrorCounter++; + } + + public int getErrorCounter() { + return iErrorCounter; + } + + //TODO detailed error counts +} diff --git a/src/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMainFrame.java b/src/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMainFrame.java new file mode 100755 index 0000000..d8a1749 --- /dev/null +++ b/src/Frontend/PIC_SIMULATOR_GUI_JAVA/GUIMainFrame.java @@ -0,0 +1,51 @@ +package Frontend.PIC_SIMULATOR_GUI_JAVA; + +import java.awt.Color; +import java.awt.Font; +import java.util.ArrayList; + +import javax.swing.BorderFactory; +import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.border.Border; + +public class GUIMainFrame extends JFrame { + + /** + * Constructor + */ + public GUIMainFrame() { + + this.setTitle("PIC-Simulator GUI"); // sets title of frame + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // if x is pressed, exit application (HIDE_ON_CLOSE-hides application, DO_NOTHING_ON_CLOSE-prevents user from closing application) + //this.setResizable(false); // prevent frame from beeing resized + this.setSize(420, 420); //sets x and y dimension of frame + this.setVisible(true); //make frame visible + + ImageIcon guiLogo = new ImageIcon("./images/gui_logo.png"); // create an ImageIcon + this.setIconImage(guiLogo.getImage()); // change icon of frame + + Color guiBackgroundColor = new Color(255, 255, 255); // 0xFFFFFF || 0, 0, 0 + //this.getContentPane().setBackground(guiBackgroundColor); //change color of background + + JLabel text = new JLabel(); // create label, passing of text at constructor possible + text.setText("Bro do you even code?"); // set text of label + text.setIcon(guiLogo); + text.setHorizontalTextPosition(JLabel.CENTER); //JLabel.LEFT, JLabel.CENTER, JLabel.RIGHT + text.setVerticalTextPosition(JLabel.TOP); //JLabel.TOP, JLabel.CENTER, JLabel.BOTTOM + text.setForeground(Color.green); // set fontcolor of text + text.setFont(new Font("Arial", Font.ITALIC, 20)); // set fontstyle, fontformat (PLAIN, BOLD, ITALIC), and size + text.setIconTextGap(-100); // set gap of text to image + text.setBackground(Color.BLUE); // set background color + text.setOpaque(true); // display background color + + Border border = BorderFactory.createLineBorder(Color.green, 3); // creates border for label, color and size of border + + text.setBorder(border); // sets border of label to "border" + text.setVerticalAlignment(JLabel.TOP); // vertically alligns label "text" (JLabel.TOP, JLabel.CENTER, JLabel.BOTTOM) + text.setHorizontalAlignment(JLabel.CENTER); // horizontally aligns label "text" (JLabel.LEFT, JLabel.CENTER, JLabel.RIGHT) + + this.add(text); // add label to frame + } +} \ No newline at end of file diff --git a/src/Frontend/PIC_SIMULATOR_GUI_JAVA/Main.java b/src/Frontend/PIC_SIMULATOR_GUI_JAVA/Main.java new file mode 100755 index 0000000..e1917b5 --- /dev/null +++ b/src/Frontend/PIC_SIMULATOR_GUI_JAVA/Main.java @@ -0,0 +1,11 @@ +package Frontend.PIC_SIMULATOR_GUI_JAVA; + +import javax.swing.JLabel; + +public class Main { + public static void main(String[] args) { + + GUIMainFrame frame = new GUIMainFrame(); + + } +} \ No newline at end of file diff --git a/src/Frontend/PIC_SIMULATOR_GUI_JAVA/ReadBackendToFrontendFile.java b/src/Frontend/PIC_SIMULATOR_GUI_JAVA/ReadBackendToFrontendFile.java new file mode 100755 index 0000000..179f89b --- /dev/null +++ b/src/Frontend/PIC_SIMULATOR_GUI_JAVA/ReadBackendToFrontendFile.java @@ -0,0 +1,12 @@ +package Frontend.PIC_SIMULATOR_GUI_JAVA; + +import java.io.File; + +public class ReadBackendToFrontendFile { + File backendToFrontendFile = new File("../SIMULATOR_DAT/gui_set.dat"); + + + public ReadBackendToFrontendFile () { + + } +} \ No newline at end of file diff --git a/src/In.java b/src/In.java new file mode 100755 index 0000000..03f5c06 --- /dev/null +++ b/src/In.java @@ -0,0 +1,346 @@ +/* + Copyright (C) 1999 (Jens Scheffler) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +import java.io.*; +import java.util.*; +import java.math.*; + +public class In { + +/** Diese Klasse stellt einige einfache Methoden zum Einlesen von der Tastatur + zur Verfügung. Es werden diverse Werte von der Tastatur eingelesen, die + jeweils durch ein Leerzeichen, einen Tabstop oder ein Zeilenendezeichen + getrennt sein müssen. + @author Jens Scheffler + @version 1.01 Spezialfassung für Programmieren 1 in Java + */ + + private In(){} // somit kann die Klasse nicht instanziiert werden! + private static BufferedReader in = + new BufferedReader(new InputStreamReader(System.in)); + private static StringTokenizer eingabe; + private static String zeichenkette; + +/** Löscht alles, was sich in der momentanen Zeile befindet. + Das heißt es wird der Eingabe bis zum Zeilenende keine Beachtung mehr + geschenkt + */ + public static void flush(){ + eingabe=null; + } + +/* Private Methode, die den Tokenizer fuellt. Dies ist uebrigens eine von + zwei Methoden, die die Klasse zum Absturz bringen kann...*/ + private static void init(){ + zeichenkette=null; + if (eingabe!=null && eingabe.hasMoreTokens()) return; + while (eingabe==null || !eingabe.hasMoreTokens()) + eingabe=new StringTokenizer(readLine()); + } + +/* Private Methode, die eine Fehlermeldung ausgibt */ + private static void error(Exception e,String prompt) { + System.out.println("Eingabefehler "+e); + System.out.println("Bitte Eingabe wiederholen..."); + System.out.print(prompt); + } + +/** Liest eine ganze Textzeile von der Tastatur ein. Soll vorher eine + Eingabeaufforderung gemacht werden, geschieht dies durch den Parameter. + Dieser kann jedoch auch wegfallen. +@param prompt eine eventuelle Eingabeaufforderung +@return die eingelesene Zeile. + */ +/* Dies ist die zweite Methode, die die Klasse zum Absturz bringen kann.*/ + public static String readLine(String prompt){ + flush(); + String erg=""; + System.out.print(prompt); + try{ + erg=in.readLine(); + } catch(IOException e){ + System.err.println(""+e+"\n Programm abgebrochen...\n"); + //System.exit(1); + } + if (erg==null) { + System.err.println("Dateiende erreicht.\nProgramm abgebrochen...\n"); + //System.exit(1); + } + return erg; + } + +/** Liest eine int-Zahl von der Tastatur ein. Soll vorher eine + Eingabeaufforderung gemacht werden, geschieht dies durch den Parameter. + Dieser kann jedoch auch wegfallen. +@param prompt eine eventuelle Eingabeaufforderung +@return die eingelesene Zahl. + */ + public static int readInteger(String prompt){ + int erg; + System.out.print(prompt); + init(); + while(true){ + try{ + erg=Integer.parseInt(eingabe.nextToken()); + } catch (NumberFormatException e) { + error(e,prompt);init();continue; + } + return erg; + } + } + +/** Liest eine long-Zahl von der Tastatur ein. Soll vorher eine + Eingabeaufforderung gemacht werden, geschieht dies durch den Parameter. + Dieser kann jedoch auch wegfallen. +@param prompt eine eventuelle Eingabeaufforderung +@return die eingelesene Zahl. + */ + public static long readLong(String prompt){ + long erg; + System.out.print(prompt); + init(); + while(true){ + try{ + erg=Long.parseLong(eingabe.nextToken()); + } catch (NumberFormatException e) {error(e,prompt);init();continue;} + return erg; + } + } + +/** Liest eine double-Zahl von der Tastatur ein. Soll vorher eine + Eingabeaufforderung gemacht werden, geschieht dies durch den Parameter. + Dieser kann jedoch auch wegfallen. +@param prompt eine eventuelle Eingabeaufforderung +@return die eingelesene Zahl. + */ + public static double readDouble(String prompt){ + double erg; + System.out.print(prompt); + init(); + while(true){ + try{ + erg=Double.valueOf(eingabe.nextToken()).doubleValue(); + } catch(NumberFormatException e) {error(e,prompt);init();continue;} + return erg; + } + } + +/** Liest eine float-Zahl von der Tastatur ein. Soll vorher eine + Eingabeaufforderung gemacht werden, geschieht dies durch den Parameter. + Dieser kann jedoch auch wegfallen. +@param prompt eine eventuelle Eingabeaufforderung +@return die eingelesene Zahl. + */ + public static float readFloat(String prompt){ + float erg; + System.out.print(prompt); + init(); + while(true){ + try{ + erg=Float.valueOf(eingabe.nextToken()).floatValue(); + } catch(NumberFormatException e) {error(e,prompt);init();continue;} + return erg; + } + } + +/** Liest eine short-Zahl von der Tastatur ein. Soll vorher eine + Eingabeaufforderung gemacht werden, geschieht dies durch den Parameter. + Dieser kann jedoch auch wegfallen. +@param prompt eine eventuelle Eingabeaufforderung +@return die eingelesene Zahl. + */ + public static short readShort(String prompt){ + short erg; + System.out.print(prompt); + init(); + while(true){ + try{ + erg=Short.valueOf(eingabe.nextToken()).shortValue(); + } catch(NumberFormatException e) {error(e,prompt);init();continue;} + return erg; + } + } + +/** Liest einen boolschen Wert von der Tastatur ein. Soll vorher eine + Eingabeaufforderung gemacht werden, geschieht dies durch den Parameter. + Dieser kann jedoch auch wegfallen. +@param prompt eine eventuelle Eingabeaufforderung +@return der eingelesene Wert. + */ + public static boolean readBoolean(String prompt){ + String try_this=readString(prompt); + while (!try_this.equals("true") && !try_this.equals("false")) + try_this=readString(); + return try_this.equals("true"); + } + +/** Liest ein Textwort von der Tastatur ein. Soll vorher eine + Eingabeaufforderung gemacht werden, geschieht dies durch den Parameter. + Dieser kann jedoch auch wegfallen. +@param prompt eine eventuelle Eingabeaufforderung +@return das eingelesene Wort. + */ + public static String readString(String prompt){ + System.out.print(prompt); + init(); + return eingabe.nextToken(); + } + + /** Liest ein Zeichen von der Tastatur ein. Soll vorher eine + Eingabeaufforderung gemacht werden, geschieht dies durch den Parameter. + Dieser kann jedoch auch wegfallen. +@param prompt eine eventuelle Eingabeaufforderung +@return das eingelesene Zeichen. + */ + public static char readChar(String prompt){ + char erg; + System.out.print(prompt); + if (zeichenkette==null || zeichenkette.length()==0) + zeichenkette=readString(""); + erg=zeichenkette.charAt(0); + zeichenkette=(zeichenkette.length()>1)?zeichenkette.substring(1):null; + return erg; + } + +/** Liest eine ganze Textzeile von der Tastatur ein. +@return die eingelesene Zeile. + */ + public static String readLine(){ + return readLine(""); + } + +/** Liest eine int-Zahl von der Tastatur ein. +@return die eingelesene Zahl. + */ + public static int readInteger(){ + return readInteger(""); + } + +/** Liest eine int-Zahl von der Tastatur ein. +@return die eingelesene Zahl. + */ + public static int readInt(){ + return readInteger(""); + } + +/** Liest eine int-Zahl von der Tastatur ein. Soll vorher eine + Eingabeaufforderung gemacht werden, geschieht dies durch den Parameter. + Dieser kann jedoch auch wegfallen. +@param prompt eine eventuelle Eingabeaufforderung +@return die eingelesene Zahl. + */ + public static int readInt(String prompt){ + return readInteger(prompt); + } + +/** Liest eine long-Zahl von der Tastatur ein. +@return die eingelesene Zahl. + */ + public static long readLong(){ + return readLong(""); + } + +/** Liest eine double-Zahl von der Tastatur ein. +@return die eingelesene Zahl. + */ + public static double readDouble(){ + return readDouble(""); + } + +/** Liest eine short-Zahl von der Tastatur ein. +@return die eingelesene Zahl. + */ + public static short readShort(){ + return readShort(""); + } + +/** Liest eine float-Zahl von der Tastatur ein. +@return die eingelesene Zahl. + */ + public static float readFloat(){ + return readFloat(""); + } + +/** Liest ein Zeichen von der Tastatur ein. +@return das eingelesene Zeichen + */ + public static char readChar(){ + return readChar(""); + } + +/** Liest ein Textwort von der Tastatur ein. +@return das eingelesene Wort. + */ + public static String readString(){ + return readString(""); + } + + /** Liest einen boolschen Wert von der Tastatur ein. +@return das eingelesene Wort. + */ + public static boolean readBoolean(){ + return readBoolean(""); + } + + /** Wandelt eine double-Zahl in einen String um. + Bei der üblichen Umwandlung von double-Werten in einen String + findet eine Rundung statt. So wird etwa die Zahl 0.1, obwohl intern + nicht darstellbar, dennoch auf dem Bildschirm ausgegeben. Diese + Methode umgeht die Rundung */ + public static String toString(double d) { + if (Double.isInfinite(d) || Double.isNaN(d)) + return ""+d; + return (new BigDecimal(d)).toString(); + } + + /** + * Setzt den Standard-Inputreader auf neuen Eingabestrom + * @param in inputstream instance, not null + */ + public static void setInputStream(InputStream in) { + if (in == null) + throw new IllegalArgumentException("in darf nicht null sein."); + In.in = new BufferedReader(new InputStreamReader(in)); + } + + /** + * Setzt den Standard-Inputreader auf neuen Eingabestrom + * @param in reader instance, not null + */ + public static void setInputStreamReader(Reader in) { + if (in == null) + throw new IllegalArgumentException("in darf nicht null sein."); + + In.in = new BufferedReader(in); + } + + /** + * Setzt den Standard-Inputreader auf neuen Eingabestrom + * + * @deprecated + * @param bin BufferedReader + */ + public static void setReader (BufferedReader bin) { + if (bin == null) + throw new IllegalArgumentException("bin darf nicht null sein."); + + In.in = bin; + + } + +} diff --git a/src/simulator_additional_functions.java b/src/simulator_additional_functions.java new file mode 100755 index 0000000..852592e --- /dev/null +++ b/src/simulator_additional_functions.java @@ -0,0 +1,127 @@ +import java.io.*; + +//how to use In.java + +public class simulator_additional_functions +{ + public static char menueSelectionChar = 'A'; + public static char secondMenueSelectionChar = 'A'; + public static String secondMenueSelectionString = ""; + public static File frontendToBackendFile = new File("../SIMULATOR_DAT/gui_change.dat"); + + public static void main(String[] args) + { + int []array = new int[9]; + array[0] = 1; + array[1] = 2; + array[2] = 4; + array[3] = 8; + array[4] = 16; + array[5] = 32; + array[6] = 64; + array[7] = 128; + array[8] = 256; + + while ((menueSelectionChar != 'S') && (menueSelectionChar != 's')) + { + menueSelectionChar = In.readChar("What do you want to do?\n(B/b)reakpoint, (P/p)rescaler, (S/s)top:"); + + switch (menueSelectionChar) + { + case 'B': + case 'b': + { + secondMenueSelectionString = In.readString("In which line do you want to set your breakpoint?:"); + + if (!frontendToBackendFile.isFile()) + { + if (Integer.parseInt(secondMenueSelectionString) >= 0) + { + try + { + FileWriter fw = new FileWriter(frontendToBackendFile); + BufferedWriter bw = new BufferedWriter(fw); + bw.write("BREAKPOINT " + secondMenueSelectionString); + bw.close(); + } + catch (IOException ioe) + {} + } + + else + { + System.out.println("Please try again, value must be greater -1"); + } + } + + else + { + System.out.println("Error can't create new File, File already exists!"); + } + }break; + + case 'P': + case 'p': + { + secondMenueSelectionChar = In.readChar("Which Prescaler you want to set? (T/t)imer0, (W/w)atchdogtimer"); + switch (secondMenueSelectionChar) + { + case 'T': + case 't': + { + if (!frontendToBackendFile.isFile()) + { + secondMenueSelectionChar = In.readChar("What value you want to set the prescaler?\n0. 1, 1. 2, 2. 4, 3. 8, 4. 16, 5. 32, 6. 64, 7. 128, 8. 256:"); + + if ((Integer.parseInt("" + secondMenueSelectionChar) >= 0) && (Integer.parseInt("" + secondMenueSelectionChar) < 9)) + { + try + { + FileWriter fw = new FileWriter(frontendToBackendFile); + BufferedWriter bw = new BufferedWriter(fw); + bw.write("PRT " + Integer.parseInt("" + secondMenueSelectionChar)); + bw.close(); + } + catch (IOException ioe) + {} + } + } + + else + { + System.out.println("Error can't create new File, File already exists!"); + } + }break; + + case 'W': + case 'w': + { + if (!frontendToBackendFile.isFile()) + { + secondMenueSelectionChar = In.readChar("What value you want to set the prescaler?\n0. 2, 1. 4, 2. 8, 3. 16, 4. 32, 5. 64, 6. 128, 7. 256:"); + + if ((Integer.parseInt("" + secondMenueSelectionChar) > 0) && (Integer.parseInt("" + secondMenueSelectionChar) < 9)) + { + try + { + FileWriter fw = new FileWriter(frontendToBackendFile); + BufferedWriter bw = new BufferedWriter(fw); + bw.write("PRW " + array[Integer.parseInt("" + secondMenueSelectionChar)]); + bw.close(); + } + catch (IOException ioe) + {} + } + } + + else + { + System.out.println("Error can't create new File, File already exists!"); + } + }break; + } + }break; + } + } + } +} \ No newline at end of file diff --git a/testfiles/TPicSim1.LST b/testfiles/TPicSim1.LST new file mode 100755 index 0000000..49b6798 --- /dev/null +++ b/testfiles/TPicSim1.LST @@ -0,0 +1,29 @@ + 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 ;19.05.2020 + 00007 ;mod. 18.10.2018 Version HSO + 00008 ; + 00009 list c=132 ;Zeilenlänge im LST auf 132 Zeichen setzen + 00010 + 00011 + 00012 ;Definition des Prozessors + 00013 device 16F84 + 00014 + 00015 ;Festlegen des Codebeginns + 00016 org 0 + 00017 start +0000 3011 00018 movlw 11h ;in W steht nun 11h, Statusreg. unverändert +0001 3930 00019 andlw 30h ;W = 10h, C=x, DC=x, Z=0 +0002 380D 00020 iorlw 0Dh ;W = 1Dh, C=x, DC=x, Z=0 +0003 3C3D 00021 sublw 3Dh ;W = 20h, C=1, DC=1, Z=0 +0004 3A20 00022 xorlw 20h ;W = 00h, C=1, DC=1, Z=1 +0005 3E25 00023 addlw 25h ;W = 25h, C=0, DC=0, Z=0 + 00024 + 00025 + 00026 ende +0006 2806 00027 goto ende ;Endlosschleife, verhindert Nirwana + 00028 + 00029 diff --git a/testfiles/TPicSim10.LST b/testfiles/TPicSim10.LST new file mode 100755 index 0000000..3338666 --- /dev/null +++ b/testfiles/TPicSim10.LST @@ -0,0 +1,315 @@ + 00001 ;TPicSim10 + 00002 ;Programm zum Test des 16F84-Simulators. + 00003 ;Es wird die richtige Funktionsweise von PCL und PCLATH am Beispiel + 00004 ;eines Tabellenzugriffs getestet + 00005 ;(c) St. Lehmann + 00006 ;19.04.2014 + 00007 ;18.10.2018 mod. für HSO + 00008 + 00009 list c=132 ;Zeilenlänge im LST auf 132 Zeichen setzen + 00010 + 00011 ;Definition einiger Symbole + 00012 indirect equ 0 + 00013 pcl equ 02h + 00014 status equ 03h + 00015 fsr equ 04h + 00016 ra equ 05h + 00017 rb equ 06h + 00018 pclath equ 0ah + 00019 intcon equ 0bh + 00020 + 00021 ;Definition des Prozessors + 00022 device 16F84 + 00023 ;Festlegen des Codebeginns + 00024 org 0 + 00025 start +0000 3000 00026 movlw 0 ;Index für Tabellenzugriff in 0FH +0001 008F 00027 movwf 0fh +0002 3005 00028 movlw 5 ;insgesamt 5 Tabellenzugriffe +0003 008E 00029 movwf 0eh +0004 3010 00030 movlw 10h ;Ergebnis wird ab 10H abgespeichert +0005 0084 00031 movwf fsr + 00032 loop +0006 3001 00033 movlw 1 ;PCLATH setzen, damit auf den Bereich 256-511 zugegriffen werden kann +0007 008A 00034 movwf pclath +0008 080F 00035 movf 0fh,w +0009 2109 00036 call tabelle +000A 0080 00037 movwf indirect +000B 0A84 00038 incf fsr +000C 0A8F 00039 incf 0fh +000D 0B8E 00040 decfsz 0eh +000E 2806 00041 goto loop +000F 018A 00042 clrf pclath +0010 080F 00043 movf 0fh,w +0011 2109 00044 call tabelle ;Fehler, der ADDWF PCL kommt nicht in die Tabelle. Grund: in W steht 5 + 00045 ;im PC 109 bzw. nach dem Fetch 10A. Zu diesem Wert wird 5 addiert und + 00046 ;die oberen Bits auf 0 gesetzt (PCLATH=0). Damit steht im PC der Wert + 00047 ;0Fh. Dorthin springt der PIC durch den ADDWF-Befehl. Hier verweilt + 00048 ;das Programm während der Stack immer weiter wächst. + 00049 + 00050 + 00051 ende +0012 2812 00052 goto ende ;Endlosschleife, verhindert Nirwana + 00053 +0013 0000 00054 nop +0014 0000 00055 nop +0015 0000 00056 nop +0016 0000 00057 nop +0017 0000 00058 nop +0018 0000 00059 nop +0019 0000 00060 nop +001A 0000 00061 nop +001B 0000 00062 nop +001C 0000 00063 nop +001D 0000 00064 nop +001E 0000 00065 nop +001F 0000 00066 nop +0020 0000 00067 nop +0021 0000 00068 nop +0022 0000 00069 nop +0023 0000 00070 nop +0024 0000 00071 nop +0025 0000 00072 nop +0026 0000 00073 nop +0027 0000 00074 nop +0028 0000 00075 nop +0029 0000 00076 nop +002A 0000 00077 nop +002B 0000 00078 nop +002C 0000 00079 nop +002D 0000 00080 nop +002E 0000 00081 nop +002F 0000 00082 nop +0030 0000 00083 nop +0031 0000 00084 nop +0032 0000 00085 nop +0033 0000 00086 nop +0034 0000 00087 nop +0035 0000 00088 nop +0036 0000 00089 nop +0037 0000 00090 nop +0038 0000 00091 nop +0039 0000 00092 nop +003A 0000 00093 nop +003B 0000 00094 nop +003C 0000 00095 nop +003D 0000 00096 nop +003E 0000 00097 nop +003F 0000 00098 nop +0040 0000 00099 nop +0041 0000 00100 nop +0042 0000 00101 nop +0043 0000 00102 nop +0044 0000 00103 nop +0045 0000 00104 nop +0046 0000 00105 nop +0047 0000 00106 nop +0048 0000 00107 nop +0049 0000 00108 nop +004A 0000 00109 nop +004B 0000 00110 nop +004C 0000 00111 nop +004D 0000 00112 nop +004E 0000 00113 nop +004F 0000 00114 nop +0050 0000 00115 nop +0051 0000 00116 nop +0052 0000 00117 nop +0053 0000 00118 nop +0054 0000 00119 nop +0055 0000 00120 nop +0056 0000 00121 nop +0057 0000 00122 nop +0058 0000 00123 nop +0059 0000 00124 nop +005A 0000 00125 nop +005B 0000 00126 nop +005C 0000 00127 nop +005D 0000 00128 nop +005E 0000 00129 nop +005F 0000 00130 nop +0060 0000 00131 nop +0061 0000 00132 nop +0062 0000 00133 nop +0063 0000 00134 nop +0064 0000 00135 nop +0065 0000 00136 nop +0066 0000 00137 nop +0067 0000 00138 nop +0068 0000 00139 nop +0069 0000 00140 nop +006A 0000 00141 nop +006B 0000 00142 nop +006C 0000 00143 nop +006D 0000 00144 nop +006E 0000 00145 nop +006F 0000 00146 nop +0070 0000 00147 nop +0071 0000 00148 nop +0072 0000 00149 nop +0073 0000 00150 nop +0074 0000 00151 nop +0075 0000 00152 nop +0076 0000 00153 nop +0077 0000 00154 nop +0078 0000 00155 nop +0079 0000 00156 nop +007A 0000 00157 nop +007B 0000 00158 nop +007C 0000 00159 nop +007D 0000 00160 nop +007E 0000 00161 nop +007F 0000 00162 nop +0080 0000 00163 nop +0081 0000 00164 nop +0082 0000 00165 nop +0083 0000 00166 nop +0084 0000 00167 nop +0085 0000 00168 nop +0086 0000 00169 nop +0087 0000 00170 nop +0088 0000 00171 nop +0089 0000 00172 nop +008A 0000 00173 nop +008B 0000 00174 nop +008C 0000 00175 nop +008D 0000 00176 nop +008E 0000 00177 nop +008F 0000 00178 nop +0090 0000 00179 nop +0091 0000 00180 nop +0092 0000 00181 nop +0093 0000 00182 nop +0094 0000 00183 nop +0095 0000 00184 nop +0096 0000 00185 nop +0097 0000 00186 nop +0098 0000 00187 nop +0099 0000 00188 nop +009A 0000 00189 nop +009B 0000 00190 nop +009C 0000 00191 nop +009D 0000 00192 nop +009E 0000 00193 nop +009F 0000 00194 nop +00A0 0000 00195 nop +00A1 0000 00196 nop +00A2 0000 00197 nop +00A3 0000 00198 nop +00A4 0000 00199 nop +00A5 0000 00200 nop +00A6 0000 00201 nop +00A7 0000 00202 nop +00A8 0000 00203 nop +00A9 0000 00204 nop +00AA 0000 00205 nop +00AB 0000 00206 nop +00AC 0000 00207 nop +00AD 0000 00208 nop +00AE 0000 00209 nop +00AF 0000 00210 nop +00B0 0000 00211 nop +00B1 0000 00212 nop +00B2 0000 00213 nop +00B3 0000 00214 nop +00B4 0000 00215 nop +00B5 0000 00216 nop +00B6 0000 00217 nop +00B7 0000 00218 nop +00B8 0000 00219 nop +00B9 0000 00220 nop +00BA 0000 00221 nop +00BB 0000 00222 nop +00BC 0000 00223 nop +00BD 0000 00224 nop +00BE 0000 00225 nop +00BF 0000 00226 nop +00C0 0000 00227 nop +00C1 0000 00228 nop +00C2 0000 00229 nop +00C3 0000 00230 nop +00C4 0000 00231 nop +00C5 0000 00232 nop +00C6 0000 00233 nop +00C7 0000 00234 nop +00C8 0000 00235 nop +00C9 0000 00236 nop +00CA 0000 00237 nop +00CB 0000 00238 nop +00CC 0000 00239 nop +00CD 0000 00240 nop +00CE 0000 00241 nop +00CF 0000 00242 nop +00D0 0000 00243 nop +00D1 0000 00244 nop +00D2 0000 00245 nop +00D3 0000 00246 nop +00D4 0000 00247 nop +00D5 0000 00248 nop +00D6 0000 00249 nop +00D7 0000 00250 nop +00D8 0000 00251 nop +00D9 0000 00252 nop +00DA 0000 00253 nop +00DB 0000 00254 nop +00DC 0000 00255 nop +00DD 0000 00256 nop +00DE 0000 00257 nop +00DF 0000 00258 nop +00E0 0000 00259 nop +00E1 0000 00260 nop +00E2 0000 00261 nop +00E3 0000 00262 nop +00E4 0000 00263 nop +00E5 0000 00264 nop +00E6 0000 00265 nop +00E7 0000 00266 nop +00E8 0000 00267 nop +00E9 0000 00268 nop +00EA 0000 00269 nop +00EB 0000 00270 nop +00EC 0000 00271 nop +00ED 0000 00272 nop +00EE 0000 00273 nop +00EF 0000 00274 nop +00F0 0000 00275 nop +00F1 0000 00276 nop +00F2 0000 00277 nop +00F3 0000 00278 nop +00F4 0000 00279 nop +00F5 0000 00280 nop +00F6 0000 00281 nop +00F7 0000 00282 nop +00F8 0000 00283 nop +00F9 0000 00284 nop +00FA 0000 00285 nop +00FB 0000 00286 nop +00FC 0000 00287 nop +00FD 0000 00288 nop +00FE 0000 00289 nop +00FF 0000 00290 nop +0100 0000 00291 nop +0101 0000 00292 nop +0102 0000 00293 nop +0103 0000 00294 nop +0104 0000 00295 nop +0105 0000 00296 nop +0106 0000 00297 nop +0107 0000 00298 nop +0108 0000 00299 nop + 00300 Tabelle +0109 0782 00301 addwf pcl +010A 3460 00302 retlw 60h +010B 3461 00303 retlw 61h +010C 3462 00304 retlw 62h +010D 3463 00305 retlw 63h +010E 3464 00306 retlw 64h +010F 3465 00307 retlw 65h +0110 3466 00308 retlw 66h +0111 3467 00309 retlw 67h +0112 3468 00310 retlw 68h +0113 3469 00311 retlw 69h +0114 346A 00312 retlw 6Ah + 00313 + 00314 + 00315 diff --git a/testfiles/TPicSim101.LST b/testfiles/TPicSim101.LST new file mode 100755 index 0000000..ece85ca --- /dev/null +++ b/testfiles/TPicSim101.LST @@ -0,0 +1,71 @@ + 00001 ;TPicSim101 + 00002 ;Programm zum Test des 16F84-Simulators. + 00003 ;Es wird die richtige Funktionsweise von PCL und PCLATH am Beispiel + 00004 ;eines Tabellenzugriffs getestet + 00005 ;(c) St. Lehmann + 00006 ;19.04.2014 + 00007 ;18.10.2018 mod. für HSO es wird die Tabelle durch ein ORG 100H auf die + 00008 ; Adresse 100H gelegt. + 00009 + 00010 list c=132 ;Zeilenlänge im LST auf 132 Zeichen setzen + 00011 + 00012 ;Definition einiger Symbole + 00013 indirect equ 0 + 00014 pcl equ 02h + 00015 status equ 03h + 00016 fsr equ 04h + 00017 ra equ 05h + 00018 rb equ 06h + 00019 pclath equ 0ah + 00020 intcon equ 0bh + 00021 + 00022 ;Definition des Prozessors + 00023 device 16F84 + 00024 ;Festlegen des Codebeginns + 00025 org 0 + 00026 start +0000 3000 00027 movlw 0 ;Index für Tabellenzugriff in 0FH +0001 008F 00028 movwf 0fh +0002 3005 00029 movlw 5 ;insgesamt 5 Tabellenzugriffe +0003 008E 00030 movwf 0eh +0004 3010 00031 movlw 10h ;Ergebnis wird ab 10H abgespeichert +0005 0084 00032 movwf fsr + 00033 loop +0006 3001 00034 movlw 1 ;PCLATH setzen, damit auf den Bereich 256-511 zugegriffen werden kann +0007 008A 00035 movwf pclath +0008 080F 00036 movf 0fh,w +0009 2100 00037 call tabelle +000A 0080 00038 movwf indirect +000B 0A84 00039 incf fsr +000C 0A8F 00040 incf 0fh +000D 0B8E 00041 decfsz 0eh +000E 2806 00042 goto loop +000F 018A 00043 clrf pclath +0010 080F 00044 movf 0fh,w +0011 2100 00045 call tabelle ;Fehler, der ADDWF PCL kommt nicht in die Tabelle. Grund: in W steht 5 + 00046 ;im PC 109 bzw. nach dem Fetch 10A. Zu diesem Wert wird 5 addiert und + 00047 ;die oberen Bits auf 0 gesetzt (PCLATH=0). Damit steht im PC der Wert + 00048 ;0Fh. Dorthin springt der PIC durch den ADDWF-Befehl. Hier verweilt + 00049 ;das Programm während der Stack immer weiter wächst. + 00050 + 00051 + 00052 ende +0012 2812 00053 goto ende ;Endlosschleife, verhindert Nirwana + 00054 + 00055 org 100H + 00056 Tabelle +0100 0782 00057 addwf pcl +0101 3460 00058 retlw 60h +0102 3461 00059 retlw 61h +0103 3462 00060 retlw 62h +0104 3463 00061 retlw 63h +0105 3464 00062 retlw 64h +0106 3465 00063 retlw 65h +0107 3466 00064 retlw 66h +0108 3467 00065 retlw 67h +0109 3468 00066 retlw 68h +010A 3469 00067 retlw 69h +010B 346A 00068 retlw 6Ah + 00069 + 00070 + 00071 diff --git a/testfiles/TPicSim11.LST b/testfiles/TPicSim11.LST new file mode 100755 index 0000000..751bc55 --- /dev/null +++ b/testfiles/TPicSim11.LST @@ -0,0 +1,52 @@ + 00001 ;TPicSim11 + 00002 ;Programm zum Test des 16F84-Simulators. + 00003 ;Es wird der Watchdog mit und ohne Vorteiler geprüft + 00004 ;(c) St. Lehmann + 00005 ;19.04.2014 + 00006 ;18.10.2018 mod. für HSO + 00007 + 00008 + 00009 list c=132 ;Zeilenlänge im LST auf 132 Zeichen setzen + 00010 + 00011 ;Definition einiger Symbole + 00012 indirect equ 0 + 00013 status equ 03h + 00014 fsr equ 04h + 00015 ra equ 05h + 00016 rb equ 06h + 00017 count equ 0ch + 00018 + 00019 ;Definition des Prozessors + 00020 device 16F84 + 00021 ;Festlegen des Codebeginns + 00022 org 0 + 00023 start + 00024 ;zuerst wird der VT dem Timer zugewiesen. Damit bekommt der Watchdog + 00025 ;die kleinste Zeit (ca. 18 ms) zugewiesen +0000 3000 00026 movlw 00000000B ;Option-Register entsp. initialisieren +0001 1683 00027 bsf status,5 ;Bank umschalten +0002 0081 00028 movwf 1 ;Option-Register +0003 1283 00029 bcf status,5 +0004 01A0 00030 clrf 20h +0005 01A1 00031 clrf 21h +0006 01A2 00032 clrf 22h +0007 01A3 00033 clrf 23h + 00034 loop1 +0008 0FA0 00035 incfsz 20h +0009 2808 00036 goto loop1 ;kein Überlauf +000A 0FA1 00037 incfsz 21h ;nächste Stelle +000B 2808 00038 goto loop1 ;kein Überlauf +000C 0FA2 00039 incfsz 22h ;ja +000D 2808 00040 goto loop1 +000E 0FA3 00041 incfsz 23h +000F 2808 00042 goto loop1 + 00043 + 00044 ;****************************************************************** + 00045 ;in 20h steht ca. 5fH + 00046 ;in 21H ca. 17H + 00047 ;Zählerstand 16-Bit ca. 175FH = 5983d + 00048 + 00049 ende +0010 2810 00050 goto ende ;Endlosschleife, verhindert Nirwana + 00051 + 00052 diff --git a/testfiles/TPicSim12.LST b/testfiles/TPicSim12.LST new file mode 100755 index 0000000..757aa1a --- /dev/null +++ b/testfiles/TPicSim12.LST @@ -0,0 +1,81 @@ + 00001 ;TPicSim12 + 00002 ;Programm zum Test des 16F84-Simulators. + 00003 ;Funktion: Beschreiben und Lesen des EEPROMs + 00004 ;(c) St. Lehmann Ersterstellung: 11.05.2011 + 00005 ;Definition einiger Symbole + 00006 ;19.05.2020 Korrektur WR-Bit (muss nach Ablauf der State Machine stehen) + 00007 ;18.10.2018 mod. für HSO + 00008 + 00009 list c=132 ;Zeilenlänge im LST auf 132 Zeichen setzen + 00010 + 00011 indirect equ 0 + 00012 status equ 03h + 00013 fsr equ 04h + 00014 ra equ 05h + 00015 rb equ 06h + 00016 count equ 0ch + 00017 eedata equ 08h + 00018 eeaddr equ 09h + 00019 eecon1 equ 08h ;auf Bank 1 + 00020 eecon2 equ 09h ;auf Bank 1 + 00021 + 00022 ;Definition des Prozessors + 00023 device 16F84 + 00024 + 00025 ;Festlegen des Codebeginns + 00026 org 0 + 00027 start +0000 3000 00028 movlw 0 ;der EEPROM-Speicher von 0 bis 3FH (63) gefüllt +0001 008C 00029 movwf count + 00030 schreiben +0002 080C 00031 movf count,w +0003 0089 00032 movwf eeaddr ;diese Adresse soll beschrieben werden +0004 3AFF 00033 xorlw 255 ;Adresse invertieren +0005 0088 00034 movwf eedata ;dieser Wert an obige Adresse schreiben + 00035 +0006 1683 00036 bsf status,5 ;auf Bank 1 +0007 1208 00037 bcf eecon1,4 ;EEIF zurücksetzen, wird überwacht +0008 1508 00038 bsf eecon1,2 ;WREN-Bit setzen, sonst kein schreiben möglich + 00039 +0009 3055 00040 movlw 55h ;State-Machine anwerfen +000A 0089 00041 movwf eecon2 +000B 30AA 00042 movlw 0AAh +000C 0089 00043 movwf eecon2 ;wenn State-Maschine ok und WR-Bit gesetzt wird, + 00044 ;dann beginnt der Schreibvorgang +000D 1488 00045 bsf eecon1,1 ;jetzt WR-Bit setzen, Schreibvorgang startet jetzt! + 00046 + 00047 warte +000E 1E08 00048 btfss eecon1,4 ;warte bis EEIF auf 1 ist +000F 280E 00049 goto warte + 00050 +0010 1108 00051 bcf eecon1,2 ;WREN auf 0 + 00052 +0011 1283 00053 bcf status,5 ;zurück auf Bank 0 + 00054 +0012 0A8C 00055 incf count +0013 080C 00056 movf count,w ;ist der Wert 40H erreicht +0014 3C40 00057 sublw 40h +0015 1D03 00058 btfss status,2 ;wenn 0, dann fertig +0016 2802 00059 goto schreiben + 00060 + 00061 +0017 018C 00062 clrf count ;jetzt gesamten Speicher lesen + 00063 lesen: +0018 080C 00064 movf count,w +0019 0089 00065 movwf eeaddr + 00066 +001A 1683 00067 bsf status,5 ;auf Bank 1 +001B 1408 00068 bsf eecon1,0 ;RD-Bit auf 1, wird vom PIC wieder auf 0 gesetzt +001C 1283 00069 bcf status,5 ;zurück auf Bank 0 + 00070 +001D 0808 00071 movf eedata,w ;Wert ins W-Register + 00072 +001E 0A8C 00073 incf count +001F 080C 00074 movf count,w ;ist der Wert 40H erreicht +0020 3C40 00075 sublw 40h +0021 1D03 00076 btfss status,2 ;wenn 0, dann fertig +0022 2818 00077 goto lesen + 00078 + 00079 ende +0023 2823 00080 goto ende + 00081 diff --git a/testfiles/TPicSim13.LST b/testfiles/TPicSim13.LST new file mode 100755 index 0000000..84a1605 --- /dev/null +++ b/testfiles/TPicSim13.LST @@ -0,0 +1,45 @@ + 00001 ;TPicSim13 + 00002 ;Programm zum Test des 16F84-Simulators. + 00003 ;Funktion: Lauflicht. Die Richtung wird durch RA,0 bestimmt + 00004 ;(c) St. Lehmann Ersterstellung: 11.05.2011 + 00005 ;Definition einiger Symbole + 00006 ;18.10.2018 mod. für HSO + 00007 + 00008 list c=132 ;Zeilenlänge im LST auf 132 Zeichen setzen + 00009 + 00010 indirect equ 0 + 00011 status equ 03h + 00012 fsr equ 04h + 00013 ra equ 05h + 00014 rb equ 06h + 00015 rp0 equ 5 + 00016 + 00017 ;Definition des Prozessors + 00018 device 16F84 + 00019 + 00020 ;Festlegen des Codebeginns + 00021 org 0 + 00022 start +0000 1683 00023 bsf status,rp0 ;auf Bank 1 umschalten +0001 0186 00024 clrf rb ;TRIS RB auf 0 = Ausgang setzen +0002 1283 00025 bcf status,rp0 ;zurück auf Bank 0 +0003 0186 00026 clrf rb ;Ausgäbge auf 0 +0004 1403 00027 bsf status,0 ;Carry auf 1 setzen + 00028 loop +0005 1C05 00029 btfss ra,0 ;in welche Richtung? +0006 280B 00030 goto links + 00031 rechts +0007 0C86 00032 rrf rb +0008 1803 00033 btfsc status,0 ;ist Carry 1? +0009 0C86 00034 rrf rb ;ja, dann nochmal schieben +000A 2805 00035 goto loop + 00036 + 00037 links +000B 0D86 00038 rlf rb +000C 1803 00039 btfsc status,0 ;ist Carry = 1 +000D 0D86 00040 rlf rb ;ja, nochmal schieben +000E 2805 00041 goto loop + 00042 + 00043 ende +000F 280F 00044 goto ende + 00045 diff --git a/testfiles/TPicSim14.LST b/testfiles/TPicSim14.LST new file mode 100755 index 0000000..4a6faa9 --- /dev/null +++ b/testfiles/TPicSim14.LST @@ -0,0 +1,45 @@ + 00001 ;TPicSim14 + 00002 ;Programm zum Test des 16F84-Simulators. + 00003 ;Funktion: Leuchtband. Die Richtung wird durch RA,0 bestimmt + 00004 ;(c) St. Lehmann Ersterstellung: 11.05.2011 + 00005 ;Definition einiger Symbole + 00006 ;18.10.2018 mod. für HSO + 00007 + 00008 list c=132 ;Zeilenlänge im LST auf 132 Zeichen setzen + 00009 + 00010 indirect equ 0 + 00011 status equ 03h + 00012 fsr equ 04h + 00013 ra equ 05h + 00014 rb equ 06h + 00015 rp0 equ 5 + 00016 + 00017 ;Definition des Prozessors + 00018 device 16F84 + 00019 + 00020 ;Festlegen des Codebeginns + 00021 org 0 + 00022 start +0000 1683 00023 bsf status,rp0 ;auf Bank 1 umschalten +0001 0186 00024 clrf rb ;TRIS RB auf 0 = Ausgang setzen +0002 1283 00025 bcf status,rp0 ;zurück auf Bank 0 +0003 0186 00026 clrf rb + 00027 loop +0004 1403 00028 bsf status,0 ;Carry auf 1 setzen +0005 1C05 00029 btfss ra,0 ;in welche Richtung? +0006 280B 00030 goto links + 00031 rechts +0007 0C86 00032 rrf rb +0008 1803 00033 btfsc status,0 ;ist Carry 1? +0009 0186 00034 clrf rb ;ja, neu starten +000A 2804 00035 goto loop + 00036 + 00037 links +000B 0D86 00038 rlf rb +000C 1803 00039 btfsc status,0 ;ist Carry = 1 +000D 0186 00040 clrf rb ;ja, neu starten +000E 2804 00041 goto loop + 00042 + 00043 ende +000F 280F 00044 goto ende + 00045 diff --git a/testfiles/TPicSim15.LST b/testfiles/TPicSim15.LST new file mode 100755 index 0000000..018703f --- /dev/null +++ b/testfiles/TPicSim15.LST @@ -0,0 +1,91 @@ + 00001 ;TPicSim15 + 00002 ;Programm zum Test des 16F84-Simulators. + 00003 ;Es wird die richtige Funktionsweise des Portlatch getestet + 00004 ; + 00005 ;(c) St. Lehmann + 00006 ;14.05.2020 + 00007 + 00008 list c=132 ;Zeilenlänge im LST auf 132 Zeichen setzen + 00009 + 00010 ;Definition einiger Symbole + 00011 indirect equ 0 + 00012 pcl equ 02h + 00013 status equ 03h + 00014 fsr equ 04h + 00015 ra equ 05h + 00016 rb equ 06h + 00017 pclath equ 0ah + 00018 intcon equ 0bh + 00019 rp0 equ 5 ;Bankumschaltbit + 00020 + 00021 ;Definition des Prozessors + 00022 device 16F84 + 00023 ;Festlegen des Codebeginns + 00024 org 0 + 00025 start +0000 2810 00026 goto main + 00027 + 00028 init +0001 1683 00029 bsf status,rp0 ;auf Bank 1 umschalten +0002 300E 00030 movlw 0Eh ;Port A wird auf xxxo iiio eingestellt +0003 0085 00031 movwf ra ;Trisregister Port A beschreiben +0004 300F 00032 movlw 0Fh ;Port B wird auf oooo iiii eingestellt +0005 0086 00033 movwf rb ;Trisregister Port B beschreiben +0006 1283 00034 bcf status,rp0 ;zurück auf Bank0 +0007 0008 00035 return + 00036 + 00037 trisRA +0008 1683 00038 bsf status,rp0 +0009 0085 00039 movwf ra +000A 1283 00040 bcf status,rp0 +000B 0008 00041 return + 00042 + 00043 trisRb +000C 1683 00044 bsf status,rp0 +000D 0086 00045 movwf rb +000E 1283 00046 bcf status,rp0 +000F 0008 00047 return + 00048 + 00049 main +0010 2001 00050 call init ;Ports initialisieren +0011 1405 00051 bsf ra,0 ;eine 1 an RA0 ausgeben +0012 0000 00052 nop +0013 1005 00053 bcf ra,0 ;eine 0 an RA0 ausgeben +0014 0000 00054 nop +0015 1386 00055 bcf rb,7 ;eine 0 an RB7 ausgeben +0016 0000 00056 nop +0017 1786 00057 bsf rb,7 ;eine 1 an RB7 ausgeben +0018 0000 00058 nop + 00059 + 00060 ;Funktionsprüfung an RA0 +0019 300F 00061 movlw 0Fh ;RA0 auf Eingang stellen +001A 2008 00062 call trisRA +001B 0000 00063 nop +001C 0000 00064 nop +001D 0000 00065 nop +001E 1405 00066 bsf ra,0 ;nur das interne Latch wird beschrieben +001F 0000 00067 nop ;der Pegel an RA0 ändert sich noch nicht. +0020 0000 00068 nop +0021 0000 00069 nop +0022 300E 00070 movlw 0Eh ;jetzt wird RA0 wieder auf Ausgang gestellt +0023 2008 00071 call trisRA ;und die 1 kommt sofort am Pin RA0 an. +0024 0000 00072 nop +0025 0000 00073 nop +0026 0000 00074 nop + 00075 + 00076 ;Funktionsprüfung an RB7 +0027 308F 00077 movlw 08Fh ;RB7 auf Eingang wechseln +0028 200C 00078 call trisRB +0029 0000 00079 nop +002A 0000 00080 nop +002B 1386 00081 bcf rb,7 ;RB7 intern auf 0 setzen, Pin bleibt unverändert +002C 0000 00082 nop +002D 0000 00083 nop +002E 300F 00084 movlw 0Fh ;RB7 wieder auf Ausgang setzen, die 0 erscheint +002F 200C 00085 call trisRB ;sofort am Pin RB7 +0030 0000 00086 nop +0031 0000 00087 nop + 00088 + 00089 ende +0032 2832 00090 goto ende + 00091 diff --git a/testfiles/TPicSim2.LST b/testfiles/TPicSim2.LST new file mode 100755 index 0000000..617db8b --- /dev/null +++ b/testfiles/TPicSim2.LST @@ -0,0 +1,33 @@ + 00001 ;TPicSim2 + 00002 ;Programm zum Test des 16F84-Simulators. + 00003 ;Es werden CALL, GOTO, RETLW, RETURN geprüft (kein RETFIE) + 00004 ;(c) St. Lehmann + 00005 ;Ersterstellung: 23.03.2016 + 00006 ;mod. 18.10.2018 für HSO + 00007 ; + 00008 list c=132 ;Zeilenlänge im LST auf 132 Zeichen setzen + 00009 + 00010 ;Definition des Prozessors + 00011 device 16F84 + 00012 + 00013 ;Festlegen des Codebeginns + 00014 org 0 + 00015 loop +0000 3011 00016 movlw 11h ;in W steht nun 11h, Statusreg. unverändert +0001 2006 00017 call up1 ;beim Call wird Rücksprungadresse auf Stack gelegt +0002 0000 00018 nop ;W = 36h, C=0, DC=0, Z=0 +0003 2008 00019 call up2 ;in W steht der Rückgabewert +0004 0000 00020 nop ;W = 77h, DC=0, C=0, Z=0; +0005 2800 00021 goto loop + 00022 + 00023 ;UP1 zählt zu W den Wert 25h hinzu und kehrt mit RETURN zurück +0006 3E25 00024 up1 addlw 25h ;W = 36h, DC=0, C=0, Z=0 +0007 0008 00025 return + 00026 + 00027 ;UP2 kehrt mit der Konstanten 77h zurück +0008 3477 00028 up2 retlw 77h + 00029 + 00030 ende +0009 2809 00031 goto ende ;Endlosschleife, verhindert Nirwana + 00032 + 00033 diff --git a/testfiles/TPicSim3.LST b/testfiles/TPicSim3.LST new file mode 100755 index 0000000..9c2a62b --- /dev/null +++ b/testfiles/TPicSim3.LST @@ -0,0 +1,62 @@ + 00001 ;TPicSim3 + 00002 ;Programm zum Test des 16F84-Simulators. + 00003 ;Es werden die Byte-orientieren File-Register Befehle geprüft + 00004 ;aber kein DECFSZ, INCFSZ, RLF, RRF + 00005 ;(c) St. Lehmann + 00006 ;Ersterstellung: 23.03.2016 + 00007 ;Korrekturen: 09.05.2017 (Fehler gefunden durch: Dominik Vogel) + 00008 ;19.05.2020 + 00009 ;mod. 18.10.2018 für HSO + 00010 + 00011 ;Hinweis: + 00012 ;Bei diesen Befehlen entscheidet das d-Bit (Destination), ob das Ergebnis + 00013 ;dieser Operation ins W- oder File-Register geschrieben wird. Wird im + 00014 ;Assemblercode der Befehl mit ",W" geschrieben, bedeutet dies, dass das + 00015 ;d-Bit 0 ist und das Ergebnis ins W-Register kommt. Fehlt ",W" ist das + 00016 ;d-Bit 1 und das Ergebnis wird ins Fileregister geschrieben. + 00017 ; + 00018 ;Alle Befehle die eine Fileregister-Adresse haben, können auch "indirekt" + 00019 ;adressieren. Dies ist im Testfile TPicSim6.LST beschrieben. + 00020 ; + 00021 list c=132 ;Zeilenlänge im LST auf 132 Zeichen setzen + 00022 + 00023 ;Definition einiger Symbole + 00024 ;für den Benutzer frei verwendbare Register + 00025 wert1 equ 0ch ;Variable Nr.1 + 00026 wert2 equ 0dh ;Variable Nr.2 + 00027 ergeb equ 0eh ;Variable Nr.3 + 00028 + 00029 ;Definition des Prozessors + 00030 device 16F84 + 00031 + 00032 ;Festlegen des Codebeginns + 00033 org 0 + 00034 loop +0000 3011 00035 movlw 11h ;in W steht nun 11h, DC=?, C=?, Z=? +0001 008C 00036 movwf wert1 ;diesen Wert abspeichern, DC=?, C=?, Z=? +0002 3014 00037 movlw 14h ;W = 14h, DC=?, C=?, Z=? +0003 070C 00038 addwf wert1,w ;W = 25h, DC=0, C=0, Z=0 +0004 078C 00039 addwf wert1 ;W = 25h, wert1 = 36h, DC=0, C=0, Z=0 +0005 050C 00040 andwf wert1,w ;W = 24h, wert1 = 36h, DC=0, C=0, Z=0 +0006 008D 00041 movwf wert2 ;W=24h, wert1=36, wert2=24h +0007 018C 00042 clrf wert1 ;W=24h, wert1=0, wert2=24h, DC=0, C=0, Z=1 +0008 090D 00043 comf wert2,w ;W=DBh, wert1=0, wert2=24h, DC=0, C=0, Z=0 +0009 030C 00044 decf wert1,w ;W=FFh, wert1=0, wert2=24h, DC=0, C=0, Z=0 +000A 0A8D 00045 incf wert2 ;W=FFh, wert1=0, wert2=25h, DC=0, C=0, Z=0 +000B 088C 00046 movf wert1 ;W=FFh, wert1=0, wert2=25h, DC=0, C=0, Z=1 +000C 048C 00047 iorwf wert1 ;W=FFh, wert1=FFh, wert2=25h, DC=0, C=0, Z=0 +000D 020D 00048 subwf wert2,w ;W=26h, wert1=FFh, wert2=25h, DC=0, C=0, Z=0 +000E 0E8D 00049 swapf wert2 ;W=26h, wert1=FFh, wert2=52h, DC=0, C=0, Z=0 +000F 068C 00050 xorwf wert1 ;W=26h, wert1=D9h, wert2=52h, DC=0, C=0, Z=0 +0010 0100 00051 clrw ;W=00h, wert1=D9h, wert2=52h, DC=0, C=0, Z=1 + 00052 +0011 020C 00053 subwf wert1,w ;W=D9h, wert1=D9h, wert2=52h, DC=1, C=1, Z=0 +0012 020D 00054 subwf wert2,w ;W=79h, wert1=D9h, wert2=52h, DC=0, C=0, Z=0 +0013 028D 00055 subwf wert2 ;W=79h, wert1=D9h, wert2=D9h, DC=0, C=0, Z=0 +0014 028D 00056 subwf wert2 ;W=79h, wert1=D9h, wert2=60h, DC=1, C=1, Z=0 + 00057 + 00058 + 00059 ende +0015 2815 00060 goto ende ;Endlosschleife, verhindert Nirwana + 00061 + 00062 diff --git a/testfiles/TPicSim4.LST b/testfiles/TPicSim4.LST new file mode 100755 index 0000000..65aa776 --- /dev/null +++ b/testfiles/TPicSim4.LST @@ -0,0 +1,107 @@ + 00001 ;TPicSim4 + 00002 ;Programm zum Test des 16F84-Simulators. + 00003 ;Es werden die Befehle DECFSZ, INCFSZ, RLF, RRF geprüft + 00004 ;(c) St. Lehmann + 00005 ;Ersterstellung: 23.03.2016 + 00006 ;Korrektur und ergänzt 09.05.2017 durch: Dominik Vogel + 00007 ;mod. 18.10.2018 für HSO + 00008 ; + 00009 list c=132 ;Zeilenlänge im LST auf 132 Zeichen setzen + 00010 + 00011 ;Definition einiger Symbole + 00012 ;für den Benutzer frei verwendbare Register + 00013 wert1 equ 0ch ;Variable Nr.1 + 00014 wert2 equ 0dh ;Variable Nr.2 + 00015 ergeb equ 0eh ;Variable Nr.3 + 00016 + 00017 ;Definition des Prozessors + 00018 device 16F84 + 00019 + 00020 ;Festlegen des Codebeginns + 00021 org 0 + 00022 loop +0000 3011 00023 movlw 11h ;in W steht nun 11h, DC=?, C=?, Z=? +0001 008C 00024 movwf wert1 ;diesen Wert abspeichern, DC=?, C=?, Z=? +0002 3E11 00025 addlw 11h ;löscht u.a. das Carry-Flag, DC=0, C=0, Z=0 +0003 0D8C 00026 rlf wert1 ;W=22h, wert1=22h, wert2=?? , DC=0, C=0, Z=0 +0004 0D8C 00027 rlf wert1 ;W=22h, wert1=44h, wert2=?? , DC=0, C=0, Z=0 +0005 0D8C 00028 rlf wert1 ;W=22h, wert1=88h, wert2=?? , DC=0, C=0, Z=0 +0006 0D0C 00029 rlf wert1,w ;W=10h, wert1=88h, wert2=?? , DC=0, C=1, Z=0 +0007 0D8C 00030 rlf wert1 ;W=10h, wert1=11h, wert2=?? , DC=0, C=1, Z=0 +0008 0D0C 00031 rlf wert1,w ;W=23h, wert1=11h, wert2=?? , DC=0, C=0, Z=0 +0009 0C8C 00032 rrf wert1 ;W=23h, wert1=08h, wert2=?? , DC=0, C=1, Z=0 +000A 008D 00033 movwf wert2 ;W=23h, wert1=08h, wert2=23h, DC=0, C=1, Z=0 +000B 0C8D 00034 rrf wert2 ;W=23h, wert1=08h, wert2=91h, DC=0, C=1, Z=0 +000C 0C0D 00035 rrf wert2,w ;W=C8h, wert1=08h, wert2=91h, DC=0, C=1, Z=0 + 00036 +000D 3009 00037 movlw 9 ;W=09h, wert1=08h, wert2=91h, DC=0, C=1, Z=0 +000E 008C 00038 movwf wert1 ;W=09h, wert1=09h, wert2=91h, DC=0, C=1, Z=0 +000F 0100 00039 clrw ;W=00h, wert1=09h, wert2=91h, DC=0, C=1, Z=1 + 00040 loop1 +0010 3E01 00041 addlw 1 ;W=01h, DC=0, C=0, Z=0 + 00042 ;W=02h, DC=0, C=0, Z=0 + 00043 ;W=03h, DC=0, C=0, Z=0 + 00044 ;W=04h, DC=0, C=0, Z=0 + 00045 ;W=05h, DC=0, C=0, Z=0 + 00046 ;W=06h, DC=0, C=0, Z=0 + 00047 ;W=07h, DC=0, C=0, Z=0 + 00048 ;W=08h, DC=0, C=0, Z=0 + 00049 ;W=09h, DC=0, C=0, Z=0 +0011 078D 00050 addwf wert2 ;wert2=92h, DC=0, C=0, Z=0 + 00051 ;wert2=94h, DC=0, C=0, Z=0 + 00052 ;wert2=97h, DC=0, C=0, Z=0 + 00053 ;wert2=9Bh, DC=0, C=0, Z=0 + 00054 ;wert2=A0h, DC=1, C=0, Z=0 + 00055 ;wert2=A6h, DC=0, C=0, Z=0 + 00056 ;wert2=ADh, DC=0, C=0, Z=0 + 00057 ;wert2=B5h, DC=1, C=0, Z=0 + 00058 ;wert2=BEh, DC=0, C=0, Z=0 +0012 0B8C 00059 decfsz wert1 ;wert1=08h, wert1=07h, ... DC,C und Z bleiben unverändert +0013 2810 00060 goto loop1 + 00061 +0014 30F0 00062 movlw 0f0h ;Wert wird bis 00h (über FFh) hochgezählt +0015 008C 00063 movwf wert1 +0016 018D 00064 clrf wert2 +0017 0100 00065 clrw + 00066 loop2 +0018 070C 00067 addwf wert1,w ;W=F0h, wert1=F0h, wert2=00h, DC=0, C=0, Z=0 + 00068 ;W=E1h, wert1=F1h, wert2=01h, DC=0, C=1, Z=0 + 00069 ;W=D3h, wert1=F2h, wert2=02h, DC=0, C=1, Z=0 + 00070 ;W=C6h, wert1=F3h, wert2=03h, DC=0, C=1, Z=0 + 00071 ;W=BAh, wert1=F4h, wert2=04h, DC=0, C=1, Z=0 + 00072 ;W=AFh, wert1=F5h, wert2=05h, DC=0, C=1, Z=0 + 00073 ;W=A5h, wert1=F6h, wert2=06h, DC=1, C=1, Z=0 + 00074 ;W=9Ch, wert1=F7h, wert2=07h, DC=0, C=1, Z=0 + 00075 ;W=94h, wert1=F8h, wert2=08h, DC=1, C=1, Z=0 + 00076 ;W=8Dh, wert1=F9h, wert2=09h, DC=0, C=1, Z=0 + 00077 ;W=87h, wert1=FAh, wert2=0Ah, DC=1, C=1, Z=0 + 00078 ;W=82h, wert1=FBh, wert2=0Bh, DC=1, C=1, Z=0 + 00079 ;W=7Eh, wert1=FCh, wert2=0Ch, DC=0, C=1, Z=0 + 00080 ;W=7Bh, wert1=FDh, wert2=0Dh, DC=1, C=1, Z=0 + 00081 ;W=79h, wert1=FEh, wert2=0Eh, DC=1, C=1, Z=0 + 00082 ;W=78h, wert1=FFh, wert2=0Fh, DC=1, C=1, Z=0 + 00083 +0019 0A8D 00084 incf wert2 ;W=F0h, wert1=F0h, wert2=01h, DC=0, C=0, Z=0 + 00085 ;W=E1h, wert1=F1h, wert2=02h, DC=0, C=1, Z=0 + 00086 + 00087 ;W=D3h, wert1=F2h, wert2=03h, DC=0, C=1, Z=0 + 00088 ;W=C6h, wert1=F3h, wert2=04h, DC=0, C=1, Z=0 + 00089 ;W=BAh, wert1=F4h, wert2=05h, DC=0, C=1, Z=0 + 00090 ;W=AFh, wert1=F5h, wert2=06h, DC=0, C=1, Z=0 + 00091 ;W=A5h, wert1=F6h, wert2=07h, DC=1, C=1, Z=0 + 00092 ;W=9Ch, wert1=F7h, wert2=08h, DC=0, C=1, Z=0 + 00093 ;W=94h, wert1=F8h, wert2=09h, DC=1, C=1, Z=0 + 00094 ;W=8Dh, wert1=F9h, wert2=0Ah, DC=0, C=1, Z=0 + 00095 ;W=87h, wert1=FAh, wert2=0Bh, DC=1, C=1, Z=0 + 00096 ;W=82h, wert1=FBh, wert2=0Ch, DC=1, C=1, Z=0 + 00097 ;W=7Eh, wert1=FCh, wert2=0Dh, DC=0, C=1, Z=0 + 00098 ;W=7Bh, wert1=FDh, wert2=0Eh, DC=1, C=1, Z=0 + 00099 ;W=79h, wert1=FEh, wert2=0Fh, DC=1, C=1, Z=0 + 00100 ;W=78h, wert1=FFh, wert2=10h, DC=1, C=1, Z=0 +001A 0F8C 00101 incfsz wert1 ;wert1=F1h, F2h, F3h .. FFh, 00h, wert2 und Flags bleiben unverändert +001B 2818 00102 goto loop2 + 00103 + 00104 ende +001C 281C 00105 goto ende ;Endlosschleife, verhindert Nirwana + 00106 + 00107 diff --git a/testfiles/TPicSim5.LST b/testfiles/TPicSim5.LST new file mode 100755 index 0000000..cf26ddd --- /dev/null +++ b/testfiles/TPicSim5.LST @@ -0,0 +1,51 @@ + 00001 ;TPicSim5 + 00002 ;Programm zum Test des 16F84-Simulators. + 00003 ;Es werden die Befehle BCF, BSF, BTFSC und BTFSS geprüft + 00004 ;(c) St. Lehmann + 00005 ;Ersterstellung: 23.03.2016 + 00006 ;mod. 18.10.2018 für HSO + 00007 ; + 00008 list c=132 ;Zeilenlänge im LST auf 132 Zeichen setzen + 00009 + 00010 ;Definition einiger Symbole + 00011 ;zuerst Hardware-Register + 00012 status equ 03h + 00013 ra equ 05h + 00014 rb equ 06h + 00015 + 00016 ;für den Benutzer frei verwendbare Register + 00017 wert1 equ 0ch ;Variable Nr.1 + 00018 wert2 equ 0dh ;Variable Nr.2 + 00019 ergeb equ 0eh ;Variable Nr.3 + 00020 + 00021 ;Definition des Prozessors + 00022 device 16F84 + 00023 + 00024 ;Festlegen des Codebeginns + 00025 org 0 + 00026 loop +0000 3011 00027 movlw 11h ;in W steht nun 11h, DC=?, C=?, Z=? +0001 008C 00028 movwf wert1 ;diesen Wert abspeichern, DC=?, C=?, Z=? +0002 018D 00029 clrf wert2 ;W=11h, wert1=11h, wert2=00h, DC=?, C=?, Z=1 +0003 178C 00030 bsf wert1,7 ;W=11h, wert1=91h, wert2=00h, DC=?, C=?, Z=1 +0004 158C 00031 bsf wert1,3 ;W=11h, wert1=99h, wert2=00h, DC=?, C=?, Z=1 +0005 120C 00032 bcf wert1,4 ;W=11h, wert1=89h, wert2=00h, DC=?, C=?, Z=1 +0006 100C 00033 bcf wert1,0 ;W=11h, wert1=88h, wert2=00h, DC=?, C=?, Z=1 + 00034 +0007 180C 00035 btfsc wert1,0 +0008 0A8D 00036 incf wert2 +0009 0A8D 00037 incf wert2 +000A 198C 00038 btfsc wert1,3 +000B 0A8D 00039 incf wert2 +000C 0A8D 00040 incf wert2 +000D 1D0C 00041 btfss wert1,2 +000E 0A8D 00042 incf wert2 +000F 0A8D 00043 incf wert2 +0010 1F8C 00044 btfss wert1,7 +0011 0A8D 00045 incf wert2 +0012 038D 00046 decf wert2 ;in wert2 muss 04h stehen + 00047 + 00048 ende +0013 2813 00049 goto ende ;Endlosschleife, verhindert Nirwana + 00050 + 00051 diff --git a/testfiles/TPicSim6.LST b/testfiles/TPicSim6.LST new file mode 100755 index 0000000..3d9464b --- /dev/null +++ b/testfiles/TPicSim6.LST @@ -0,0 +1,95 @@ + 00001 ;TPicSim6 + 00002 ;Programm zum Test des 16F84-Simulators. + 00003 ;Es werden die Byte-orientieren File-Register-Befehle im + 00004 ;Zusammenhang mit der indirekten Adressierung geprüft + 00005 ; + 00006 ;(c) St. Lehmann + 00007 ;Ersterstellung: 23.03.2016 + 00008 + 00009 ;Hinweis: + 00010 ;Bei der indirekten Adressierung werden die Register "IND" oder auch als + 00011 ;"indirect" bezeichnet und das Register FSR (File Select Register) + 00012 ;benutzt. Dabei beinhaltet das FSR-Register die Zieladresse in die etwas + 00013 ;geschrieben oder von der etwas gelesen werden soll. Der eigentliche + 00014 ;Zugriff erfolgt über das Ansprechen der Registeradresse 0 (IND). Der PIC + 00015 ;ersetzt in dem Falle die Adresse 0 durch die Adresse im FSR-Register. + 00016 ;Da die Adresse im FSR-Register 8-Bit umfasst, die Adresse bei der direkten + 00017 ;Adressierung jedoch nur 7 Bit, kann man durch die indirekte Adressierung + 00018 ;auch auf Bank 1 zugreifen ohne das RP0-Bit zu setzen. + 00019 ; + 00020 ;Bei diesen Befehlen entscheidet das d-Bit (Destination), ob das Ergebnis + 00021 ;dieser Operation ins W- oder File-Register geschrieben wird. Wird im + 00022 ;Assemblercode der Befehl mit ",W" geschrieben, bedeutet dies, dass das + 00023 ;d-Bit 0 ist und das Ergebnis ins W-Register kommt. Fehlt ",W" ist das + 00024 ;d-Bit 1 und das Ergebnis wird ins Fileregister geschrieben. + 00025 ; + 00026 list c=132 ;Zeilenlänge im LST auf 132 Zeichen setzen + 00027 + 00028 ;Definition einiger Symbole + 00029 ;zuerst Hardware-Register + 00030 indirect equ 00h + 00031 status equ 03h + 00032 fsr equ 04h + 00033 ra equ 05h + 00034 rb equ 06h + 00035 + 00036 ;für den Benutzer frei verwendbare Register + 00037 wert1 equ 0ch ;Variable Nr.1 + 00038 wert2 equ 0dh ;Variable Nr.2 + 00039 ergeb equ 0eh ;Variable Nr.3 + 00040 + 00041 ;Definition des Prozessors + 00042 device 16F84 + 00043 + 00044 ;Festlegen des Codebeginns + 00045 org 0 + 00046 loop +0000 3020 00047 movlw 20h ;in W steht nun 20h, DC=?, C=?, Z=? +0001 008C 00048 movwf wert1 ;diesen Wert abspeichern, DC=?, C=?, Z=? +0002 3010 00049 movlw 10h ;W = 10h, DC=?, C=?, Z=? +0003 0084 00050 movwf fsr ;W=10h, FSR=10h, wert1=20h, wert2=?? , DC=?, C=?, Z=? +0004 008D 00051 movwf wert2 ;W=10h, FSR=10h, wert1=20h, wert2=10h, DC=?, C=?, Z=? +0005 080C 00052 movf wert1,w ;W=20h + 00053 ;der Speicherbereich von 10h bis 1Fh wird mit Zahlen 20h, 21h, etc. gefüllt + 00054 loop1 +0006 0080 00055 movwf indirect ;W=20h, FSR=10h, F10=20h +0007 3E01 00056 addlw 1 ;W=20h, 21h, 22h, etc +0008 0A84 00057 incf fsr ;FSR=11h, 12h, etc +0009 0B8D 00058 decfsz wert2 +000A 2806 00059 goto loop1 + 00060 +000B 301F 00061 movlw 1fh ;FSR-Zeiger wieder auf Anfang stellen +000C 0084 00062 movwf fsr +000D 30F0 00063 movlw 0f0h +000E 008D 00064 movwf wert2 +000F 0100 00065 clrw + 00066 loop2 +0010 0700 00067 addwf indirect,w +0011 0384 00068 decf fsr +0012 0F8D 00069 incfsz wert2 +0013 2810 00070 goto loop2 + 00071 ;im W-Register muss 78h stehen +0014 008D 00072 movwf wert2 +0015 0A84 00073 incf fsr +0016 0C80 00074 rrf indirect ;F10=10h +0017 0A80 00075 incf indirect ;F10=11h +0018 0C80 00076 rrf indirect ;F10=08h, C=1 +0019 1780 00077 bsf indirect,7 ;F10=88h +001A 1003 00078 bcf status,0 ;C=0 +001B 0D80 00079 rlf indirect ;F10=10h, C=1 +001C 0A84 00080 incf fsr ;fsr=11h +001D 0D80 00081 rlf indirect ;F11=43h, C=0 +001E 0E80 00082 swapf indirect ;F11=34h +001F 0680 00083 xorwf indirect ;F11=4Ch +0020 1A80 00084 btfsc indirect,5 +0021 2800 00085 goto loop +0022 1D00 00086 btfss indirect,2 +0023 2800 00087 goto loop +0024 1980 00088 btfsc indirect,3 +0025 2827 00089 goto ende +0026 2800 00090 goto loop + 00091 + 00092 ende +0027 2827 00093 goto ende ;Endlosschleife, verhindert Nirwana + 00094 + 00095 diff --git a/testfiles/TPicSim7.LST b/testfiles/TPicSim7.LST new file mode 100755 index 0000000..3cf6027 --- /dev/null +++ b/testfiles/TPicSim7.LST @@ -0,0 +1,85 @@ + 00001 ;TPicSim7 + 00002 ;Programm zum Test des 16F84-Simulators. + 00003 ;Es wird der Timer0 mit und ohne Vorteiler geprüft + 00004 ;(c) St. Lehmann Ersterstellung: 23.01.2003 + 00005 ;19.04.2014 überarbeitet + 00006 ;18.10.2018 mod. für HSO + 00007 ;20.04.2021 Tippfehler im Kommentar korrigiert + 00008 + 00009 list c=132 ;Zeilenlänge im LST auf 132 Zeichen setzen + 00010 + 00011 ;Definition einiger Symbole + 00012 indirect equ 0 + 00013 status equ 03h + 00014 fsr equ 04h + 00015 ra equ 05h + 00016 rb equ 06h + 00017 count equ 0ch + 00018 + 00019 ;Definition des Prozessors + 00020 device 16F84 + 00021 ;Festlegen des Codebeginns + 00022 org 0 + 00023 start + 00024 ;zuerst Timer0 intern durch den Befehlstakt erhöhen VT = 1:4 + 00025 ;somit wird nach jedem 4. Befehlstakt (Achtung GOTO etc) TMR0 erhöht +0000 3001 00026 movlw 00000001B ;Option-Register entsp. initialisieren +0001 1683 00027 bsf status,5 ;Bank umschalten +0002 0081 00028 movwf 1 ;Option-Register +0003 1283 00029 bcf status,5 +0004 3001 00030 movlw 1 ;Timer 0 auf 1 +0005 0081 00031 movwf 1 +0006 0190 00032 clrf 10h ;zähler + 00033 loop1 +0007 0000 00034 nop +0008 0000 00035 nop +0009 0000 00036 nop +000A 0A90 00037 incf 10h +000B 0801 00038 movf 1,w ;lese Timerwert aus +000C 1D03 00039 btfss status,2 ;wenn Timer = 0, dann fertig +000D 2807 00040 goto loop1 + 00041 ;num muss 80H in 10h stehen + 00042 + 00043 ;nun mit einem VT = 1:16 + 00044 ;somit wird nach jedem 16. Befehlstakt (Achtung GOTO etc) TMR0 erhöht +000E 3003 00045 movlw 00000011B ;Option-Register entsp. initialisieren +000F 1683 00046 bsf status,5 ;Bank umschalten +0010 0081 00047 movwf 1 ;Option-Register +0011 1283 00048 bcf status,5 +0012 3001 00049 movlw 1 ;Timer 0 auf 1 +0013 0081 00050 movwf 1 +0014 0190 00051 clrf 10h ;zähler + 00052 loop2 +0015 0A90 00053 incf 10h +0016 0801 00054 movf 1,w ;lese Timerwert aus +0017 1D03 00055 btfss status,2 ;wenn Timer = 0, dann fertig +0018 2815 00056 goto loop2 + 00057 ;num muss 31H in 10h stehen + 00058 ;***************************************************************** + 00059 ;jetzt wird der Timer0 durch den externen Takt an RA4 hochgezählt. + 00060 ;zuerst ohne VT, damit zählt jede fallende Flanke an RA +0019 3038 00061 movlw 00111000B ;Option-Register initialisieren +001A 1683 00062 bsf status,5 +001B 0081 00063 movwf 1 ;Wert ins Option-Register +001C 1283 00064 bcf status,5 +001D 0181 00065 clrf 1 ;Timer löschen + 00066 loop3 +001E 1E01 00067 btfss 1,4 ;bis im Timer0 der Wert 16 erreicht wird +001F 281E 00068 goto loop3 + 00069 + 00070 ;jetzt auch mit VT 1:4, damit zählt jede 4. fallende Flanke an RA +0020 3031 00071 movlw 00110001B ;Option-Register initialisieren +0021 1683 00072 bsf status,5 +0022 0081 00073 movwf 1 ;Wert ins Option-Register +0023 1283 00074 bcf status,5 +0024 0181 00075 clrf 1 ;Timer löschen + 00076 loop4 +0025 1D81 00077 btfss 1,3 ;bis im Timer0 der Wert 8 erreicht wird +0026 2825 00078 goto loop4 + 00079 + 00080 ;****************************************************************** + 00081 + 00082 ende +0027 2827 00083 goto ende ;Endlosschleife, verhindert Nirwana + 00084 + 00085 diff --git a/testfiles/TPicSim8.LST b/testfiles/TPicSim8.LST new file mode 100755 index 0000000..e8210af --- /dev/null +++ b/testfiles/TPicSim8.LST @@ -0,0 +1,116 @@ + 00001 ;TPicSim8 + 00002 ;Programm zum Test des 16F84-Simulators. + 00003 ;Es werden die Interrupts für TMR0, RB0 (INT) und RB4-7 geprüft + 00004 ;(c) St. Lehmann + 00005 ;19.05.2020 + 00006 + 00007 list c=132 ;Zeilenlänge im LST auf 132 Zeichen setzen + 00008 + 00009 ;Definition einiger Symbole + 00010 indirect equ 0 + 00011 status equ 03h + 00012 fsr equ 04h + 00013 ra equ 05h + 00014 rb equ 06h + 00015 intcon equ 0bh + 00016 + 00017 ;Definition des Prozessors + 00018 device 16F84 + 00019 ;Festlegen des Codebeginns + 00020 org 0 + 00021 start +0000 281C 00022 goto main + 00023 ;Interrupt-Service-Routine ISR muss an Adresse 4 stehen, deshalb die 3 NOPs +0001 0000 00024 nop +0002 0000 00025 nop +0003 0000 00026 nop + 00027 + 00028 ISR +0004 1D0B 00029 btfss intcon,2 ;war es ein Timer-Interrupt? +0005 280B 00030 goto isr1 ;nein +0006 3054 00031 movlw 54h ;ja, 54h = T in 20h schreiben +0007 00A0 00032 movwf 20h +0008 128B 00033 bcf intcon,5 ;Timer-Interrupt sperren +0009 110B 00034 bcf intcon,2 ;Interrupt-Flag zurücksetzen +000A 281B 00035 goto isrend + 00036 ISR1 +000B 1C8B 00037 btfss intcon,1 ;war es ein RB0-Interrupt? +000C 2812 00038 goto isr2 ;nein +000D 3049 00039 movlw 'I' ;schreibe ein I an 21h +000E 00A1 00040 movwf 21h +000F 120B 00041 bcf intcon,4 ;RB0-Interrupt sperren +0010 108B 00042 bcf intcon,1 ;RB0-Interrupt-Flag löschen +0011 281B 00043 goto isrend + 00044 ISR2 +0012 1C0B 00045 btfss intcon,0 ;war es ein RB4-7 Interrupt? +0013 2819 00046 goto isr3 ;dürfte nie passieren +0014 3052 00047 movlw 'R' ;schreibe ein R nach 22h +0015 00A2 00048 movwf 22h +0016 118B 00049 bcf intcon,3 ;keine RB4-7 Interrupts erlauben +0017 100B 00050 bcf intcon,0 ;auch das Flag löschen +0018 281B 00051 goto isrend + 00052 ISR3 +0019 3046 00053 movlw 'F' ;Fehlermeldung +001A 00A3 00054 movwf 23h + 00055 + 00056 isrend +001B 0009 00057 retfie ;Ende der Inetrrupt-Service-Routine + 00058 + 00059 + 00060 main: + 00061 ;Der TMR0 wird vom Befehlstakt incrementiert. beim Überlauf wird ein Interrupt ausgelöst +001C 3001 00062 movlw 00000001B ;Option-Register entsp. initialisieren +001D 1683 00063 bsf status,5 ;Bank umschalten +001E 0081 00064 movwf 1 ;Option-Register +001F 1283 00065 bcf status,5 +0020 3020 00066 movlw 20h ;nur Timer-Interrupt erlauben +0021 008B 00067 movwf intcon +0022 178B 00068 bsf intcon,7 ;Globale Freigabe, ab jetzt kann ein Interrupt durchkommen + 00069 loop1 +0023 1A8B 00070 btfsc intcon,5 ;fertig, wenn ISR dieses Bit zurücksetzt +0024 2823 00071 goto loop1 ;bis Timer überläuft + 00072 + 00073 ;zuerst die wirksame Flanke für RB0 festlegen (hier die fallende Flanke) +0025 300F 00074 movlw 00001111b +0026 1683 00075 bsf status,5 +0027 0081 00076 movwf 1 +0028 1283 00077 bcf status,5 + 00078 ;nun den RB0-Interrupt freigeben, Rest sperren +0029 3010 00079 movlw 10h +002A 008B 00080 movwf intcon +002B 178B 00081 bsf intcon,7 + 00082 loop2 +002C 1A0B 00083 btfsc intcon,4 +002D 282C 00084 goto loop2 + 00085 + 00086 ;Beim RB4-7 Interrupts wird ein Flankenwechsel nur an den Pins die als Eingang arbeiten erkannt +002E 3008 00087 movlw 08h ;RB4-7 Interrupt freigeben +002F 008B 00088 movwf intcon +0030 178B 00089 bsf intcon,7 ;GIE + 00090 loop3 +0031 198B 00091 btfsc intcon,3 ;wird in ISR zurückgesetzt +0032 2831 00092 goto loop3 + 00093 + 00094 ;das gleiche nochmals, nur sind RB4-6 Ausgänge und werden deshalb ignoriert +0033 308F 00095 movlw 10001111B +0034 1683 00096 bsf status,5 +0035 0086 00097 movwf 6 ;TRIS RB +0036 1283 00098 bcf status,5 +0037 3008 00099 movlw 08h ;RB4-7 Interrupt freigeben +0038 008B 00100 movwf intcon ;aber nur RB7 ist aktiv +0039 178B 00101 bsf intcon,7 ;GIE + 00102 loop4 +003A 198B 00103 btfsc intcon,3 ;wird in ISR zurückgesetzt +003B 283A 00104 goto loop4 + 00105 + 00106 + 00107 ;****************************************************************** + 00108 ;wenn alles richtig, dann + 00109 ;in 20h steht 54H + 00110 ;in 21H ein 49H + 00111 ;in 22H ein 52H + 00112 + 00113 ende +003C 283C 00114 goto ende ;Endlosschleife, verhindert Nirwana + 00115 + 00116 diff --git a/testfiles/TPicSim9.LST b/testfiles/TPicSim9.LST new file mode 100755 index 0000000..39f09b1 --- /dev/null +++ b/testfiles/TPicSim9.LST @@ -0,0 +1,48 @@ + 00001 ;TPicSim9 + 00002 ;Programm zum Test des 16F84-Simulators. + 00003 ;Funktion: SLEEP-Befehl + 00004 ;(c) St. Lehmann Ersterstellung: 31.03.2016 + 00005 ;19.05.2020 + 00006 ;20.04.2021 Ergänzungen bei den Kommentaren + 00007 ;Definition einiger Symbole + 00008 + 00009 list c=132 ;Zeilenlänge im LST auf 132 Zeichen setzen + 00010 + 00011 status equ 03h + 00012 rb equ 06h + 00013 var equ 0ch + 00014 liste1 equ 10h + 00015 liste2 equ 11h + 00016 liste3 equ 12h + 00017 liste4 equ 13h + 00018 + 00019 ;Definition des Prozessors + 00020 device 16F84 + 00021 + 00022 ;Festlegen des Codebeginns + 00023 org 0 + 00024 ;wenn mit eingeschaltetem Watchdog-Timer der SLEEP-Befehl aktiviert wird, + 00025 ;dann wird das Programm nach ca. 2,3s weiter laufen. + 00026 + 00027 ;wenn der Watchdog-Timer ausgeschaltet ist, beendet ein RESET den SLEEP-Modus + 00028 ;bei einem RESET am MCLR-Pin springt der Controller zur Adresse 0 /PD und /TO + 00029 ;sind entsprechend gesetzt. + 00030 ;bei einem Watchdog-Timeout macht der Controller beim Befehl der auf den SLEEP + 00031 ;folgt weiter. Das gilt auch, wenn ein Interrupt den SLEEP beendet. + 00032 + 00033 ;Auch ein Interrupt an RB0 oder RB4 bis RB7 beendet den SLEEP-Modus, wenn GIE + 00034 ;gesetzt ist + 00035 + 00036 start +0000 018C 00037 clrf var ; +0001 0E03 00038 swapf status,w +0002 0090 00039 movwf liste1 ;T0=1 , PD=1 +0003 0063 00040 sleep ;warte bis Watchdogtimer anspricht +0004 0E03 00041 swapf status,w +0005 0091 00042 movwf liste2 ;T0=0 , PD=0 bei Watchdog-Timeout + 00043 ;T0=1 , PD=0 bei RESET oder Interrupt + 00044 + 00045 + 00046 ende +0006 2806 00047 goto ende + 00048