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 support@ccsinfo.com

about #byte #bit and xxxx.bits

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



Joined: 24 Jun 2015
Posts: 2

View user's profile Send private message

about #byte #bit and xxxx.bits
PostPosted: Wed Jun 24, 2015 11:38 am     Reply with quote

hello,

i have a question, i can do:
Code:

#BYTE IFS0=0X0084

#BIT IEC0_AD1IE=0X0094.13


but could i do any word to write 3 bits for one register? for example, the register "IPC3bits.AD1IP" have 3 bits, would be the solution this?
Code:

#BIT IPC3_AD1IP0=0x00A4.4
#BIT IPC3_AD1IP1=0x00A4.5
#BIT IPC3_AD1IP2=0x00A4.6

ipc3_ad1ip0=0;      //IPC3bits.AD1IP=6
ipc3_ad1ip1=1;
ipc3_ad1ip2=1;

or is there any other solution to write directly "6" in ipc3.ad1ip register??

thanks in advance...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 24, 2015 11:50 am     Reply with quote

Yes, declare a structure with bitfields. Then write to the bitfields in your
code. The compiler will handle inserting the correct data into the bits.
Look at the .LST file to see this.
Code:

#include <16F690.h>
#fuses INTRC_IO,NOWDT
#use delay(clock=4M)

// This structure divides PortB into two bitfields.
struct {
int8 Columns:4;    // B0-3: Output pins
int8 Rows:4;       // B4-7: Input pins
}PortB;

#byte PortB = getenv("SFR:PORTB") 

//=========================
void main()

set_tris_b(0);

PortB.Columns = 6;
PortB.Rows = 3;


while(TRUE);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Wed Jun 24, 2015 12:06 pm     Reply with quote

There is another thing you can do, and a comment.

#byte creates a byte variable at a location if asked to. #word creates a 16bit word. To use bit 13, you should be using #word.

However #byte can also do something else. If given the name of an already declared variable, it can _locate_ this variable at the location. So you can declare a struct, using bit fields, like:
Code:

#struct
{
    int8 dummy:4; //bits 0 to 3
    int8 ip:3;
    int8 dummy2:1;
} ipc3bits ;

#byte ipc3bits=0xA4

You can then write to the variable ipc3bits.ip as a 3bit integer sitting at the required location in the register!....
brutto



Joined: 24 Jun 2015
Posts: 2

View user's profile Send private message

PostPosted: Sat Jun 27, 2015 2:53 am     Reply with quote

thanks guys, i will try with that
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