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.

Include: uart.h<br />

Prototype: void putsUART1(unsigned int *buffer);<br />

void putsUART2(unsigned int *buffer);<br />

Arguments: buffer This is the pointer to the string of data to be transmitted.<br />

Return Value: None<br />

Remarks: This function writes the data to be transmitted into the transmit buffer<br />

until NULL character is encountered.<br />

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

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

Source File: putsUART1.c<br />

putsUART2.c<br />

Code Example: putsUART1(Txdata_loc);<br />

dsPIC Peripheral Libraries<br />

2004 Microchip Technology Inc. DS51456B-page 147<br />

3.12.2 Individual Macros<br />

getcUART1<br />

getcUART2<br />

Description: This function is identical toReadUART1 and ReadUART2.<br />

Source File: #define to ReadUART1 and ReadUART2 in uart.h<br />

putcUART1<br />

putcUART2<br />

Description: This function is identical to WriteUART1 and WriteUART2.<br />

Source File: #define to WriteUART1 and WriteUART2 in uart.h<br />

EnableIntU1RX<br />

EnableIntU2RX<br />

Description: This macro enables the UART receive interrupt.<br />

Include: uart.h<br />

Arguments: None<br />

Remarks: This macro sets UART Receive Interrupt Enable bit of Interrupt<br />

Enable<br />

Control register.<br />

Code Example: EnableIntU2RX;<br />

EnableIntU1TX<br />

EnableIntU2TX<br />

Description: This macro enables the UART transmit interrupt.<br />

Include: uart.h<br />

Arguments: None<br />

Remarks: This macro sets UART Transmit Interrupt Enable bit of Interrupt<br />

Enable<br />

Control register.<br />

{<br />

(* (Receiveddata) ++) = ReadUART1 ();<br />

}<br />

}<br />

int main (void)<br />

{<br />

/ * Dữ liệu được truyền đi bằng cách sử dụng mô-đun giao tiếp UART * /<br />

Txdata char [] = {'M', 'i', 'c', 'r', 'o', 'c', 'h', 'i', 'p', '<br />

',' Tôi ',' C ',' D ',' 2 ',' \ 0 '};<br />

/ * Giữ giá trị đăng ký độ truyền * /<br />

int baudvalue;<br />

/ * Giữ giá trị của UART cấu hình reg * /<br />

int U1MODEvalue;<br />

/ * Giữ các thông tin liên quan đến UART<br />

TX & RX ngắt chế độ * /<br />

int U1STAvalue;<br />

/ * Tắt UART1module * /<br />

CloseUART1 ();<br />

/ * Cấu hình uart1 nhận và truyền gián đoạn * /<br />

ConfigIntUART1 (UART_RX_INT_EN & UART_RX_INT_PR6 &<br />

UART_TX_INT_DIS & UART_TX_INT_PR2);<br />

/ * Cấu hình UART1 mô-đun để truyền 8 bit dữ liệu với một stopbit.<br />

Ngoài ra Kích hoạt chế độ loopback * /<br />

baudvalue = 5;<br />

U1MODEvalue = UART_EN & UART_IDLE_CON &<br />

UART_DIS_WAKE & UART_EN_LOOPBACK &<br />

UART_EN_ABAUD & UART_NO_PAR_8BIT &<br />

UART_1STOPBIT;<br />

U1STAvalue = UART_INT_TX_BUF_EMPTY &<br />

UART_TX_PIN_NORMAL &<br />

UART_TX_ENABLE & UART_INT_RX_3_4_FUL &<br />

UART_ADR_DETECT_DIS &<br />

UART_RX_OVERRUN_CLEAR;<br />

OpenUART1 (U1MODEvalue, U1STAvalue, baudvalue);<br />

dsPIC<br />

®<br />

Thư viện Công cụ Ngôn ngữ<br />

DS51456B trang 150 2004 Microchip Technology Inc<br />

/ * Load truyền đệm và truyền đến vô cùng nhân vật là

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

Saved successfully!

Ooh no, something went wrong!