Dmitry Kovalev / Mbed 2 deprecated LGstaandart

Dependencies:   mbed

Fork of LG2 by Dmitry Kovalev

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers uart_m.c Source File

uart_m.c

00001 /****************************************Copyright (c)****************************************************
00002 **                                 http://www.PowerAVR.com
00003 **                                 http://www.PowerMCU.com
00004 **--------------File Info---------------------------------------------------------------------------------
00005 ** File name:           uart.c
00006 ** Last modified Date:  2010-05-12
00007 ** Last Version:        V1.00
00008 ** Descriptions:        
00009 **
00010 **--------------------------------------------------------------------------------------------------------
00011 ** Created by:          PowerAVR
00012 ** Created date:        2010-05-10
00013 ** Version:             V1.00
00014 ** Descriptions:        
00015 **
00016 *--------------------------------------------------------------------------------------------------------      YJVTHF
00017 
00018 *********************************************************************************************************/
00019 
00020                            /* LPC17xx definitions    */
00021 #include "uart_m.h"
00022 #include "Global.h" 
00023 //555
00024 
00025 //#define FPCLK                      (100000000)                        //� pll  
00026 //#define FPCLK                      (12000000)                         //� pll  
00027 #define FOSC                        12000000                            /*  ������Ƶ��                  */
00028 #define FCCLK                      (FOSC  * 8)                          /*  ��ʱ��Ƶ��<=100Mhz          */
00029                                                                     /*  FOSC��������                */
00030 #define FCCO                       (FCCLK * 3)                          /*  PLLƵ��(275Mhz~550Mhz)      */
00031 
00032 //#define FPCLK                      (FCCLK / 4)                        //� pll  
00033 
00034 
00035 //#define FPCLK                   (100000000 / 4)                        //� pll  
00036 //#define FPCLK                   (100000000)                        //� pll  
00037   #define FPCLK                   (103200000)        
00038 //#define FPCLK                     (25000000)                        //� pll  
00039 
00040 
00041 
00042 
00043 int UART0_BPS =     9600 ;                                           /* ����0ͨ�Ų�����             */
00044 int UART1_BPS =     4800;                                               /* ����0ͨ�Ų�����             */
00045 int UART2_BPS =     9600 ;                                              /* ����0ͨ�Ų�����             */
00046 int UART3_BPS =     19200 ;                                             /* ����0ͨ�Ų�����             */
00047 
00048 #define   UART_LCR_ODD  0x0b
00049 #define   UART_LCR_EVEN  0x1b
00050 
00051 
00052 int UART_LCR   =  UART_LCR_EVEN   ;
00053 
00054 
00055 
00056 
00057 char InCon[1024];
00058 char OutCon[1024];
00059 
00060 unsigned int  ConInPnt = 0;
00061 unsigned int  ConInCur = 0;
00062 unsigned int  ConOutPnt = 0;
00063 unsigned int  ConOutCur = 0;
00064 
00065 
00066 char InCon1[1024];
00067 char OutCon1[1024];
00068 
00069 unsigned int  ConInPnt1 = 0;
00070 unsigned int  ConInCur1 = 0;
00071 unsigned int  ConOutPnt1 = 0;
00072 unsigned int  ConOutCur1 = 0;
00073 
00074 
00075 char InCon2[1024];
00076 char OutCon2[1024];
00077 
00078 unsigned int  ConInPnt2 = 0;
00079 unsigned int  ConInCur2 = 0;
00080 unsigned int  ConOutPnt2 = 0;
00081 unsigned int  ConOutCur2 = 0;
00082 
00083 char InCon3[1024];
00084 char OutCon3[1024];
00085 
00086 unsigned int  ConInPnt3 = 0;
00087 unsigned int  ConInCur3 = 0;
00088 unsigned int  ConOutPnt3 = 0;
00089 unsigned int  ConOutCur3 = 0;
00090 
00091 
00092 
00093 unsigned int InCon2M[16];
00094 unsigned int OutCon2M[16];
00095 
00096 unsigned int  ConInPnt2M = 0;
00097 unsigned int  ConInCur2M = 0;
00098 unsigned int  ConOutPnt2M = 0;
00099 unsigned int  ConOutCur2M = 0;
00100 
00101 unsigned int InCon3M[16];
00102 unsigned int OutCon3M[16];
00103 
00104 unsigned int  ConInPnt3M = 0;
00105 unsigned int  ConInCur3M = 0;
00106 unsigned int  ConOutPnt3M = 0;
00107 unsigned int  ConOutCur3M = 0;
00108 
00109 
00110 
00111 
00112 
00113 unsigned int    OutBufConCount = 0;
00114 unsigned int    OutBufCon1Count = 0;
00115 unsigned int    OutBufCon2Count = 0;
00116 unsigned int    OutBufCon3Count = 0;
00117 
00118 
00119 
00120 /*********************************************************************************************************
00121 ** Function name:       UART0_Init
00122 ** Descriptions:        ��Ĭ��ֵ��ʼ������0�����ź�ͨѶ����������Ϊ8λ����λ��1λֹͣλ������żУ��
00123 ** input parameters:    ��
00124 ** output parameters:   ��
00125 ** Returned value:      ��
00126 *********************************************************************************************************/
00127 void UART0_Init (void)
00128 {
00129     uint16_t usFdiv;
00130     LPC_PINCON->PINSEL0 |= (1 << 4);             /* Pin P0.2 used as TXD0 (Com0) */
00131     LPC_PINCON->PINSEL0 |= (1 << 6);             /* Pin P0.3 used as RXD0 (Com0) */
00132     LPC_UART0->LCR  = 0x83;                      /* ����������               */
00133 
00134  // LPC_UART0->FDR = 0x00000085; // c��  ��� LPC17xx-User-Manual_0[1].05 �� ���  311
00135                        //���������� �� 8 �������� �� 5 
00136 //      usFdiv = 4;
00137 
00138     usFdiv = (FPCLK / 16) / UART0_BPS;           /* ������                   */
00139     LPC_UART0->DLM  = usFdiv / 256;
00140     LPC_UART0->DLL  = usFdiv % 256; 
00141     LPC_UART0->LCR  = 0x03;                      /* ����������                   */
00142     LPC_UART0->FCR  = 0x07;
00143 }
00144 void UART1_Init_temp (void)
00145 {
00146     uint16_t usFdiv;
00147     LPC_PINCON->PINSEL4 |= (2 << 0);             /* Pin P2.0 used as TXD0 (Com0) */
00148     LPC_PINCON->PINSEL4 |= (2 << 2);             /* Pin P2.1 used as RXD0 (Com0) */
00149     LPC_UART1->LCR  = 0x83;                      /* ����������               */
00150     usFdiv = (FPCLK / 16) / UART1_BPS;           /* ������                   */
00151     LPC_UART1->DLM  = usFdiv / 256;
00152     LPC_UART1->DLL  = usFdiv % 256; 
00153     LPC_UART1->LCR  =  0x03;                      /* ����������                   */
00154     LPC_UART1->FCR  = 0x07;
00155 }
00156 
00157 void UART2_Init (void)
00158 {
00159     uint16_t usFdiv;
00160     LPC_PINCON->PINSEL0 |= (1 << 20);             /* Pin P0.10 used as TXD2 (Com2) */
00161     LPC_PINCON->PINSEL0 |= (1 << 22);             /* Pin P0.11 used as RXD2 (Com2) */
00162     LPC_SC->PCONP = LPC_SC->PCONP|(1<<24);        /*����UART2��Դ����λ            */
00163 
00164     LPC_UART2->LCR  = 0x83;                       /* ����������                */
00165     usFdiv = (FPCLK / 16) / 9600;                       /* ������                    */
00166     LPC_UART2->DLM  = usFdiv / 256;
00167     LPC_UART2->DLL  = usFdiv % 256; 
00168     LPC_UART2->LCR  = 0x03;                       /* ����������                    */
00169     LPC_UART2->FCR  = 0x07;
00170 }
00171 
00172 
00173 void UART3_Init (void)
00174 {
00175     uint16_t usFdiv;
00176     /* UART0 */
00177     LPC_PINCON->PINSEL1 |= (3 << 18);             /* Pin P0.25 used as TXD0 (Com0) */
00178     LPC_PINCON->PINSEL1 |= (3 << 20);             /* Pin P0.26 used as RXD0 (Com0) */
00179         LPC_SC->PCONP = LPC_SC->PCONP|(1<<25);        /*����UART2��Դ����λ            */  
00180 
00181     LPC_UART3->LCR  = 0x83;                      /* ����������               */
00182     usFdiv = (FPCLK / 16) / UART3_BPS;           /* ������                   */
00183     LPC_UART3->DLM  = usFdiv / 256;
00184     LPC_UART3->DLL  = usFdiv % 256; 
00185     LPC_UART3->LCR  =   UART_LCR; 
00186     LPC_UART3->FCR  = 0x07;
00187 }
00188 
00189 void UART2_InitSet (unsigned int speed, unsigned int SetLsr)
00190 {
00191     uint16_t usFdiv;
00192 
00193     LPC_PINCON->PINSEL0 |= (1 << 20);             /* Pin P0.10 used as TXD2 (Com2) */
00194     LPC_PINCON->PINSEL0 |= (1 << 22);             /* Pin P0.11 used as RXD2 (Com2) */
00195 
00196     LPC_SC->PCONP = LPC_SC->PCONP|(1<<24);        /*����UART2��Դ����λ            */
00197 
00198     LPC_UART2->LCR  = 0x83;                       /* ����������                */
00199     usFdiv = (FPCLK / 16) / speed;                      /* ������                    */
00200     LPC_UART2->DLM  = usFdiv / 256;
00201     LPC_UART2->DLL  = usFdiv % 256; 
00202     LPC_UART2->LCR  = SetLsr;                       /* ����������                    */
00203     LPC_UART2->FCR  = 0x07;
00204 
00205 }
00206 
00207 
00208 void UART3_InitSet (unsigned int speed, unsigned int SetLsr)
00209 {
00210         uint16_t usFdiv;
00211     /* UART0 */
00212     LPC_PINCON->PINSEL1 |= (3 << 18);                   /* Pin P0.25 used as TXD0 (Com0) */
00213     LPC_PINCON->PINSEL1 |= (3 << 20);                   /* Pin P0.26 used as RXD0 (Com0) */
00214   
00215     LPC_SC->PCONP =         LPC_SC->PCONP|(1<<25);        /*����UART2��Դ����λ            */  
00216     LPC_UART3->LCR  =   0x83;                           /* ����������               */
00217     usFdiv =                        (FPCLK / 16) / speed;         /* ������                   */
00218     LPC_UART3->DLM  =   usFdiv / 256;
00219     LPC_UART3->DLL  =   usFdiv % 256; 
00220     LPC_UART3->LCR  =   SetLsr; 
00221     LPC_UART3->FCR  =   0x07;
00222 }
00223 
00224 
00225 
00226 
00227 void UART_InitSet (unsigned int Num,unsigned int Speed, unsigned int SetLsr)
00228 {
00229     uint16_t usFdiv;
00230 
00231     usFdiv = ((FPCLK  / 16) / Speed) +1;          
00232     //usFdiv = ((FPCLK  / 4) / Speed) + 1 ;          
00233 
00234     if (Num == 0) 
00235     {
00236         LPC_PINCON->PINSEL0 |= (1 << 4);             /* Pin P0.2 used as TXD0 (Com0) */
00237         LPC_PINCON->PINSEL0 |= (1 << 6);             /* Pin P0.3 used as RXD0 (Com0) */
00238         LPC_UART0->LCR  = 0x83;                      /* ����������               */
00239      // LPC_UART0->FDR = 0x00000085;                // c��  ��� LPC17xx-User-Manual_0[1].05 �� ���  311
00240                                                     //���������� �� 8 �������� �� 5 
00241     //      usFdiv = 4;
00242         LPC_UART0->DLM  = usFdiv / 256;
00243         LPC_UART0->DLL  = usFdiv % 256; 
00244         LPC_UART0->LCR  = SetLsr;                      /* ����������                   */
00245         LPC_UART0->FCR  = 0x07;
00246     }
00247     if (Num == 1)
00248     {
00249         LPC_PINCON->PINSEL4 |= (2 << 0);             /* Pin P2.0 used as TXD0 (Com0) */
00250         LPC_PINCON->PINSEL4 |= (2 << 2);             /* Pin P2.1 used as RXD0 (Com0) */
00251     
00252         LPC_UART1->LCR  = 0x83;                      /* ����������               */
00253         LPC_UART1->DLM  = usFdiv / 256;
00254         LPC_UART1->DLL  = usFdiv % 256; 
00255         LPC_UART1->LCR  = SetLsr;                      /* ����������                   */
00256         LPC_UART1->FCR  = 0x07;
00257     }
00258     if (Num == 2)
00259     {
00260         LPC_PINCON->PINSEL0 |= (1 << 20);             /* Pin P0.10 used as TXD2 (Com2) */
00261         LPC_PINCON->PINSEL0 |= (1 << 22);             /* Pin P0.11 used as RXD2 (Com2) */
00262         LPC_SC->PCONP = LPC_SC->PCONP|(1<<24);        /*����UART2��Դ����λ            */
00263         LPC_UART2->LCR  = 0x83;                      /* ����������               */
00264         LPC_UART2->DLM  = usFdiv / 256;
00265         LPC_UART2->DLL  = usFdiv % 256; 
00266         LPC_UART2->LCR  = SetLsr;                      /* ����������                   */
00267         LPC_UART2->FCR  = 0x07;
00268     }
00269     if (Num == 3)
00270     {
00271         LPC_PINCON->PINSEL1 |= (3 << 18);                   /* Pin P0.25 used as TXD0 (Com0) */
00272         LPC_PINCON->PINSEL1 |= (3 << 20);                   /* Pin P0.26 used as RXD0 (Com0) */
00273         LPC_SC->PCONP =         LPC_SC->PCONP|(1<<25);        /*����UART2��Դ����λ            */  
00274         LPC_UART3->LCR  = 0x83;                      /* ����������               */
00275         LPC_UART3->DLM  = usFdiv / 256;
00276         LPC_UART3->DLL  = usFdiv % 256; 
00277         LPC_UART3->LCR  = SetLsr;                      /* ����������                   */
00278         LPC_UART3->FCR  = 0x07;
00279     }
00280 }
00281 
00282 
00283 
00284 
00285 
00286 
00287 
00288  
00289 
00290 
00291 
00292 
00293 
00294 
00295 
00296 
00297 
00298 
00299 
00300 
00301 
00302 
00303 
00304 
00305 
00306 
00307 
00308 /*********************************************************************************************************
00309 ** Function name:       UART0_SendByte
00310 ** Descriptions:        �Ӵ���0��������
00311 ** input parameters:    data: ���͵�����
00312 ** output parameters:   ��
00313 ** Returned value:      ��
00314 *********************************************************************************************************/
00315 int UART0_SendByte (int ucData)
00316 {
00317     while (!(LPC_UART0->LSR & 0x20));
00318     return (LPC_UART0->THR = ucData);
00319 
00320 }
00321 
00322 
00323 
00324 
00325 
00326 
00327 /*----------------------------------------------------------------------------
00328   Read character from Serial Port   (blocking read)
00329  *----------------------------------------------------------------------------*/
00330 int UART0_GetChar (void) 
00331 {
00332     while (!(LPC_UART0->LSR & 0x01));
00333     return (LPC_UART0->RBR);
00334 }
00335 /*----------------------------------------------------------------------------
00336   Read character from Serial Port   (blocking read)
00337  *----------------------------------------------------------------------------*/
00338 int UART1_GetChar (void) 
00339 {
00340     while (!(LPC_UART1->LSR & 0x01));
00341     return (LPC_UART1->RBR);
00342 }
00343 
00344 /*----------------------------------------------------------------------------
00345   Read character from Serial Port   (blocking read)
00346  *----------------------------------------------------------------------------*/
00347 int UART2_GetChar (void) 
00348 {
00349     while (!(LPC_UART2->LSR & 0x01));
00350     return (LPC_UART2->RBR);
00351 }
00352 /*----------------------------------------------------------------------------
00353   Read character from Serial Port   (blocking read)
00354  *----------------------------------------------------------------------------*/
00355 int UART3_GetChar (void) 
00356 {
00357     while (!(LPC_UART3->LSR & 0x01));
00358     return (LPC_UART3->RBR);
00359 }
00360 
00361 int UART0_Chek (void) 
00362 {
00363     if (LPC_UART0->LSR & 0x01) return 1; else return 0;
00364 }
00365 
00366 int UART1_Chek (void) 
00367 {
00368     if (LPC_UART1->LSR & 0x01)return 1; else return 0;
00369 }
00370 
00371 
00372 int UART2_Chek (void) 
00373 {
00374 
00375     if (LPC_UART2->LSR & 0x01)return 1; else return 0;
00376 }
00377 
00378 int UART3_Chek (void) 
00379 {
00380     if (LPC_UART3->LSR & 0x01)return 1; else return 0;
00381  
00382 }
00383 
00384 
00385 
00386 
00387 
00388 
00389 void UART0_SendString (char *s) 
00390 {
00391     while (*s != 0) 
00392     {
00393         UART0_SendByte(*s++);
00394     }
00395 }
00396 
00397 
00398 
00399 
00400 
00401 int UART2_SendByte (int ucData)
00402 {
00403     while (!(LPC_UART2->LSR & 0x20));
00404     return (LPC_UART2->THR = ucData);
00405 }
00406 
00407 
00408 
00409 void UART0_SendChar(uint16_t disp)
00410 {
00411     uint16_t dispbuf[4];
00412     uint8_t i;
00413 
00414     dispbuf[3] = disp%10 + '0';
00415     dispbuf[2] = disp/10%10 + '0';
00416     dispbuf[1] = disp/10/10%10 + '0';
00417     dispbuf[0] = disp/10/10/10%10 + '0';
00418     for(i=0;i<4;i++)
00419         UART0_SendByte(dispbuf[i]); 
00420 }
00421 
00422 
00423 
00424 void Concol (void )
00425 {
00426     if (OutBufConCount == 0)    
00427     {
00428 
00429         if (ConOutPnt != ConOutCur)
00430             if (LPC_UART0->LSR & 0x20)
00431             {
00432                 ConOutCur++;
00433                 ConOutCur = ConOutCur & 0x3ff; 
00434                 SetDeUART0 ();
00435                 LPC_UART0->THR = OutCon[ConOutCur];
00436             }
00437     }
00438     if (LPC_UART0->LSR & 0x01)
00439         {
00440             ConInCur++;
00441             ConInCur = ConInCur & 0x3ff; 
00442             InCon[ConInCur] = (LPC_UART0->RBR);
00443         }
00444     
00445     if (!(LPC_UART0->LSR & 0x40)) SetDeUART0 (); else ClrDeUART0() ;                //���������� 485 
00446 
00447 } 
00448 
00449 
00450 
00451 void WriteConN (char *s, unsigned int N) 
00452 {
00453     OutBufCon1Count = 0;
00454  
00455     while (N != 0) 
00456     {
00457         BackLightON
00458         N--;
00459         ConOutPnt1++;
00460         ConOutPnt1 = ConOutPnt1 & 0x3ff; 
00461         OutCon1[ConOutPnt1] = (*s++);
00462         
00463     }
00464     
00465     Gyro.UARTFlag=1;
00466     OutBufCon1Count = 100;
00467     BackLightOFF
00468 }
00469 void Concol1 (void )
00470 {int temp=2;
00471     //if (OutBufCon1Count == 0) 
00472     if (Time_UART <30)  Gyro.PinReg  |=  PinRegBitTXE; 
00473     if (Time_UART <15)
00474         {
00475             Gyro.UARTFlag=0;
00476         if (ConOutPnt1 != ConOutCur1)
00477             {
00478              if (LPC_UART1->LSR & 0x20)
00479                 {
00480                 ConOutCur1++;
00481                 ConOutCur1 = ConOutCur1 & 0x3ff; 
00482                 LPC_UART1->THR = OutCon1[ConOutCur1];
00483                 }
00484             }
00485         else 
00486             {   
00487                 Gyro.UARTFlag=1;
00488                 if (Time_UART==0)
00489                 {
00490                     Gyro.UARTFlag=0;
00491                     Time_UART=Gyro.DropDelayGLD;
00492                     Gyro.PinReg  &=  ~PinRegBitTXE;
00493                 }
00494             }
00495     
00496         }
00497     if (LPC_UART1->LSR & 0x01)
00498     {
00499         ConInCur1++;
00500         ConInCur1 = ConInCur1 & 0x3ff; 
00501         InCon1[ConInCur1] = (LPC_UART1->RBR);
00502     }
00503 } 
00504 
00505 void Concol1111 (void )
00506 {
00507     //if (OutBufCon1Count == 0) 
00508     if (Time_UART == 0)
00509     {
00510         if (ConOutPnt1 != ConOutCur1)
00511             {
00512                 if (LPC_UART1->LSR & 0x20)
00513                 {
00514                 ConOutCur1++;
00515                 ConOutCur1 = ConOutCur1 & 0x3ff; 
00516                 LPC_UART1->THR = OutCon1[ConOutCur1];
00517                 }
00518             }
00519     if (!(LPC_UART1->LSR & 0x40))  Gyro.PinReg  |=  PinRegBitTXE; else Gyro.PinReg  &=  ~PinRegBitTXE;
00520     }
00521     else if (OutBufCon1Count == 0)
00522     {
00523         
00524         Gyro.PinReg  |=  PinRegBitTXE;
00525     }
00526         
00527     if (LPC_UART1->LSR & 0x01)
00528     {
00529         ConInCur1++;
00530         ConInCur1 = ConInCur1 & 0x3ff; 
00531         InCon1[ConInCur1] = (LPC_UART1->RBR);
00532     }
00533 } 
00534 
00535 void Concol1Fast (void )
00536 {
00537     if (OutBufCon1Count == 0)   
00538     {
00539         while((ConOutPnt1 != ConOutCur1) && (LPC_UART1->LSR & 0x20))
00540         {
00541                 ConOutCur1++;
00542                 ConOutCur1 = ConOutCur1 & 0x3ff; 
00543                 SetDeUART1 ();  
00544                 LPC_UART1->THR = OutCon1[ConOutCur1];
00545         }
00546     }
00547     while (LPC_UART1->LSR & 0x01)
00548     {
00549         ConInCur1++;
00550         ConInCur1 = ConInCur1 & 0x3ff; 
00551         InCon1[ConInCur1] = (LPC_UART1->RBR);
00552     }
00553     if (!(LPC_UART1->LSR & 0x40)) SetDeUART1 (); else ClrDeUART1() ;                //���������� 485 
00554 } 
00555 
00556 
00557 
00558 
00559 void Concol2 (void )
00560 {
00561     if (OutBufCon2Count == 0)   
00562     {
00563         if (ConOutPnt2 != ConOutCur2)
00564             if (LPC_UART2->LSR & 0x20)
00565             {
00566                 ConOutCur2++;
00567                 ConOutCur2 = ConOutCur2 & 0x3ff; 
00568                 SetDeUART2 ();  
00569                 LPC_UART2->THR = OutCon2[ConOutCur2];
00570             }
00571     }
00572     if (LPC_UART2->LSR & 0x01)
00573     {
00574         ConInCur2++;
00575         ConInCur2 = ConInCur2 & 0x3ff; 
00576         InCon2[ConInCur2] = (LPC_UART2->RBR);
00577     }
00578     if (!(LPC_UART2->LSR & 0x40)) SetDeUART2 (); else ClrDeUART2() ;                //���������� 485 
00579 } 
00580 
00581 
00582 
00583 
00584 
00585 void Concol3 (void )
00586 {
00587     if (OutBufCon3Count == 0)   
00588     {
00589         if (ConOutPnt3 != ConOutCur3)
00590             if (LPC_UART3->LSR & 0x20)
00591             {
00592                 ConOutCur3++;
00593                 ConOutCur3 = ConOutCur3 & 0x3ff; 
00594                 SetDeUART3 ();  
00595                 LPC_UART3->THR = OutCon3[ConOutCur3];
00596             }
00597     }
00598     if (LPC_UART3->LSR & 0x01)
00599     {
00600         ConInCur3++;
00601         ConInCur3 = ConInCur3 & 0x3ff; 
00602         InCon3[ConInCur3] = (LPC_UART3->RBR);
00603     }
00604     
00605     if (!(LPC_UART3->LSR & 0x40)) SetDeUART3 (); else ClrDeUART3() ;                //���������� 485 
00606 } 
00607 
00608 
00609 
00610 void Concol2M (void )
00611 {
00612     if (OutBufCon2Count == 0)   
00613     {
00614         if (ConOutPnt2M != ConOutCur2M)
00615             if (LPC_UART2->LSR & 0x20)
00616             {
00617                 ConOutCur2++;
00618                 ConOutCur2 = ConOutCur2 & 0x3ff; 
00619                 SetDeUART2 ();  
00620                 LPC_UART2->THR = OutCon2[ConOutCur2];
00621             }
00622     }
00623     if (LPC_UART2->LSR & 0x01)
00624     {
00625         ConInCur2++;
00626         ConInCur2 = ConInCur2 & 0x3ff; 
00627         InCon2[ConInCur2] = (LPC_UART2->RBR);
00628     }
00629     if (!(LPC_UART2->LSR & 0x40)) SetDeUART2 (); else ClrDeUART2() ;                //���������� 485 
00630 } 
00631 
00632 
00633 
00634 
00635 
00636 
00637 void WriteCon (char *s)
00638 {
00639     OutBufConCount = 0;
00640     while (*s != 0) 
00641     {
00642         ConOutPnt++;
00643         ConOutPnt = ConOutPnt & 0x3ff; 
00644         OutCon[ConOutPnt] = (*s++);
00645     }
00646 }
00647 
00648 void WriteCon1 (char *s) 
00649 {
00650     OutBufCon1Count = 0;
00651     while (*s != 0) 
00652     {
00653         ConOutPnt1++;
00654         ConOutPnt1 = ConOutPnt1 & 0x3ff; 
00655         OutCon1[ConOutPnt1] = (*s++);
00656     }
00657 }
00658 
00659 
00660 
00661 void WriteCon0N (char *s, unsigned int N) 
00662 {
00663     OutBufConCount = 0;
00664     while (N != 0) 
00665     {
00666         N--;
00667         ConOutPnt++;
00668         ConOutPnt = ConOutPnt & 0x3ff; 
00669         OutCon[ConOutPnt] = (*s++);
00670     }
00671     OutBufConCount = 10;
00672 }
00673 
00674 
00675 void WriteCon2 (char *s) 
00676 {
00677     OutBufCon2Count = 0;
00678     while (*s != 0) 
00679     {
00680         ConOutPnt2++;
00681         ConOutPnt2 = ConOutPnt2 & 0x3ff; 
00682         OutCon2[ConOutPnt2] = (*s++);
00683     }
00684 }
00685 void WriteCon3 (char *s) 
00686 {
00687     OutBufCon3Count = 0;
00688     while (*s != 0) 
00689     {
00690         ConOutPnt3++;
00691         ConOutPnt3 = ConOutPnt3 & 0x3ff; 
00692         OutCon3[ConOutPnt3] = (*s++);
00693     }
00694 }
00695 
00696 
00697 
00698 
00699 void    WriteConF (char *s, unsigned int Num)
00700 {
00701         if (Num == 0) WriteCon(s);
00702         if (Num == 1) WriteCon1(s);
00703         if (Num == 2) WriteCon2(s);
00704         if (Num == 2) WriteCon3(s);
00705 
00706 }
00707 
00708 
00709 
00710 
00711 void WriteConByte (unsigned int In) 
00712 {
00713     ConOutPnt++;
00714     ConOutPnt = ConOutPnt & 0x3ff; 
00715     OutCon[ConOutPnt] = In;
00716 }
00717 
00718 void WriteCon1Byte (unsigned int In) 
00719 {
00720     ConOutPnt1++;
00721     ConOutPnt1 = ConOutPnt1 & 0x3ff; 
00722     OutCon1[ConOutPnt1] = In;
00723 }
00724 
00725 
00726 void WriteCon2Byte (unsigned int temp) 
00727 {
00728     ConOutPnt2++;
00729     ConOutPnt2 = ConOutPnt2 & 0x3ff; 
00730     OutCon2[ConOutPnt2] = temp;
00731 }
00732 
00733 void WriteCon3Byte (unsigned int temp) 
00734 {
00735     ConOutPnt3++;
00736     ConOutPnt3 = ConOutPnt3 & 0x3ff; 
00737     OutCon3[ConOutPnt3] = temp;
00738 }
00739 
00740 
00741 
00742 
00743 
00744 void WriteConByteF (unsigned int In,unsigned int Num ) 
00745 {
00746         if (Num == 0) WriteConByte(In);
00747         if (Num == 1) WriteCon1Byte(In);
00748         if (Num == 2) WriteCon2Byte(In);
00749         if (Num == 3) WriteCon3Byte(In);
00750     
00751 }
00752 
00753 
00754 
00755 
00756 
00757 
00758 
00759 
00760 
00761 int ReadCon (char *s) 
00762 { 
00763     int i = 0;
00764     while (ConInPnt != ConInCur) 
00765     {
00766     i++;
00767     ConInPnt++;
00768     ConInPnt = ConInPnt & 0x3ff; 
00769     (*s++) = InCon[ConInPnt] ;
00770     }
00771     (*s++) = 0;
00772     return i;
00773 }
00774 
00775 int ReadCon1 (char *s) 
00776 { 
00777     int i = 0;
00778     while (ConInPnt1 != ConInCur1) 
00779     {
00780     i++;
00781     ConInPnt1++;
00782     ConInPnt1 = ConInPnt1 & 0x3ff; 
00783     (*s++) = InCon1[ConInPnt1] ;
00784     }
00785     (*s++) = 0;
00786     return i;
00787 }
00788 
00789 int ReadCon2 (char *s) 
00790 { 
00791     int i = 0;
00792     while (ConInPnt2 != ConInCur2) 
00793     {
00794         i++;
00795         ConInPnt2++;
00796         ConInPnt2 = ConInPnt2 & 0x3ff; 
00797         (*s++) = InCon2[ConInPnt2] ;
00798     }
00799     (*s++) = 0;
00800     return i;
00801 
00802 }
00803 
00804 
00805 int ReadCon3 (char *s) 
00806 { 
00807     int i = 0;
00808     while (ConInPnt3 != ConInCur3) 
00809     {
00810         i++;
00811         ConInPnt3++;
00812         ConInPnt3 = ConInPnt3 & 0x3ff; 
00813         (*s++) = InCon3[ConInPnt3] ;
00814     }
00815     (*s++) = 0;
00816     return i;
00817 
00818 }
00819 
00820 
00821 
00822 
00823 
00824 int ReadChekCon (char *s) 
00825 { 
00826     int i = 0;
00827     int ConInPntTemp = ConInPnt;
00828     while (ConInPntTemp != ConInCur) 
00829     {
00830         i++;
00831         ConInPntTemp++;
00832         ConInPntTemp = ConInPntTemp & 0x3ff; 
00833         (*s++) = InCon[ConInPntTemp] ;
00834     }
00835     (*s++) = 0;
00836     return i;
00837 }
00838 
00839 int ReadChekCon1 (char *s) 
00840 { 
00841     int i = 0;
00842     int ConInPntTemp = ConInPnt1;
00843     while (ConInPntTemp != ConInCur1) 
00844     {
00845         i++;
00846         ConInPntTemp++;
00847         ConInPntTemp = ConInPntTemp & 0x3ff; 
00848         (*s++) = InCon1[ConInPntTemp] ;
00849     }
00850     (*s++) = 0;
00851     return i;
00852 }
00853 
00854 
00855 
00856 
00857 int ReadChekCon2 (char *s) 
00858 {   
00859     int i = 0;
00860     int ConInPntTemp = ConInPnt2;
00861     while (ConInPntTemp != ConInCur2) 
00862     {
00863         i++;
00864         ConInPntTemp++;
00865         ConInPntTemp = ConInPntTemp & 0x3ff; 
00866         (*s++) = InCon2[ConInPntTemp] ;
00867     }
00868     (*s++) = 0;
00869     return i;
00870 }
00871 
00872 
00873 int ReadChekCon3 (char *s) 
00874 {   
00875     int i = 0;
00876     int ConInPntTemp = ConInPnt3;
00877     while (ConInPntTemp != ConInCur3) 
00878     {
00879         i++;
00880         ConInPntTemp++;
00881         ConInPntTemp = ConInPntTemp & 0x3ff; 
00882         (*s++) = InCon3[ConInPntTemp] ;
00883     }
00884     (*s++) = 0;
00885     return i;
00886 }
00887 
00888 
00889 
00890 
00891 
00892 
00893 int ChekInCon ( void )  {if (ConInPnt != ConInCur) return 1; else return 0;}
00894 int ChekInCon1 ( void ) {if (ConInPnt1 != ConInCur1) return 1; else return 0;}
00895 int ChekInCon2 ( void ) {if (ConInPnt2 != ConInCur2) return 1; else return 0;}
00896 int ChekInCon3 ( void ) {if (ConInPnt3 != ConInCur3) return 1; else return 0;}
00897 
00898 int ChekOutCon ( void )     {if (!(LPC_UART0->LSR & 0x40)) return 1; else return 0;}
00899 int ChekOutCon1 ( void )    {if (!(LPC_UART1->LSR & 0x40)) return 1; else return 0;}
00900 int ChekOutCon2 ( void )    {if (!(LPC_UART2->LSR & 0x40)) return 1; else return 0;}
00901 int ChekOutCon3 ( void )    {if (!(LPC_UART3->LSR & 0x40)) return 1; else return 0;}
00902 
00903 
00904 
00905 
00906 void Delay(int t)
00907 {
00908 }
00909 
00910 
00911 void SetDeUART0 (void)  {if ((PortEUART0 & (PinEUART0)) == 0)   {PortEUART0   |= (PinEUART0); Delay(10);}   }
00912 void ClrDeUART0 (void)  {if ((PortEUART0 & (PinEUART0)))                { Delay(10); PortEUART0   &= (~(PinEUART0));}}
00913 
00914 void SetDeUART1 (void)  {if ((PortEUART1 & (PinEUART1)) == 0)   {PortEUART1   |= (PinEUART1); Delay(10);}   }
00915 void ClrDeUART1 (void)  {if ((PortEUART1 & (PinEUART1)))                { Delay(10); PortEUART1   &= (~(PinEUART1));}}
00916 
00917 
00918 
00919 void SetDeUART2 (void)  {if ((PortEUART2 & (PinEUART2)) == 0) {PortEUART2   |= (PinEUART2); Delay(10);}}
00920 void ClrDeUART2 (void)  {if ((PortEUART2 & (PinEUART2)))            {Delay(10); PortEUART2   &= (~(PinEUART2));}}
00921 
00922 
00923 void SetDeUART3 (void)  {if ((PortEUART3 & (PinEUART3)) == 0)   {PortEUART3   |= (PinEUART3); Delay(10);}}
00924 void ClrDeUART3 (void)  {if ((PortEUART3 & (PinEUART3)))            {Delay(10);PortEUART3   &= (~(PinEUART3));}}
00925 
00926 
00927 
00928 
00929