timer0 #32
@@ -2,11 +2,13 @@ package de.darkress.pic16f84sim.microcontroller;
|
||||
|
||||
public class Timer
|
||||
{
|
||||
private boolean getPrescalerAsssignment() {
|
||||
private static int cyclesToTimerIncrease = getPrescalerFactor();
|
||||
|
||||
private static boolean getPrescalerAsssignment() {
|
||||
return (Memory.getOption() & 0x08) == 0x08;
|
||||
}
|
||||
|
||||
private int getPrescalerFactor() {
|
||||
private static int getPrescalerFactor() {
|
||||
final int MULTIPLIER = 2;
|
||||
int prescalerPower = Memory.getOption() & 0x07;
|
||||
int prescaler = (int)Math.pow(2, prescalerPower);
|
||||
@@ -16,4 +18,24 @@ public class Timer
|
||||
}
|
||||
return prescaler;
|
||||
}
|
||||
|
||||
private static void increaseTimerRegister()
|
||||
{
|
||||
int timerRegister = Memory.getRegister(0x01);
|
||||
timerRegister = (timerRegister + 1) % 256;
|
||||
if(timerRegister == 0) //check for timer Overflow --> interrupt
|
||||
{
|
||||
System.out.println("Timer Overflow");
|
||||
}
|
||||
Memory.setRegister(0x01, timerRegister);
|
||||
}
|
||||
|
||||
public static void addToTimer(int increase)
|
||||
{
|
||||
cyclesToTimerIncrease -= increase; // TODO: Rethink everything
|
||||
if(cyclesToTimerIncrease == 0)
|
||||
{
|
||||
cyclesToTimerIncrease = getPrescalerFactor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user