TMR0 works

This commit is contained in:
Mike Schwörer 2017-05-16 17:31:41 +02:00
parent 83a0a42684
commit 405b82d086
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
3 changed files with 21 additions and 11 deletions

View File

@ -841,6 +841,11 @@ namespace PIC_Simulator.PIC
Interrupt_RB(Register[index], (byte)wert); Interrupt_RB(Register[index], (byte)wert);
} }
if (index == ADDR_TMR0)
{
Zaehler.Reset();
}
Register[index] = (byte)(wert & 0xFF); Register[index] = (byte)(wert & 0xFF);
if (index == ADDR_PORT_A || index == ADDR_TRIS_A) if (index == ADDR_PORT_A || index == ADDR_TRIS_A)
@ -942,7 +947,7 @@ namespace PIC_Simulator.PIC
private void SetRegister(uint index, uint wert) private void SetRegister(uint index, uint wert)
{ {
if ((Register[ADDR_STATUS] & STATUS_BIT_RP0) == STATUS_BIT_RP0) if (GetBit(Register[ADDR_STATUS], STATUS_BIT_RP0))
{ {
SetRegisterOhneBank(0x80 + index, wert); SetRegisterOhneBank(0x80 + index, wert);
} }

View File

@ -16,7 +16,7 @@ namespace PIC_Simulator.PIC
bool tmr_mode = programm.GetRegisterOhneBank(PICProgramm.ADDR_OPTION, PICProgramm.OPTION_BIT_T0CS); bool tmr_mode = programm.GetRegisterOhneBank(PICProgramm.ADDR_OPTION, PICProgramm.OPTION_BIT_T0CS);
bool edge_mode = programm.GetRegisterOhneBank(PICProgramm.ADDR_OPTION, PICProgramm.OPTION_BIT_T0SE); bool edge_mode = programm.GetRegisterOhneBank(PICProgramm.ADDR_OPTION, PICProgramm.OPTION_BIT_T0SE);
if (!tmr_mode) if (tmr_mode)
{ {
bool curr_A4 = programm.GetRegisterOhneBank(PICProgramm.ADDR_PORT_A, 4); bool curr_A4 = programm.GetRegisterOhneBank(PICProgramm.ADDR_PORT_A, 4);
@ -43,18 +43,18 @@ namespace PIC_Simulator.PIC
prev_RA4 = programm.GetRegisterOhneBank(PICProgramm.ADDR_PORT_A, 4); prev_RA4 = programm.GetRegisterOhneBank(PICProgramm.ADDR_PORT_A, 4);
} }
private uint prescale_cntr = 0; // Zähler für timer private uint count = 0; // Zähler für timer
private void TimerHochzaehlen(uint cycles) private void TimerHochzaehlen(uint cycles)
{ {
uint current = programm.GetRegisterOhneBank(PICProgramm.ADDR_TMR0); uint current = programm.Register[PICProgramm.ADDR_TMR0];
uint scale = BerechneVorskalierung(); uint scale = BerechneVorskalierung();
prescale_cntr += cycles; count += cycles;
while (prescale_cntr >= scale) while (count >= scale)
{ {
prescale_cntr -= scale; count -= scale;
uint Result = current + 1; uint Result = current + 1;
if (Result > 0xFF) if (Result > 0xFF)
@ -64,9 +64,9 @@ namespace PIC_Simulator.PIC
Result %= 0x100; Result %= 0x100;
uint tmp_psc = prescale_cntr; uint tmp_psc = count;
programm.SetRegisterOhneBank(PICProgramm.ADDR_TMR0, Result); programm.Register[PICProgramm.ADDR_TMR0] = (byte) Result;
prescale_cntr = tmp_psc; count = tmp_psc;
} }
} }
@ -83,5 +83,10 @@ namespace PIC_Simulator.PIC
return prescale_mode ? 1 : (PICProgramm.SHL(2, scale)); return prescale_mode ? 1 : (PICProgramm.SHL(2, scale));
} }
public void Reset()
{
count = 0;
}
} }
} }

View File

@ -18,7 +18,7 @@
[X] Testprogramm 4 (DECFSZ, RLF, RRF... [X] Testprogramm 4 (DECFSZ, RLF, RRF...
[X] Testprogramm 5 (Bitbefehle) [X] Testprogramm 5 (Bitbefehle)
[X] Testprogramm 6 (indirekte Adressierung) [X] Testprogramm 6 (indirekte Adressierung)
[ ] Testprogramm 7 (Timer 0 ) [X] Testprogramm 7 (Timer 0 )
[X] Ext. Taktgeber an RA4 + IO-Pin [X] Ext. Taktgeber an RA4 + IO-Pin
[ ] Testprogramm 7 (Interrupts) [ ] Testprogramm 7 (Interrupts)
[ ] Testprogramm 9 (Sleep-Befehl) [ ] Testprogramm 9 (Sleep-Befehl)