newbie question for PORT turning on and off

Status
Not open for further replies.

daisordan

New Member
im using p18f4455 with C
If i wanna turn on all PORT D (RD0 to RD7)i should use "TRISD=0b00000000;" which 0 = output and 1 = input. If i wanna turn RD0 on it should be "TRISD=0b00000001;" But i found some other code on the internet which is "PORTD=0b00000000;"
what is the different between TRISD and PORTD? Are they doing the same things?
And now if i have to turn on RD0 for 5seconds then turn it off. turn on RD1 for 5 seconds and turn off. Should i do it like

TRISD=0b00000001;
Delay10KTCYx(70);
TRISD=0b00000000;
Delay10KTCYx(70);
TRISD=0b00000010;
Delay10KTCYx(70);
TRISD=0b00000000;

I am new from C code... thanks for the helping
 
Last edited:
Tris only sets the I/O input is a 1 and output is a 0

Port sets the pin on as your thinking and 1 is on and 0 is off
 
I didn't see the 18f4455 Latx is how you wold write it if you want. But most Hills will set it right just using Port and Tris.
 
LATx = x is a variable in this case, like A,B,C,D

LATA, LATB, LATC, LATD depending on PIC size of course.
 
Last edited:
Atom I no what LAT IS this is what I'm saying Most Hills will read your code Like this

TRISA = 0b00000000
PORTA = 0b11111111 that sets all pins high when the Hill compiles, And it see's you set the port to output

It will compile and change PORTA to LATA

Like this

Code:
        MOVLW 63
        MOVWF LATA,0

How nice of them to do that for us LOL

Now this is for only chips that have port latches
 
Last edited:
Hey Burt, im just repeating what i learned here. If you want to read a port on a 18F you use PORT and to write use LAT.

Cool that it compiles like that
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…