Compare commits
5 Commits
pinoutInCl
...
timer0Inte
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc53450507 | ||
|
|
791201c884 | ||
|
|
60b288a762 | ||
|
|
101c6ec464 | ||
|
|
4e5f53d46d |
@@ -2,20 +2,16 @@ package de.darkress.pic16f84sim;
|
||||
|
||||
import de.darkress.pic16f84sim.cli.Cli;
|
||||
import de.darkress.pic16f84sim.commands.Command;
|
||||
import de.darkress.pic16f84sim.decoder.CommandDecoder;
|
||||
import de.darkress.pic16f84sim.microcontroller.Cycles;
|
||||
import de.darkress.pic16f84sim.microcontroller.Memory;
|
||||
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
||||
import de.darkress.pic16f84sim.microcontroller.Watchdog;
|
||||
import de.darkress.pic16f84sim.parser.Parser;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
class Main
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Command[] program = Parser.parser("de/darkress/pic16f84sim/TestPrograms/TPicSim11.LST");
|
||||
Command[] program = Parser.parser("de/darkress/pic16f84sim/TestPrograms/TPicSim8.LST");
|
||||
|
||||
Memory.initMemory();
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ public class Cli
|
||||
System.out.printf("%s:\t\t%s\t", "PortA", Integer.toBinaryString(Memory.getPortA()));
|
||||
System.out.printf("%s:\t\t%s\t", "PortB", Integer.toBinaryString(Memory.getPortB()));
|
||||
System.out.printf("%n");
|
||||
printf(Memory.getRegister(0x0B), "IntCon", true);
|
||||
System.out.printf("%n");
|
||||
}
|
||||
|
||||
private static void printf(int value, String description, boolean hex) {
|
||||
|
||||
18
de/darkress/pic16f84sim/commands/Retfie.java
Normal file
18
de/darkress/pic16f84sim/commands/Retfie.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package de.darkress.pic16f84sim.commands;
|
||||
|
||||
import de.darkress.pic16f84sim.microcontroller.Cycles;
|
||||
import de.darkress.pic16f84sim.microcontroller.Memory;
|
||||
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
||||
import de.darkress.pic16f84sim.microcontroller.Stack;
|
||||
|
||||
public class Retfie extends LiteralCommandUtils implements Command
|
||||
{
|
||||
@Override
|
||||
public void execute()
|
||||
{
|
||||
Cycles.incCycles();
|
||||
Memory.setRegister(0x0B, Memory.getRegister(0x0B) | 0x80); //Set GIE
|
||||
ProgramCounter.setPcFromStack(Stack.pop() + 1);
|
||||
Cycles.incCycles(); // Simulate 2-Cycle Instruction
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,7 @@ public class CommandDecoder
|
||||
|
||||
if (input == 0x0009)
|
||||
{
|
||||
//retfie();
|
||||
return new Retfie();
|
||||
}
|
||||
|
||||
if (input == 0x0008)
|
||||
|
||||
13
de/darkress/pic16f84sim/microcontroller/Interrupt.java
Normal file
13
de/darkress/pic16f84sim/microcontroller/Interrupt.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package de.darkress.pic16f84sim.microcontroller;
|
||||
|
||||
public class Interrupt
|
||||
{
|
||||
private static boolean globalInterruptEnabled() {
|
||||
return (Memory.getRegister(0x0B) & 0x80) == 0x80; // Check GIE
|
||||
|
||||
}
|
||||
public static boolean checkTimerInterruptConditions() {
|
||||
boolean timerInterruptEnabled = (Memory.getRegister(0x0B) & 0x20) == 0x20;
|
||||
return globalInterruptEnabled() && timerInterruptEnabled;
|
||||
}
|
||||
}
|
||||
@@ -37,8 +37,11 @@ public class ProgramCounter
|
||||
Memory.setPCL(pc & 0x00FF);
|
||||
}
|
||||
|
||||
public static void resetProgramCounter() {
|
||||
pc = 0;
|
||||
Memory.setPCL(0x0);
|
||||
public static void setProgramCounter(int value) {
|
||||
if(value <= 0xFF && value >= 0)
|
||||
{
|
||||
pc = value;
|
||||
Memory.setPCL(pc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,12 @@ public class Timer
|
||||
if(timerRegister == 0) //check for timer Overflow --> interrupt
|
||||
{
|
||||
System.out.println("Timer Overflow");
|
||||
Memory.setRegister(0x0B, Memory.getRegister(0x0B) | 0x04); //set T0IF
|
||||
if(Interrupt.checkTimerInterruptConditions())
|
||||
{
|
||||
Stack.push(ProgramCounter.getPc());
|
||||
ProgramCounter.setProgramCounter(0x04); // Interrupt Vector
|
||||
}
|
||||
}
|
||||
Memory.setTimer(timerRegister);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class Watchdog
|
||||
public static void resetProgram()
|
||||
{
|
||||
Memory.setRegister(0x03, Memory.getRegister(0x03) | 0x10); //Set !T0 in StatusReg
|
||||
ProgramCounter.resetProgramCounter();
|
||||
ProgramCounter.setProgramCounter(0);
|
||||
watchdogTimer = 18000;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user