Prescaler, Watchdog, (Cycle-) Timer
This commit is contained in:
40
src/main/java/fabrik/simulator/pic16f84/Timer.java
Normal file
40
src/main/java/fabrik/simulator/pic16f84/Timer.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user