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

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

Port Pin Toggle

Postby asbase » Sat Sep 21, 2013 3:29 pm

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: 1905
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 550 times
Been thanked: 1064 times
Contact:

Re: PORT PIN TOGGLE

Postby kersing » Sat Sep 21, 2013 5:13 pm

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

Postby Kenrix2 » Sun Sep 22, 2013 10:26 am

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 162 times
These users thanked the author Kenrix2 for the post:
asbase (Mon Sep 23, 2013 3:58 am)
Rating: 5%
 

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

Postby brandonb » Sun Sep 22, 2013 1:15 pm

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

Postby asbase » Mon Sep 23, 2013 4:10 am

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 139 times

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

Re: Port Pin Toggle

Postby asbase » Mon Sep 23, 2013 4:12 am

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

Postby brandonb » Mon Sep 23, 2013 6:04 am

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

Postby Kenrix2 » Mon Sep 23, 2013 8:23 am

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

Postby asbase » Wed Sep 25, 2013 2:06 pm

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?

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8601
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2474 times
Been thanked: 3558 times
Contact:

Re: Port Pin Toggle

Postby medelec35 » Wed Sep 25, 2013 2:53 pm

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 146 times
These users thanked the author medelec35 for the post (total 2):
Kenrix2 (Wed Sep 25, 2013 11:30 pm) • asbase (Thu Sep 26, 2013 1:25 am)
Rating: 10%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

Postby Kenrix2 » Wed Sep 25, 2013 11:30 pm

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.
These users thanked the author Kenrix2 for the post (total 2):
asbase (Thu Sep 26, 2013 1:25 am) • medelec35 (Fri Sep 27, 2013 7:35 am)
Rating: 10%