main.LST
上传用户:lyfy_2008
上传日期:2014-07-13
资源大小:3016k
文件大小:15k
- C51 COMPILER V7.02b MAIN 09/28/2006 22:04:34 PAGE 1
- C51 COMPILER V7.02b, COMPILATION OF MODULE MAIN
- OBJECT MODULE PLACED IN main.OBJ
- COMPILER INVOKED BY: C:KeilC51BINC51.EXE main.c BROWSE DEBUG OBJECTEXTEND
- stmt level source
- 1 //#include <stdio.h>
- 2 #include <string.h>
- 3 #include <reg51.h> /* special function register declarations */
- 4
- 5 //#include "epphal.h"
- 6 #include "d12ci.h"
- 7 #include "mainloop.h"
- 8 #include "usb100.h"
- 9 #include "chap_9.h"
- 10 //#include "protodma.h"
- 11 #include"address.h"
- 12 //#include"2-16.h"
- 13 //#include"24C00.H"
- 14
- 15
- 16 /*
- 17 //*************************************************************************
- 18 // USB protocol function pointer arrays
- 19 //*************************************************************************
- 20 */
- 21
- 22 #define uchar unsigned char
- 23 unsigned char code Tab[]=
- 24 { //数码管数据0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
- 25 0x12,0x9F,0x31,0x15,0x9C,0x54,0x50,0x1F,
- 26 0x10,0x14,0x18,0xD0,0x72,0x91,0x70,0x78
- 27 };
- 28 void send(uchar buf1,uchar buf2); //数码管显示程序
- 29 void EndpointII();//处理 2*16LCD和IIC
- 30 //USB标准请求
- 31 code void (*StandardDeviceRequest[])(void) =
- 32 {
- 33 get_status,
- 34 clear_feature,
- 35 reserved,
- 36 set_feature,
- 37 reserved,
- 38 set_address,
- 39 get_descriptor,
- 40 reserved,
- 41 get_configuration,
- 42 set_configuration,
- 43 get_interface,
- 44 set_interface,
- 45 reserved,
- 46 reserved,
- 47 reserved,
- 48 reserved
- 49 };
- 50
- 51 //用户厂商请求
- 52 code void (*VendorDeviceRequest[])(void) =
- 53 {
- 54 reserved,
- 55 reserved,
- C51 COMPILER V7.02b MAIN 09/28/2006 22:04:34 PAGE 2
- 56 reserved,
- 57 reserved,
- 58 reserved,
- 59 reserved,
- 60 reserved,
- 61 reserved,
- 62 reserved,
- 63 reserved,
- 64 reserved,
- 65 reserved,
- 66 reserved,
- 67 reserved,
- 68 reserved,
- 69 reserved
- 70 };
- 71
- 72 /*
- 73 //*************************************************************************
- 74 // Public static data
- 75 //*************************************************************************
- 76 */
- 77
- 78 extern EPPFLAGS bEPPflags;
- 79 extern unsigned long ClockTicks;
- 80 extern unsigned char idata GenEpBuf[];
- 81 extern IO_REQUEST idata ioRequest;
- 82
- 83 extern unsigned char ioSize, ioCount;
- 84 extern unsigned char idata EpBuf[];
- 85 extern unsigned char idata mainbuflen;
- 86
- 87 CONTROL_XFER ControlData;
- 88 BOOL bNoRAM;
- 89
- 90 //定时器0初始化程序
- 91 //定时器用来定时检测按键状态
- 92 void init_timer0(void)
- 93 {
- 94 1 TMOD &= 0XF0; /* clear Timer 0 */
- 95 1 TMOD |= 0X1;
- 96 1 TL0 = 0X0; /* value set by user */
- 97 1 TH0 = 0X0; /* value set by user */
- 98 1 ET0 = 1; /* IE.1*/
- 99 1 TR0 = 1; /* TCON.4 start timer */
- 100 1 PT0 = 1;
- 101 1
- 102 1 EA = 1;
- 103 1 }
- 104
- 105 //中断设置
- 106 void init_special_interrupts(void)
- 107 {
- 108 1 IT1 = 0;
- 109 1 EX1 = 1;
- 110 1 PX1 = 0;
- 111 1 }
- 112
- 113 //I/O口初始化程序
- 114 void init_port()
- 115 {
- 116 1 P0 = 0xFF;
- 117 1 P1 = 0xFF;
- C51 COMPILER V7.02b MAIN 09/28/2006 22:04:34 PAGE 3
- 118 1 P2 = 0xFF;
- 119 1 P3 = 0xFF;
- 120 1 }
- 121 void init()
- 122 {
- 123 1 send(0xff,0xff);//数码管关
- 124 1 LEDDATA=0x00;//LED关
- 125 1
- 126 1 }
- 127 void main(void)
- 128 {
- 129 1 init_port();//初始化I/O口
- 130 1 // initlcd();
- 131 1 // printscreen("Hello!!" ,"Wellcome to USB");
- 132 1 init_timer0();//初始化定时器0
- 133 1 init_special_interrupts();//设置中断
- 134 1 init();
- 135 1 bEPPflags.value = 0;
- 136 1 reconnect_USB();//重新连接USB
- 137 1 /* Main program loop */
- 138 1
- 139 1 while( TRUE )
- 140 1 {
- 141 2
- 142 2 if (bEPPflags.bits.timer)
- 143 2 {
- 144 3 DISABLE;//定时器溢出,检测按键状态
- 145 3 bEPPflags.bits.timer = 0;
- 146 3 ENABLE;
- 147 3
- 148 3 if(bEPPflags.bits.configuration)//设备未配置返回
- 149 3 check_key_LED(); //检测键盘
- 150 3 }
- 151 2
- 152 2
- 153 2 if (bEPPflags.bits.bus_reset)
- 154 2 {//设备复位处理
- 155 3 DISABLE;
- 156 3 bEPPflags.bits.bus_reset = 0;
- 157 3 ENABLE;
- 158 3
- 159 3 } // if bus reset
- 160 2
- 161 2 if(bEPPflags.bits.ep1_rxdone) //端点1输出
- 162 2 { //控制LED/数码管/
- 163 3 /*
- 164 3 GenEpBuf[0] 操作对象
- 165 3 1 LED
- 166 3 2 数码管
- 167 3 3 锋鸣器
- 168 3 0x55 读IIC
- 169 3 */
- 170 3 DISABLE;
- 171 3 bEPPflags.bits.ep1_rxdone=0;
- 172 3 ENABLE;
- 173 3 if(GenEpBuf[0]==1) P1 = GenEpBuf[1]; //LEDDATA=GenEpBuf[1];
- 174 3 if(GenEpBuf[0]==2)send(Tab[GenEpBuf[1]],Tab[GenEpBuf[2]]);
- 175 3 if(GenEpBuf[0]==3)BEEB=GenEpBuf[1]&0x01;
- 176 3 if(GenEpBuf[0]==0x55)
- 177 3 {
- 178 4 // Read24c02_nByte(GenEpBuf[1],10,EpBuf) ;
- 179 4 D12_WriteEndpoint(5, 10, EpBuf);
- C51 COMPILER V7.02b MAIN 09/28/2006 22:04:34 PAGE 4
- 180 4 }
- 181 3 GenEpBuf[0]=0;
- 182 3
- 183 3 }
- 184 2
- 185 2
- 186 2 if (bEPPflags.bits.setup_packet)
- 187 2 {//Setup包处理
- 188 3 DISABLE;
- 189 3 bEPPflags.bits.setup_packet = 0;
- 190 3 ENABLE;
- 191 3 control_handler();//调用请求处理子程序
- 192 3 } // if setup_packet
- 193 2
- 194 2 if(bEPPflags.bits.main_rxdone) //端点2输出
- 195 2 {
- 196 3 DISABLE;
- 197 3 bEPPflags.bits.main_rxdone=0;
- 198 3 ENABLE;
- 199 3 EndpointII();//操作LCD和I2C
- 200 3 } //if main_rxdone
- 201 2 } // Main Loop
- 202 1 }
- 203
- 204 //返回stall应答
- 205 void stall_ep0(void)
- 206 {
- 207 1 D12_SetEndpointStatus(0, 1);
- 208 1 D12_SetEndpointStatus(1, 1);
- 209 1 }
- 210
- 211 //断开USB总线
- 212 void disconnect_USB(void)
- 213 {
- 214 1 // Initialize D12 configuration
- 215 1 D12_SetMode(D12_NOLAZYCLOCK, D12_SETTOONE | D12_CLOCK_12M);
- 216 1 }
- 217
- 218 //连接USB总线
- 219 void connect_USB(void)
- 220 {
- 221 1 // reset event flags
- 222 1 DISABLE;
- 223 1 bEPPflags.value = 0;//清除所有状态
- 224 1 ENABLE;
- 225 1
- 226 1 // V2.1 enable normal+sof interrupt
- 227 1 D12_SetDMA(D12_ENDP4INTENABLE | D12_ENDP5INTENABLE);
- 228 1
- 229 1 // Initialize D12 configuration
- 230 1 D12_SetMode(D12_NOLAZYCLOCK|D12_SOFTCONNECT, D12_SETTOONE | D12_CLOCK_12M);
- 231 1 }
- 232
- 233 //重新连接到USB总线
- 234 void reconnect_USB(void)
- 235 {
- 236 1 unsigned long clk_cnt;
- 237 1 disconnect_USB();
- 238 1 clk_cnt = ClockTicks;
- 239 1 while(ClockTicks < clk_cnt + 20);
- 240 1 connect_USB();
- 241 1 }
- C51 COMPILER V7.02b MAIN 09/28/2006 22:04:34 PAGE 5
- 242
- 243 //恢复到未配置状态
- 244 void init_unconfig(void)
- 245 {
- 246 1 D12_SetEndpointEnable(0); /* Disable all endpoints but EPP0. */
- 247 1 }
- 248
- 249 //设置配置状态
- 250 void init_config(void)
- 251 {
- 252 1 D12_SetEndpointEnable(1); /* Enable generic/iso endpoints. */
- 253 1 }
- 254
- 255 //从端点号1发送数据
- 256 void single_transmit(unsigned char * buf, unsigned char len)
- 257 {
- 258 1 if( len <= EP0_PACKET_SIZE) {
- 259 2 D12_WriteEndpoint(1, len, buf);
- 260 2 }
- 261 1 }
- 262
- 263 //发送端点号1建立代码
- 264 void code_transmit(unsigned char code * pRomData, unsigned short len)
- 265 {
- 266 1 ControlData.wCount = 0;
- 267 1 if(ControlData.wLength > len)
- 268 1 ControlData.wLength = len;
- 269 1
- 270 1 ControlData.pData = pRomData;
- 271 1 if( ControlData.wLength >= EP0_PACKET_SIZE) {
- 272 2 D12_WriteEndpoint(1, EP0_PACKET_SIZE, ControlData.pData);//发送16字节数据
- 273 2 ControlData.wCount += EP0_PACKET_SIZE;
- 274 2 DISABLE;
- 275 2 bEPPflags.bits.control_state = USB_TRANSMIT;
- 276 2 ENABLE;
- 277 2 }
- 278 1 else {
- 279 2 D12_WriteEndpoint(1, ControlData.wLength, pRomData);//发送16字节内数据
- 280 2 ControlData.wCount += ControlData.wLength;
- 281 2 DISABLE;
- 282 2 bEPPflags.bits.control_state = USB_IDLE;
- 283 2 ENABLE;
- 284 2 }
- 285 1 }
- 286
- 287 //LED和按键处理子程序
- 288 void check_key_LED(void)
- 289 {
- 290 1 static unsigned char c ;
- 291 1 c =KEYDATA;
- 292 1 D12_WriteEndpoint(3,1,&c); //输入键盘数据
- 293 1
- 294 1
- 295 1 }
- 296 //数码管显示程序,左buf1,右buf2
- 297 void send(uchar buf1,uchar buf2)
- 298 {
- 299 1 uchar i;
- 300 1 uchar temp=buf2;
- 301 1 for(i=0;i!=8;i++)
- 302 1 {
- 303 2 if(temp&0x01)SPIDATA=1;
- C51 COMPILER V7.02b MAIN 09/28/2006 22:04:34 PAGE 6
- 304 2 else SPIDATA=0;
- 305 2 SPICLK=0;SPICLK=1;
- 306 2 temp>>=1;
- 307 2 }
- 308 1 temp=buf1;
- 309 1 for(i=0;i!=8;i++)
- 310 1 {
- 311 2 if(temp&0x01)SPIDATA=1;
- 312 2 else SPIDATA=0;
- 313 2 SPICLK=0;SPICLK=1;
- 314 2 temp>>=1;
- 315 2 }
- 316 1 SPILatch=0;
- 317 1 SPILatch=1;
- 318 1 }
- 319
- 320 void EndpointII()//2*16LCD/IIC
- 321 {
- 322 1
- 323 1 // if(EpBuf[0]==1) PrintUsb(EpBuf+2,EpBuf[1]); //LCD
- 324 1 // if(EpBuf[0]==2) Write24c02_nByte(EpBuf[2],EpBuf[1],EpBuf+3);//IIC
- 325 1 EpBuf[0]=0;
- 326 1 }
- 327
- 328 //请求处理子程序 处理Setup包
- 329 void control_handler()
- 330 {
- 331 1 unsigned char type, req;
- 332 1 type = ControlData.DeviceRequest.bmRequestType & USB_REQUEST_TYPE_MASK;
- 333 1 req = ControlData.DeviceRequest.bRequest & USB_REQUEST_MASK;
- 334 1 if (type == USB_STANDARD_REQUEST)
- 335 1 (*StandardDeviceRequest[req])();//调用标准请求
- 336 1 else if (type == USB_VENDOR_REQUEST)
- 337 1 (*VendorDeviceRequest[req])();//调用厂商请求
- 338 1 else
- 339 1 stall_ep0();
- 340 1 }
- MODULE INFORMATION: STATIC OVERLAYABLE
- CODE SIZE = 630 ----
- CONSTANT SIZE = 112 ----
- XDATA SIZE = ---- ----
- PDATA SIZE = ---- ----
- DATA SIZE = 25 8
- IDATA SIZE = ---- ----
- BIT SIZE = ---- ----
- END OF MODULE INFORMATION.
- C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)