Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

18f4550 turn on turn off pins

Status
Not open for further replies.

ggmssr

Member level 2
Member level 2
Joined
Oct 25, 2011
Messages
48
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,586
Hello

i need help

I use 18f4550 pic and need to switch on and off some pic output pins, to turn some led or relay on or off.

I use mikroc. how this can be done?

- - - Updated - - -

Second qustion can this output be as toggle switch?
 

Toggle code. switch is connected to RB0 such that if switch is pressed RB0 is 1. This toggles RA0

Code:
void main() {
      if(PORTB.F0 == 1) {
           Delay_ms(30);
           if(PORTB.F0 == 1) {
                     PORTA.F0 = ~PORTA.F0 //toggles RA0 pin
}
}
}
 
  • Like
Reactions: ggmssr

    ggmssr

    Points: 2
    Helpful Answer Positive Rating
Big thanks,

Can I use port C and how will go for other pins.

Like this?

PORTC.F0 = ~PORTC.F0 //toggles RC0 pin

PORTC.F1 = ~PORTC.F1 //toggles RC1 pin

- - - Updated - - -

Do i need some pins initialisaation?

- - - Updated - - -

Where is RC3 pin on 18f4550?
 

Yes you can do like that. You can also refer to it like this:
Code:
RC0_bit = ~ RC0_bit;
RC0_bit is the same thing as PORTC.F0.

Do i need some pins initialisaation?

You need to make the pins output.
To write to RC0, RC0 must be declared as output. This is done by clearing the corresponding TRIS bit:
Code:
TRISC0_bit = 0;

By clearing the entire TRISC, you make all PORTC pins output:
Code:
TRISC = 0;

Where is RC3 pin on 18f4550?
Go through the datasheet:
ww1.microchip.com/downloads/en/devicedoc/39632c.pdf

You can find the pinout in the datasheet. Here it is:

8881629900_1353749966.png


Hope this helps.
Tahmid.
 
  • Like
Reactions: ggmssr

    ggmssr

    Points: 2
    Helpful Answer Positive Rating
Thanks Tahmid you are helpful,

Can I ask I dont see RC3 in 18f4550 pinout scheme? Is that mean that I cant use bit 2 on port C?
 

Looks like PIC 18F4550 doesn't have RC3.

It has RC0, RC1, RC2, RC4, RC5, RC6 and RC7.

Is that mean that I cant use bit 2 on port C?
Of course you can. PIC 18F4550 has bit 2 on PORTC - RC2. It doesn't have bit 3 on PORTC - RC3.

Hope this helps.
Tahmid.
 
  • Like
Reactions: ggmssr

    ggmssr

    Points: 2
    Helpful Answer Positive Rating
Ok, big thanks.

Ca I ask one more thing, I'm total beginner?

What is purpose of LAT and TRIS ?

LATB2_bit

TRISB2_bit
 

Just for clarification:

I found this on page 119 of the datasheet:

5766656800_1353750606.png


The last sentence clearly tells of the absence of RC3.

Hope this helps.
Tahmid.
 
  • Like
Reactions: ggmssr

    ggmssr

    Points: 2
    Helpful Answer Positive Rating
Ca I ask one more thing, I'm total beginner?

What is purpose of LAT and TRIS ?

LATB2_bit

TRISB2_bit

- - - Updated - - -

Sorry for this basic questions. :-(
 

TRIS sets whether the pin should be output or input. If TRISB2_bit is set to 1, PORTB2 is set as input. If TRISB2_bit is set to 0, PORTB2 is set as output.

In PIC18 when writing to the ports, you should write to LAT. If you want PORTB2 to output 1, write
Code:
LATB2_bit = 1;
If you want PORTB2 to output 0, write
Code:
LATB2_bit = 0;

Hope this helps.
Tahmid.
 
  • Like
Reactions: ggmssr

    ggmssr

    Points: 2
    Helpful Answer Positive Rating
Mr. Tahmid you are great teacher and you are very helpfull.

Thanks.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top