?? ch375_slaver.lst
字號(hào):
C51 COMPILER V7.06 CH375_SLAVER 03/31/2006 12:09:34 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE CH375_SLAVER
OBJECT MODULE PLACED IN .\HEX\ch375_slaver.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ch375_slaver.c BROWSE DEBUG OBJECTEXTEND OBJECT(.\HEX\ch375_slaver.obj)
stmt level source
1 //CH375的slaver的程序
2 /***************************************
3 ** USB 1.1 Slaver for CH375 **
4 ****************************************/
5 #ifndef __MAIN_C__
6 #define __MAIN_C__
7 #endif
8
9 #include "head.h"
10 #include "ch375inc.h"
11 #include "usbDef.h"
12 #include "uart.h"
13 #include "descriptor.h"
14 #include "mcuFun.h"
15 #include "ch375.h"
16
17 #define DELAY_START_value 1 /* 根據(jù)單片機(jī)的時(shí)鐘選擇延時(shí)初值 */
18
19
20 #define DBG_MSK_0 (1<<0)
21 #define DBG_MSK_1 (1<<1)
22 #define DBG_MSK_2 (1<<2)
23 #define DBG_MSK_3 (1<<3)
24 uint8 eaCount, debug=0xff;
25 uint16 tCount;
26 unsigned char RECV_LEN; /* 剛接收到的數(shù)據(jù)的長(zhǎng)度 */
27 unsigned char idata RECV_BUFFER[ CH375_MAX_DATA_LEN ]; /* 數(shù)據(jù)緩沖區(qū),用于保存接收到的下傳數(shù)據(jù),長(zhǎng)度為0到64
-字節(jié) */
28 unsigned char idata *cmd_buf;
29 unsigned char idata *ret_buf;
30
31 typedef union _REQUEST_PACK
32 {
33 unsigned char buffer[8];
34 struct
35 {
36 unsigned char bmReuestType; //標(biāo)準(zhǔn)請(qǐng)求字
37 unsigned char bRequest; //請(qǐng)求代碼
38 unsigned int wvalue; //特性選擇高
39 unsigned int wIndx; //索引
40 unsigned int wLength; //數(shù)據(jù)長(zhǎng)度
41 }r;
42 } mREQUEST_PACKET, *mpREQUEST_PACKET;
43
44
45
46 unsigned char mVarSetupRequest; // USB請(qǐng)求碼
47 unsigned char mVarSetupLength; // 后續(xù)數(shù)據(jù)長(zhǎng)度
48 unsigned char code * VarSetupDescr; // 描述符偏移地址
49
50 unsigned char VarUsbAddress ; //USB設(shè)備地址
51 bit CH375FLAGERR; //錯(cuò)誤清0
52 bit CH375CONFLAG; //配置標(biāo)志
53
54 mREQUEST_PACKET request;
C51 COMPILER V7.06 CH375_SLAVER 03/31/2006 12:09:34 PAGE 2
55
56 //我的連接
57 //CH375 51
58 //D0-7 P0.0-7
59 //A0 P2.6
60 //RD RD
61 //WR WR
62 //CS P2.7
63 //INT INT0
64 //故
65 //0x7fff 命令端口, A0=1
66 //0x3fff 數(shù)據(jù)端口, A0=0
67
68 sbit led = P1^0;
69 sbit CH375_INT_WIRE = P3^2; // CH375中斷請(qǐng)求輸出,低電平有效
70
71 void delay50ms(void);
72 void delay1s(void);
73 void flash_led(void);
74
75
76
77 void delay50ms(void)
78 {
79 1 unsigned char i, j;
80 1 for( i=200; i!=0; i-- )
81 1 for( j=250; j!=0; j-- );
82 1 }
83
84 void delay1s(void)
85 {
86 1 unsigned char i,j,k;
87 1
88 1 for( i=10; i!=0; i-- )
89 1 for( j=200; j!=0; j-- )
90 1 for( k=250; k!=0; k-- );
91 1 }
92 //-----------------------------
93 //led以2s的頻率閃爍10s
94 //-----------------------------
95 void flash_led(void)
96 {
97 1 unsigned char i;
98 1
99 1 for( i=10;i>0;i-- )
100 1 {
101 2 led=!led;
102 2 delay1s();
103 2 }
104 1 }
105
106
107
108 //串行數(shù)據(jù)接收程序
109 void receive(void)
110 {
111 1 unsigned int count;
112 1 unsigned char buf;
113 1
114 1 RECV_LEN=0;
115 1 cmd_buf = RECV_BUFFER; // 接收緩沖區(qū)
116 1 while( 1 )
C51 COMPILER V7.06 CH375_SLAVER 03/31/2006 12:09:34 PAGE 3
117 1 {
118 2 RI=0;
119 2 *cmd_buf = SBUF;
120 2 cmd_buf++;
121 2 RECV_LEN++;
122 2 if( RECV_LEN == 64 )
123 2 {
124 3 while( 1 )
125 3 {
126 4 count=10000;
127 4 while( RI==0 )
128 4 {
129 5 count--;
130 5 if( count==0 )
131 5 return;
132 5 }
133 4 RI=0;
134 4 buf=SBUF;
135 4 }
136 3 }
137 2 count=10000;
138 2 while( RI==0 )
139 2 {
140 3 count--;
141 3 if( count==0 )
142 3 return;
143 3 }
144 2 }
145 1 }
146
147 void main(void)
148 {
149 1 unsigned char length, cc;
150 1 tOut t;
151 1 eaCount=0; //中斷總是關(guān)閉的
152 1 led = 0;
153 1 ComInit();
154 1
155 1 uartPutStr(__DATE__);
156 1 uartPutStr("\n\r");
157 1 uartPutStr(__TIME__);
158 1 uartPutStr("\n\r");
159 1 // delay1s(); // 延時(shí)等待CH375初始化完成,如果單片機(jī)由CH375提供復(fù)位信號(hào)則不必延時(shí)
160 1 // delay1s();
161 1 CH375_Init( ); // 初始化CH375
162 1 uartPrint("ch375 inited!\n\r", NULL, 0);
163 1 uartPutStr(">>>>>>>>>>>>>>>>>\n\r");
164 1 uartPrint("usb rec: %\n\r", &cc, 1);
165 1 while ( 1 )
166 1 {
167 2 if(w(&t, 100))
168 2 {
169 3 reset(&t);
170 3 led=!led;
171 3 }
172 2 if( RI==1 ) // 從串口接收到的數(shù)據(jù)
173 2 {
174 3 //led=1;
175 3 receive();
176 3 //led=0;
177 3 uartPrint("uart rec!\n\r", NULL, 0);
178 3 // 將從串口接收到的數(shù)據(jù)發(fā)送到USB設(shè)備
C51 COMPILER V7.06 CH375_SLAVER 03/31/2006 12:09:34 PAGE 4
179 3 ret_buf = RECV_BUFFER; // 接收緩沖區(qū)
180 3 length = RECV_LEN; // 剛接收到的數(shù)據(jù)長(zhǎng)度
181 3 if( length!=0 )
182 3 {
183 4 CH375_WR_CMD_PORT( CMD_WR_USB_DATA7 ); // 向USB端點(diǎn)2的發(fā)送緩沖區(qū)寫入數(shù)據(jù)塊
184 4 CH375_WR_DAT_PORT( length ); // 首先寫入后續(xù)數(shù)據(jù)長(zhǎng)度
185 4 while( length-- )
186 4 {
187 5 CH375_WR_DAT_PORT( *ret_buf ); // 數(shù)據(jù)
188 5 ret_buf++;
189 5 }
190 4 }
191 3 }
192 2
193 2 CH375_INT_WIRE=1;
194 2 if( CH375_INT_WIRE==0 ) // 從USB設(shè)備接收到數(shù)據(jù)
195 2 {
196 3 cc++;
197 3 uartPrint("usb rec: %\n\r", &cc, 1);
198 3 mCh375Interrupt();
199 3
200 3 // 將從USB設(shè)備接收到的數(shù)據(jù)發(fā)送到串口
201 3 ret_buf = RECV_BUFFER; // 接收緩沖區(qū)
202 3 length = RECV_LEN; // 剛接收到的數(shù)據(jù)長(zhǎng)度
203 3 while( length-- )
204 3 {
205 4 SendChar( *ret_buf );
206 4 ret_buf++;
207 4 }
208 3 }
209 2 }
210 1 }
211
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 342 ----
CONSTANT SIZE = 246 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 20 6
IDATA SIZE = 64 ----
BIT SIZE = 2 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -