Very Basic application. With 12F615
PWM stopped working so I suspected actual chip.
Created a very basic test.
Surprisingly if use whole port = 1 or use port masking only Bit 0 works in simulation and in practice on real hardware.
However If I use separate port A bit 0, bit 1, and bit2 etc. then ports work as expected.
Why don’t all bits toggle every ½ second?
A simple flowchart, does not work as expected
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
A simple flowchart, does not work as expected
- Attachments
-
- 12F615 port test.fcf
- (4 KiB) Downloaded 268 times
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: A simple flowchart, does not work as expected
With entire port A set at 1, so all of port A should be at 5V (except GP3 which is input only) here is C code created by Flowcode:
//Output
//Output: 1 -> PORT A
trisio = 0x00;
gpio = 1;
That’s why only A0 only lights up
Also If I’m right about GP3, should Flowcode warn that GP3 is an I/P only pin.
Otherwise I would expect it to light LED on my chip since it does in the simulation.
//Output
//Output: 1 -> PORT A
trisio = 0x00;
gpio = 1;
That’s why only A0 only lights up
Also If I’m right about GP3, should Flowcode warn that GP3 is an I/P only pin.
Otherwise I would expect it to light LED on my chip since it does in the simulation.
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: A simple flowchart, does not work as expected
medelec35 wrote:
whole port .
Above code was automatically compiled by Flowcode, after port A output was set for ALL bits = 1
See attachment.
I would assume that if all bits of port A set to 1
Then Flowcode would light All LEDs and not just bit 0 LED
So question is why is only bit 0 set, when I ticked ENTIRE port A to be set for 1?
- Attachments
-
- port question.JPG (51.32 KiB) Viewed 5417 times
Martin
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Re: A simple flowchart, does not work as expected
The value "1" is 0b00000001 in binary and would only turn on output A0.
If the value was "2", this is 0b00000010 in binary and would only turn on output A1.
If the value was "3", this is 0b00000011 in binary and would turn on both A0 and A1.
If the value was "255", this is 0b11111111 in binary and would turn on all outputs on the port.
If the value was "2", this is 0b00000010 in binary and would only turn on output A1.
If the value was "3", this is 0b00000011 in binary and would turn on both A0 and A1.
If the value was "255", this is 0b11111111 in binary and would turn on all outputs on the port.
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: A simple flowchart, does not work as expected
So are you saying : If you tick Entire port and set for 1 as in the picture then only bit 0 will be set at 1. if thas the case why is there a option to have Entire port ticked. If I did not know any different, if i saw an option for Entire port , and put a 1 in the Variable or Value box, I would expect the whole port (bits 0-7) to be set at 5 V (unless its i/p only) Not just set bit 0 to 5V and bits 1-7 to 0V.
Aslo if I set bit 3 to a value of 1
then after a delay set Enitre port to a value of 0
then LED at bit 3 will will go out.
So in effect Entire port set to 1 = only bit 0 will be set at 1, all other bits (1 -7) set a 0 (this is what you are saying)?
then Entire port set to 0 = all bits witll be set at 0..... This does not make sence, surly its wrong, or am I missing somthing obvious?
Aslo if I set bit 3 to a value of 1
then after a delay set Enitre port to a value of 0
then LED at bit 3 will will go out.
So in effect Entire port set to 1 = only bit 0 will be set at 1, all other bits (1 -7) set a 0 (this is what you are saying)?
then Entire port set to 0 = all bits witll be set at 0..... This does not make sence, surly its wrong, or am I missing somthing obvious?
Martin
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Re: A simple flowchart, does not work as expected
A port on a PICmicro is 8-bit's wide. When outputting to an entire port, you are setting the output that should be present on the entire port - and the value you enter will be the value (ie. the bit-pattern) on the entire port.
If you want an entire port to be on, write 255 to the port.
If you want an entire port to be off, write 0 to the port.
If you want the top half of the port to be on and the lower half of the port to be off, write 0xF0 to the port.
"Entire port" means you are setting the output of the entire port at once. It does not mean you are setting every individual pin on that port to the same value.
If you want an entire port to be on, write 255 to the port.
If you want an entire port to be off, write 0 to the port.
If you want the top half of the port to be on and the lower half of the port to be off, write 0xF0 to the port.
"Entire port" means you are setting the output of the entire port at once. It does not mean you are setting every individual pin on that port to the same value.
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: A simple flowchart, does not work as expected
Ah I see. That explains it!
So that means also If i want certain bits on, all I need to do is set port at 255 Enable Entire port, then use masking, mask bits I would like to be set.
Simple when you know how.
So that means also If i want certain bits on, all I need to do is set port at 255 Enable Entire port, then use masking, mask bits I would like to be set.
Simple when you know how.

Martin
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Re: A simple flowchart, does not work as expected
Yes - you've got it!
And just for completeness, if you are using the "single bit" option, then you need to enter "0" for "off" and anything else for "on".
And just for completeness, if you are using the "single bit" option, then you need to enter "0" for "off" and anything else for "on".