Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

18f4550 turn on turn off pins

Status
Not open for further replies.

ggmssr

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?
 

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
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

ggmssr

Member level 2
Joined
Oct 25, 2011
Messages
48
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,586
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?
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,791
Reputation
3,574
Reaction score
1,650
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,545
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:



Hope this helps.
Tahmid.
 
  • Like
Reactions: ggmssr

    ggmssr

    points: 2
    Helpful Answer Positive Rating

ggmssr

Member level 2
Joined
Oct 25, 2011
Messages
48
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,586
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?
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,791
Reputation
3,574
Reaction score
1,650
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,545
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

ggmssr

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

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

What is purpose of LAT and TRIS ?

LATB2_bit

TRISB2_bit
 

ggmssr

Member level 2
Joined
Oct 25, 2011
Messages
48
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,586
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. :-(
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,791
Reputation
3,574
Reaction score
1,650
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,545
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

ggmssr

Member level 2
Joined
Oct 25, 2011
Messages
48
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,586
Mr. Tahmid you are great teacher and you are very helpfull.

Thanks.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top