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

16 bits mask

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



Joined: 11 Nov 2008
Posts: 3

View user's profile Send private message

16 bits mask
PostPosted: Tue Nov 11, 2008 11:52 am     Reply with quote

Hi. I'm trying to write a small application that is running 16 leds turning them on and off on a specific sequence. I made an array of 16bit values that is masked to reveal if a given led should be on or off.

Eg.:
Code:

int16 sequence[] = {
   0b0001000000000001,
   0b0000010000000011
};

int16 mask[] = {
   0b1000000000000000,
   0b0100000000000000,
   0b0010000000000000, ..... etc
}

Below is a function call repeated over and over. The ptr variable indicates the position in the sequence.

Code:
for (i=0; i<16; i++) // scan all 16 bits
{
    if ((sequence[ptr] & mask[i]) == mask[i])
    {
         ... code to turn led on ...
    }

    else { ... turn the led off ... }
}
ptr++;

Actually, this works on half of the leds (the 8 last ones) while the first 8 leds are constantly turned on.

I searched the forum and I can't find any example of masking 16bit values so I was wondering if it was possible or if there was a trick to get it to work properly.

Any help would be appreciated.
Thanks in advance
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Nov 11, 2008 1:33 pm     Reply with quote

I don't see anything wrong with your code. I would look at the .lst file and see what the assembly code for that section is doing. That usually tells me what I have done wrong in my C code.
_________________
The search for better is endless. Instead simply find very good and get the job done.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 11, 2008 1:59 pm     Reply with quote

If you can't make it work, post a small version of the program that
demonstrates the problem. It must be compilable without errors.
It must have the #include, #fuses, and #use delay() statements
and a main(). It must be short (50 lines max).

Post a description of the LED circuits, including component values
and part numbers (if relevant).

Post your compiler version.

Tell us if this code is being tested on actual hardware, or if it's a Proteus
simulation.
piko



Joined: 11 Nov 2008
Posts: 3

View user's profile Send private message

PostPosted: Tue Nov 11, 2008 11:44 pm     Reply with quote

Thanks guys. Actually I discovered that my problem was the PIC itself. I swapped to another chip (same model) and it was working fine...

I can't believe I wasted 1 hour on that while it was only a bugged pic Crying or Very sad

I will post my code when I'm done for the community to use.

Thanks again.
Ttelmah
Guest







PostPosted: Wed Nov 12, 2008 9:51 am     Reply with quote

As a separate comment, why not look at the inbuilt 'bit test' function, rather than using the mask?.

Best Wishes
piko



Joined: 11 Nov 2008
Posts: 3

View user's profile Send private message

PostPosted: Wed Nov 12, 2008 1:58 pm     Reply with quote

Quote:
why not look at the inbuilt 'bit test' function, rather than using the mask?.


I come from a foreing world where it is normal not to look at the documentation because you know 'C' doesn't offer what you want !

I never get used to all the bling blings that comes with CCS that is meant to ease my life so I do it the hard way Sad

Actually, only because I'm used to masks and the concept in my head involved one, I didn't look further. Your way would be nice as well. Thank you :D
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Nov 12, 2008 4:51 pm     Reply with quote

C at least offers a shift operator that also can do the job.
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