Port Pin Toggle
Moderator: Benj
-
- Posts: 20
- Joined: Sun Jun 03, 2012 12:53 pm
- Location: Malaysia
- Has thanked: 13 times
- Contact:
Port Pin Toggle
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.
While 1
portb.0=!portb.0
delay 100ms
end while
portb.0 connect to led.
flowcode simulator work but real hardware fail.
Thanks.
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
Re: PORT PIN TOGGLE
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
― C.S. Lewis
-
- Flowcode v5 User
- Posts: 211
- Joined: Tue Feb 19, 2013 9:51 pm
- Has thanked: 72 times
- Been thanked: 177 times
Re: Port Pin Toggle
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 374 times
-
- Posts: 438
- Joined: Mon Aug 29, 2011 12:26 am
- Location: arizona
- Has thanked: 175 times
- Been thanked: 173 times
Re: Port Pin Toggle
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
}
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
}
-
- Posts: 20
- Joined: Sun Jun 03, 2012 12:53 pm
- Location: Malaysia
- Has thanked: 13 times
- Contact:
Re: Port Pin Toggle
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.
Thanks.
- Attachments
-
- Flowcode1.fcf
- (10.5 KiB) Downloaded 357 times
-
- Posts: 20
- Joined: Sun Jun 03, 2012 12:53 pm
- Location: Malaysia
- Has thanked: 13 times
- Contact:
Re: Port Pin Toggle
Can we just do it without C in simple way?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
}
-
- Posts: 438
- Joined: Mon Aug 29, 2011 12:26 am
- Location: arizona
- Has thanked: 175 times
- Been thanked: 173 times
Re: Port Pin Toggle
yes, sorry about that, i thought that was what you were going after, i noticed the mikroc coding,Can we just do it without C in simple way?
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;
Code: Select all
#define togglebit(port,bit) port^=(1<<bit)
Code: Select all
togglebit(latb,0);
-
- Flowcode v5 User
- Posts: 211
- Joined: Tue Feb 19, 2013 9:51 pm
- Has thanked: 72 times
- Been thanked: 177 times
Re: Port Pin Toggle
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.
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.
-
- Posts: 20
- Joined: Sun Jun 03, 2012 12:53 pm
- Location: Malaysia
- Has thanked: 13 times
- Contact:
Re: Port Pin Toggle
my problem here is.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.
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?
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Port Pin Toggle
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
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 367 times
Martin
-
- Flowcode v5 User
- Posts: 211
- Joined: Tue Feb 19, 2013 9:51 pm
- Has thanked: 72 times
- Been thanked: 177 times
Re: Port Pin Toggle
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.
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.