problem writing to PCL PIC16f877


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2009
    Posts
    3

    Default problem writing to PCL PIC16f877

    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

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    some
    Code:
    @ 
    
    asm
    ...
    
    Endasm
    missing ???

    Code:
    '******************************************************************************	
    '******************************************************************************
    ' 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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Sep 2009
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    It's OK to ask about Assembly language questions, especially when it's in the General category like you've posted it.
    Quote Originally Posted by quentin View Post
    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 ...
    Code:
    	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
    DT

  6. #6
    Join Date
    Sep 2009
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    I get it thank you.

Similar Threads

  1. PIC KIT 2 writing problem ?
    By KaanInal in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd January 2010, 12:59
  2. pic16f877 problem repeating serial data
    By TomRiddle in forum Serial
    Replies: 2
    Last Post: - 6th February 2008, 13:56
  3. Mutliple ADC problem with PIC16F877
    By andyto in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd October 2007, 17:47
  4. Problem on writing EEPROM in Winpic800 with picbasic pro
    By selimkara in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th May 2007, 16:33
  5. Writing / Reading EEPROM 24LC256 Problem
    By schmoddel in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th February 2004, 18:55

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts