• PUDN用户
    了解作者
  • C/C++
    开发工具
  • 286KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 40
    下载次数
  • 2009-06-10 15:36
    上传日期
usb转rs232源代码,有原理图.自己可以制作.
usbto232.rar
  • usbto232
  • HAL.OBJ
    11.7KB
  • TPBULK.C
    9.8KB
  • HAL.C
    2KB
  • SL811.LST
    60.2KB
  • HPI.C
    22.1KB
  • TPBULK.LST
    17.9KB
  • USBHOST.PLG
    163B
  • main.LST
    7.9KB
  • Rbc.h
    2B
  • SL811.OBJ
    38.7KB
  • COMMON.H
    3.4KB
  • ISR.OBJ
    30.4KB
  • USBHOST.lnp
    144B
  • AT89X52.H
    6.4KB
  • main.OBJ
    61.6KB
  • HPI.OBJ
    86.7KB
  • Control.Sch
    39KB
  • HAL.H
    930B
  • usb转rs232.rar
    37.7KB
  • MAIN.H
    2B
  • Fat.OBJ
    58.1KB
  • ISR.C
    2.8KB
  • HPI.LST
    45.6KB
  • HAL.LST
    5.1KB
  • MAIN.C
    3.1KB
  • Fat.c
    5.5KB
  • USBHOST.hex
    32KB
  • USBHOST
    341.2KB
  • USBHOST.Uv2
    1.8KB
  • Fat.h
    545B
  • RBCCMD.H
    14.5KB
  • Fat.LST
    11.2KB
  • USBHOST.M51
    100.3KB
  • SL811.C
    30.3KB
  • ISR.LST
    7.2KB
  • HPI.H
    6.9KB
  • TPBULK.H
    1.3KB
  • TPBULK.OBJ
    78.2KB
  • SL811.H
    7.6KB
内容介绍
#include "common.h" #include "SL811.H" #include "HAL.H" extern XXGFLAGS bdata bXXGFlags; XXGPKG usbstack; unsigned char remainder; unsigned char xdata DBUF[BUFFER_LENGTH]; pUSBDEV idata uDev; // Multiple USB devices attributes, Max 5 devices //xdata pHUBDEV uHub; // Struct for downstream device on HUB //pDevDesc idata pDev; // Device descriptor struct //pCfgDesc idata pCfg; // Configuration descriptor struct //pIntfDesc idata pIfc; // Interface descriptor struct //pEPDesc idata pEnp; // Endpoint descriptor struct //pStrDesc idata pStr; // String descriptor struct //xdata pHidDesc pHid; // HID class descriptor struct //xdata pHubDesc pHub; // HUD class descriptor struct //xdata pPortStatus pStat; // HID ports status //***************************************************************************************** // SL811H variables initialization //***************************************************************************************** unsigned char SL811_GetRev(void) { //SL811Write(SL811_ADDR_PORT, 0x0e); return SL811Read(0x0e); } void USBReset(void) { unsigned char temp; temp=SL811Read(CtrlReg); SL811Write(CtrlReg,temp|0x08); DelayMs(25); SL811Write(CtrlReg,temp); } //***************************************************************************************** // usbXfer: // successful transfer = return TRUE // fail transfer = return FALSE //***************************************************************************************** unsigned char usbXfer(void) { unsigned char xferLen, data0, data1,cmd; unsigned char intr,result,remainder,dataX,bufLen,addr,timeout; //------------------------------------------------ // Default setting for usb trasnfer //------------------------------------------------ dataX=timeout=0; //result = SL811Read(EP0Status); data0 = EP0_Buf; // DATA0 buffer address data1 = data0 + (unsigned char)usbstack.wPayload; // DATA1 buffer address bXXGFlags.bits.DATA_STOP=FALSE; bXXGFlags.bits.TIMEOUT_ERR=FALSE; //------------------------------------------------ // Define data transfer payload //------------------------------------------------ if (usbstack.wLen >= usbstack.wPayload) // select proper data payload xferLen = usbstack.wPayload; // limit to wPayload size else // else take < payload len xferLen = usbstack.wLen; // // For IN token if (usbstack.pid==PID_IN) // for current IN tokens { // cmd = sDATA0_RD; // FS/FS on Hub, sync to sof } // For OUT token else if(usbstack.pid==PID_OUT) // for OUT tokens { if(xferLen) // only when there are { //intr=usbstack.setup.wLength; //usbstack.setup.wLength=WordSwap(usbstack.setup.wLength); SL811BufWrite(data0,usbstack.buffer,xferLen); // data to transfer on USB //usbstack.setup.wLength=intr; } cmd = sDATA0_WR; // FS/FS on Hub, sync to sof // implement data toggle bXXGFlags.bits.bData1 = uDev.bData1[usbstack.endpoint]; uDev.bData1[usbstack.endpoint] = (uDev.bData1[usbstack.endpoint] ? 0 : 1); // DataToggle if(bXXGFlags.bits.bData1) cmd |= 0x40; // Set Data1 bit in command } // For SETUP/OUT token else // for current SETUP/OUT tokens { if(xferLen) // only when there are { intr=usbstack.setup.wLength; usbstack.setup.wValue=WordSwap(usbstack.setup.wValue); usbstack.setup.wIndex=WordSwap(usbstack.setup.wIndex); usbstack.setup.wLength=WordSwap(usbstack.setup.wLength); SL811BufWrite(data0,(unsigned char *)&usbstack.setup,xferLen); // data to transfer on USB usbstack.setup.wLength=intr; } cmd = sDATA0_WR; // FS/FS on Hub, sync to sof } //------------------------------------------------ // For EP0's IN/OUT token data, start with DATA1 // Control Endpoint0's status stage. // For data endpoint, IN/OUT data, start ???? //------------------------------------------------ if (usbstack.endpoint == 0 && usbstack.pid != PID_SETUP) // for Ep0's IN/OUT token cmd |= 0x40; // always set DATA1 //------------------------------------------------ // Arming of USB data transfer for the first pkt //------------------------------------------------ SL811Write(EP0Status,((usbstack.endpoint&0x0F)|usbstack.pid)); // PID + EP address SL811Write(EP0Counter,usbstack.usbaddr); // USB address SL811Write(EP0Address,data0); // buffer address, start with "data0" SL811Write(EP0XferLen,xferLen); // data transfer length SL811Write(IntStatus,INT_CLEAR); // clear interrupt status SL811Write(EP0Control,cmd); // Enable ARM and USB transfer start here //------------------------------------------------ // Main loop for completing a wLen data trasnfer //------------------------------------------------ while(TRUE) { //---------------Wait for done interrupt------------------ while(TRUE) // always ensure requested device is { // inserted at all time, then you will //intr=SL811Read(cSOFcnt); //intr=SL811Read(IntEna); intr = SL811Read(IntStatus); // wait for interrupt to be done, and if((intr & USB_RESET) || (intr & INSERT_REMOVE)) // proceed to parse result from slave { // device. bXXGFlags.bits.DATA_STOP = TRUE; // if device is removed, set DATA_STOP return FALSE; // flag true, so that main loop will } // know this condition and exit gracefully if(intr & USB_A_DONE) break; // interrupt done !!! } SL811Write(IntStatus,INT_CLEAR); // clear interrupt status result = SL811Read(EP0Status); // read EP0status register remainder = SL811Read(EP0Counter); // remainder value in last pkt xfer //-------------------------ACK---------------------------- if (result & EP0_ACK) // Transmission ACK { // SETUP TOKEN if(usbstack.pid == PID_SETUP) // do nothing for SETUP/OUT token break; // exit while(1) immediately // OUT TOKEN else if(usbstack.pid == PID_OUT) break; // IN TOKEN else if(usbstack.pid == PID_IN) { // for IN token only usbstack.wLen -= (WORD)xferLen; // update remainding wLen value cmd ^= 0x40; // toggle DATA0/DATA1 dataX++; // point to next dataX //------------------------------------------------ // If host requested for more data than the slave // have, and if the slave's data len is a multiple // of its endpoint payload size/last xferLen. Do // not overwrite data in previous buffer. //------------------------------------------------ if(remainder==xferLen) // empty data detected bufLen = 0; // do not overwriten previous data else // reset bufLen to zero bufLen = xferLen; // update previous buffer length //------------------------------------------------ // Arm for next data transfer when requested data // length have not reach zero, i.e. wLen!=0, and // last xferlen of data was completed, i.e. // remainder is equal to zero, not a short pkt //------------------------------------------------ if(!remainder && usbstack.wLen) // remainder==0 when last xferLen { // was all completed or wLen!=0 addr = (dataX & 1) ? data1:data0; // select next address for data xferLen = (BYTE)(usbstack.wLen>=usbstack.wPayload) ? usbstack.wPayload:usbstack.wLen; // get data length required //if (FULL_SPEED) // sync with SOF transfer cmd |= 0x20; // always sync SOF when FS, regardless SL811Write(EP0XferLen, xferLen); // select next xfer length SL811Write(EP0Address, addr); // data buffer addr SL811Write(IntStatus
评论
    相关推荐
    • usbto232.rar
      USB serial port 232 will be converted into the information
    • USBto232.rar
      USB接口转换成RS-232接口的驱动程序
    • usbto232.rar
      采用atmel公司的mega8芯片设计的USB cdc类,实现usb接口与rs232接口数据的相互转发
    • MAX1402-Evaluation-KitEvaluation-System.rar
      MAX1402 Evaluation KitEvaluation System
    • MAX3110E.rar
      MAX3110E串口芯片说明文档,主要说明MAX3110E芯片各种属性,可参考进行编程
    • GPIB-pyvisa:使用 pyvisa 通过 GPIB 控制仪器
      Pyvisa 是一个 Python 包,用于支持“虚拟仪器软件架构”(VISA),以便通过 GPIB、RS232、以太网或 USB 控制测量设备和测试设备。 使用 pip 安装 pyvisa: $ pip install pyvisa 详细信息可以在找到 4.NI驱动安装 ...
    • Proteus7.12.rar
      Proteus7.12完美破解版.rar电路仿真软件很好用可以仿真单片数字模拟电路
    • VHDL 的实例程序,共44个.rar
      经典VHDL 的实例程序,共44个!要下载的尽快
    • USBtoRS232Driver.rar
      USB转串口驱动程序,可以用在笔记本电脑上,方便的通过串口给单片机下载程序!
    • 模糊控制程序.rar
      模糊PID控制程序的源码,是作业,有讲解,