📄 vdipnew.lst
字号:
C51 COMPILER V7.20 VDIPNEW 02/23/2009 14:04:45 PAGE 1
C51 COMPILER V7.20, COMPILATION OF MODULE VDIPNEW
OBJECT MODULE PLACED IN VDIPNEW.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE VDIPNEW.C
line level source
1 #include <REGX52.h>
2 //*****************************************************************************************
3 //
4 // Constants and variables for serial port
5 //
6 //*****************************************************************************************
7 // Define serial port flags
8 char _CTS = 0x04; // RTS# is PORT3 PIN 2
9 char _RTS = 0x08; // CTS# is PORT3 PIN 3
10 char FLOW_NONE = 0x00;
11 char FLOW_RTS_CTS = 0x01;
12 char FLOW_CONTROL_ENABLED = 0x00; // Initialise FLOW_CONTROL_ENABLED to off
13
14 // Define serial port Rx buffer variables
15 char SERIAL_RX_FIFO[0x20]; // Allocate buffer for RX FIFO USE MULTIPLE OF 0x04!
16 char RX_FIFO_SIZE = sizeof(SERIAL_RX_FIFO); // Initialise FIFO size variable
17 char RX_FIFO_COUNT = 0x00; // Reset RX FIFO count
18 char * RX_FIFO_HEAD_PTR = &SERIAL_RX_FIFO[0x00]; // Initialise head pointer
19 char * RX_FIFO_TAIL_PTR = &SERIAL_RX_FIFO[0x00]; // Initialise tail pointer
20 char * RX_FIFO_START = &SERIAL_RX_FIFO[0x00]; //RX_FIFO_TAIL_PTR; // Set lowest address of R
-X_FIFO
21 char * RX_FIFO_END =&SERIAL_RX_FIFO[0x00] + sizeof(SERIAL_RX_FIFO); // Set highest address of RX_FIFO
22 char RX_STATUS = 0x00; // Reset RX status
23 char RX_FIFO_OVERRUN = 0x01;
24
25 char RX_FIFO_UPPER_LIMIT = 0x03 *(sizeof(SERIAL_RX_FIFO)/ 0x04); // Buffer limit for handshaking
26 char RX_FIFO_LOWER_LIMIT = (sizeof(SERIAL_RX_FIFO) / 0x04); // Buffer limit for handshaking
27 char* reset_screen = { " PENDRIVE PROJECT :: STESALIT LIMITED "} ;
28
29
30 //*****************************************************************************************
31 //
32 // Define states for state machine
33 //
34 //*****************************************************************************************
35
36 enum { // Enum states
37 VNC1L_Idle, // Idle state
38 VNC1L_DiskAvailable,
39 VNC1L_CreateFile,
40 VNC1L_WriteFile,
41 VNC1L_EndFile,
42 VNC1L_WaitForRemove
43 };
44
45 char VNC1L_State = VNC1L_Idle; // Initialise state to idle
46
47 char Synchronised = 0x01;
48 char GotDisk = 0x01;
49
50 ///////////////////////////////////////////////////////////////////////////////////////////
51 ///////////////////////////////////////////////////////////////////////////////////////////
52 //
53 // Routines for serial port
54 //
C51 COMPILER V7.20 VDIPNEW 02/23/2009 14:04:45 PAGE 2
55 ///////////////////////////////////////////////////////////////////////////////////////////
56 ///////////////////////////////////////////////////////////////////////////////////////////
57
58
59 //*****************************************************************************************
60 //
61 // Reset Rx FIFO
62 //
63 //*****************************************************************************************
64 void serial_resetrxfifo()
65 {
66 1 ES = 0; /* Enable serial interrupt */
67 1 EA = 0; /* Enable global interrupt */
68 1 RX_FIFO_COUNT = 0x00; // Reset FIFO count to 0
69 1 RX_STATUS = 0x00; // Reset FIFO status
70 1 RX_FIFO_HEAD_PTR = (&SERIAL_RX_FIFO[0x00]); // Set FIFO head pointer to address of first byte of SERIA
-L_RX_FIFO
71 1 RX_FIFO_TAIL_PTR = (&SERIAL_RX_FIFO[0x00]); // Set FIFO tail pointer to address of first byte of SERIA
-L_RX_FIFO
72 1 ES = 1; /* Enable serial interrupt */
73 1 EA = 1; /* Enable global interrupt */
74 1 if (FLOW_CONTROL_ENABLED == 0x01) // If using flow control
75 1 {
76 2 P3_3=0;
77 2 }
78 1 }
79 //*****************************************************************************************
80 //
81 // Initialise serial port (Baud rate, handshaking, interrupt enable, enable receiver)
82 //
83 //*****************************************************************************************
84 void serial_init(long BaudRate, char Handshaking) // Set up serial port
85 {
86 1 ES = 0; /* Enable serial interrupt */
87 1 EA = 0; /* Enable global interrupt */
88 1 P3_3=1; // TRISC bits 1 for input, 0 for output
89 1 SCON = 0x50; /* uart in mode 1 (8 bit), REN=1 */
90 1 TMOD = TMOD | 0x20 ; /* Timer 1 in mode 2 */
91 1 switch (BaudRate) // Set Baud rate
92 1 {
93 2 case 9600:
94 2 TH1 = 0xFD; /* 9600 Bds at 11.059MHz */
95 2 TL1 = 0xFD; /* 9600 Bds at 11.059MHz */
96 2 default:
97 2 TH1 = 0xFD; /* 9600 Bds at 11.059MHz */
98 2 TL1 = 0xFD; /* 9600 Bds at 11.059MHz */ // Default to 9600 if not a valid achievable
-Baud rate
99 2 }
100 1 TR1 = 1; /* Timer 1 run */
101 1
102 1 if (Handshaking == FLOW_RTS_CTS)
103 1 {
104 2 P3_3=0;
105 2 FLOW_CONTROL_ENABLED = 0x01; // Set flow control enabled flag
106 2 }
107 1
108 1 ES = 1; /* Enable serial interrupt */
109 1 EA = 1;
110 1 TI=1;
111 1 RI=1;
112 1 serial_resetrxfifo(); // Reset Rx FIFO
113 1 }
C51 COMPILER V7.20 VDIPNEW 02/23/2009 14:04:45 PAGE 3
114 //*****************************************************************************************
115 //
116 // Send a byte directly from the transmit register
117 //
118 //*****************************************************************************************
119 void serial_sendbyte(char TX_BYTE)
120 {
121 1 if (FLOW_CONTROL_ENABLED == 0x01)
122 1 {
123 2 while (P3_2); // Wait for CTS# to become active (low)
124 2 }
125 1 while(!TI);
126 1
127 1 TI=0;
128 1 SBUF = TX_BYTE; // Move byte to send into sbuf
129 1 }
130 //*****************************************************************************************
131 //
132 // Read a byte directly from the receive character register
133 //
134 //*****************************************************************************************
135 void delay_ms(int i )
136 {
137 1 unsigned int j,k,l;
138 1 l=i;
139 1 for (j=0;j<=l;j++)
140 1 {
141 2 for (k=0;k<=500;k++)
142 2 {
143 3 ;
144 3 }
145 2 }
146 1 }
147 void delay_s(int i )
148 {
149 1 unsigned int j,k,l;
150 1 l=i;
151 1 for (j=0;j<=l;j++)
152 1 {
153 2 for (k=0;k<=5000;k++)
154 2 {
155 3 ;
156 3 }
157 2 }
158 1 }
159 //*****************************************************************************************
160 //
161 // Add a byte from the receive character register to the receive FIFO buffer
162 //
163 //*****************************************************************************************
164 void serial_addtorxfifo()
165 {
166 1 if (RX_FIFO_COUNT >= RX_FIFO_SIZE) // If Rx FIFO is full
167 1 {
168 2 RX_STATUS = RX_STATUS | RX_FIFO_OVERRUN; // Set overrun flag
169 2 if (FLOW_CONTROL_ENABLED == 0x01) // If using flow control
170 2 {
171 3 P3_3=1;
172 3 }
173 2 return;
174 2 }
175 1
C51 COMPILER V7.20 VDIPNEW 02/23/2009 14:04:45 PAGE 4
176 1 if (RX_FIFO_COUNT >= RX_FIFO_UPPER_LIMIT) // Keep some space in the FIFO for bytes already being sent
177 1 {
178 2 if (FLOW_CONTROL_ENABLED == 0x01) // If using flow control
179 2 {
180 3 P3_3 =1;
181 3 }
182 2 }
183 1 ES = 0; /* Enable serial interrupt */
184 1 EA = 0; /* Enable global interrupt */
185 1 *RX_FIFO_HEAD_PTR++ = SBUF; // Add received byte to RX_FIFO and then increment head pointer
186 1 RX_FIFO_COUNT++; // Increment byte count
187 1
188 1 if (RX_FIFO_HEAD_PTR >= RX_FIFO_END) // If head pointer is greater than allocated FIFO end address
189 1 {
190 2 RX_FIFO_HEAD_PTR = RX_FIFO_START; // Wrap-around buffer to start address again (circuluar FIFO)
191 2 }
192 1
193 1 if ((RX_FIFO_COUNT < RX_FIFO_UPPER_LIMIT) && (FLOW_CONTROL_ENABLED == 0x01)) // If Rx FIFO is not full
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -