这是源程序,大家给我看一看,怎么回事,为什么USB上的数据不能再txt中显示出来。
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/interrupt.h> /* for sei() */
#include <util/delay.h> /* for _delay_ms() */
#include <avr/eeprom.h>
#include <avr/pgmspace.h> /* required by usbdrv.h */
#include "usbdrv.h"
#include "oddebug.h" /* This is also an example for using debug macros */
/* ------------------------------------------------------------------------- */
/* ----------------------------- USB interface ----------------------------- */
/* ------------------------------------------------------------------------- */
PROGMEM char usbHidReportDescriptor[39] = { /* USB report descriptor */
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x06, // USAGE (Keyboard)
0xa1, 0x01, // COLLECTION (Application)
//0x85, 0x01, // Report Id (1) //报告类型为1
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x08, // REPORT_COUNT (8)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x08, // REPORT_SIZE (8)
0x15, 0x00, // Logical Minimum (0), //从0--ff
0x25, 0x65, // Logical Maximum(101),
0x05, 0x07, // Usage Page (Key Codes),
0x19, 0x00, // Usage Minimum (0),
0x29, 0x65, // Usage Maximum (101),
0x81, 0x00, // Input (Data, Array), ;Key arrays (4 bytes)
0xc0 //
};
/* Since we define only one feature report, we don't use report-IDs (which
* would be the first byte of the report). The entire report consists of 128
* opaque data bytes.
*/
/* The following variables store the status of the current data transfer */
/* ------------------------------------------------------------------------- */
/* usbFunctionRead() is called when the host requests a chunk of data from
* the device. For more information see the documentation in usbdrv/usbdrv.h.
*/
/* ------------------------------------------------------------------------- */
static uchar inputBuffer1[1] = {0}; /* kbd */
static uchar idleRate = 0; /* in 4 ms units */
usbMsgLen_t usbFunctionSetup(uchar data[8])
{
usbRequest_t *rq = (void *)data;
if (rq->bRequest == USBRQ_HID_GET_REPORT) {
/* wValue: ReportType (highbyte), ReportID (lowbyte) */
//if (rq->wValue.bytes[0] == 1) {
usbMsgPtr = inputBuffer1;
return sizeof(inputBuffer1);
//}
//return 0;
} else if (rq->bRequest == USBRQ_HID_SET_REPORT) {
/* wValue: ReportType (highbyte), ReportID (lowbyte) */
/* we have no output/feature reports */
return 0;
} else if (rq->bRequest == USBRQ_HID_GET_IDLE) {
usbMsgPtr = &idleRate;
return 1;
} else if (rq->bRequest == USBRQ_HID_SET_IDLE) {
idleRate = rq->wValue.bytes[1];
}
return 0;
}
void port_init(void)
{
PORTD = 0x68;
PORTB = 0; /* no pullups on USB and ISP pins */
DDRD = 0X10; /* all outputs except PD2 = INT0 */
DDRB = 0X00; /* all USB and ISP pins inputs */
DDRC = 0X03;
}
/* ------------------------------------------------------------------------- */
SIGNAL(SIG_OVERFLOW0)
{
TIMSK0|=0x01;//溢出中断
//sendcount=0;
inputBuffer1[0]=0;
}
int main(void)
{
uchar keyDidChange = 0, i;
uchar idleCounter = 0;
wdt_enable(WDTO_1S);
cli();
port_init();
/* Even if you don't use the watchdog, turn it off here. On newer devices,
* the status of the watchdog (on/off, period) is PRESERVED OVER RESET!
*/
DBG1(0x00, 0, 0); /* debug output: main starts */
/* RESET status: all port bits are inputs without pull-up.
* That's the way we need D+ and D-. Therefore we don't need any
* additional hardware initialization.
*/
odDebugInit();
usbInit();
usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
i = 0;
while(--i){ /* fake USB disconnect for > 250 ms */
wdt_reset();
_delay_ms(1);
}
usbDeviceConnect();
EIMSK|=0X01;//GICR |= 0xE0; //INT1 INT0 EN
EICRA = 0x02;//EICRA = (EICRA & ~(_BV(ISC11) | _BV(ISC10))) | _BV(ISC11);//MCUCR = MCUCR & 0xFB; //ISC10=0 下降沿
TCCR0B=5;//TCCR0 = 5; /* prescaler = 1/1024 -> overflow at 21.8 ms */
TIMSK0|=0x01;
sei();
DBG1(0x01, 0, 0); /* debug output: main loop starts */
//usbSetInterrupt(0,0);
for(;;){ /* main event loop */
DBG1(0x02, 0, 0); /* debug output: main loop iterates */
inputBuffer1[0] = 0x28;
if(usbInterruptIsReady()){
/* use last key and not current key status in order to avoid lost
changes in key status. */
usbSetInterrupt(inputBuffer1, sizeof(inputBuffer1));
}
wdt_reset();
usbPoll();
}
return 0;
}
/* ------------------------------------------------------------------------- */
|