Hallo zusammen,
da ich nun Tage gerübelt, Stunden gesucht (Im Programm und Datenblatt) und schon voller Verzweiflung war,
sicherlich für alle C-ler und geübte ehr unwichtig mal der nette Hinweiß:
Wenn man den PCLATH auslesen will um für eine indirkete Adressierung immer richtig zu landen, reicht es nicht
movf PCLATH,w
movwf PCLATH
zu schreiben.
Und ja, das steht auch so im Datenblatt:
Man muss PCL lesen, dann wird PCLATH ebenfalls mit dem aktuellen PC geladen. - weiß nicht wie oft ich das nun übersehen habe.
kurz gesagt:
movf PCL,w ;lese Program Counter
so ist es richtig, der PCL wird geladen, dabei wird PCLATH geladen und nun kann man das manipolieren beginnen und man landet da wo man es erwartet.
der ganze Sprungverteiler sind dann so aus:
movf PCL,w ;lese Program Counter
MOVF Temp0,W ;lade Offset
rlncf WREG, W ; 2Bytes pro Befehl
ADDWF PCL,F ;Addiere Offset
Bra Offset0
Bra Offset1
Bra Offset2
Gruß
Cobra
Das hatte ich schon einmal geschrieben:
Zitat von: pic18 in 04.02.2024, 19:50:11 CETIch habe im Datenblatt vom 18F4685 die Antwort gefunden. Ist schon so lange her das ich in Assembler programmiert habe.
ZitatThe Program Counter (PC) specifies the address of the
instruction to fetch for execution. The PC is 21 bits wide
and is contained in three separate 8-bit registers. The
low byte, known as the PCL register, is both readable
and writable. The high byte, or PCH register, contains
the PC<15:8> bits; it is not directly readable or writable.
Updates to the PCH register are performed through the
PCLATH register. The upper byte is called PCU. This
register contains the PC<20:16> bits; it is also not
directly readable or writable. Updates to the PCU
register are performed through the PCLATU register.
The contents of PCLATH and PCLATU are transferred
to the program counter by any operation that writes to
the PCL. Similarly, the upper two bytes of the program
counter are transferred to PCLATH and PCLATU by an
operation that reads PCL. This is useful for computed
offsets to the PC (see Section 5.1.4.1 "Computed
GOTO").
Du solltest aber darauf achten, das der PC nicht überläuft, sonst springt dein Pic woanders hin. Vielleicht kannst du das so absichern:
Sprung_anfang
movf PCL,w ;lese Program Counter
MOVF Temp0,W ;lade Offset
rlncf WREG, W ; 2Bytes pro Befehl
ADDWF PCL,F ;Addiere Offset
Bra Offset0
Bra Offset1
Sprung_ende
Bra Offset2
IF (high (Sprung_anfang) != high (Sprung_ende))
ERROR "PCL Ueberlauf"
ENDIF
Oh,
Tatsächlich pic18 das habe ich auch übersehen.
Danke für den Tipp, wäre eine Idee da noch eine Sicherung rein zu machen