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

output(x & 0xF0) destroys the whole direction pin config

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



Joined: 23 Jun 2014
Posts: 10

View user's profile Send private message

output(x & 0xF0) destroys the whole direction pin config
PostPosted: Sun Aug 07, 2016 7:53 am     Reply with quote

As display routine, I have the following code:

Code:


byte const LEDPortB[12] = {
 0b11110000,
 0b10000000,
 0b11010000,
 0b11000000,
 0b10100000,
 0b01100000,
 0b01110000,
 0b11100000,
 0b11110000,
 0b11100000,
 0b00000000
 };


byte const LEDPortC[12] = {
 0b01010000,
 0b01000000,
 0b10010000,
 0b11010000,
 0b11000000,
 0b11010000,
 0b11010000,
 0b01000000,
 0b11010000,
 0b11010000,
 0b00000000
 };



void Display(int16 Column3value,int16 Column2Value,int16 Column1Value)
{
                           output_high(LED1);
                           output_b(LEDPortB[11] & 0xF0);
                           output_c(LEDPortC[11] & 0xF0);
                           output_b(LEDPortB[Column1value] & 0xF0);
                           output_c(LEDPortC[Column1value] & 0xF0);
                           output_low(LED1);
         
                           output_high(LED2);
                           output_b(LEDPortB[11] & 0xF0);
                           output_c(LEDPortC[11] & 0xF0);
                           output_b(LEDPortB[Column3value] & 0xF0);
                           output_c(LEDPortC[Column3value] & 0xF0);
                           output_low(LED2);
         
                           output_high(LED3);
                           output_b(LEDPortB[11] & 0xF0);
                           output_c(LEDPortC[11] & 0xF0);
                           output_b(LEDPortB[Column2value] & 0xF0);
                           output_c(LEDPortC[Column2value] & 0xF0);
                           output_low(LED3); ;
 }


setup_ccp1(CCP_PWM_HALF_BRIDGE | CCP_PWM_H_H);



As seen from the code I plan to use the C5,C6,C7,C8 as the output to 7segment. I have defined a PWM on C2 as output. I want to use the C0 as input port, but the above code automatically assigns all ports of C as output and as expected I can not use the C0 as input.

I thought if I write
Code:
output_c(LEDPortC[Column2value] & 0xF0);

The compiler should address only the high 4 bits and do not touch the lower ones. It is true that above command filters the above bits and send it to port C, BUT it assigns the whole C as output?, How can I assign the C0 as input in this manner?

I must find a similar command such as output_c() that partially modifies the port so that i can use my lookup table.

thanks in advance.
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Aug 07, 2016 10:45 am     Reply with quote

Basic PIC101...
you need to read the datasheet and the ccs manual, esp. the sections on PORTS. Especially how to use TRIS, fast_IO, and standard I/O.

Since you don't present you complete program we have no idea if you are using std or fast I/O. There's probably 100+ examples and threads about this on the site....

more reading is required.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Sun Aug 07, 2016 11:59 am     Reply with quote

As a comment, think about it. A '0' is just as much an output value, as a '1'. Just because you & the byte to be sent, with 0xF0, doesn't change it from being a byte. You are sending a whole byte out portD, just with the bottom 4 bits all set to zero....

Fast_io, is the normal way to do what you want, or do direct I/O, to the port latch.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Aug 07, 2016 12:56 pm     Reply with quote

Also look in the July 2016 edition of the CCS manual in the
"General Purpose I/O" section on pages 68 and 69 in the
Acrobat reader (numbered pages 56 and 57):
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
rxpu99



Joined: 23 Jun 2014
Posts: 10

View user's profile Send private message

PostPosted: Tue Aug 09, 2016 5:24 am     Reply with quote

Thank all of you for the tips. I found a solution with the command output_bit(port,bool value).

I changed my btye orşented output_port() to bit oriented output_bit(pin,value)

I select the bit using bitC7=((LEDPortC[Column1value] >> 7 ) & 1);

and send the bit to the output.

output_bit(PIN_C7,bitC7);

Is there a much simpler , shorter elegant way to do it?

Code:

void Display(int16 Column3value,int16 Column2Value,int16 Column1Value)
{
                           output_high(LED1);
                          output_b(LEDPortB[11] & 0xF0);
                          // output_c(LEDPortC[11] & 0xF0);
                          output_b(LEDPortB[Column1value] & 0xF0);
                           
                              bitC7=((LEDPortC[Column1value] >> 7 ) & 1);
                           bitC6=((LEDPortC[Column1value] >> 6 ) & 1);
                            bitC5=((LEDPortC[Column1value] >> 5 ) & 1);
                           bitC4=((LEDPortC[Column1value] >> 4) & 1);
                           
                           output_bit(PIN_C7,bitC7);
                            output_bit(PIN_C6,bitC6);
                             output_bit(PIN_C5,bitC5);
                              output_bit(PIN_C4,bitC4);
                             output_low(LED1);
         
                     
                           output_high(LED2);
                           output_b(LEDPortB[11] & 0xF0);
                           output_b(LEDPortB[Column3value] & 0xF0);
                           bitC7=((LEDPortC[Column3value] >> 7 ) & 1);
                           bitC6=((LEDPortC[Column3value] >> 6 ) & 1);
                           bitC5=((LEDPortC[Column3value] >> 5 ) & 1);
                           bitC4=((LEDPortC[Column3value] >> 4) & 1);
                           
                           output_bit(PIN_C7,bitC7);
                           output_bit(PIN_C6,bitC6);
                           output_bit(PIN_C5,bitC5);
                           output_bit(PIN_C4,bitC4);
                           output_low(LED2);
         
         
         
         
                          output_high(LED3);
                          output_b(LEDPortB[11] & 0xF0);
                          output_b(LEDPortB[Column2value] & 0xF0);
                          bitC7=((LEDPortC[Column2value] >> 7 ) & 1);
                          bitC6=((LEDPortC[Column2value] >> 6 ) & 1);
                          bitC5=((LEDPortC[Column2value] >> 5 ) & 1);
                          bitC4=((LEDPortC[Column2value] >> 4) & 1);
                           
                           output_bit(PIN_C7,bitC7);
                           output_bit(PIN_C6,bitC6);
                           output_bit(PIN_C5,bitC5);
                           output_bit(PIN_C4,bitC4);
                           
                           output_low(LED3); ;
 
 
 
 }

Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Tue Aug 09, 2016 7:28 am     Reply with quote

Depends whether any other bits are set as output in the port.

If so, then you have to use 'bit by bit'. or these pins will be changed. Understand the PIC itself only has bitwise or bytewise output instructions.

However the code can be a lot simpler/faster. Using rotations is silly.
Code:

//                             bitC7=((LEDPortC[Column1value] >> 7 ) & 1);
//                           bitC6=((LEDPortC[Column1value] >> 6 ) & 1);
//                            bitC5=((LEDPortC[Column1value] >> 5 ) & 1);
//                           bitC4=((LEDPortC[Column1value] >> 4) & 1);
             
                            output_bit(PIN_C7, Column1Value&0x80 !=0);
                            output_bit(PIN_C6, Column1Value&0x40 !=0);
                            output_bit(PIN_C5, Column1Value&0x20 !=0);
                            output_bit(PIN_C4, Column1Value&0x10 !=0);

Compare the code size, and the time needed for this.....

Then don't repeat all this, make it a function. So:
Code:

void nibble_to_port(int8 value)
{
   output_bit(PIN_C7, value&0x80 !=0);
   output_bit(PIN_C6, value&0x40 !=0);
   output_bit(PIN_C5, value&0x20 !=0);
   output_bit(PIN_C4, value&0x10 !=0);
}

void Display(int16 Column3value,int16 Column2Value,int16 Column1Value)
{
    output_high(LED1);

    output_b(LEDPortB[11] & 0xF0);
    //Puzzled by this, your very next instruction changes what is output
    //Are you sure this is wanted....
    output_b(LEDPortB[Column1value] & 0xF0);
    //This overrides the instruction before.....
    nibble_to_port(Column1Value);     
    output_low(LED1);           
etc...


There are lots of strange things though. You output Column3value, with LED2 selected, and Column2value with LED3. You put two successive values out port B in each part, without latching it or any delay. The second will override the first only a few uSec after it is output.
guy



Joined: 21 Oct 2005
Posts: 297

View user's profile Send private message Visit poster's website

PostPosted: Sun Aug 14, 2016 11:21 pm     Reply with quote

Instead of
Code:
void nibble_to_port(int8 value)
{
   output_bit(PIN_C7, value&0x80 !=0);
   output_bit(PIN_C6, value&0x40 !=0);
   output_bit(PIN_C5, value&0x20 !=0);
   output_bit(PIN_C4, value&0x10 !=0);
}


I would use
Code:
void nibble_to_port(int8 value)
{
   output_bit(PIN_C7, bit_test(value,7));
   output_bit(PIN_C6, bit_test(value,6));
   output_bit(PIN_C5, bit_test(value,5));
   output_bit(PIN_C4, bit_test(value,4));
}


I believe it is better optimized and definitely more readable and 'the CCS way' of doing things.
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