⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uart_dv.lst

📁 MXIC旺宏液晶电视芯片MX88V44的源码
💻 LST
📖 第 1 页 / 共 3 页
字号:
 166          * ===========================================================================
 167          * 2003-01-20    KM Ho                   This is first time implement
 168          * 2004-05-14    Eson W.                 Modify for 8051 component
 169          **/
 170          void    UART_TxByte()
 171          {
 172   1              if (UARTFlag & TX_FLAG)                         //check is TX flag setting
 173   1              {
 174   2                      SBUF = Tx_Buf[Tx_Index++];
 175   2                      if (Tx_Index >= Tx_Length)              //close the TX (send complete)
 176   2                      {
 177   3                              UARTFlag &= (TX_FLAG ^ CLEAN_UARTFlag);         //clean TX flag
 178   3                              if (Tx_Buf[1] != ACK)
C51 COMPILER V7.02b   UART_DV                                                              05/24/2006 17:59:20 PAGE 4   

 179   3                                      UARTFlag |= TX_WAITACK;                                 //set wait ACK flag **
 180   3                      }
 181   2              }
 182   1      }
 183          
 184          /**--------------------------------------------------------------------------
 185          * Name          void    UART_SendOut(char cmd_length);
 186          *                               char    *sendbuf        sending buffer
 187          *                               char    cmd_length      length of command
 188          *
 189          * Description   The Routine will
 190          *                                       1. wait last time send complete,
 191          *                                       2. Send First byte
 192          *                                       3. Set flag.
 193          *
 194          * Flow Chart
 195          *
 196          * Return
 197          *
 198          * DATE          Author          Description
 199          * ===========================================================================
 200          * 2003-01-16    K.M. Ho         This is first time implement
 201          * 2004-05-14    Eson W.                 Modify for 8051 component
 202          */
 203          void    UART_SendOut(char *sendbuf, char send_length)
 204          {
 205   1              char    i;
 206   1              char    send_times;
 207   1      
 208   1              send_times = 0;
 209   1      
 210   1              while(1)
 211   1              {
 212   2                      if (UARTFlag & (TX_FLAG|TX_WAITACK))
 213   2                      {                                                               //UART is busy for last TX
 214   3                              for (i=0; i<120; i++);
 215   3                              ++send_times;
 216   3                              if (send_times>120)                     //send out fail times > 3
 217   3                                      return;
 218   3                      }
 219   2                      else
 220   2                      {                       //Ready to send out first byte
 221   3      
 222   3                              UARTFlag |= TX_FLAG;                                    //set flag for send
 223   3                              for (i=0; i<send_length; i++)                   //copy send data to TX buffer
 224   3      //                              Tx_Buf[i] = ReTx_Buf[i] = sendbuf[i];
 225   3                                      Tx_Buf[i] = sendbuf[i];
 226   3      //                      Tx_Length = ReTx_Length = send_length;  //copy sending data length
 227   3                              Tx_Length = send_length;        //copy sending data length
 228   3                              Tx_Index = 1;                                                   //Trigger UART TX INT
 229   3                              SBUF=Tx_Buf[0];                                                 //put first data to THR
 230   3                              return;
 231   3                      }
 232   2              }
 233   1      }
 234          
 235          /**--------------------------------------------------------------------------
 236          * Name          void    PrepareSendBuf(char buf_index, int addr, char data_length,
 237          *                                                                               char  cmd_type);
 238          *                               char    *sendbuf        sending buffer (MAX. 24bytes)
 239          *                               int             addr            address of Read/Write/Fill
 240          *                               char    data_length     data length
C51 COMPILER V7.02b   UART_DV                                                              05/24/2006 17:59:20 PAGE 5   

 241          *                               char    cmd_type        type of command
 242          *
 243          * Description   prepare the sending buffer
 244          *
 245          * Flow Chart
 246          *
 247          * Return                None
 248          *
 249          * DATE          Author          Description
 250          * ===========================================================================
 251          * 2004-04-15    K.M. Ho         This is first time implement
 252          */
 253          void    PrepareSendBuf(char *sendbuf, int addr, char data_length, char cmd_type)
 254          {
 255   1              struct UART_PACK        *tx_pack;
 256   1              char                            crc_byte;
 257   1              char                            i;
 258   1      
 259   1              tx_pack = (struct UART_PACK *)sendbuf;  //TX struct pointer to sending buffer
 260   1              tx_pack->syn1   = SYN_BYTE;                     //SYN
 261   1              tx_pack->cmd    = cmd_type;                     //command
 262   1              tx_pack->length = data_length;          //data length
 263   1              tx_pack->reserve=0x00;                          //reserve is always 0
 264   1      //      tx_pack->addr   = addr;
 265   1              sendbuf[4]              = (char) (addr    &0x00ff);             //addr low byte
 266   1              sendbuf[5]              = (char)((addr>>8)&0x00ff);             //addr high byte
 267   1              tx_pack->crc    = 0x00;                         //clean CRC
 268   1              tx_pack->syn2   = SYN_BYTE;                     //put SYN to send buffe
 269   1      
 270   1              crc_byte = 0;                                           //clean CRC check byte
 271   1              for (i=0; i<data_length+UART_PACK_SIZE; i++)
 272   1                      crc_byte ^= sendbuf[i];                 //make CRC check byte
 273   1      
 274   1              tx_pack->crc  = crc_byte;                       //put in CRC byte
 275   1      }
 276          
 277          /**--------------------------------------------------------------------------
 278          * Name          void    UART_ParseFun(void);
 279          *
 280          * Description   Parse the recive buf when the PARSE flag is setting
 281          *                               There are
 282          *                               ACK                     device RX is OK
 283          *                               NACK            device RX in not OK, request resend
 284          *                               MSGSHOW         device request show message on PC screen
 285          *                               DEVICEINF       device respond information
 286          *                               MEMRESPOND      device respond memory content of address
 287          *                               REGRESPOND                                 register
 288          *
 289          * Flow Chart    1. copy RX buffer data to tmp and make CRC check byte
 290          *                               2. clean PARSE flag
 291          *                               3. is CRC right?        No, send NACK command
 292          *                               4. parse COMMAND
 293          *                               5. send ACK command if need.
 294          *
 295          * Return
 296          *
 297          * DATE          Author          Description
 298          * ===========================================================================
 299          * 2003-01-22    KM Ho           This is first time implement
 300          * 2003-03-27    KM Ho           Modify RX ACK command process
 301          * 2004-05-19    Eson W.
 302          * 2004-11-17    KMHo            Add EEPROM Read/Write Command
C51 COMPILER V7.02b   UART_DV                                                              05/24/2006 17:59:20 PAGE 6   

 303          **/
 304          
 305          void    UART_ParseFun()
 306          {
 307   1              struct UART_PACK        *rx_pack;
 308   1              char    crc_byte;
 309   1              char    buf_index;
 310   1              BYTE    i, send_length;
 311   1              BYTE    sendtemp[32];
 312   1      
 313   1              buf_index = UART_RxInUse ^ 1;   //chang to Rx complete buffer
 314   1                                                                              //RX buf is double buffer
 315   1              rx_pack = (struct UART_PACK *)Rx_Buf[buf_index];
 316   1      
 317   1              crc_byte = 0x00;                                                //make CRC check byte
 318   1              for(i=0; i<Parse_Length; i++)
 319   1                      crc_byte  ^= Rx_Buf[buf_index][i];
 320   1      
 321   1              UARTFlag &= (RX_PARSE^CLEAN_UARTFlag);  //clean parse flag
 322   1      
 323   1              if (crc_byte)                                                   //CRC error sent NACK and return
 324   1              {
 325   2                      PrepareSendBuf(sendtemp, 0, 0, NACK);
 326   2                      UART_SendOut(sendtemp, UART_PACK_SIZE);
 327   2                      return;
 328   2              }
 329   1      
 330   1              if (rx_pack->cmd == ACK)                //if ACK command will clean UARTFlag
 331   1              {                                                               //                               and return
 332   2                      UARTFlag &= (TX_WAITACK ^ CLEAN_UARTFlag);      //clean wait ACK
 333   2                      return;
 334   2              }
 335   1                              //*** --------------------------------------------------------- ***
 336   1                              //      The Respond data from Byte 16
 337   1                              //      There are ACK cmd 8Bytes + Respond Cmd 8Bytes+ Respond data
 338   1                              //*** --------------------------------------------------------- ***

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -