#### File: D:\bobes\0 skola\_car4\my matlab\HIL - PID speed\firmware\Vejlupek_Car4_HIL_PIDSpeed_dspic\sources\dsPIC_Multiplexed_out_UART2.c
        1   #include "p33fxxxx.h"
        2   #include <uart.h>
        3   #include "Vejlupek_Car4_HIL_PIDSpeed.h"
        4   #include "Vejlupek_Car4_HIL_PIDSpeed_private.h"
        5
        6   uint8_T send232Buff_Uart2(int16_T valeur, uint8_T cannal)
        7   {                                      /*  0U -- 63U */
        8     uint8_T Tmp;
        9     uint8_T Tmp2;
       10     Tmp = ~(TxPtrHaut_Uart2 - TxPtrBas_Uart2);/* Tmp = 7 - (Haut - Bas) modulo 32	*/
       11     Tmp = Tmp & (Tx_BUFF_SIZE_Uart2-1);
       12     Tmp2 = (cannal & 0x03)+2;            /*	 Nbr bits a envoye */
       13     if (Tmp >= Tmp2) {                   /*  Si on a la place ds le buffer d'envoye */
       14       TxTab_Uart2[TxPtrHaut_Uart2] = ((cannal << 2) & 0xFC) | 1;
       15
       16       /* envoie 6 derniers bits du canal et bit 1=0 ; bit 0=1 */
       17       /* signature octet controle en poids faible	*/
       18       TxPtrHaut_Uart2 = (TxPtrHaut_Uart2 + 1) & (Tx_BUFF_SIZE_Uart2-1);
       19       for (Tmp=1; Tmp < Tmp2 ; Tmp++) {
       20         TxTab_Uart2[TxPtrHaut_Uart2] = valeur & 0xFF;
       21         valeur = valeur >> 8;
       22         TxPtrHaut_Uart2 = (TxPtrHaut_Uart2 + 1) & (Tx_BUFF_SIZE_Uart2-1);
       23       }
       24
       25       Tmp = 0;                           /* bufferisation reussit	*/
       26       _U2TXIF = 1;
       27       _U2TXIE = 1;
       28     } else
       29       Tmp = 1;
       30     return Tmp;
       31   }