Menu

#26 patch to set the pc from cli of pic18f4455

closed-fixed
None
5
2013-03-26
2011-06-17
Anonymous
No

Hello,

When I set the pcl from the cli, it is ignoring the high byte of the
address. The cli does not allow setting the pc, though the gui
"Move PC here" can do so.

Attached is the hack that allows the user to set the pcl to a 16-bit
value. It puts the high byte in pclath and the low byte in pcl, and
also updates the pc with the 16-bit address.

The only downside is that it involves setting the pcl to a 16-bit
address, which is technically not correct as the pcl is an 8-bit
register. The correct way of doing it might be to allow pc to be set
from the command line. But, I could not figure out how to do that.

This is the gpsim output when I set the pc/pcl from cli, without the
hack:
gpsim snsr.cod

gpsim - the GNUPIC simulator
version: Release 0.26.99

type help for help
**gpsim> SimulationMode:82
**gpsim>
P18F4455 does not support USB registers and functionality

Config3H_2x21::set ( 0x83 )
Setting config word 0x300000 = 0xe12
CLKO not simulated
Setting config word 0x300002 = 0x1e26
Disabling WDT
Setting config word 0x300004 = 0x82ff
Config3H_2x21::set ( 0x82 )
FIXME ccp2con::setIOpin called for port portc1 then portb3 0xa0c3af8 0xa0c3520
Setting config word 0x300006 = 0xff81
Setting config word 0x300008 = 0xc00f
Setting config word 0x30000a = 0xe00f
Setting config word 0x30000c = 0x400f
Program_Counter16::put_value 0x0

**gpsim> pc=0xF64
ERROR:" cannot assign a Value to a Program_Counter16"
**gpsim> pcl=0xF64
Program_Counter16::put_value 0x64
**gpsim> pcl
pcl = 0x64
**gpsim> pclath
pclath = 0x0
**gpsim> pclath=0x0f
PCLATH::put_value(f)
**gpsim> pcl=0xF64
Program_Counter16::put_value 0x64
**gpsim> step
0x0000000000000000 p18f4455 0x0064 0xF000 nop
424: clrw
**gpsim>

When I use the "Move PC here" from the gui, the pc is set correctly.
Below is the output, when that is done:

gpsim snsr.cod

gpsim - the GNUPIC simulator
version: Release 0.26.99

type help for help
**gpsim> SimulationMode:82
**gpsim>
P18F4455 does not support USB registers and functionality

Config3H_2x21::set ( 0x83 )
Setting config word 0x300000 = 0xe12
CLKO not simulated
Setting config word 0x300002 = 0x1e26
Disabling WDT
Setting config word 0x300004 = 0x82ff
Config3H_2x21::set ( 0x82 )
FIXME ccp2con::setIOpin called for port portc1 then portb3 0x8305938 0x8305360
Setting config word 0x300006 = 0xff81
Setting config word 0x300008 = 0xc00f
Setting config word 0x30000a = 0xe00f
Setting config word 0x30000c = 0x400f
Program_Counter16::put_value 0x0
Program_Counter16::put_value 0xf64

**gpsim> step
0x0000000000000000 p18f4455 0x0F64 0x0E01 movlw 0x01
246: ; incf reg + 2, F
Wrote: 0x0001 to W(0x0FE8) was 0x0000
**gpsim>

Below is the output with this hack:
gpsim snsr.cod

gpsim - the GNUPIC simulator
version: Release 0.26.99

type help for help
**gpsim> SimulationMode:82
**gpsim>
**gpsim>
P18F4455 does not support USB registers and functionality

Config3H_2x21::set ( 0x83 )

**gpsim> Setting config word 0x300000 = 0xe12
CLKO not simulated
Setting config word 0x300002 = 0x1e26
Disabling WDT
Setting config word 0x300004 = 0x82ff
Config3H_2x21::set ( 0x82 )
FIXME ccp2con::setIOpin called for port portc1 then portb3 0x93675b8 0x9366fe0
Setting config word 0x300006 = 0xff81
Setting config word 0x300008 = 0xc00f
Setting config word 0x30000a = 0xe00f
Setting config word 0x30000c = 0x400f
Program_Counter16::put_value 0x0

**gpsim> pcl
pcl = 0x0
**gpsim> pcl=0xf64
Program_Counter16::put_value 0xf64
**gpsim> pcl
pcl = 0x64
**gpsim> pclath
pclath = 0xf
**gpsim> pc
pc = 0xf64
**gpsim> step
0x0000000000000000 p18f4455 0x0F64 0x0E01 movlw 0x01
246: ; incf reg + 2, F
Wrote: 0x0001 to W(0x0FE8) was 0x0000
**gpsim>

Thanks

Discussion

  • Nobody/Anonymous

    root directory: gpsim/src

     
  • Robert Pearce

    Robert Pearce - 2011-06-17

    That's the wrong fix. PCL is explicitly the least significant byte and it should not be possible to set it that way. What should be possible is to say:
    pc=0xF64
    However, that seems to produce an error message on 18F

     
  • Robert Pearce

    Robert Pearce - 2011-06-19

    The right fix is really simple, and has been put in at r2179.

    Incidentally the hack patch here uncomments some commented lines "because setting pcl doesn't set pclath". Well it damn well SHOULDN'T set pclath, that's why I commented the lines. Read my comments.

     
  • Nobody/Anonymous

    "The correct way of doing it might be to allow pc to be set
    from the command line. But, I could not figure out how to do that."

    Thanks for the fix.

     
  • Nobody/Anonymous

    Below is the gpsim output with r2179. Setting the PC does not
    seem to be setting the pclath.

    Program_Counter16::put_value 0x0

    **gpsim> pc=0x10a2
    Program_Counter16::put_value 0x10a2
    **gpsim> pcl
    pcl = 0xa2
    **gpsim> pclath
    pclath = 0x0
    **gpsim> pclatu
    pclatu = 0x0
    **gpsim> step
    0x0000000000000000 p18f4455 0x10A2 0x0E01 movlw 0x01
    246: ; incf reg + 2, F
    Wrote: 0x0001 to W(0x0FE8) was 0x0000
    **gpsim>

     
  • Nobody/Anonymous

    Though, I am not sure if it should be writing to pclath.

    But, other that, the fix seems to be working well.

    Thanks

     
  • Robert Pearce

    Robert Pearce - 2011-06-21

    No. Read my comments. Setting the PC SHOULD NOT SET PCLATH. Read the data sheet - pclath and pclatu are write-shadow registers that are set by the program for computed jumps, they are explicitly NOT the upper parts of the actual PC and are explicitly NOT affected by goto or call instructions, interrupts, reset, or anything else that changes the PC directly.

     
  • Roy Rankin

    Roy Rankin - 2013-03-26
    • assigned_to: nobody --> bdt-rob
    • status: open --> closed-fixed
     

Anonymous
Anonymous

Add attachments
Cancel