PDA

View Full Version : problem writing to PCL PIC16f877



quentin
- 21st September 2009, 19:05
Hi

For some reason I am unable to write to PCL when simulating the most basic code in MPLAB.

Has this happened to anyone?

Anyone know what the problem is?

Example of code below, org @ 0x100 because I am using a bootloader.


;******Configuration*****************************

list p = 16f877a
include <p16f877a.inc>


;******Vectors***********************************

org 0x0100 ;reset vector address
goto Main
org 0x0110 ; start writing program from this address

;******Main Program******************************

Main
movlw 010h
addwf PCL,f
goto Main

end

Acetronics2
- 21st September 2009, 19:31
Hi,

some


@

asm
...

Endasm



missing ???



'************************************************* *****************************
'************************************************* *****************************
' We never should reach those lines ... but ... IF PC lost ...

@ ORG 1017
LOW Relay ' To be sure !!!
PAUSE Relaydelay
GOTO securite


This is for a 16F84 ...

Alain

quentin
- 21st September 2009, 19:40
Thanks for your reply Alain, I however have no clue what it is you are suggesting.

I want to write to my program counter, and for some reason when I do I get random values in it instead of what I wrote to it.

I would like to try and find out why.

Thanks
Quentin

mackrackit
- 21st September 2009, 21:27
We mainly use PicBasic here. If you are inserting ASM into PBP code then
"@"
or
asm
"code"
endasm

is how the assembly "stuff"is used.

Darrel Taylor
- 22nd September 2009, 02:26
It's OK to ask about Assembly language questions, especially when it's in the General category like you've posted it.

Hi

For some reason I am unable to write to PCL when simulating the most basic code in MPLAB.
A computed goto should also set PCLATH before changing PCL.

In your case, PCLATH has not been set, and when you add 10h to PCL, instead of jumping forward 16 addresses (0x0121), it will jump to (0x0021) which is in the middle of the bootloader.

But when simulating it in MPLAB, there is no bootloader, so that range of addresses is outside the range of compiled code.

Still not sure what you want to do ... a computed goto or a Table lookup, but if it's the latter, this might help ...
list p = 16f877a
include &lt;p16f877a.inc>


;******Vectors***********************************

org 0x0100 ;reset vector address
goto Main
org 0x0110 ; start writing program from this address

;******Main Program******************************

Main
movlw high(table)
movwf PCLATH
movlw 010h
call table
goto Main

table
addwf PCL,f
retlw .0
retlw .1
retlw .2
retlw .3
retlw .4
retlw .5
retlw .6
retlw .7
retlw .8
retlw .9
retlw .10
retlw .11
retlw .12
retlw .13
retlw .14
retlw .15
retlw .16
retlw .17
retlw .18
retlw .19
retlw .20
retlw .21
retlw .22

end

quentin
- 22nd September 2009, 06:59
I get it thank you.