17.02.2015 Views

CCS C Compiler Manual PCB / PCM / PCH

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Common Questions & Answers<br />

}<br />

set_tris_b(ALL_IN);<br />

i = PORTB;<br />

// i now contains the portb value.<br />

Remember when using the #BYTE, the created variable is treated like memory. You must<br />

maintain the tri-state control registers yourself via the SET_TRIS_X function. Following is an<br />

example of placing a structure on an I/O port:<br />

struct port_b_layout<br />

{int data : 4;<br />

int rw : 1;<br />

int cd : 1;<br />

int enable : 1;<br />

int reset : 1; };<br />

struct port_b_layout port_b;<br />

#byte port_b = 6<br />

struct port_b_layout const INIT_1 = {0, 1,1, 1,1 };<br />

struct port_b_layout const INIT_2 = {3, 1,1, 1,0 };<br />

struct port_b_layout const INIT_3 = {0, 0,0, 0,0 };<br />

struct port_b_layout const FOR_SEND = {0,0,0, 0,0 };<br />

// All outputs<br />

struct port_b_layout const FOR_READ = {15,0,0, 0,0 };<br />

// Data is an input<br />

main() {<br />

int x;<br />

set_tris_b((int)FOR_SEND);<br />

port_b = INIT_1;<br />

delay_us(25);<br />

// The constant<br />

// structure is<br />

// treated like<br />

// a byte and<br />

// is used to<br />

// set the data<br />

// direction<br />

}<br />

port_b = INIT_2;<br />

port_b = INIT_3;<br />

set_tris_b((int)FOR_READ);<br />

port_b.rw=0;<br />

port_b.cd=1;<br />

port_b.enable=0;<br />

x = port_b.data;<br />

port_b.enable=0<br />

// These constant structures delay_us(25);<br />

// are used to set all fields<br />

// on the port with a single<br />

// command<br />

// Here the individual<br />

// fields are accessed<br />

// independently.<br />

How does the compiler determine TRUE and FALSE on<br />

expressions?<br />

When relational expressions are assigned to variables, the result is always 0 or 1.<br />

For example:<br />

bytevar = 5>0; //bytevar will be 1<br />

bytevar = 0>5; //bytevar will be 0<br />

The same is true when relational operators are used in expressions.<br />

359

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!