Port Pin Toggle

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
asbase
Posts: 20
Joined: Sun Jun 03, 2012 12:53 pm
Location: Malaysia
Has thanked: 13 times
Contact:

Port Pin Toggle

Post by asbase »

Please advice

While 1
portb.0=!portb.0
delay 100ms
end while

portb.0 connect to led.

flowcode simulator work but real hardware fail.

Thanks.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: PORT PIN TOGGLE

Post by kersing »

Please post your flowchart so we can take a look at it to see what the issue might be.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Re: Port Pin Toggle

Post by Kenrix2 »

Since I am new to Flowcode V5 I am both curious and confused by your post. Is this this what you are talking about?
Attachments
Port_Pin_Toggle.fcf
(6.5 KiB) Downloaded 314 times

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: Port Pin Toggle

Post by brandonb »

first you have to turn off the analog selects, then use tris to make pin output, then use toggle like this, this is just to toggle b0 pin, with out any other pins accounted for

anselb=0;// disable bport analog module
trisb&=~(1<<0);// set b0 as output
latb&=~(1<<0);// set b0 as low
while(1){
latb^=1<<0;// toggle b0 pin
delay_ms(100);// delay 100 ms
}

asbase
Posts: 20
Joined: Sun Jun 03, 2012 12:53 pm
Location: Malaysia
Has thanked: 13 times
Contact:

Re: Port Pin Toggle

Post by asbase »

This one also not working as simulator in the real hardware. First of all, it can turn off but cannot turn off without go into another switch. Please comment.
Thanks.
Attachments
Flowcode1.fcf
(10.5 KiB) Downloaded 301 times

asbase
Posts: 20
Joined: Sun Jun 03, 2012 12:53 pm
Location: Malaysia
Has thanked: 13 times
Contact:

Re: Port Pin Toggle

Post by asbase »

brandonb wrote:first you have to turn off the analog selects, then use tris to make pin output, then use toggle like this, this is just to toggle b0 pin, with out any other pins accounted for

anselb=0;// disable bport analog module
trisb&=~(1<<0);// set b0 as output
latb&=~(1<<0);// set b0 as low
while(1){
latb^=1<<0;// toggle b0 pin
delay_ms(100);// delay 100 ms
}
Can we just do it without C in simple way?

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: Port Pin Toggle

Post by brandonb »

Can we just do it without C in simple way?
yes, sorry about that, i thought that was what you were going after, i noticed the mikroc coding,
to toggle a bit just make the pin or port an output with a flowcode output icon, then use this if your gonna toggle the bit on B0

Code: Select all

 latb^=1<<0;
don't know if this is already defined in flowcode but you can put this in the supplimentary code window in project options under defines

Code: Select all

#define togglebit(port,bit) port^=(1<<bit)
then you can do this in c code

Code: Select all

togglebit(latb,0);

Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Re: Port Pin Toggle

Post by Kenrix2 »

Hello asbase,
I tried your program in hardware using a different micro and it works just like in simulation. You have the switches set for active high so each will need a pull down resistor, I usually use 4.7k to 10k ohm. Could you double check your wiring, configuration settings and clock speed. I am not familiar with the micro your using, is there anything unusual about the ports?
The reason for the "C code" being mentioned was because of your post using "portb.0" which sure confused me.

asbase
Posts: 20
Joined: Sun Jun 03, 2012 12:53 pm
Location: Malaysia
Has thanked: 13 times
Contact:

Re: Port Pin Toggle

Post by asbase »

Kenrix2 wrote:Hello asbase,
I tried your program in hardware using a different micro and it works just like in simulation. You have the switches set for active high so each will need a pull down resistor, I usually use 4.7k to 10k ohm. Could you double check your wiring, configuration settings and clock speed. I am not familiar with the micro your using, is there anything unusual about the ports?
The reason for the "C code" being mentioned was because of your post using "portb.0" which sure confused me.
my problem here is.
switch 1 press, led 1 on
switch 2 press, led 2 on
switch 2 press again, led 2 on (not toggle to off)
switch 2 press again remain the same...
switch 1 press, led 1 off
switch 1 press, led 1 remain off
switch 2 press, led 2 off

the switch only functioning after back from another switch....

on my 18f4550

how about your?

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Port Pin Toggle

Post by medelec35 »

Hi asbase,
I have attached a Flowchart which should allow more switches to be added if necessary.
There are other ways of doing this, If you want an alternative then let me know.

Martin
Attachments
Swith Toggle1a .fcf
(10 KiB) Downloaded 314 times
Martin

Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Re: Port Pin Toggle

Post by Kenrix2 »

Hello again asbase,
When I said your program works "just like" in simulation, I really meant "exactly". Your text description of how it operates does not match how it simulates or how it works in hardware. Nothing is supposed to happen when the switch is pressed, only on release. So I can only conclude your using toggle type switches that are installed upside down or your using momentary switches that are normally pulled high instead of low. Perhaps you could attach a schematic so we see where the problem is. I hope you try medelec35's solution (thank you for sharing that medelec35) since it seems to be what your really after. The problem with working with microcontrollers is that they do exactly what you tell them to do. The trick is to get them to do what you want them to do. Good luck with your project.

Post Reply