Prescaler, Watchdog, (Cycle-) Timer

This commit is contained in:
2024-05-13 20:53:56 +02:00
parent 3722bff281
commit af17397a1c
6 changed files with 117 additions and 91 deletions

View File

@ -0,0 +1,40 @@
package fabrik.simulator.pic16f84;
public class Timer {
private static final int TIMERREG = 0x1;
private static final int T0IF = 0x2;
private static final int T0SE = 0x4;
private static final int T0CS = 0x5;
private static final int INTCON = 0x0B;
private static final int OPTION = 0x81;
public static void cycles(int cycles){
if (DataRegister.getDirectBit(OPTION, T0CS) == 0){
if (PreScaler.isPrescalerOnTimer()){
for (int i = 0; i < cycles; i++){
PreScaler.decrement();
}
} else {
increment();
}
}
}
public static void incrementFromInstructionCycle(){
if (DataRegister.getDirectBit(OPTION, T0CS) == 0){
increment();
}
}
private static void increment() {
int timer = DataRegister.getDirectRegister(TIMERREG);
timer++;
if (timer > 0xFF){
DataRegister.setDirectRegister(TIMERREG, 0);
DataRegister.setBit(INTCON, T0IF);
} else {
DataRegister.setDirectRegister(1, timer);
}
}
}