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

📄 mainloop.lst

📁 固件源代码 C52驱动编程源码学习中
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.01  MAINLOOP                                                               09/27/2003 23:46:51 PAGE 1   


C51 COMPILER V7.01, COMPILATION OF MODULE MAINLOOP
OBJECT MODULE PLACED IN mainloop.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE mainloop.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

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

  56          };
  57          
  58          
  59          
  60          /*
  61          //*************************************************************************
  62          //  Public static data
  63          //*************************************************************************
  64          */
  65          extern EPPFLAGS bEPPflags;
  66          extern unsigned long ClockTicks;
  67          
  68          extern unsigned char idata GenEpBuf[];
  69          extern IO_REQUEST idata ioRequest;
  70          
  71          extern unsigned char ioSize, ioCount;
  72          extern unsigned char xdata MainEpBuf[];
  73          extern unsigned char idata EpBuf[];
  74          //------------
  75          extern void fn_usb_isr(void);
  76          //-----------
  77          
  78          CONTROL_XFER ControlData;
  79          unsigned char bNoRAM;
  80          
  81          
  82          //==================================================
  83          /*
  84            PCON:         SMOD | - | - | - | GF1|GF0|PD |IDL|
  85            TCON:         TF1  | - |TF0| - |IE1 |IT1|IE0|IT0|
  86              
  87          */
  88          /* Configure Timer 0
  89             - Mode                  = 1
  90             - Interrupt                   = ENABLED
  91             - Clock Source                = INTERNAL
  92             - Enable Gating Control    = DISABLED
  93          */
  94          
  95          
  96          void init_timer0(void)
  97          {
  98   1              TMOD &= 0XF0;                /* clear Timer 0   */
  99   1              TMOD  |= 0X1;
 100   1              TL0 = 0X0;                   /* value set by user    */
 101   1              TH0 = 0X0;                   /* value set by user  */
 102   1              ET0 = 1;                     /* IE.1*/
 103   1              TR0 = 1;                     /* TCON.4 start timer  */
 104   1              PT0 = 1;
 105   1      
 106   1              //EA = 1;
 107   1      }
 108          
 109          
 110          void init_port()
 111          {
 112   1              P0 = 0xFF;
 113   1              P1 = 0xFF;
 114   1              P2 = 0xFF;
 115   1              P3 = 0xFF;
 116   1              MCU_D12CS = 0x0;        //D12 Select
 117   1              D12SUSPD = 0;           //D12 not in Suspend
C51 COMPILER V7.01  MAINLOOP                                                               09/27/2003 23:46:51 PAGE 3   

 118   1      }
 119          
 120          /*Serial Port */
 121          /*Mode            = 1  /8-bit UART
 122            Serial Port Interrupt    = Disabled         */
 123          /*Receive         = Enabled   */
 124          /*Auto Addressing    = Disabled   */
 125          void init_serial(void)
 126          {
 127   1              SCON = 0X52;            /* SCON: SM0|SM1|SM2|REN|TB8|RB8|TI|RI          */
 128   1              PCON = 0X80 | PCON;     /* PCON: SMOD | - | - | - | GF1|GF0|PD |IDL|    */
 129   1              TMOD = 0X20;            /* TMOD: GATE|C/T|M1|M0|GATE|C/T|M1|M0 */
 130   1              TCON = 0x69;            /* TCON: TF1|TR1|TF0|TR0|IE1|IT1|IE0|IT0 */
 131   1              TH1 = 0xF3;             /*TH1=0xF3: */
 132   1      }
 133          
 134          //=================================================================
 135          void disconnect_USB(void)
 136          {
 137   1              // Initialize D12 configuration
 138   1              D12_SetMode(D12_NOLAZYCLOCK, D12_SETTOONE | D12_CLOCK_12M);
 139   1      }
 140          
 141          void connect_USB(void)
 142          {
 143   1              // reset event flags
 144   1      
 145   1              DISABLE;
 146   1              bEPPflags.value = 0;
 147   1              ENABLE;
 148   1      
 149   1              // V2.1 enable normal+sof interrupt
 150   1              D12_SetDMA(D12_ENDP4INTENABLE | D12_ENDP5INTENABLE);
 151   1      
 152   1              // Initialize D12 configuration
 153   1      
 154   1              //D12_SetMode(D12_NOLAZYCLOCK ,D12_SETTOONE | D12_CLOCK_12M );
 155   1              D12_SetMode(D12_NOLAZYCLOCK | D12_SOFTCONNECT,D12_SETTOONE | D12_CLOCK_12M );
 156   1      
 157   1      }
 158          
 159          
 160          void reconnect_USB(void)
 161          {
 162   1              unsigned long clk_cnt;
 163   1      
 164   1              MCU_LED0 = 0;
 165   1              MCU_LED1 = 0;
 166   1      
 167   1              // Pull-down D12's SUSPEND pin
 168   1              // Disable 74HCT123 pulse generation before disconnect
 169   1              // Release D12's SUSPEND pin after receiving bus reset from host
 170   1              D12SUSPD = 0;
 171   1              disconnect_USB();
 172   1      
 173   1              printf("Wait for 1 second ...\n");
 174   1      
 175   1              clk_cnt = ClockTicks;
 176   1              while(ClockTicks < clk_cnt + 20)
 177   1                      ;
 178   1      
 179   1              connect_USB();
C51 COMPILER V7.01  MAINLOOP                                                               09/27/2003 23:46:51 PAGE 4   

 180   1      
 181   1              MCU_LED0 = 1;
 182   1              MCU_LED1 = 1;
 183   1      
 184   1      }
 185          //------------------------------
 186          void stall_ep0(void)
 187          {
 188   1              D12_SetEndpointStatus(0, 1);
 189   1              D12_SetEndpointStatus(1, 1);
 190   1      }
 191          
 192          //---------------
 193          void on_exit(void)
 194          {
 195   1       
 196   1      }
 197          //----------------------------------
 198          void check_key_LED(void)
 199          {
 200   1              static unsigned char c, last_key = 0xf;
 201   1      
 202   1              c = MCU_SWM0 & MCU_SWM1;
 203   1              c &= 0x0f;
 204   1              if (c != last_key) 
 205   1              {
 206   2                      D12_WriteEndpoint(3, 1, &c);
 207   2              }
 208   1      
 209   1              last_key = c;
 210   1      
 211   1              if(bEPPflags.bits.ep1_rxdone) 
 212   1              {
 213   2                      DISABLE;
 214   2                      bEPPflags.bits.ep1_rxdone = 0;
 215   2                      ENABLE;
 216   2                      MCU_LED0 = !(GenEpBuf[3] & 0x1);

⌨️ 快捷键说明

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