writing to PORT

Thread Starter

pf elec

Joined Nov 30, 2008
6
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
 

mik3

Joined Feb 4, 2008
4,843
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.
 

Thread Starter

pf elec

Joined Nov 30, 2008
6
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
 

n9352527

Joined Oct 14, 2005
1,198
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.
 

MaxHeadRoom

Joined Jul 18, 2013
28,702
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.
 
Top