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

📄 f334.lst

📁 使用单片机C8050F330对无线发射接受模块进行配置与控制,使组件成为一个无线通讯中的基站.
💻 LST
📖 第 1 页 / 共 5 页
字号:
1095   1        {
1096   2          key_pre=key_buf;
1097   2              key_press_time=0;
1098   2        }
1099   1      }
1100          
1101          
1102          void Key_process(void)
1103          {
1104   1            if ((key_work==0x55) && (key_time==0))
1105   1            {
1106   2                   key_work=0;key_time=1000; //key_zt==0  关机 key_zt==99 开机
C51 COMPILER V8.02   F334                                                                  07/13/2006 10:09:54 PAGE 19  

1107   2      
1108   2      
1109   2               if (key_zt==0)    //如果当前状态是关机状态,此时有按键信号,则开机,延时开背光
1110   2               {
1111   3                          key_zt=99;
1112   3                  S2410_PWR=0;
1113   3                  LcdBackLight_Delay_AfterS2410=1800;
1114   3                              GPS_SW=0;
1115   3                  DAC0=0x0800;
1116   3                  Control_inf(88,0,1);
1117   3               }
1118   2               else if (key_zt==99) //如果当前状态是开机状态,此时有按键信号,则判断长按,关机
1119   2               {                    //如果不长按,key_zt 不能变
1120   3                         DAC0=0x0000;
1121   3                     Control_inf(88,0,0);
1122   3               }
1123   2            }
1124   1      }
1125          
1126          void Delay_1uS(void)
1127          {
1128   1              unsigned char i;
1129   1              for(i=0;i<200;i++);
1130   1      }
1131          
1132          /***************************************************************************
1133                  ??16????BH1415H
1134          ****************************************************************************
1135          **/
1136          void send_contr_word(unsigned int Cotrdata)
1137          {
1138   1              unsigned int C_word;
1139   1              unsigned char i;
1140   1              bh_en=0;
1141   1              for(i=0;i<16;i++)
1142   1              {
1143   2                      C_word=Cotrdata&0x0001;
1144   2                      if (C_word!=0)
1145   2                      {
1146   3                              bh_clk=1;Delay_1uS();
1147   3                              bh_data=0;Delay_1uS();
1148   3                              bh_clk=0;Delay_1uS();
1149   3                      }
1150   2                      else
1151   2                      {
1152   3                              bh_clk=1;Delay_1uS();
1153   3                              bh_data=1;Delay_1uS();
1154   3                              bh_clk=0;Delay_1uS();
1155   3                      }
1156   2                      Cotrdata=_iror_(Cotrdata,1);
1157   2              }
1158   1              bh_data=1;
1159   1              bh_clk=1;
1160   1              bh_en=1;
1161   1      }
1162          /***************************************************************************
1163          
1164          ??????:??????,????1?,?????,1???
1165                  
1166          ****************************************************************************
1167          **/
1168          void Control_inf(unsigned char dx1,dx2,dx3)                     
C51 COMPILER V8.02   F334                                                                  07/13/2006 10:09:54 PAGE 20  

1169          {
1170   1              unsigned int control_data;
1171   1      
1172   1              control_data=dx1 * 10+dx2;                                                      /*?????????????????*/                                                                                   
1173   1              control_data=control_data | 0x0800;                                     /*??????????,1????*/            
1174   1              control_data=(control_data & 0xcfff);                           /*D12?D13????????,0x00*/        
1175   1              
1176   1              if(dx3)
1177   1              {
1178   2                      control_data=((control_data & 0x3fff) | 0x4000);        /*D14?D15????????,0x01*/
1179   2              }
1180   1              else control_data=control_data & 0x3fff;
1181   1              send_contr_word(control_data);                                          /*Send the Control work of 16 bit*/
1182   1      }
1183          
1184          void Variable_Init(void)
1185          {
1186   1        RecvByte=0;
1187   1        LcdBackLight_Delay_AfterS2410=0;
1188   1      
1189   1        key_press_time=0;
1190   1      
1191   1        key_zt=0;key_time=0;
1192   1      
1193   1        riqi[0]=0+0x30;riqi[1]=5+0x30;riqi[2]=0+0x30;
1194   1        riqi[3]=7+0x30;riqi[4]=2+0x30;riqi[5]=0+0x30;
1195   1        GPS_Alarm[0]=8+0x30;GPS_Alarm[1]=5+0x30;
1196   1        weixing[0]=0+0x30;weixing[1]=0+0x30;
1197   1        GPS_Current_pre=0;GPS_Current=0;
1198   1        GPS_time=0;
1199   1        GPS_Alarm_js=0;
1200   1      
1201   1        for (ii=0;ii<9;ii++)       // Longitude
1202   1        {
1203   2          Longitude[ii]=0x30;
1204   2        }
1205   1        for (ii=0;ii<10;ii++)        // Latitude
1206   1        {
1207   2          Latitude[ii]=0x30;
1208   2        }
1209   1          
1210   1        DGPS=0x30;
1211   1      
1212   1        for (ii=0;ii<4;ii++)         // HDOP
1213   1        {
1214   2          HDOP[ii]=0x30;
1215   2        }     
1216   1                      
1217   1        fm[0]=0x30;
1218   1        fm[1]=0x30;
1219   1        fm[2]=0x30;
1220   1        fmbak=0;
1221   1        
1222   1        SRI=0;
1223   1        surt_js=0;
1224   1        b_light=0x30;
1225   1      }
1226          
1227          //----------------------------------------------------------------------------
1228          //Interrupt Service Routine
1229          //----------------------------------------------------------------------------
1230          void PCA_ISR(void) interrupt 11
C51 COMPILER V8.02   F334                                                                  07/13/2006 10:09:54 PAGE 21  

1231          {
1232   1          static char SUTXST = 0;              //SW_UART TX????
1233   1              static char SURXST = 0;              //SW_UART RX????
1234   1              static unsigned RXSHIFT = 0;         //SW_UART RX?????
1235   1          unsigned int PCA_TEMP;               //??????,????PCA?????
1236   1                                                   //???
1237   1      
1238   1         // Check receive interrupt flag first; service if CCF0 is set.
1239   1              if (CCF0){
1240   2                      CCF0 = 0;                                                                               // Clear interrupt flag.
1241   2                      switch (SURXST){
1242   3                              
1243   3                              // State 0: START bit received.
1244   3                              // In this state, a negative edge on SW_TX has caused the interrupt,
1245   3                              // meaning a START has been detected and the PCA0CP0 registers have 
1246   3                              // captured the value of PCA0.
1247   3                              // - Check for receive enable and good START bit
1248   3                              // - Switch PCA module 0 to software timer mode
1249   3                              // - Add 3/2 bit time to module 0 capture registers to sample LSB.
1250   3                              // - Increment RX state variable.
1251   3                              case 0:
1252   3                                  
1253   3                                      if (SREN & ~SW_RX){                                     // Check for receive enable and a good
1254   4                                                                                                              // START bit.  
1255   4                                                                                                                                      
1256   4                                              PCA_TEMP = (PCA0CPH0 << 8);         // Read module 0 contents into
1257   4                                              PCA_TEMP |= PCA0CPL0;                   // PCA_TEMP.
1258   4      
1259   4                                              PCA_TEMP += TH_TIME_COUNT;              // Add 3/2 bit times to PCA_TEMP
1260   4      
1261   4                                              PCA0CPL0 = PCA_TEMP;                            // Restore PCA0CPL0 and PCA0CPH0
1262   4                                              PCA0CPH0 = (PCA_TEMP >> 8);     // with the updated value
1263   4      
1264   4                                              PCA0CPM0 = 0x49;                                // Change module 0 to software
1265   4                                                                                                              // timer mode, interrupts enabled.
1266   4      
1267   4                                              SURXST++;                                                       // Update RX state variable.
1268   4                              }
1269   3                                      break;
1270   3                              
1271   3                              // States 1-8: Bit Received
1272   3                              // - Sample SW_RX pin
1273   3                              // - Shift new bit into RXSHIFT
1274   3                              // - Add 1 bit time to module 0 capture registers
1275   3                              // - Increment RX state variable
1276   3                              case 1:
1277   3                              case 2:
1278   3                              case 3:
1279   3                              case 4:
1280   3                              case 5:
1281   3                              case 6:
1282   3                              case 7:
1283   3                              case 8:
1284   3                                              
1285   3                                      RXSHIFT = RXSHIFT >> 1;                         // Shift right 1 bit
1286   3                                      if (SW_RX)                                                              // If SW_RX=1, 
1287   3                                              RXSHIFT |= 0x80;                                        // shift '1' into RXSHIFT msb
1288   3                                      
1289   3                                      PCA_TEMP = (PCA0CPH0 << 8);             // Read module 0 contents into
1290   3                                      PCA_TEMP |= PCA0CPL0;                           // PCA_TEMP.
1291   3      
1292   3                                      PCA_TEMP += TIME_COUNT;                         // Add 1 bit time to PCA_TEMP
C51 COMPILER V8.02   F334                                                                  07/13/2006 10:09:54 PAGE 22  

1293   3      
1294   3                                      PCA0CPL0 = PCA_TEMP;                                    // Restore PCA0CPL0 and PCA0CPH0
1295   3                                      PCA0CPH0 = (PCA_TEMP >> 8);             // with the updated value
1296   3                                      
1297   3                                      SURXST++;                                                               // Update RX state variable.
1298   3                                      break;
1299   3      
1300   3                              // State 9: 8-bits received, Capture STOP bit.
1301   3                              // - Move RXSHIFT into RDR.
1302   3                              // - Set SRI (indicate receive complete).
1303   3                              // - Prepare module 0 for next transfer.
1304   3                              // - Reset RX state variable.
1305   3                              // - Trigger IE7 if user-level interrupt support is enabled.
1306   3                              case 9:
1307   3      
1308   3                                      RDR = RXSHIFT;                                                  // Move received data to receive register.
1309   3                                      SRI = 1;                                                                // Set receive complete indicator.
1310   3      
1311   3                                      PCA0CPM0 = 0x11;                                                // Switch module 0 to negative capture
1312   3                                                                                                                      // mode; interrupt enabled for START
1313   3                                                                                                                      // detection.
1314   3      
1315   3                                      SURXST = 0;                                                             // Reset RX state variable.
1316   3      
1317   3                              
1318   3                                      break;
1319   3                                      
1320   3                              }
1321   2                      }
1322   1                      
1323   1                      // Check Transmit interrupt; service if CCF1 is set.
1324   1                      else if (CCF1){ 
1325   2                              CCF1 = 0;                                                                       // Clear interrupt flag
1326   2                              switch (SUTXST){
1327   3                                      
1328   3                                      // State 0: Transmit Initiated.
1329   3                                      // Here, the user has loaded a byte to transmit into TDR, and set the
1330   3                                      // module 1 interrupt to initiate the transfer.
1331   3                                      // - Transmit START bit (drop SW_TX)
1332   3                                      // - Read PCA0, add one bit time, & store in module 1 capture registers
1333   3                                      //   for first bit.
1334   3                                      // - Increment TX state variable.
1335   3                                      case 0:
1336   3                          STXBSY = 1;                         // SW_UART TX?
1337   3                                              SW_TX = 0;                                                      // Drop TX pin as START bit.
1338   3                                              
1339   3                                              PCA_TEMP = PCA0L;                                       // Read PCA counter value into
1340   3                                              PCA_TEMP |= (PCA0H << 8);                   // PCA_TEMP.
1341   3      
1342   3                                              PCA_TEMP += TIME_COUNT;                     // Add 1 bit time.
1343   3      
1344   3                                              PCA0CPL1 = PCA_TEMP;                            // Store updated match value into
1345   3                                              PCA0CPH1 = (PCA_TEMP >> 8);     // module 1 capture/compare registers.
1346   3      
1347   3                                              PCA0CPM1 |= 0x48;                                       // Enable module 1 software timer.
1348   3      
1349   3                                              SUTXST++;                                                       // Update TX state variable.                            
1350   3                                              break;
1351   3      
1352   3                                      // States 1-9: Transmit Bit.
1353   3                                      // - Output LSB of TDR onto TX
1354   3                                      // - Shift TDR 1 bit right.
C51 COMPILER V8.02   F334                                                                  07/13/2006 10:09:54 PAGE 23  

1355   3                                      // - Shift a '1' into MSB of TDR for STOP bit in State 9.
1356   3                                      // - Add 1 bit time to module 1 capture register
1357   3                                      case 1:
1358   3                                      case 2:
1359   3                                      case 3:
1360   3                                      case 4:
1361   3                                      case 5:
1362   3                                      case 6:
1363   3                                      case 7:
1364   3                                      case 8:
1365 

⌨️ 快捷键说明

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