Pin-Timer

This commit is contained in:
2024-05-13 23:13:28 +02:00
parent af17397a1c
commit c65d9c94de
2 changed files with 27 additions and 0 deletions

View File

@ -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++;