writing to PORT

Discussion in 'Embedded Systems and Microcontrollers' started by pf elec, Nov 30, 2008.

  1. pf elec

    Thread Starter New Member

    Nov 30, 2008
    6
    0
    I am learning to use MPLAB.I did programing in assambly back then on a Apple 2.I cant find the way to write to PORTC (or TRISC etc) whit a 16F877.Builds OK.But it works when i program for a 18F8722.
    Thanks
     
  2. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    Every PIC microcontroller has different pin functions and memory locations. Thus, if you program in assembly for one PIC uC then you cant use the same code for another PIC uC. You can only use the same code (just change the port pins numbers if necessary) only with high level programming languages.
     
  3. pf elec

    Thread Starter New Member

    Nov 30, 2008
    6
    0
    Hello
    Here a tiny program that i use to change CPORT.I configures MPLAB for the 16F877 and added the conresponding linker but i cant write any register.
    Thank you

    ;test
    include p16f877a.inc
    code 00h
    clrw
    movf TRISC
    movlw 55
    movwf PORTC
    end
     
  4. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
  5. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    4
    First, you need to pay attention to the banking. IIRC, TRISC and PORTC are on different bank. Check the datasheet on the correct bank assignment, and switch to that bank before accessing the register.

    Second, check for multiplexed pin configuration. Some PICs use the same pin for different functions. Make sure that all the required pins are configured as digital IO.
     
  6. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,570
    2,381
    This is an older thread I just came across but possibly the question was not fully addressed.
    Although I would have thought the OP would have an error indicating that CLRW instruction has been dropped in most instruction sets now.
    There are still quite a few example programs out there by Microchip etc that still have the instruction and also Microchip was lax about showing this in any later revisions, so at first it caused some head scratching.
    Microchip now advise using 'clrf WREG'
    Max.
     
Loading...