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

📄 term3.lst

📁 使用单片机C8050F330对无线发射接受模块进行配置与控制,使组件成为一个无线通讯中的基站.
💻 LST
📖 第 1 页 / 共 4 页
字号:
 915          void Key_scan(void)
 916          {
 917   1        unsigned char key_buf=0;
 918   1      
 919   1        if (KEY==0)
 920   1        {
C51 COMPILER V7.50   TERM3                                                                 04/06/2007 17:58:07 PAGE 16  

 921   2          key_buf=99;
 922   2        }
 923   1      
 924   1        if (key_buf==key_pre)
 925   1        {
 926   2          if (key_buf!=0)
 927   2          {
 928   3            key_work=0x55;
 929   3          }
 930   2          else
 931   2          {
 932   3            key_work=0;
 933   3                key_press_time=0;
 934   3          }
 935   2        }
 936   1        else
 937   1        {
 938   2          key_pre=key_buf;
 939   2              key_press_time=0;
 940   2        }
 941   1      }
 942          
 943          
 944          void Key_process(void)
 945          {
 946   1            if ((key_work==0x55) && (key_time==0))
 947   1            {
 948   2                   key_work=0;key_time=1000; //key_zt==0  关机 key_zt==99 开机
 949   2      
 950   2      
 951   2               if (key_zt==0)    //如果当前状态是关机状态,此时有按键信号,则开机,延时开背光
 952   2               {
 953   3                          key_zt=99;
 954   3                  LcdBackLight_Delay_AfterS2410=1800;
 955   3                              GPS_SW=0;
 956   3               }
 957   2               else if (key_zt==99) //如果当前状态是开机状态,此时有按键信号,则判断长按,关机
 958   2               {                    //如果不长按,key_zt 不能变
 959   3               }
 960   2            }
 961   1      }
 962          
 963          void Delay_1uS(void)
 964          {
 965   1              unsigned char i;
 966   1              for(i=0;i<200;i++);
 967   1      }
 968           
 969          void Variable_Init(void)
 970          {
 971   1        RecvByte=0;
 972   1        LcdBackLight_Delay_AfterS2410=0;
 973   1      
 974   1        key_press_time=0;
 975   1      
 976   1        key_zt=0;key_time=0;
 977   1      
 978   1        riqi[0]=0+0x30;
 979   1        riqi[1]=6+0x30;
 980   1        riqi[2]=0+0x30;
 981   1        riqi[3]=8+0x30;
 982   1        riqi[4]=0+0x30;
C51 COMPILER V7.50   TERM3                                                                 04/06/2007 17:58:07 PAGE 17  

 983   1        riqi[5]=5+0x30;
 984   1      
 985   1        GPS_Alarm[0]=8+0x30;
 986   1        GPS_Alarm[1]=5+0x30;
 987   1      
 988   1        weixing[0]=0+0x30;
 989   1        weixing[1]=0+0x30;
 990   1      
 991   1        GPS_Current_pre=0;
 992   1        GPS_Current=0;
 993   1        GPS_time=0;
 994   1        GPS_Alarm_js=0;
 995   1      //  GPS_SW = 1;
 996   1      
 997   1        SW_IsFrame = 0;
 998   1      
 999   1        Batt_Low = 1+0x30;
1000   1      
1001   1        for (ii=0;ii<9;ii++)       // Longitude
1002   1        {
1003   2          Longitude[ii]=0x30;
1004   2        }
1005   1        for (ii=0;ii<10;ii++)        // Latitude
1006   1        {
1007   2          Latitude[ii]=0x30;
1008   2        }
1009   1          
1010   1        DGPS=0x30;
1011   1      
1012   1        for (ii=0;ii<4;ii++)         // HDOP
1013   1        {
1014   2          HDOP[ii]=0x30;
1015   2        }     
1016   1                      
1017   1        fm[0]=0x30;
1018   1        fm[1]=0x30;
1019   1        fm[2]=0x30;
1020   1        fmbak=0;
1021   1        
1022   1        SRI=0;
1023   1        surt_js=0;
1024   1        b_light=0x30;
1025   1      }
1026          
1027          //----------------------------------------------------------------------------
1028          //Interrupt Service Routine
1029          //----------------------------------------------------------------------------
1030          void PCA_ISR(void) interrupt 11
1031          {
1032   1          static char SUTXST = 0;              //SW_UART TX????
1033   1              static char SURXST = 0;              //SW_UART RX????
1034   1              static unsigned RXSHIFT = 0;         //SW_UART RX?????
1035   1          unsigned int PCA_TEMP;               //??????,????PCA?????
1036   1                                                   //???
1037   1      
1038   1         // Check receive interrupt flag first; service if CCF0 is set.
1039   1              if (CCF0){
1040   2                      CCF0 = 0;                                                                               // Clear interrupt flag.
1041   2                      switch (SURXST){
1042   3                              
1043   3                              // State 0: START bit received.
1044   3                              // In this state, a negative edge on SW_TX has caused the interrupt,
C51 COMPILER V7.50   TERM3                                                                 04/06/2007 17:58:07 PAGE 18  

1045   3                              // meaning a START has been detected and the PCA0CP0 registers have 
1046   3                              // captured the value of PCA0.
1047   3                              // - Check for receive enable and good START bit
1048   3                              // - Switch PCA module 0 to software timer mode
1049   3                              // - Add 3/2 bit time to module 0 capture registers to sample LSB.
1050   3                              // - Increment RX state variable.
1051   3                              case 0:
1052   3                                  
1053   3                                      if (SREN & ~SW_RX){                                     // Check for receive enable and a good
1054   4                                                                                                              // START bit.  
1055   4                                                                                                                                      
1056   4                                              PCA_TEMP = (PCA0CPH0 << 8);         // Read module 0 contents into
1057   4                                              PCA_TEMP |= PCA0CPL0;                   // PCA_TEMP.
1058   4      
1059   4                                              PCA_TEMP += TH_TIME_COUNT;              // Add 3/2 bit times to PCA_TEMP
1060   4      
1061   4                                              PCA0CPL0 = PCA_TEMP;                            // Restore PCA0CPL0 and PCA0CPH0
1062   4                                              PCA0CPH0 = (PCA_TEMP >> 8);     // with the updated value
1063   4      
1064   4                                              PCA0CPM0 = 0x49;                                // Change module 0 to software
1065   4                                                                                                              // timer mode, interrupts enabled.
1066   4      
1067   4                                              SURXST++;                                                       // Update RX state variable.
1068   4                              }
1069   3                                      break;
1070   3                              
1071   3                              // States 1-8: Bit Received
1072   3                              // - Sample SW_RX pin
1073   3                              // - Shift new bit into RXSHIFT
1074   3                              // - Add 1 bit time to module 0 capture registers
1075   3                              // - Increment RX state variable
1076   3                              case 1:
1077   3                              case 2:
1078   3                              case 3:
1079   3                              case 4:
1080   3                              case 5:
1081   3                              case 6:
1082   3                              case 7:
1083   3                              case 8:
1084   3                                              
1085   3                                      RXSHIFT = RXSHIFT >> 1;                         // Shift right 1 bit
1086   3                                      if (SW_RX)                                                              // If SW_RX=1, 
1087   3                                              RXSHIFT |= 0x80;                                        // shift '1' into RXSHIFT msb
1088   3                                      
1089   3                                      PCA_TEMP = (PCA0CPH0 << 8);             // Read module 0 contents into
1090   3                                      PCA_TEMP |= PCA0CPL0;                           // PCA_TEMP.
1091   3      
1092   3                                      PCA_TEMP += TIME_COUNT;                         // Add 1 bit time to PCA_TEMP
1093   3      
1094   3                                      PCA0CPL0 = PCA_TEMP;                                    // Restore PCA0CPL0 and PCA0CPH0
1095   3                                      PCA0CPH0 = (PCA_TEMP >> 8);             // with the updated value
1096   3                                      
1097   3                                      SURXST++;                                                               // Update RX state variable.
1098   3                                      break;
1099   3      
1100   3                              // State 9: 8-bits received, Capture STOP bit.
1101   3                              // - Move RXSHIFT into RDR.
1102   3                              // - Set SRI (indicate receive complete).
1103   3                              // - Prepare module 0 for next transfer.
1104   3                              // - Reset RX state variable.
1105   3                              // - Trigger IE7 if user-level interrupt support is enabled.
1106   3                              case 9:
C51 COMPILER V7.50   TERM3                                                                 04/06/2007 17:58:07 PAGE 19  

1107   3      
1108   3                                      RDR = RXSHIFT;                                                  // Move received data to receive register.
1109   3                                      SRI = 1;                                                                // Set receive complete indicator.
1110   3      
1111   3                                      PCA0CPM0 = 0x11;                                                // Switch module 0 to negative capture
1112   3                                                                                                                      // mode; interrupt enabled for START
1113   3                                                                                                                      // detection.
1114   3      
1115   3                                      SURXST = 0;                                                             // Reset RX state variable.
1116   3      
1117   3                              
1118   3                                      break;
1119   3                                      
1120   3                              }
1121   2                      }
1122   1                      
1123   1                      // Check Transmit interrupt; service if CCF1 is set.
1124   1                      else if (CCF1){ 
1125   2                              CCF1 = 0;                                                                       // Clear interrupt flag
1126   2                              switch (SUTXST){
1127   3                                      
1128   3                                      // State 0: Transmit Initiated.
1129   3                                      // Here, the user has loaded a byte to transmit into TDR, and set the
1130   3                                      // module 1 interrupt to initiate the transfer.
1131   3                                      // - Transmit START bit (drop SW_TX)
1132   3                                      // - Read PCA0, add one bit time, & store in module 1 capture registers
1133   3                                      //   for first bit.
1134   3                                      // - Increment TX state variable.
1135   3                                      case 0:
1136   3                          STXBSY = 1;                         // SW_UART TX?
1137   3                                              SW_TX = 0;                                                      // Drop TX pin as START bit.
1138   3                                              
1139   3                                              PCA_TEMP = PCA0L;                                       // Read PCA counter value into
1140   3                                              PCA_TEMP |= (PCA0H << 8);                   // PCA_TEMP.
1141   3      
1142   3                                              PCA_TEMP += TIME_COUNT;                     // Add 1 bit time.
1143   3      
1144   3                                              PCA0CPL1 = PCA_TEMP;                            // Store updated match value into
1145   3                                              PCA0CPH1 = (PCA_TEMP >> 8);     // module 1 capture/compare registers.
1146   3      
1147   3                                              PCA0CPM1 |= 0x48;                                       // Enable module 1 software timer.
1148   3      
1149   3                                              SUTXST++;                                                       // Update TX state variable.                            
1150   3                                              break;
1151   3      
1152   3                                      // States 1-9: Transmit Bit.
1153   3                                      // - Output LSB of TDR onto TX
1154   3                                      // - Shift TDR 1 bit right.
1155   3                                      // - Shift a '1' into MSB of TDR for STOP bit in State 9.
1156   3                                      // - Add 1 bit time to module 1 capture register
1157   3                                      case 1:
1158   3                                      case 2:
1159   3                                      case 3:
1160   3                                      case 4:
1161   3                                      case 5:
1162   3                                      case 6:
1163   3                                      case 7:
1164   3                                      case 8:
1165   3                                      case 9:
1166   3                                              
1167   3                                              SW_TX = (TDR & 0x01);                   // Output LSB of TDR onto SW_TX pin.
1168   3                                              TDR >>= 1;                                                      // Shift TDR right 1 bit.
C51 COMPILER V7.50   TERM3                                                                 04/06/2007 17:58:07 PAGE 20  

1169   3                                              TDR |= 0x80;                                            // Shift '1' into MSB of TDR for
1170   3                                                                                                                              // STOP bit in State 9.
1171   3      
1172   3                                              PCA_TEMP = (PCA0CPH1 << 8);     // Read module 1 contents into
1173   3                                              PCA_TEMP |= PCA0CPL1;                   // PCA_TEMP.
1174   3      
1175   3                                              PCA_TEMP += TIME_COUNT;                 // Add 1 bit time to PCA_TEMP
1176   3              
1177   3                                              PCA0CPL1 = PCA_TEMP;                            // Restore PCA0CPL1 and PCA0CPH1
1178   3                                              PCA0CPH1 = (PCA_TEMP >> 8);     // with the updated value       
1179   3      
1180   3                                              SUTXST++;                     // Update TX state variable.
1181   3                                              break;
1182   3                                              
1183   3                                      // State 10: Last bit has been transmitted.  Transmit STOP bit
1184   3                                      // and end transfer.  
1185   3                                      // - Transmit STOP bit
1186   3                                      // - Set TX Complete indicator, clear Busy flag
1187   3                                      // - Reset TX state
1188   3                                      // - Prepare module 1 for next transfer.
1189   3                                      // - Trigger IE7 interrupt if user-level interrupts enabled.
1190   3                                      case 10:
1191   3      
1192   3                                              STI = 1;                                                                // Indicate TX complete.
1193   3                                              SUTXST = 0;                                                     // Reset TX state.
1194   3                                              SW_TX = 1;                                                      // SW_TX should remain high.
1195   3      
1196   3                                              PCA0CPM1 = 0x01;                                        // Disable module 1 software timer; leave
1197   3                                                                                                                              // interrupt enabled for next transmit.                                 
1198   3                                              STXBSY = 0;                                                     // SW_UART TX free.     
1199   3                                              break;
1200   3                                      }
1201   2      }
1202   1      
1203   1      
1204   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   3124    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =    193       5
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      4    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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