30.10.2014 Views

o_195h4n6al16jb186b1b2qs7fgssa.pdf

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

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

transmitted into the transmit buffer.<br />

Once the transmit buffer is full, it waits till the data gets transmitted and<br />

then writes the next data into the Transmit register.<br />

The control remains in this functionif SPI module isdisabled while<br />

SPITBF bit is set.<br />

Source File: putsSPI1.c<br />

putsSPI2.c<br />

Code Example: putsSPI1(10,Txdata_loc);<br />

getsSPI1<br />

getsSPI2<br />

Description: This function reads a string of data of specified length and stores it<br />

into<br />

the location specified.<br />

Include: spi.h<br />

Prototype: unsigned int getsSPI1(<br />

unsigned int length,<br />

unsigned int *rdptr,<br />

unsigned int spi_data_wait);<br />

unsigned int getsSPI2(<br />

unsigned int length,<br />

unsigned int *rdptr,<br />

unsigned int spi_data_wait);<br />

Arguments: length This is the length of the string to be received.<br />

rdptr This is the pointer to the location where the data<br />

received have to be stored.<br />

spi_data_wait This is the timeout count for which the module<br />

has to wait before return.<br />

If the timeout count is ‘N’, the actual timeout<br />

would be about (19*N - 1) instruction cycles.<br />

Return Value: This function returns the number of bytes yet to be received.<br />

If the return value is a ‘0’, it indicates that the complete string has been<br />

received.<br />

If the return value is a nonzero, it indicates thatthe complete string has<br />

not been received.<br />

Remarks: None<br />

Source File: getsSPI1.c<br />

getsSPI2.c<br />

Code Example: Datarem = getsSPI1(6, Rxdata_loc, 40);<br />

dsPIC Peripheral Libraries<br />

TMR1 = 0;<br />

thời gian chờ = 0;<br />

TRISDbits.TRISD0 = 0;<br />

/ * Cấu hình SPI2 ngắt * /<br />

ConfigIntSPI2 (SPI_INT_EN & SPI_INT_PRI_6);<br />

/ * Cấu hình spi1 mô-đun totransmit giá trị timer1 16 bit<br />

trong chế độ thạc sĩ * /<br />

SPICONValue = FRAME_ENABLE_OFF & FRAME_SYNC_OUTPUT &<br />

ENABLE_SDO_PIN & SPI_MODE16_ON &<br />

SPI_SMP_ON & SPI_CKE_OFF &<br />

SLAVE_SELECT_ENABLE_OFF &<br />

CLK_POL_ACTIVE_HIGH &<br />

MASTER_ENABLE_ON &<br />

SEC_PRESCAL_7_1 &<br />

PRI_PRESCAL_64_1;<br />

SPISTATValue = SPI_ENABLE & SPI_IDLE_CON &<br />

SPI_RX_OVFLOW_CLR;<br />

OpenSPI1 (SPICONValue, SPISTATValue);<br />

dsPIC Thư viện ngoại vi<br />

2004 Microchip Technology Inc DS51456B trang 165<br />

/ * Cấu hình SPI2 mô-đun để nhận được giá trị bộ đếm thời gian 16 bit<br />

chế độ nô lệ * /<br />

SPICONValue = FRAME_ENABLE_OFF & FRAME_SYNC_OUTPUT &<br />

ENABLE_SDO_PIN & SPI_MODE16_ON &<br />

SPI_SMP_OFF & SPI_CKE_OFF &<br />

SLAVE_SELECT_ENABLE_OFF &<br />

CLK_POL_ACTIVE_HIGH &<br />

MASTER_ENABLE_OFF &<br />

SEC_PRESCAL_7_1 &<br />

PRI_PRESCAL_64_1;<br />

SPISTATValue = SPI_ENABLE & SPI_IDLE_CON &<br />

PI_RX_OVFLOW_CLR;<br />

OpenSPI2 (SPICONValue, SPISTATValue);<br />

T1CON = 0x8000;<br />

trong khi (thời gian chờ

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

Saved successfully!

Ooh no, something went wrong!