基于51單片機(jī)的模擬usb 鍵盤制作例程
這回是拿以前做的Mass storage來改的,所以比較快,修改了一下描述符以及端點(diǎn)處理等,就行了。用了一個(gè)4*4的小鍵盤,有0-9十個(gè)數(shù)字鍵,Num Lock鍵,Caps Lock鍵,Shift鍵,Ctrl鍵,Alt鍵,回車鍵等。
最多可以有三個(gè)鍵同時(shí)按下,如果相交的話,最多只能兩個(gè)鍵按下。
以下是通過串口返回的調(diào)試信息:
系統(tǒng)啟動(dòng)................................
斷開USB連接........................
USBD12芯片初始化
設(shè)置地址.....................
地址為: 0
連接USB...............
USB總線復(fù)位................................
USB總線掛起................................
USB總線復(fù)位................................
USB總線掛起................................
USB總線復(fù)位................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取設(shè)備描述符................................
USB總線復(fù)位................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
設(shè)置地址.....................
地址為: 2
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取設(shè)備描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取配置描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取字符串描述符................................
獲取語言ID................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取字符串描述符................................
獲取設(shè)備序列號(hào)................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取配置描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取字符串描述符................................
獲取語言ID................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取字符串描述符................................
獲取產(chǎn)品字符串................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取字符串描述符................................
獲取語言ID................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取字符串描述符................................
獲取產(chǎn)品字符串................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取設(shè)備描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取配置描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取配置描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
設(shè)置配置................................
USB類請(qǐng)求................................
設(shè)置空閑................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符(從接口)..............................
獲取報(bào)告描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符(從接口)..............................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符(從接口)..............................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符(從接口)..............................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符(從接口)..............................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符(從接口)..............................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符(從接口)..............................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符(從接口)..............................
端點(diǎn)2輸出................................
端點(diǎn)2的數(shù)據(jù)是 0x01
端點(diǎn)2輸出................................
端點(diǎn)2的數(shù)據(jù)是 0x03
端點(diǎn)2輸出................................
端點(diǎn)2的數(shù)據(jù)是 0x01
端點(diǎn)2輸出................................
端點(diǎn)2的數(shù)據(jù)是 0x00
端點(diǎn)2輸出................................
端點(diǎn)2的數(shù)據(jù)是 0x02
端點(diǎn)2輸出................................
端點(diǎn)2的數(shù)據(jù)是 0x03
斷開USB連接........................
USBD12芯片初始化
設(shè)置地址.....................
地址為: 0
連接USB...............
USB總線復(fù)位................................
USB總線掛起................................
USB總線復(fù)位................................
USB總線掛起................................
USB總線復(fù)位................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取設(shè)備描述符................................
USB總線復(fù)位................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
設(shè)置地址.....................
地址為: 2
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取設(shè)備描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取配置描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取字符串描述符................................
獲取語言ID................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取字符串描述符................................
獲取設(shè)備序列號(hào)................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取配置描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取字符串描述符................................
獲取語言ID................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取字符串描述符................................
獲取產(chǎn)品字符串................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取字符串描述符................................
獲取語言ID................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取字符串描述符................................
獲取產(chǎn)品字符串................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取設(shè)備描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取配置描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
獲取配置描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
設(shè)置配置................................
USB類請(qǐng)求................................
設(shè)置空閑................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符(從接口)..............................
獲取報(bào)告描述符................................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符(從接口)..............................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符(從接口)..............................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符(從接口)..............................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符(從接口)..............................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符(從接口)..............................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符(從接口)..............................
USB標(biāo)準(zhǔn)請(qǐng)求................................
獲取描述符(從接口)..............................
端點(diǎn)2輸出................................
端點(diǎn)2的數(shù)據(jù)是 0x01
端點(diǎn)2輸出................................
端點(diǎn)2的數(shù)據(jù)是 0x03
端點(diǎn)2輸出................................
端點(diǎn)2的數(shù)據(jù)是 0x01
端點(diǎn)2輸出................................
端點(diǎn)2的數(shù)據(jù)是 0x00
端點(diǎn)2輸出................................
端點(diǎn)2的數(shù)據(jù)是 0x02
端點(diǎn)2輸出................................
端點(diǎn)2的數(shù)據(jù)是 0x03
在設(shè)備管理器里看到的圖:
原理圖
(用的是以前做IDE轉(zhuǎn)USB的板,所以上面還有個(gè)IDE接口和573鎖存器,可以不用理會(huì)它們):
(用的是以前做IDE轉(zhuǎn)USB的板,所以上面還有個(gè)IDE接口和573鎖存器,可以不用理會(huì)它們):
(注意:原理圖上所標(biāo)的晶體值是以前的,這個(gè)程序中使用的是22.1184M的晶體.它關(guān)系到串口波特率,如果你不使用串口,那么可以不用理會(huì)它.)
注意:圖中串口電平轉(zhuǎn)換部分的C8和C10接反了,C11負(fù)端應(yīng)接VDD。D12的SUSPEND(12腳)應(yīng)該接地。USB接頭的D+和D-跟芯的D+和D-之間應(yīng)該串聯(lián)22歐姆的匹配電阻。片由于圖得比較匆忙,所以沒留意。右擊選擇圖片另存為可以看到完整圖片了.
評(píng)論