/** EUSART1 Generated Driver File @Company Microchip Technology Inc. @File Name eusart1.c @Summary This is the generated driver implementation file for the EUSART1 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs @Description This source file provides APIs for EUSART1. Generation Information : Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.65.2 Device : PIC18F25K50 Driver Version : 2.01 The generated drivers are tested against the following: Compiler : XC8 1.45 MPLAB : MPLAB X 4.15 */ /* (c) 2018 Microchip Technology Inc. and its subsidiaries. Subject to your compliance with these terms, you may use Microchip software and any derivatives exclusively with Microchip products. It is your responsibility to comply with third party license terms applicable to your use of third party software (including open source software) that may accompany Microchip software. THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. */ /** Section: Included Files */ #include "eusart1.h" /** Section: EUSART1 APIs */ void EUSART1_Initialize(void) { // Set the EUSART1 module to the options selected in the user interface. // ABDOVF no_overflow; CKTXP async_noninverted_sync_fallingedge; BRG16 16bit_generator; WUE disabled; ABDEN disabled; DTRXP not_inverted; BAUDCON1 = 0x08; // SPEN enabled; RX9 8-bit; CREN enabled; ADDEN disabled; SREN disabled; RCSTA1 = 0x90; // TX9 8-bit; TX9D 0; SENDB sync_break_complete; TXEN disabled; SYNC asynchronous; BRGH hi_speed; CSRC slave_mode; TXSTA1 = 0x04; // SPBRG1 103; 0x67 = 115200, 0x33 = 230400 (both 0.16% error) SPBRG1 = 0x33; //SPBRG1 = 0x67; // SPBRGH1 0; SPBRGH1 = 0x00; } bool EUSART1_is_tx_ready(void) { return (bool)(PIR1bits.TX1IF && TXSTA1bits.TXEN); } bool EUSART1_is_rx_ready(void) { return PIR1bits.RC1IF; } bool EUSART1_is_tx_done(void) { return TXSTA1bits.TRMT; } uint8_t EUSART1_Read(void) { while(!PIR1bits.RC1IF) { } if(1 == RCSTA1bits.OERR) { // EUSART1 error - restart RCSTA1bits.CREN = 0; RCSTA1bits.CREN = 1; } return RCREG1; } void EUSART1_Write(uint8_t txData) { while(0 == PIR1bits.TX1IF) { } TXREG1 = txData; // Write the data byte to the USART. } /** End of File */