想要利用现在市面上出售的USB键盘作为输入设备,向单片机输入数据,涉及到单片机和USB通信的问题……读了USB1.1协议,反而更加迷惑了,网上也搜不到(请不要和我说搜“HID”之类的,如果能搜到,请回复搜到的网址)
手头有一个程序,是AVR利用PS/2接口和键盘连接的
大家帮忙看一下怎么改?(或者有没有USB转接为PS/2的电路)
文件:main.c
C/C++ code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/********************************************
Chip type : AT90S4434
Clock frequency : 8,000000 MHz
Memory model : Tiny
Internal SRAM size : 256
External SRAM size : 0
Data Stack size : 64
*********************************************/
#include <90s4434.h>
#include "kb.h"
#include <delay.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15
#endasm
#include <lcd.h>
// Declare your global variables here
void main(void)
{
// Declare your local variables here
unsigned char key;
// Input/Output Ports initialization
// Port A
PORTA=0x00;
DDRA=0x00;
// Port B
PORTB=0x00;
DDRB=0x00;
// Port C
PORTC=0x00;
DDRC=0x00;
// Port D
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Output Compare
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Output Compare
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Output Compare
// OC2 output: Disconnected
TCCR2=0x00;
ASSR=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Oon
// INT1: Off
GIMSK= 0x40; // Enable INT0 interrupt
MCUCR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
// LCD module initialization
//lcd_init(20); // Init 20 Zeichendisplay
lcd_init(16); // Init 16 Zeichendisplay
InitKeyBoard(); // Initialize keyboard reception
while(1)
{
key = getchar_kb();
lcd_putchar(key);
delay_ms(5);
}
}
一周热门 更多>