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

📄 mainloop.lst

📁 基于C51和PDIUSBD12USB接口芯片的USB通信固件设计源程序代码
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.01  MAINLOOP                                                               08/18/2003 08:43:22 PAGE 1   


C51 COMPILER V7.01, COMPILATION OF MODULE MAINLOOP
OBJECT MODULE PLACED IN Mainloop.OBJ
COMPILER INVOKED BY: C:\Keil7.0\C51\BIN\C51.EXE Mainloop.c OPTIMIZE(2,SPEED) DEBUG OBJECTEXTEND TABS(6)

stmt level    source

   1          #include <stdio.h>
   2          #include <string.h>
   3          
   4          #include <reg51.h>                /* special function register declarations   */
   5          
   6          #include "epphal.h"
   7          #include "d12ci.h"
   8          #include "mainloop.h"
   9          #include "usb100.h"
  10          #include "chap_9.h"
  11          #include "protodma.h"
  12          /*
  13          //*************************************************************************
  14          // USB protocol function pointer arrays
  15          //*************************************************************************
  16          */
  17          
  18          
  19          //USB标准请求
  20          code void (*StandardDeviceRequest[])(void) =
  21          {
  22                get_status,
  23                clear_feature,
  24                reserved,
  25                set_feature,
  26                reserved,
  27                set_address,
  28                get_descriptor,
  29                reserved,
  30                get_configuration,
  31                set_configuration,
  32                get_interface,
  33                set_interface,
  34                reserved,
  35                reserved,
  36                reserved,
  37                reserved
  38          };
  39          
  40          //用户厂商请求
  41          code void (*VendorDeviceRequest[])(void) =
  42          {
  43                reserved,
  44                reserved,
  45                reserved,
  46                reserved,
  47                reserved,
  48                reserved,
  49                reserved,
  50                reserved,
  51                reserved,
  52                reserved,
  53                reserved,
  54                reserved,
  55                read_write_register,
C51 COMPILER V7.01  MAINLOOP                                                               08/18/2003 08:43:22 PAGE 2   

  56                reserved,
  57                reserved,
  58                reserved
  59          };
  60          
  61          /*
  62          //*************************************************************************
  63          //  Public static data
  64          //*************************************************************************
  65          */
  66          
  67          extern EPPFLAGS bEPPflags;
  68          extern unsigned long ClockTicks;
  69          extern unsigned char idata GenEpBuf[];
  70          extern IO_REQUEST idata ioRequest;
  71          
  72          extern unsigned char ioSize, ioCount;
  73          extern unsigned char idata EpBuf[];
  74          
  75          CONTROL_XFER ControlData;
  76          BOOL bNoRAM;
  77          
  78          code char * _NAME_USB_REQUEST_DIRECTION[] =
  79          {
  80          "Host_to_device",
  81          "Device_to_host"
  82          };
  83          
  84          code char * _NAME_USB_REQUEST_RECIPIENT[] =
  85          {
  86          "Device",
  87          "Interface",
  88          "Endpoint(0)",
  89          "Other"
  90          };
  91          
  92          code char * _NAME_USB_REQUEST_TYPE[] =
  93          {
  94          "Standard",
  95          "Class",
  96          "Vendor",
  97          "Reserved"
  98          };
  99          
 100          code char * _NAME_USB_STANDARD_REQUEST[] =
 101          {
 102          "GET_STATUS",
 103          "CLEAR_FEATURE",
 104          "RESERVED",
 105          "SET_FEATURE",
 106          "RESERVED",
 107          "SET_ADDRESS",
 108          "GET_DESCRIPTOR",
 109          "SET_DESCRIPTOR",
 110          "GET_CONFIGURATION",
 111          "SET_CONFIGURATION",
 112          "GET_INTERFACE",
 113          "SET_INTERFACE",
 114          "SYNC_FRAME"
 115          };
 116          
 117          
C51 COMPILER V7.01  MAINLOOP                                                               08/18/2003 08:43:22 PAGE 3   

 118          void help_devreq(unsigned char typ, unsigned char req)
 119          {
 120   1            typ >>= 5;
 121   1      
 122   1            if(typ == USB_STANDARD_REQUEST) {
 123   2            }
 124   1            else {
 125   2                  if(bEPPflags.bits.verbose)
 126   2                        printf("Request Type = %s, bRequest = 0x%bx.\n", _NAME_USB_REQUEST_TYPE[typ],
 127   2                              req);
 128   2            }
 129   1      }
 130          
 131          /* Configure Timer 0
 132             - Mode                  = 1
 133             - Interrupt                   = ENABLED
 134             - Clock Source                = INTERNAL
 135             - Enable Gating Control    = DISABLED
 136          */
 137          //定时器0初始化程序
 138          //定时器用来定时检测按键状态
 139          void init_timer0(void)
 140          {
 141   1            TMOD &= 0XF0;                    /* clear Timer 0   */
 142   1            TMOD  |= 0X1;
 143   1            TL0 = 0X0;                   /* value set by user    */
 144   1            TH0 = 0X0;                  /* value set by user  */
 145   1            ET0 = 1;                  /* IE.1*/
 146   1            TR0 = 1;                /* TCON.4 start timer  */
 147   1            PT0 = 1;
 148   1      
 149   1            EA = 1;
 150   1      }
 151          
 152          /* Interrupt Control Unit */
 153          /*   ****  Enabled interrupts in Interrupt Enable Register ****
 154                 ****  GLOBAL INTERRUPT MUST BE ENABLED FOR ANY OTHER
 155                 ****  INTERRUPT TO WORK!
 156          */
 157          /*                  GLOBAL INTERRUPT DISABLED ALL INTERRUPTS
 158                                        ARE DISABLED          */
 159          /*                    External interrupt 0      */
 160          /*                        Priority Level = 0    */
 161          /*                        Timer 0 interrupt     */
 162          /*                       Priority Level = 0     */
 163          //中断设置
 164          void init_special_interrupts(void)
 165          {
 166   1            IT0 = 0;
 167   1            EX0 = 1;
 168   1            PX0 = 0;
 169   1      }
 170          
 171          //I/O口初始化程序
 172          void init_port()
 173          {
 174   1            P0 = 0xFF;
 175   1            P1 = 0xFF;
 176   1            P2 = 0xFF;
 177   1            P3 = 0xFF;
 178   1            MCU_D12CS = 0x0;
 179   1            D12SUSPD = 0;
C51 COMPILER V7.01  MAINLOOP                                                               08/18/2003 08:43:22 PAGE 4   

 180   1      }
 181          
 182          /*Serial Port */
 183          /*Mode            = 1  /8-bit UART
 184            Serial Port Interrupt    = Disabled         */
 185          /*Receive         = Enabled   */
 186          /*Auto Addressing    = Disabled   */
 187          //串行口设置
 188          void init_serial(void)
 189          {
 190   1            SCON = 0X52;
 191   1            PCON = 0X80 | PCON;
 192   1            TMOD = 0X20;
 193   1            TCON = 0x69;    // TCON 
 194   1            TH1 = 0xF3;
 195   1      }
 196          
 197          
 198          void main(void)
 199          {
 200   1            unsigned char key, i;
 201   1      
 202   1            init_port();//初始化I/O口
 203   1            init_serial();//初始化串行口
 204   1            //注:串行口是用来外扩LCD和键盘,用于查询显示当前的工作状态
 205   1            //在USB Smart Board标准配置中并未带该LCD和键盘,这里给出的程序仅供参考
 206   1      
 207   1            init_timer0();//初始化定时器0
 208   1            init_special_interrupts();//设置中断
 209   1      
 210   1            MCU_D12CS = 0x1;
 211   1            
 212   1            MCU_D12CS = 0x0;
 213   1      
 214   1            D12_ReadChipID();
 215   1      
 216   1            if(MCU_SWM0 == 0 && MCU_SWM1 == 0) {
 217   2                  MCU_D12RST = 0;//DMA设置
 218   2                  MCU_D12RST = 1;
 219   2                  D12_SetDMA(0x0);
 220   2            }
 221   1      
 222   1            bEPPflags.value = 0;
 223   1            reconnect_USB();//重新连接USB
 224   1      /*
 225   1            if((i = D12_GetDMA()) == 0xC3) {
 226   1                  D12_SendResume();//发送恢复处理
 227   1            }
 228   1            else {
 229   1                  bEPPflags.value = 0;
 230   1                  reconnect_USB();//重新连接USB
 231   1            }
 232   1      */
 233   1            /* Main program loop */
 234   1      
 235   1            while( TRUE ){
 236   2      
 237   2                  if (bEPPflags.bits.timer){
 238   3                        DISABLE;//定时器溢出,检测按键状态
 239   3                        bEPPflags.bits.timer = 0;
 240   3                        ENABLE;
 241   3      
C51 COMPILER V7.01  MAINLOOP                                                               08/18/2003 08:43:22 PAGE 5   

 242   3                        if(bEPPflags.bits.configuration)//设备未配置返回
 243   3                              check_key_LED();
 244   3                  }
 245   2      
 246   2                  if(RI) {
 247   3                        key = _getkey();//按键输入
 248   3                        switch(key) {//显示查询状态
 249   4                              case 'i':
 250   4                                    if(bEPPflags.bits.control_state == USB_IDLE)
 251   4                                          printf("Control state = USB_IDLE.");
 252   4                                    else if(bEPPflags.bits.control_state == USB_RECEIVE)
 253   4                                          printf("Control state = USB_RECEIVE.");
 254   4                                    else if(bEPPflags.bits.control_state == USB_TRANSMIT)
 255   4                                          printf("Control state = USB_TRANSMIT.");
 256   4                                    printf(" ControlData.wCount = %x.\n", ControlData.wCount);
 257   4                                    printf("Endpoint 4 (Bulk Out) Status = %bx, Endpoint 5 (Bulk In) Status = %bx.\n",
 258   4                                       D12_ReadEndpointStatus(4), D12_ReadEndpointStatus(5));
 259   4                                    if(bEPPflags.bits.dma_state == DMA_IDLE)
 260   4                                          printf("DMA_State = DMA_IDLE.\n");

⌨️ 快捷键说明

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