HIDUSB手柄(玩游戏比键盘爽)
=======================================FC.c=========================================
#include"FC.h"
#includeutil/delay.h>
#includeavr/io.h>
inlineU8FC_Read(void)
{
U8i,buf=0;
PORTD|=FC_LATCH;//latch=H;
_delay_us(1);
for(i=0;i8;i++)
{
buf=1;
PORTD|=FC_CLOCK;//clock=H;
PORTD=~FC_LATCH;//latch=L;
_delay_us(1);
if(PINDFC_DATA)
{
buf++;
}
PORTD=~FC_CLOCK;//clock=L;
_delay_us(1);
}
if(buf==0x7F)
PORTC|=(14);
if(buf==0xBF)
PORTC=~(14);
returnbuf;
}
voidFC_Init(void)
{
DDRD|=0x60;//PD6,PD5inoutput
DDRD=~FC_DATA;//ThisisFCofPORTs
DDRC|=(14);//ThisisLEDofPORTs
}
============================FC.h=================================================
#ifndefFC_H
#defineFC_H
#ifndefU8
typedefunsignedcharU8;
#endif
#ifndefU16
typedefunsignedintU16;
#endif
#ifndefU32
typedefunsignedlongU32;
#endif
#defineFC_CLOCK(15)
#defineFC_LATCH(16)
#defineFC_DATA(17)
U8FC_Read(void);
voidFC_Init(void);
#endif
===========================END===================================================