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

Using Array of bits with struct

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



Joined: 09 Feb 2005
Posts: 48

View user's profile Send private message

Using Array of bits with struct
PostPosted: Wed May 09, 2018 6:12 am     Reply with quote

In CCS C web page, there is a explanation like that:
Quote:
Bit Arrays
You can create an array of bits (or booleans). You cannot create a pointer to an array of bits or to a bit.


However, I am using compiler version 5.076. My code is simplified at below.
Program output is always NOT. Why? Is there any restriction using of bits array in struct?
Code:

struct x
{
  short arraybits [200];
} K;

While(True) {

K.arraybits[3]=True;
if (K.arraybits[3]==True) {
   printf(lcd_putc,"OK");
else
  printf(lcd_putc,"NOT");

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 09, 2018 8:13 am     Reply with quote

I ran the following program in vs. 5.078 in MPLAB vs. 8.92 simulator
and it works. It displayed this in the Output window:
Quote:
OK

Test program:
Code:
#include <18F46K22.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOPBADEN
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

//======================================
void main()
{                                                                     
struct x
{
short arraybits [200];
}K;


K.arraybits[3]=True;

if(K.arraybits[3]==True)
   printf("OK");
else
   printf("NOT");
 

while(TRUE);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Wed May 09, 2018 9:05 am     Reply with quote

Two things:

First as written the code could work if the RAM location just happened to be 'TRUE' at boot. Therefore I've amended it with:
Code:

#include <18F46K22.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOPBADEN
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

//======================================
void main()
{                                                                     
struct x
{
short arraybits [200];
}K;


K.arraybits[3]=True;

if(K.arraybits[3]==True)
{
   printf("OK");
   K.Arraybits[3]=FALSE;
   if(K.arraybits[3]==FALSE)
   {
      printf("OK");
   }

else
   printf("NOT");
 

while(TRUE);
}

This correctly displays 'OKOK' with the current compiler. Verifying that the code both sets and clears the bit.

However I then 'went back in time', and realised a critical difference. Going back to 5.049, I had to add the 'NOXINST' fuse. The older compiler was not setting this by default, and it makes the code go really screwy!...
sraiderk



Joined: 09 Feb 2005
Posts: 48

View user's profile Send private message

PostPosted: Thu May 10, 2018 1:31 am     Reply with quote

Thank you for all reply.

I tried the Ttelmah's code with pic18f27k40 and ccs c version 5.076. There is no problem. I mean that I saw "OKOK" output on LCD. So, I will check my orginal code to find reason why problem occuring. Because, it's really big code. Thanks...
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