当前位置:首页 > 单片机 > 单片机
[导读]  At this moment, I accomplish the interface of UART communication for PIC32MZ EC Starter Kit. This interface configures the PIC32MZ for communication with a host PC at 115200 baud. There are five f

  At this moment, I accomplish the interface of UART communication for PIC32MZ EC Starter Kit. This interface configures the PIC32MZ for communication with a host PC at 115200 baud. There are five functions in the interface -- Uart_Init(), Uart_Getc(), Uart_Gets(), Uart_Putc() and Uart_Puts().

  Uart_Init() configures PIC32MZ UART1 with 115200-8-None-1. It uses PPS to select RPC13, RPC14 as TX and RX.

Uart_Getc() is a reception funtion for a character. It will be blocked until a character got.

  Uart_Gets() is a reception funtion for string. It will receive multiple characters until the 'r' 'n' or the buffer is full.

  Uart_Putc() is a transmit function for a character.

Uart_Puts() is a transmit funtion for string. It will transmit multiple character until ''.

  Below is the code.


voidUart_Init(void){LATCSET=0x6000;/*BothRC13andRC14HIGH*/TRISCSET=0x4000;/*RC14Input*/TRISCCLR=0x2000;/*RC13Output*/Seq_UnLock();RPC13Rbits.RPC13R=1;/*U1TXonRPC13*/U1RXRbits.U1RXR=7;/*U1RXonRPC14*/Seq_Lock();U1BRG=((PBCLK2_FREQUENCY/BAUDRATE)/16)-1;U1MODE=0x8000;//LoopbackmodeisenabledU1STA=0x1400;IFS3bits.U1RXIF=0;IFS3bits.U1TXIF=0;}charUart_Getc(void){if(U1STAbits.OERR){U1STAbits.OERR=0;return0;}while(!U1STAbits.URXDA);charret=U1RXREG;IFS3bits.U1RXIF=0;returnret;}voidUart_Gets(char*s){charc;intsize=0;if(s==(void*)0)return;while(size



本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭