Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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
 
Last edited:
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.
 
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 :D
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top