?? pdiusbd12.lst
字號:
C51 COMPILER V7.50 PDIUSBD12 11/24/2008 09:12:37 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE PDIUSBD12
OBJECT MODULE PLACED IN PDIUSBD12.OBJ
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE PDIUSBD12.c BROWSE DEFINE(__DEBUG__) DEBUG OBJECTEXTEND
line level source
1 /*===============================================================================//
2 //== 文 件 名:PDIUSBD12.c
3 //== author :gnsusn
4 //== 說 明:對PDIUSBD12芯片的操作
5 //== 修改日志:2008.8.13 創建文件
6 //==
7 //===============================================================================*/
8 #include "PDIUSBD12.h"
9 #include "USB.h"
10 #include "functions.h"
11
12 //***************************************************************************************
13 //=======================================================================================
14 #define D12_COMMAND_ADD (*(unsigned char volatile xdata*)0x6001)
15 #define D12_DATA_ADD (*(unsigned char volatile xdata*)0x6000)
16
17 extern unsigned char usb_transmit_buf[8]; //== 用于給USB發送數據的緩沖區,在USB.c中定義
18 extern EPPFLAGS bEPPflags; //== 程序運行狀態標志,在USB.c中定義
19 extern CONTROL_DATA_BUFF Control_Data; //== setup 包,在USB.c中定義
20
21 D12_INTERRUPT_REGISTER D12_interrupt_register; //== D12中斷寄存器的標志
22 D12_LAST_STATUS D12_last_status; //== 端點的最后處理狀態
23
24 /****************************** PDIUSBD12硬件提取層 ******************************/
25 //===============================================================================//
26 //== 函 數 名:write_D12_command
27 //== 功 能:向D12寫入一個字節的命令
28 //== 說 明:
29 //== 時 間:2008.8.13 創建函數
30 //== 入口參數:D12_command:向D12寫入的命令
31 //== 返 回 值:0
32 //===============================================================================//
33 unsigned char write_D12_command(unsigned char D12_command)
34 {
35 1 D12_COMMAND_ADD = D12_command;
36 1 return 0;
37 1 }
38
39 //===============================================================================//
40 //== 函 數 名:write_a_D12_data
41 //== 功 能:向D12寫入一個字節的命令
42 //== 說 明:
43 //== 時 間:2008.8.13 創建函數
44 //== 入口參數:D12_data:向D12寫入的數據
45 //== 返 回 值:0
46 //===============================================================================//
47 unsigned char write_a_D12_data(unsigned char D12_data)
48 {
49 1 D12_DATA_ADD = D12_data;
50 1 return 0;
51 1 }
52
53 //===============================================================================//
54 //== 函 數 名:read_a_usb_data
55 //== 功 能:從D12讀出一個字節
C51 COMPILER V7.50 PDIUSBD12 11/24/2008 09:12:37 PAGE 2
56 //== 說 明:
57 //== 時 間:2008.8.13 創建函數
58 //== 入口參數:無
59 //== 返 回 值:ret:從D12讀出的數據
60 //===============================================================================//
61 unsigned char read_a_D12_data(void)
62 {
63 1 unsigned char ret;
64 1
65 1 ret = D12_DATA_ADD;
66 1 return ret;
67 1 }
68
69 /**************************** PDIUSBD12硬件提取層結束 ****************************/
70
71
72 /****************************** PDIUSBD12硬件命令層 ******************************/
73 //===============================================================================//
74 //== 函 數 名:set_usb_addr
75 //== 功 能:設置D12的地址
76 //== 說 明:開機后單片機設置D12的地址,并使能這個地址,這個地址默認為0
77 //== :設置地址使能寫入一個字節
78 //== :D7:置1使能該功能
79 //== :D6~D0:寫入的字節即為地址
80 //== 時 間:2008.8.13 創建函數
81 //== 入口參數:無
82 //== 返 回 值:0
83 //===============================================================================//
84 unsigned char set_usb_addr(unsigned char addr)
85 {
86 1 #ifdef __DEBUG__
87 1 Print_Msg("Runing set_usb_addr()!\r\n");
88 1 #endif
89 1
90 1 write_D12_command(Set_Address);
91 1 write_a_D12_data(Address_Enable|addr); //== Address_Enable:0x80 使能這個地址
92 1
93 1 #ifdef __DEBUG__
94 1 Print_Msg(" 設置地址.....................!\r\n");
95 1 Print_Msg(" 地址為:");
96 1 Print_Long(addr);
97 1 Print_Msg("!\r\n");
98 1 #endif
99 1
100 1 return 0;
101 1 }
102
103 //===============================================================================//
104 //== 函 數 名:set_endpoint_enable
105 //== 功 能:使能端點0
106 //== 說 明:通過設置設置地址(設備地址)/使能命令后才可使能(端點0)普通/同步端點
107 //== 時 間:2008.8.13 創建函數
108 //== 入口參數:無
109 //== 返 回 值:0
110 //===============================================================================//
111 unsigned char set_endpoint_enable(void)
112 {
113 1 #ifdef __DEBUG__
114 1 Print_Msg("Runing set_endpoint_enable()!\r\n");
115 1 #endif
116 1 #ifdef __DEBUG__
117 1 Print_Msg(" 使能端點0!\r\n");
C51 COMPILER V7.50 PDIUSBD12 11/24/2008 09:12:37 PAGE 3
118 1 #endif
119 1
120 1 write_D12_command(Set_Endpoint_Enable);
121 1 write_a_D12_data(0x01); //== 值1 表示普通/同步端點使能
122 1 return 0;
123 1 }
124
125 //===============================================================================//
126 //== 函 數 名:set_endpoint_disable
127 //== 功 能:禁止端點0
128 //== 說 明:通過設置設置地址(設備地址)/使能命令后才可使能(端點0)普通/同步端點
129 //== 時 間:2008.8.13 創建函數
130 //== 入口參數:無
131 //== 返 回 值:0
132 //===============================================================================//
133 unsigned char set_endpoint_disable(void)
134 {
135 1 #ifdef __DEBUG__
136 1 Print_Msg("Runing set_endpoint_disable()!\r\n");
137 1 #endif
138 1 #ifdef __DEBUG__
139 1 Print_Msg(" 禁止端點0!\r\n");
140 1 #endif
141 1 write_D12_command(Set_Endpoint_Enable);
142 1 write_a_D12_data(0x00); //== 值1 表示普通/同步端點使能
143 1 return 0;
144 1 }
145 //===============================================================================//
146 //== 函 數 名:read_interrupt_register
147 //== 功 能:從D12讀出中斷狀態寄存器
148 //== 說 明:
149 //== 時 間:2008.8.13 創建函數
150 //== 入口參數:無
151 //== 返 回 值:0
152 //===============================================================================//
153 unsigned char read_interrupt_register(void)
154 {
155 1 #ifdef __DEBUG__
156 1 Print_Msg("Runing read_interrupt_register()!\r\n");
157 1 #endif
158 1
159 1 write_D12_command(Read_Interrupt_Register);
160 1 D12_interrupt_register.Register[0] = read_a_D12_data();
161 1 D12_interrupt_register.Register[1] = read_a_D12_data();
162 1
163 1 #ifdef __DEBUG__
164 1 Print_Msg(" 中斷寄存器數據是:");
165 1 Print_Hex(D12_interrupt_register.Register, 2);
166 1 Print_Msg("\r\n");
167 1 #endif
168 1 return 0;
169 1 }
170
171 //===============================================================================//
172 //== 函 數 名:select_endpoint
173 //== 功 能:選擇端點
174 //== 說 明:
175 //== 時 間:2008.8.13 創建函數
176 //== 入口參數:endp:端點索引號(0-5)
177 //== 返 回 值:bit0--1表示緩沖區滿,0表示緩沖區空
178 // bit1--1表示端點處于停止狀態,0表示運行
179 //===============================================================================//
C51 COMPILER V7.50 PDIUSBD12 11/24/2008 09:12:37 PAGE 4
180 unsigned char select_endpoint(unsigned char endp)
181 {
182 1 unsigned char ret;
183 1 #ifdef __DEBUG__ //== 打印調試信息
184 1 Print_Msg("Runing select_endpoint()!\r\n");
185 1 #endif
186 1
187 1 write_D12_command(Select_EndPoint+endp);
188 1 ret = read_a_D12_data();
189 1
190 1 #ifdef __DEBUG__
191 1 Print_Msg(" 選擇了端點:");
192 1 Print_Long(endp);
193 1 Print_Msg(" 端點狀態:");
194 1 Print_Hex(&ret, 1);
195 1 Print_Msg("!\r\n");
196 1 #endif
197 1
198 1 return ret;
199 1 }
200
201 //===============================================================================//
202 //== 函 數 名:read_last_status
203 //== 功 能:讀取端點最后處理狀態,命令為0x40+endp
204 //== 說 明:該命令同時復位中斷寄存器中的相應位,并將狀態清零,表示已讀取。
205 //== 時 間:2008.8.13 創建函數
206 //== 入口參數:endp:端點索引號(0-5)
207 //== 返 回 值:端點最后處理狀態寄存器
208 //===============================================================================//
209 unsigned char read_last_status(unsigned char endp)
210 {
211 1 unsigned char ret;
212 1 #ifdef __DEBUG__ //== 打印調試信息
213 1 Print_Msg("Runing read_last_status()!\r\n");
214 1 #endif
215 1
216 1 write_D12_command(Read_Last_Status+endp);
217 1 ret = read_a_D12_data();
218 1
219 1 #ifdef __DEBUG__
220 1 Print_Msg(" 讀取端點 ");
221 1 Print_Long(endp);
222 1 Print_Msg(" 最后處理狀態狀態,");
223 1 Print_Msg(" 端點狀態是:");
224 1 Print_Hex(&ret, 1);
225 1 Print_Msg("!\r\n");
226 1 #endif
227 1
228 1 return ret;
229 1 }
230
231 //===============================================================================//
232 //== 函 數 名:set_endpoint_status
233 //== 功 能:設置端點狀態,停止或運行端點,命令為0x40+endp
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -