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

📄 usbmouse.lst

📁 USB Mouse
💻 LST
📖 第 1 页 / 共 5 页
字号:
1038   5                      default: break;      
1039   5                         }
1040   4                       break;
1041   4                       
1042   4                       case 3: //其它接收者
1043   4                        switch (Control_Data.DeviceRequest.bRequest)
1044   4                         {
1045   5                      default: break;      
C51 COMPILER V7.06   USBMOUSE                                                              12/10/2007 14:20:43 PAGE 18  

1046   5                         }break;
1047   4                                        
1048   4                       default: break;
1049   4                  }      
1050   3                 break;
1051   3      
1052   3             case 0x40:  //用户请求
1053   3                 Prints("USB用户请求.\r\n");
1054   3                 switch(Control_Data.DeviceRequest.bmRequestType&0x1F)
1055   3                  {
1056   4                       case 0:    //接收者为设备
1057   4                   switch (Control_Data.DeviceRequest.bRequest)
1058   4                    {                           
1059   5                         default: break;
1060   5                        }
1061   4                       break;
1062   4                       
1063   4                       case 1:   //接收者为接口
1064   4                    switch (Control_Data.DeviceRequest.bRequest)
1065   4                         {
1066   5                          default: break;
1067   5                      }
1068   4                   break;
1069   4                       
1070   4                       case 2:   //接收者为端点
1071   4                        switch (Control_Data.DeviceRequest.bRequest)
1072   4                         {
1073   5                      default: break;      
1074   5                         }
1075   4                       break;
1076   4                       
1077   4                       case 3: //其它接收者
1078   4                        switch (Control_Data.DeviceRequest.bRequest)
1079   4                         {
1080   5                      default: break;      
1081   5                         }               
1082   4                       break;
1083   4                                        
1084   4                       default: break;
1085   4                  }
1086   3              }
1087   2        }
1088   1      }
1089          /******************************************************************************/
1090          
1091          /**********************端点1输出***********************************************/
1092          /*void endp1_out(void)
1093          {
1094           Prints("端点1输出.\r\n");
1095          }*/
1096          /******************************************************************************/
1097          
1098          /*************************端点1输入*****************************************/
1099          /*void endp1_in(void)
1100          {
1101           Prints("端点1输入.\r\n");
1102          }*/
1103          /******************************************************************************/
1104          
1105          /***************************端点2输出****************************************/
1106          void endp2_out(void)
1107          {
C51 COMPILER V7.06   USBMOUSE                                                              12/10/2007 14:20:43 PAGE 19  

1108   1       uint8 i,j;
1109   1      
1110   1       j=read_endpoint_buff(4,64,buffer);
1111   1       P2=~buffer[0];
1112   1       Prints("端点2输出.\r\n");
1113   1       Prints("    端点2的数据是  ");
1114   1       for(i=0;i<j;i++)
1115   1        {
1116   2         PrintHex(buffer[i]);
1117   2         if(i==16)Prints("\r\n");
1118   2        }
1119   1       Prints("\r\n");
1120   1      }
1121          /******************************************************************************/
1122          
1123          
1124          //用来返回数据的缓冲
1125          uint8 idata InBuffer[64];
1126          
1127          /****************************主端点输入处理************************************/
1128          void endp2_in(void)                                      
1129          {
1130   1       uint8 i;
1131   1       
1132   1      // Prints("端点2输入.\r\n");
1133   1       for(i=0;i<4;i++)
1134   1        {
1135   2         InBuffer[i]=0;
1136   2        }
1137   1       KeyCanChange=0;  //禁止修改按键值
1138   1        
1139   1       if((KeyPress&(~0xC0))||(KeyUp&0xC0)||KeyDown&0xC0) //如果有按键按住或者有按键值变化
1140   1       {
1141   2        KeyUp=0;
1142   2        KeyDown=0;
1143   2        if(KeyPress&KEY1)  //往左移(X减小)
1144   2        {
1145   3         InBuffer[1]=-1;
1146   3        }
1147   2        else
1148   2        {
1149   3        }
1150   2        
1151   2        if(KeyPress&KEY2)   //往右移(X轴增加)
1152   2        {
1153   3         InBuffer[1]=1;
1154   3        }
1155   2        else
1156   2        {
1157   3        }  
1158   2        
1159   2        if(KeyPress&KEY3)  //往上移(Y减小)
1160   2        {
1161   3         InBuffer[2]=-1;
1162   3        }
1163   2        else
1164   2        {
1165   3        }
1166   2      
1167   2        if(KeyPress&KEY4)  //向下移(Y轴增加)
1168   2        {
1169   3         InBuffer[2]=1;
C51 COMPILER V7.06   USBMOUSE                                                              12/10/2007 14:20:43 PAGE 20  

1170   3        }
1171   2        else
1172   2        {
1173   3        }  
1174   2       
1175   2        if(KeyPress&KEY5)  //滚轮下滚
1176   2        {
1177   3         InBuffer[3]=-1;
1178   3        }
1179   2        else
1180   2        {
1181   3        }
1182   2      
1183   2        if(KeyPress&KEY6)  //滚轮上滚
1184   2        {
1185   3         InBuffer[3]=1;
1186   3        }
1187   2        else
1188   2        {
1189   3        }
1190   2        
1191   2        if(KeyPress&KEY7) //左键
1192   2        {
1193   3         InBuffer[0]|=0x01;
1194   3        }
1195   2        else
1196   2        {
1197   3        }
1198   2          
1199   2        if(KeyPress&KEY8)
1200   2        {
1201   3         InBuffer[0]|=0x02;  //右键
1202   3        }
1203   2        else
1204   2        {
1205   3        }
1206   2      /*
1207   2      //EDN USB板键盘不够,没有中键  
1208   2        if(KeyMapOk&(1<<1))   //中键
1209   2        {
1210   2         InBuffer[0]|=0x04;
1211   2        }
1212   2        else
1213   2        {
1214   2        }
1215   2      */
1216   2      
1217   2       //返回4个字节数据
1218   2       write_endpoint_buff(5,4,InBuffer);
1219   2       }
1220   1       else //如果无按键按下或者按键动作,则不返回数据
1221   1       {
1222   2       }
1223   1       KeyCanChange=1; //允许修改按键值
1224   1      }
1225          /******************************************************************************/
1226          
1227          code uint8 HeadTable[][74]={
1228          "********************************************************************\r\n",
1229          "******                 EDN USB学习板鼠标程序                  ******\r\n",
1230          "******                      AT89S52 CPU                       ******\r\n",
1231          "******                  建立日期:",__DATE__,"                 ******\r\n",
C51 COMPILER V7.06   USBMOUSE                                                              12/10/2007 14:20:43 PAGE 21  

1232          "******                   建立时间:",__TIME__,"                   ******\r\n",
1233          "******                    作者:电脑圈圈                      ******\r\n",
1234          "******                    欢迎访问作者的                      ******\r\n",
1235          "******           USB专区:http://group.ednchina.com/93/       ******\r\n",
1236          "******      BLOG1:http://www.ednchina.com/blog/computer00    ******\r\n",
1237          "******                BLOG2:http://computer00.21ic.org       ******\r\n",
1238          "******                  请按K1-K8分别进行测试                 ******\r\n",
1239          "******    K1:鼠标左移  K2:鼠标右移  K3:鼠标上移  K4:鼠标下移  ******\r\n",
1240          "******    K5:滚轮下滚  K6:滚轮上滚  K7:左鼠标键 K8:鼠标右键   ******\r\n",
1241          "********************************************************************\r\n",
1242          };
1243          
1244          /***************************主函数**********************************************/
1245          void main(void)
1246          {
1247   1       uint8 i;
1248   1       InitUART();  //串口初始化
1249   1       Printc(0x0c);  //清屏
1250   1       Printc(0x0c);
1251   1       Prints("系统启动.\r\n");
1252   1       for(i=0;i<18;i++)        //显示信息
1253   1       {
1254   2        Prints(HeadTable[i]);
1255   2       }
1256   1       disconnect_usb();         //断开USB连接
1257   1       delay(1000);          //延迟 
1258   1       init_usb();               //初始化USB芯片
1259   1       connect_usb();            //连接USB
1260   1       InitKeyboard();       //
1261   1       KeyCanChange=1;
1262   1      
1263   1       while(1)
1264   1        {
1265   2         LEDs=~KeyPress;
1266   2         if(!USB_INT)         //中断产生
1267   2          {
1268   3               read_interrupt_register();
1269   3               if(Interrupt_Register.Interrupt.bus_reset){usb_bus_reset();continue;}
1270   3               if(Interrupt_Register.Interrupt.suspend_change){usb_bus_suspend();continue;}
1271   3           if(Interrupt_Register.Interrupt.control_out_port){endp0_out();continue;}
1272   3               if(Interrupt_Register.Interrupt.control_in_port&&usb_flags.flags.usb_endp0_in){endp0_in();continue;}
1273   3      //       if(Interrupt_Register.Interrupt.port_out_1)endp1_out();
1274   3      //       if(Interrupt_Register.Interrupt.port_in_1)endp1_in();
1275   3               if(Interrupt_Register.Interrupt.main_out_port){endp2_out();}
1276   3               if(Interrupt_Register.Interrupt.main_in_port){endp2_in();}
1277   3          }
1278   2        }
1279   1      }
1280          /******************************************************************************/


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   2655    ----
   CONSTANT SIZE    =   2450    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     41      16
   IDATA SIZE       =    128    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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