Pin-Timer + PreScaler
This commit is contained in:
@ -30,14 +30,8 @@ public class PreScaler {
|
|||||||
scaler--;
|
scaler--;
|
||||||
if (scaler == 0) {
|
if (scaler == 0) {
|
||||||
scaler = getFactor();
|
scaler = getFactor();
|
||||||
Timer.incrementFromInstructionCycle();
|
Timer.increment();
|
||||||
}
|
}
|
||||||
System.err.println("VT: " + scaler);
|
System.err.println("VT: " + scaler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void cycles(int i) {
|
|
||||||
for (int j = 0; j < i; j++) {
|
|
||||||
decrement();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
package fabrik.simulator.pic16f84;
|
package fabrik.simulator.pic16f84;
|
||||||
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
|
|
||||||
public class Timer {
|
public class Timer {
|
||||||
private static final int TIMERREG = 0x1;
|
private static final int TIMERREG = 0x1;
|
||||||
private static final int T0IF = 0x2;
|
private static final int T0IF = 0x2;
|
||||||
@ -25,12 +23,6 @@ public class Timer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void incrementFromInstructionCycle(){
|
|
||||||
if (DataRegister.getDirectBit(OPTION, T0CS) == 0){
|
|
||||||
increment();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void incrementFromPin (int register){
|
public static void incrementFromPin (int register){
|
||||||
if (DataRegister.getDirectBit(OPTION, T0CS) == 1){
|
if (DataRegister.getDirectBit(OPTION, T0CS) == 1){
|
||||||
int newpin = (register >> 4) & 1;
|
int newpin = (register >> 4) & 1;
|
||||||
@ -39,12 +31,18 @@ public class Timer {
|
|||||||
if (DataRegister.getDirectBit(OPTION, T0SE) == 0) {
|
if (DataRegister.getDirectBit(OPTION, T0SE) == 0) {
|
||||||
// Low to high
|
// Low to high
|
||||||
if (newpin == 1 && oldpin == 0) {
|
if (newpin == 1 && oldpin == 0) {
|
||||||
increment();
|
if (PreScaler.isPrescalerOnTimer())
|
||||||
|
PreScaler.decrement();
|
||||||
|
else
|
||||||
|
increment();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// High to low
|
// High to low
|
||||||
if (newpin == 0 && oldpin == 1) {
|
if (newpin == 0 && oldpin == 1) {
|
||||||
increment();
|
if (PreScaler.isPrescalerOnTimer())
|
||||||
|
PreScaler.decrement();
|
||||||
|
else
|
||||||
|
increment();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
oldpin = newpin;
|
oldpin = newpin;
|
||||||
@ -52,7 +50,7 @@ public class Timer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void increment() {
|
public static void increment() {
|
||||||
int timer = DataRegister.getDirectRegister(TIMERREG);
|
int timer = DataRegister.getDirectRegister(TIMERREG);
|
||||||
timer++;
|
timer++;
|
||||||
if (timer > 0xFF){
|
if (timer > 0xFF){
|
||||||
|
|||||||
Reference in New Issue
Block a user