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

📄 usbkeyboard.lst

📁 EDN USB学习板之实战第一个USB程序: USB键盘
💻 LST
📖 第 1 页 / 共 5 页
字号:
1022   4                   switch (Control_Data.DeviceRequest.bRequest)
1023   4                    {                           
1024   5                         default: break;
1025   5                        }
1026   4                       break;
1027   4      
1028   4                       case 1:   //接收者为接口
1029   4                    switch (Control_Data.DeviceRequest.bRequest)
1030   4                         {
1031   5                  case   SET_REPORT: set_report();   break; //设置报告
1032   5                  case     SET_IDLE: set_idle();     break; //设置空闲
1033   5                  case SET_PROTOCOL: set_protocol(); break; //设置协议
1034   5                          default: break;
1035   5                      }
1036   4                       
1037   4                       break;
1038   4      
1039   4                       case 2:   //接收者为端点
1040   4                        switch (Control_Data.DeviceRequest.bRequest)
1041   4                         {
1042   5                      default: break;      
1043   5                         }
1044   4                       break;
1045   4                       
C51 COMPILER V8.02   USBKEYBOARD                                                           12/12/2007 21:37:17 PAGE 18  

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

1108          
1109          /***************************端点2输出****************************************/
1110          void endp2_out(void)
1111          {
1112   1       uint8 i,j;
1113   1      
1114   1       j=read_endpoint_buff(4,64,buffer);
1115   1       LEDs=~buffer[0];
1116   1       Prints("端点2输出.\r\n");
1117   1       Prints("    端点2的数据是  ");
1118   1       for(i=0;i<j;i++)
1119   1        {
1120   2         PrintHex(buffer[i]);
1121   2         if(i==16)Prints("\r\n");
1122   2        }
1123   1       Prints("\r\n");
1124   1      }
1125          /******************************************************************************/
1126          
1127          
1128          //用来返回数据的缓冲
1129          uint8 idata InBuffer[64];
1130          
1131          /****************************主端点输入处理************************************/
1132          void endp2_in(void)                                      
1133          {
1134   1       uint8 i;
1135   1      // Prints("端点2输入.\r\n");
1136   1       KeyCanChange=0;  //禁止修改按键值 
1137   1       if(KeyPress) //如果有按键按下
1138   1        {
1139   2         if(KeyPress&(KEY1)) //左Ctrl键
1140   2          {
1141   3           InBuffer[0] |=1;
1142   3          }
1143   2         else
1144   2          {
1145   3           InBuffer[0]&=~1;
1146   3          }   
1147   2         if(KeyPress&(KEY2)) //左shift键
1148   2          {
1149   3           InBuffer[0]|=1<<1;
1150   3          }
1151   2         else
1152   2          {
1153   3           InBuffer[0]&=~(1<<1);
1154   3          }
1155   2              
1156   2         if(KeyPress&(KEY3)) //左ALT键
1157   2          {
1158   3           InBuffer[0]|=1<<2;
1159   3          }
1160   2         else
1161   2          {
1162   3               InBuffer[0]&=~(1<<2);
1163   3              }
1164   2      
1165   2         i=2;
1166   2         if(KeyPress&(KEY4))
1167   2          {
1168   3           InBuffer[i++]=0x62;            //0键
1169   3          }
C51 COMPILER V8.02   USBKEYBOARD                                                           12/12/2007 21:37:17 PAGE 20  

1170   2         if(KeyPress&(KEY5))
1171   2          {
1172   3               InBuffer[i++]=0x59;        //1键
1173   3              }
1174   2         if(KeyPress&(KEY6))
1175   2          {
1176   3           InBuffer[i++]=0x5A;            //2键
1177   3          }
1178   2         if(KeyPress&(KEY7))
1179   2          {
1180   3           InBuffer[i++]=0x39;            //Caps Lock键
1181   3          }
1182   2         if(KeyPress&(KEY8))
1183   2          {
1184   3           InBuffer[i++]=0x53;            //Num Lock键
1185   3          }
1186   2         for(;i<8;i++)
1187   2         {
1188   3          InBuffer[i]=0;  //多余的清0
1189   3         }
1190   2        }
1191   1       else //如果无按键按下,则返回0
1192   1        {
1193   2         for(i=0;i<8;i++)
1194   2          {
1195   3               InBuffer[i]=0;
1196   3              }
1197   2        }
1198   1       if(KeyUp||KeyDown)
1199   1       {
1200   2        //返回8个字节数据
1201   2        KeyUp=0;
1202   2        KeyDown=0;
1203   2        write_endpoint_buff(5,8,InBuffer);
1204   2       }
1205   1       KeyCanChange=1; //允许修改按键值
1206   1      }
1207          /******************************************************************************/
1208          
1209          code uint8 HeadTable[][74]={
1210          "********************************************************************\r\n",
1211          "******                 EDN USB学习板键盘程序                  ******\r\n",
1212          "******                      AT89S52 CPU                       ******\r\n",
1213          "******                  建立日期:",__DATE__,"                 ******\r\n",
1214          "******                   建立时间:",__TIME__,"                   ******\r\n",
1215          "******                    作者:电脑圈圈                      ******\r\n",
1216          "******                    欢迎访问作者的                      ******\r\n",
1217          "******           USB专区:http://group.ednchina.com/93/       ******\r\n",
1218          "******      BLOG1:http://www.ednchina.com/blog/computer00    ******\r\n",
1219          "******                BLOG2:http://computer00.21ic.org       ******\r\n",
1220          "******                  请按K1-K8分别进行测试                 ******\r\n",
1221          "******       K1:左Ctrl键  K2:左Shift键  K3:左Alt键  K4:0键    ******\r\n",
1222          "******       K5:1键  K6:2键  K7:Caps Lock键 K8:Num Lock键     ******\r\n",
1223          "********************************************************************\r\n",
1224          };
1225          
1226          
1227          
1228          /***************************主函数**********************************************/
1229          void main(void)
1230          {
1231   1       uint8 i;
C51 COMPILER V8.02   USBKEYBOARD                                                           12/12/2007 21:37:17 PAGE 21  

1232   1       InitUART();  //串口初始化
1233   1       Printc(0x0c);  //清屏
1234   1       Printc(0x0c);
1235   1       Prints("系统启动.\r\n");
1236   1       for(i=0;i<18;i++)        //显示信息
1237   1       {
1238   2        Prints(HeadTable[i]);
1239   2       } 
1240   1       disconnect_usb();         //断开USB连接
1241   1       delay(1000);          //延迟
1242   1       init_usb();               //初始化USB芯片
1243   1       connect_usb();            //连接USB
1244   1       InitKeyboard();       //
1245   1      
1246   1       while(1)
1247   1        { 
1248   2         if(!USB_INT)         //中断产生
1249   2          {
1250   3               read_interrupt_register();
1251   3               if(Interrupt_Register.Interrupt.bus_reset){usb_bus_reset();continue;}
1252   3               if(Interrupt_Register.Interrupt.suspend_change){usb_bus_suspend();continue;}
1253   3           if(Interrupt_Register.Interrupt.control_out_port){endp0_out();continue;}
1254   3               if(Interrupt_Register.Interrupt.control_in_port&&usb_flags.flags.usb_endp0_in){endp0_in();continue;}
1255   3      //       if(Interrupt_Register.Interrupt.port_out_1)endp1_out();
1256   3      //       if(Interrupt_Register.Interrupt.port_in_1)endp1_in();
1257   3               if(Interrupt_Register.Interrupt.main_out_port){endp2_out();}
1258   3               if(Interrupt_Register.Interrupt.main_in_port){endp2_in();}
1259   3          }
1260   2        }
1261   1      }
1262          /******************************************************************************/


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   2758    ----
   CONSTANT SIZE    =   2516    ----
   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 + -