Files
Scanning the repository...
Last update 2 months 3 days
by DenisAlaime
FilesProjet éco-shell3. ProgramationExemple_ScooterKICK_SCOOTERSource | |
---|---|
.. | |
Main.c | |
X2CScope.c | |
X2CScopeComm.c | |
init_dspic.c | |
uart1.c |
uart1.c/** UART1 Generated Driver File @Company Microchip Technology Inc. @File Name uart1.c @Summary This is the generated driver implementation file for the UART1 driver using PIC24 / dsPIC33 / PIC32MM MCUs @Description This header file provides implementations for driver APIs for UART1. Generation Information : Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - 1.170.0 Device : dsPIC33CK64MP105 The generated drivers are tested against the following: Compiler : XC16 v1.61 MPLAB : MPLAB X v5.45 */ /* (c) 2020 Microchip Technology Inc. and its subsidiaries. You may use this software and any derivatives exclusively with Microchip products. 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, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION. 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. MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE TERMS. */ /** Section: Included Files */ #include <xc.h> #include "uart1.h" #include "UserParms.h" /** Section: UART1 APIs */ #ifdef X2C_SCOPE void UART1_Initialize(void) { /** Set the UART1 module to the options selected in the user interface. Make sure to set LAT bit corresponding to TxPin as high before UART initialization */ // URXEN disabled; RXBIMD RXBKIF flag when Break makes low-to-high transition after being low for at least 23/11 bit periods; UARTEN enabled; MOD Asynchronous 8-bit UART; UTXBRK disabled; BRKOVR TX line driven by shifter; UTXEN disabled; USIDL disabled; WAKE disabled; ABAUD disabled; BRGH enabled; // Data Bits = 8; Parity = None; Stop Bits = 1 Stop bit sent, 1 checked at RX; U1MODE = (0x8080 & ~(1<<15)); // disabling UARTEN bit // STSEL 1 Stop bit sent, 1 checked at RX; BCLKMOD disabled; SLPEN disabled; FLO Off; BCLKSEL FOSC/2; C0EN disabled; RUNOVF disabled; UTXINV disabled; URXINV disabled; HALFDPLX disabled; U1MODEH = 0x00; // OERIE disabled; RXBKIF disabled; RXBKIE disabled; ABDOVF disabled; OERR disabled; TXCIE disabled; TXCIF disabled; FERIE disabled; TXMTIE disabled; ABDOVE disabled; CERIE disabled; CERIF disabled; PERIE disabled; U1STA = 0x00; // URXISEL RX_ONE_WORD; UTXBE enabled; UTXISEL TX_BUF_EMPTY; URXBE enabled; STPMD disabled; TXWRE disabled; U1STAH = 0x22; // BaudRate = 115200; Frequency = 100000000 Hz; BRG 216; U1BRG = 0xD8; // BRG 0; U1BRGH = 0x00; // P1 0; U1P1 = 0x00; // P2 0; U1P2 = 0x00; // P3 0; U1P3 = 0x00; // P3H 0; U1P3H = 0x00; // TXCHK 0; U1TXCHK = 0x00; // RXCHK 0; U1RXCHK = 0x00; // T0PD 1 ETU; PTRCL disabled; TXRPT Retransmit the error byte once; CONV Direct logic; U1SCCON = 0x00; // TXRPTIF disabled; TXRPTIE disabled; WTCIF disabled; WTCIE disabled; BTCIE disabled; BTCIF disabled; GTCIF disabled; GTCIE disabled; RXRPTIE disabled; RXRPTIF disabled; U1SCINT = 0x00; // ABDIF disabled; WUIF disabled; ABDIE disabled; U1INT = 0x00; U1MODEbits.UARTEN = 1; // enabling UART ON bit U1MODEbits.UTXEN = 1; U1MODEbits.URXEN = 1; } uint8_t UART1_Read(void) { while((U1STAHbits.URXBE == 1)) { } if ((U1STAbits.OERR == 1)) { U1STAbits.OERR = 0; } return U1RXREG; } void UART1_Write(uint8_t txData) { while(U1STAHbits.UTXBF == 1) { } U1TXREG = txData; // Write the data byte to the USART. } bool UART1_IsRxReady(void) { return (U1STAHbits.URXBE == 0); } bool UART1_IsTxReady(void) { return ((!U1STAHbits.UTXBF) && U1MODEbits.UTXEN ); } bool UART1_IsTxDone(void) { return U1STAbits.TRMT; } /******************************************************************************* !!! Deprecated API !!! !!! These functions will not be supported in future releases !!! *******************************************************************************/ uint32_t __attribute__((deprecated)) UART1_StatusGet (void) { uint32_t statusReg = U1STAH; return ((statusReg << 16 ) | U1STA); } void __attribute__((deprecated)) UART1_Enable(void) { U1MODEbits.UARTEN = 1; U1MODEbits.UTXEN = 1; U1MODEbits.URXEN = 1; } void __attribute__((deprecated)) UART1_Disable(void) { U1MODEbits.UARTEN = 0; U1MODEbits.UTXEN = 0; U1MODEbits.URXEN = 0; } #endif