17.02.2015 Views

CCS C Compiler Manual PCB / PCM / PCH

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Functional Overview<br />

configure the second interface.<br />

spi_data_is_in()<br />

spi_data_is_in2()<br />

spi_write(value)<br />

spi_write2(value)<br />

spi_read(value)<br />

spi_read2(value)<br />

Returns TRUE if the SPI receive buffer has a byte of data.<br />

Transmits the value over the SPI interface. This will cause the<br />

data to be clocked out on the SDO pin.<br />

Performs an SPI transaction, where the value is clocked out on<br />

the SDO pin and data clocked in on the SDI pin is returned. If<br />

you just want to clock in data then you can use spi_read() without<br />

a parameter.<br />

Relevant Preprocessor:<br />

None<br />

Relevant Interrupts:<br />

#int_ssp<br />

#int_ssp2<br />

Transaction (read or write) has completed on the indicated<br />

peripheral.<br />

Relevant getenv() Parameters:<br />

SPI<br />

Returns TRUE if the device has an SPI peripheral<br />

Example Code:<br />

//configure the device to be a master, data transmitted on H-to-L clock transition<br />

setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16);<br />

spi_write(0x80);<br />

value=spi_read();<br />

value=spi_read(0x80);<br />

//write 0x80 to SPI device<br />

//read a value from the SPI device<br />

//write 0x80 to SPI device the same time you are reading a value.<br />

Timer0<br />

These options lets the user configure and use timer0. It is available on all devices and is always<br />

enabled. The clock/counter is 8-bit on pic16s and 8 or 16 bit on pic18s. It counts up and also<br />

provides interrupt on overflow. The options available differ and are listed in the device header<br />

file.<br />

Relevant Functions:<br />

setup_timer_0(mode)<br />

set_timer0(value) or<br />

set_rtcc(value)<br />

Sets the source, prescale etc for timer0<br />

Initializes the timer0 clock/counter. Value may be a 8 bit or 16<br />

bit depending on the device.<br />

69

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

Saved successfully!

Ooh no, something went wrong!