watchdog #33
@@ -5,7 +5,7 @@ public class Cycles {
|
||||
|
||||
public static void incCycles()
|
||||
{
|
||||
Timer.increaseTimer();
|
||||
Timer.decreasePrescaler();
|
||||
cycles++;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,8 @@ public class Memory
|
||||
setDataFromIndirectAddress(indirectAddress, data);
|
||||
return;
|
||||
}
|
||||
if(address == 0x01) //Reset PrescalerCounter if change on Option or Timer Register
|
||||
if(address == 0x01 && !Timer.getPrescalerAssignment()) //Reset PrescalerCounter if change on Option or Timer
|
||||
// Register
|
||||
{
|
||||
Timer.resetTimeToTimerIncrease();
|
||||
Timer.setCyclesToTimerIncrease(Timer.getCyclesToTimerIncrease() - 1); //Decrease by one to account for
|
||||
@@ -86,7 +87,7 @@ public class Memory
|
||||
|
||||
private static void setDataFromIndirectAddress(int address, int data)
|
||||
{
|
||||
if(address == 0x81 || address == 0x01) //Reset PrescalerCounter if change on Option or Timer Register
|
||||
if((address == 0x81 || address == 0x01) && !Timer.getPrescalerAssignment()) //Reset PrescalerCounter if change on Option or Timer Register
|
||||
{
|
||||
Timer.resetTimeToTimerIncrease();
|
||||
Timer.setCyclesToTimerIncrease(Timer.getCyclesToTimerIncrease() - 1); //Decrease by one to account for
|
||||
|
||||
@@ -36,4 +36,9 @@ public class ProgramCounter
|
||||
pc++;
|
||||
Memory.setPCL(pc & 0x00FF);
|
||||
}
|
||||
|
||||
public static void resetProgramCounter() {
|
||||
pc = 0;
|
||||
Memory.setPCL(0x0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class Timer
|
||||
cyclesToTimerIncrease = getPrescalerFactor();
|
||||
}
|
||||
|
||||
private static boolean getPrescalerAsssignment() {
|
||||
public static boolean getPrescalerAssignment() {
|
||||
return (Memory.getOption() & 0x08) == 0x08;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Timer
|
||||
final int MULTIPLIER = 2;
|
||||
int prescalerPower = Memory.getOption() & 0x07;
|
||||
int prescaler = (int)Math.pow(2, prescalerPower);
|
||||
if(!getPrescalerAsssignment())
|
||||
if(!getPrescalerAssignment())
|
||||
{
|
||||
return prescaler * MULTIPLIER;
|
||||
}
|
||||
@@ -50,17 +50,27 @@ public class Timer
|
||||
Memory.setTimer(timerRegister);
|
||||
}
|
||||
|
||||
public static void increaseTimer()
|
||||
public static void decreasePrescaler()
|
||||
{
|
||||
if(!timerEnabled())
|
||||
{
|
||||
return;
|
||||
if(getPrescalerAssignment()) { // Assigned to WatchdogTimer
|
||||
cyclesToTimerIncrease--;
|
||||
if(cyclesToTimerIncrease == 0) {
|
||||
resetTimeToTimerIncrease();
|
||||
Watchdog.increaseWatchdogTimer();
|
||||
}
|
||||
} else {
|
||||
Watchdog.increaseWatchdogTimer();
|
||||
}
|
||||
cyclesToTimerIncrease--;
|
||||
if(cyclesToTimerIncrease == 0)
|
||||
{
|
||||
resetTimeToTimerIncrease();
|
||||
increaseTimerRegister();
|
||||
if(timerEnabled()) {
|
||||
if(!getPrescalerAssignment()) { // Assigned to timer0
|
||||
cyclesToTimerIncrease--;
|
||||
if(cyclesToTimerIncrease == 0) {
|
||||
resetTimeToTimerIncrease();
|
||||
Timer.increaseTimerRegister();
|
||||
}
|
||||
} else {
|
||||
Timer.increaseTimerRegister();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
29
de/darkress/pic16f84sim/microcontroller/Watchdog.java
Normal file
29
de/darkress/pic16f84sim/microcontroller/Watchdog.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package de.darkress.pic16f84sim.microcontroller;
|
||||
|
||||
public class Watchdog
|
||||
{
|
||||
private static int watchdogTimer = 18000;
|
||||
public static int getWatchdogTimer()
|
||||
{
|
||||
return watchdogTimer;
|
||||
}
|
||||
|
||||
public static void increaseWatchdogTimer()
|
||||
{
|
||||
watchdogTimer++;
|
||||
}
|
||||
|
||||
private static void checkWatchdog()
|
||||
{
|
||||
if(watchdogTimer > 18000)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void resetProgram()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user