CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

parallel output

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

parallel output
PostPosted: Sun Jan 19, 2014 1:37 am     Reply with quote

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: 19568

View user's profile Send private message

PostPosted: Sun Jan 19, 2014 2:46 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jan 19, 2014 3:22 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jan 19, 2014 3:30 pm     Reply with quote

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: 19568

View user's profile Send private message

PostPosted: Sun Jan 19, 2014 3:30 pm     Reply with quote

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: 19568

View user's profile Send private message

PostPosted: Mon Jan 20, 2014 5:23 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 20, 2014 3:52 pm     Reply with quote

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: 19568

View user's profile Send private message

PostPosted: Tue Jan 21, 2014 2:01 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jan 21, 2014 3:30 pm     Reply with quote

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: 19568

View user's profile Send private message

PostPosted: Tue Jan 21, 2014 4:05 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jan 21, 2014 4:18 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jan 21, 2014 4:50 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jan 22, 2014 11:57 am     Reply with quote

"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

View user's profile Send private message

PostPosted: Wed Jan 22, 2014 12:09 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jan 22, 2014 12:34 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group