From c65d9c94de0d1a6e6bb1817bbef05cad705fe921 Mon Sep 17 00:00:00 2001 From: paulmart-n Date: Mon, 13 May 2024 23:13:28 +0200 Subject: [PATCH] Pin-Timer --- .../fabrik/simulator/pic16f84/IOPorts.java | 2 ++ .../java/fabrik/simulator/pic16f84/Timer.java | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/main/java/fabrik/simulator/pic16f84/IOPorts.java b/src/main/java/fabrik/simulator/pic16f84/IOPorts.java index 388ba16..9ccb944 100644 --- a/src/main/java/fabrik/simulator/pic16f84/IOPorts.java +++ b/src/main/java/fabrik/simulator/pic16f84/IOPorts.java @@ -57,6 +57,8 @@ public class IOPorts { DataRegister.setDirectRegister(PORTB, ((~((~dataLatch[B])&0xFF | trisLatch[B])) | (trisLatch[B] & DataRegister.getDirectRegister(PORTB))) & 0xFF); DataRegister.setDirectRegister(TRISA, trisLatch[A]); DataRegister.setDirectRegister(TRISB, trisLatch[B]); + if (((trisLatch[A] >> 4) & 1 )== 1) + Timer.incrementFromPin(DataRegister.getDirectRegister(PORTA)); ToggleButtonGroup[] buttons = Controller_Frontend.getPORTbuttons(); for (int i = 0; i < buttons.length; i++){ int port = (i < 8) ? PORTA : PORTB; diff --git a/src/main/java/fabrik/simulator/pic16f84/Timer.java b/src/main/java/fabrik/simulator/pic16f84/Timer.java index cf29aab..dfa6eae 100644 --- a/src/main/java/fabrik/simulator/pic16f84/Timer.java +++ b/src/main/java/fabrik/simulator/pic16f84/Timer.java @@ -1,5 +1,7 @@ package fabrik.simulator.pic16f84; +import javafx.stage.Stage; + public class Timer { private static final int TIMERREG = 0x1; private static final int T0IF = 0x2; @@ -8,6 +10,8 @@ public class Timer { private static final int INTCON = 0x0B; private static final int OPTION = 0x81; + private static int oldpin = 0; + public static void cycles(int cycles){ if (DataRegister.getDirectBit(OPTION, T0CS) == 0){ @@ -27,6 +31,27 @@ public class Timer { } } + public static void incrementFromPin (int register){ + if (DataRegister.getDirectBit(OPTION, T0CS) == 1){ + int newpin = (register >> 4) & 1; + if (newpin != oldpin) { + System.out.println(newpin + " " + oldpin); + if (DataRegister.getDirectBit(OPTION, T0SE) == 0) { + // Low to high + if (newpin == 1 && oldpin == 0) { + increment(); + } + } else { + // High to low + if (newpin == 0 && oldpin == 1) { + increment(); + } + } + oldpin = newpin; + } + } + } + private static void increment() { int timer = DataRegister.getDirectRegister(TIMERREG); timer++;