View previous topic :: View next topic |
Author |
Message |
nailuy
Joined: 21 Sep 2010 Posts: 159
|
parallel output |
Posted: Sun Jan 19, 2014 1:37 am |
|
|
Hy guys, I have misunderstanding:
I fount on net this operator !! (two bonded logical negation) what is mean?
also my question is:
How to put variable value on parallel output?
Code: |
int8 var=15;
output_bit(PIN_B0, (var & 1));
output_bit(PIN_B1, (var & 2));
output_bit(PIN_B2, (var & 4));
output_bit(PIN_B3, (var & 8));
output_bit(PIN_B4, (var & 16));
output_bit(PIN_B5, (var & 32));
output_bit(PIN_B6, (var & 64));
output_bit(PIN_B7, (var & 128));
|
on the output instead of:
B7 B6 B5 B4 B3 B2 B1 B0
0 0 0 0 1 1 1 1
(00001111)
I have :
B7 B6 B5 B4 B3 B2 B1 B0
0 0 0 0 0 0 0 0
(00000000)
Best regards. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19551
|
|
Posted: Sun Jan 19, 2014 2:46 am |
|
|
Simply use output_b(var);
Can't get much simpler.....
The bit output, would work, but be much slower, but do a search here for the RMW problem (search here for this term). This depends on what is actually connected to your output pins.
As a comment though is var & 2 (for example), ever going to be '1' (the value required by the output_bit function?. This relates to your !! question....
Double negation, is sometimes used as a way of converting a numeric value to a logical (0/1) value. Negation in C, returns TRUE depending on a value being zero. Negate again, and you have TRUE when a value is non zero. Generally !=0, is easier to understand, and gives the same truth table.
Best Wishes |
|
|
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Sun Jan 19, 2014 3:22 pm |
|
|
Thanks Ttelmah.
But if I want to use:
B7 C2 A5 B6 B1 C3 B0 C0
0 0 0 0 1 1 1 1
and:
RMW problem I try to search and nothing to find.
Do yu have title for that post?
I try:
output_bit(PIN_B0, !!(var & 1));
output_bit(PIN_B1, !!(var & 2));
output_bit(PIN_B2, !!(var & 4));
output_bit(PIN_B3, !!(var & 8));
output_bit(PIN_B4, !!(var & 16));
output_bit(PIN_B5, !!(var & 32));
output_bit(PIN_B6, !!(var & 64));
output_bit(PIN_B7, !!(var & 128));
and again not working.
I'm beginner and some signs I'm not understandings.
Best regards . |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 19, 2014 3:30 pm |
|
|
Post a complete, compilable test program. That means, post the #include
for the PIC, #fuses, #use delay(), and #defines, variable declarations,
and main(). Also post your compiler version.
Then we can see what you are doing and maybe offer help. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19551
|
|
Posted: Sun Jan 19, 2014 3:30 pm |
|
|
A search for RMW, finds dozens of posts about this.
<http://www.ccsinfo.com/forum/viewtopic.php?t=42268&highlight=rmw>
Is a good start since it points to a number of others. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19551
|
|
Posted: Mon Jan 20, 2014 5:23 am |
|
|
Lets add something here.
The code you've posted now, _will_ work, unless you have another problem. RMW, is the most likely, however could be something 'silly' to do with your code or hardware.
Though it'll work, there is a more elegant way of doing this using a CCS function:
output_bit(PIN_B0, bit_test(var,0));
etc..
Used with a constant, the compiler codes 'bit_test', to use the single instruction 'BTFSC' (bit test in F, skip if clear). Saves two instructions on each output.
So start at the beginning. Have you proved that you can do something much simpler (toggling a single pin), and your processor is running, and at the correct speed.
If it still fails, simplify. Just the fuses, and a simple program to output a pattern on the port. If this doesn't work, post it. Should be no longer than perhaps 20 lines.
That you have nothing, suggests you have something fundamentally 'wrong'. |
|
|
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Mon Jan 20, 2014 3:52 pm |
|
|
Thank you again Ttelmah
now I make mini test program:
Compiler is : PCWHD 4.140
Code: | #include <16F76_test3.h>
void main()
{
var=15;
output_bit(PIN_B0, (var,0));
output_bit(PIN_B1, (var,1));
output_bit(PIN_B2, (var,2));
output_bit(PIN_B3, (var,3));
output_bit(PIN_B4, (var,4));
output_bit(PIN_B5, (var,5));
output_bit(PIN_C6, (var,6));
output_bit(PIN_C7, (var,7));
output_low (PIN_A5);
output_low(PIN_C3);
while(TRUE)
{
//TODO: User Code
}
} |
and in the header file is:
Code: | #include <16F76.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOBROWNOUT //No brownout reset
#use delay(clock=20000000)
int8 var=0; |
How can I solve now? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19551
|
|
Posted: Tue Jan 21, 2014 2:01 am |
|
|
Start by actually putting the bit_test instructions....
But simple questions:
Have you verified the chip is running at all?. Has it got a 20Mhz crystal on the OSC1/OSC2 pins?. Is MCLR pulled up?. |
|
|
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Tue Jan 21, 2014 3:30 pm |
|
|
Yes
MCLR I have 4.6V
And frequency is 4Mhz so I changed.
Problem still persist.
What I can do next? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19551
|
|
Posted: Tue Jan 21, 2014 4:05 pm |
|
|
As I said, start by putting the bit test instructions.
Look what I posted, and what you have done. They are radically different.... |
|
|
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Tue Jan 21, 2014 4:18 pm |
|
|
What do you mean on Bit test instruction.
you want to put .LST file?
I read your post from up but I'm not understanding.
you want to put only this command :
Code: | output_bit(PIN_B0, bit_test(var,0)); |
and disable all other line? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jan 21, 2014 4:50 pm |
|
|
He means that you left out all the bit_test function names in your first
posted code. He means put the bit_test function name into your code,
as you did below (in bold):
Quote: | output_bit(PIN_B0, bit_test(var,0)); |
|
|
|
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Wed Jan 22, 2014 11:57 am |
|
|
"bit_test" is function in help mode I understand what is doing.
now I tested this:
Code: |
#include <16F76_test3.h>
void main()
{
var=15;
output_bit(PIN_B0, bit_test(var,7));
output_low (PIN_A5);
output_low(PIN_C3);
while(TRUE)
{
//TODO: User Code
}
}
|
and results are for B0 output LO.
and this
Code: |
#include <16F76_test3.h>
void main()
{
var=15;
output_bit(PIN_B0, bit_test(var,0));
output_low (PIN_A5);
output_low(PIN_C3);
while(TRUE)
{
//TODO: User Code
}
}
|
and results are for B0 output LO.
Thank you.
What I do next to find where is the problem?
Best regards. |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Wed Jan 22, 2014 12:09 pm |
|
|
As asked, have you verified that your processor are indeed running by using the blink LED test.
Regards |
|
|
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Wed Jan 22, 2014 12:34 pm |
|
|
Quote: | As asked, have you verified that your processor are indeed running by using the blink LED test.
Regards |
As you see in code I have 2 separate output:
output_low (PIN_A5);
output_low(PIN_C3);
and both 2 leds are working.
so hardware is okay, MCLR is the same.
I try to see with my scope and
output LO from B0 is more fast LO that A5.
With My scope LECROY WaveSurfer 64MXs-B time between this is aprox 2us.
So code is read right.
PS
CASE SOLVED.
Best regards. |
|
|
|