C51 COMPILER V8.08   UART                                                                  07/28/2012 21:52:51 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE UART
OBJECT MODULE PLACED IN uart.OBJ
COMPILER INVOKED BY: D:\Program Files\keil_51\C51\BIN\C51.EXE uart.c LARGE BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include "NEW_8051.H"
   2          #include "task.h"
   3          //起始标志 0x5A 结束标志 0xA5  0x00 无反应
   4          #define START 0X5A //起始位
   5          #define END   0XA5 //结束位
   6          sbit LED1=P2^5;
   7          /*
   8                  0x5a+C+L+DATA+CS+0xA5
   9                  C 控制码 
  10                  L 长度
  11                  DATA 数据
  12                  CS  较验和  C+L+DATA
  13          
  14          
  15           和取模
  16              接收成功返回1字节：0x06
  17          */
  18          
  19          bit uart_rBIT=0;
  20          uchar ReceVeryfy=0;
  21          uchar ReceState=0;
  22          uchar ucDataBuff[220];
  23          uchar ReceCount=0;
  24          uchar ucControlCode;
  25          uchar ucLength;
  26          /**********************************/
  27          void Send_data(unsigned char d)   /*从串口发送数据*/
  28          {
  29   1                ES=0;
  30   1            SBUF=d;
  31   1                while(TI==0);       //等待发送完毕
  32   1            TI=0;
  33   1                ES=1;
  34   1      }
  35          /*******************************************/
  36          void MAIN_RS_INT(void) interrupt 4
  37          {
  38   1          uchar DataTemp;
  39   1              uchar i;
  40   1           //uart_rBIT=1;
  41   1          if(RI)  // 接收
  42   1          {
  43   2                      RI = 0;
  44   2                      //ucUdateTime=200;
  45   2                      DataTemp = SBUF;
  46   2                      /************************************/
  47   2                      switch (ReceState)
  48   2                      {
  49   3                              case 0:
  50   3                                      if(START == DataTemp)
  51   3                      {
  52   4                          ReceState = 1;
  53   4                      }
  54   3                                      break;
  55   3                              case 1:
C51 COMPILER V8.08   UART                                                                  07/28/2012 21:52:51 PAGE 2   

  56   3                                      ucControlCode=DataTemp; //接收控制码
  57   3                                      ReceVeryfy += ucControlCode;//开始计算校验和                    
  58   3                                       ReceState = 2;                                                 
  59   3                                      break;
  60   3                              case 2:
  61   3                                      ucLength=DataTemp;
  62   3                                      ReceVeryfy += ucLength;//计算校验和
  63   3                                      ReceState = 3;          
  64   3                                      break;
  65   3                              case 3:                 
  66   3                                      if(ReceCount<ucLength)
  67   3                                      {
  68   4                                              ReceVeryfy += DataTemp;
  69   4                                              ucDataBuff[ReceCount]=DataTemp;
  70   4                                              ReceCount++;                                    
  71   4                                              
  72   4                                      }
  73   3                                      else
  74   3                                      {
  75   4                                              if(ReceVeryfy == DataTemp)
  76   4                           {
  77   5                              
  78   5                                                      ReceVeryfy=0;
  79   5                                                      ReceCount=0;
  80   5                                                      ReceState=4;
  81   5                                                      //LED1=~LED1;
  82   5                           }
  83   4                                               else
  84   4                                               {
  85   5                                                      ReceState=0;
  86   5                                               }      
  87   4                                      }
  88   3                                      break;
  89   3                                      case 4:
  90   3                                               if(END == DataTemp) //接收到结束码后 串口接收标志位置1
  91   3                                               {
  92   4                                                      uart_rBIT=1;
  93   4                                                      ReceState=0;
  94   4                                               }
  95   3                                      break;
  96   3                              default:                                 
  97   3                                      ReceState=0;
  98   3                                      break;
  99   3                      }
 100   2      /**************************************************/
 101   2              if( uart_rBIT )
 102   2              {
 103   3                      uart_rBIT = 0;
 104   3                      switch (ucControlCode)
 105   3                      {
 106   4                              case 0x01://扇区擦除命令
 107   4                                              for(i=1;i<=ucDataBuff[0];i++)
 108   4                                          {
 109   5                                                      sector_erase(i*0x200);
 110   5                                              }
 111   4                                              Send_data(0x06);
 112   4                                      break;
 113   4                              case 0x02://字幕数据命令
 114   4                                              
 115   4                                              for(BuffCount=0;BuffCount<ucLength;BuffCount++)
 116   4                                              {
 117   5                                                      byte_program(0x200+BuffCount+uiBaseAddress,ucDataBuff[BuffCount]);//把字幕数据写入EEP 第二个扇区后所
C51 COMPILER V8.08   UART                                                                  07/28/2012 21:52:51 PAGE 3   

             -以要加上0x200
 118   5                                              }
 119   4                                              uiBaseAddress=uiBaseAddress+ucLength;
 120   4                                              if(ucLength<190)
 121   4                                              {
 122   5                                                      uiFontNumber=uiBaseAddress;//字模的总数量
 123   5                                                      uiBaseAddress=0;
 124   5                                                      sector_erase(0);
 125   5                                                      byte_program(0x100,uiFontNumber>>8);
 126   5                                                      byte_program(0x101,uiFontNumber);       
 127   5                                              }
 128   4                                              //ucEEPArray=1;//EEP有字幕数据标志
 129   4                                              Send_data(0x06);
 130   4                                      break;
 131   4                              
 132   4                                      case 0x04:
 133   4                                              ES = 0;
 134   4                                              //Send_data(uiBaseAddress>>8);
 135   4                                              //Send_data(uiBaseAddress);                     
 136   4                                              /*for( i=0;i<250;i++ )
 137   4                                              {
 138   4                                                      SBUF = byte_read(0x200+i);
 139   4                                                      while( TI == 0 );
 140   4                                                      TI = 0;
 141   4                                              }*/                     
 142   4                                              ES = 1;
 143   4                                       break;
 144   4                              default:
 145   4                                      break;
 146   4                      }
 147   3      
 148   3              }
 149   2                              
 150   2              }
 151   1      /*****************************************/
 152   1      /*      if(TI)
 153   1          {
 154   1              TI = 0;
 155   1              }  */
 156   1      
 157   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    415    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =    225       1
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      1    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)
