📄 f34x_uart_stdio.lst
字号:
174 1 { // check for newline character
175 2 while (!(SCON1 & 0x02)); // wait until UART1 is ready to transmit
176 2 SCON1 &= ~0x02; // clear TI1 interrupt flag
177 2 SBUF1 = 0x0d; // output carriage return
178 2 }
179 1 while (!(SCON1 & 0x02)); // wait until UART1 is ready to transmit
C51 COMPILER V8.08 F34X_UART_STDIO 04/13/2008 09:11:04 PAGE 4
180 1 SCON1 &= ~0x02; // clear TI1 interrupt flag
181 1 return (SBUF1 = c); // output <c> using UART 1
182 1
183 1 }
184
185 //-----------------------------------------------------------------------------
186 // _getkey
187 //-----------------------------------------------------------------------------
188 //
189 // Return Value : byte received from UART0/1
190 // Parameters : none
191
192 // This is an overloaded fuction found in the stdio library. When the
193 // function _getkey is called, either by user code or through calls to stdio
194 // routines such as scanf, the following routine will be executed instead
195 // of the function located in the stdio library.
196 //
197 // The function checks the UART global variable to determine which UART to
198 // use to receive a character.
199 //
200 // The routine waits for RI0/RI1 to be set, indicating that a byte has
201 // been received across the UART0/UART1 RX line. The routine saves the
202 // received character into a local variable, clears the RI0/RI1 interrupt
203 // flag, and returns the received character value.
204 //
205 //-----------------------------------------------------------------------------
206 char _getkey () {
207 1 char c;
208 1 while (!(SCON1 & 0x01)); // wait until UART1 receives a character
209 1 c = SBUF1; // save character to local variable
210 1 SCON1 &= ~0x01; // clear UART1 receive interrupt flag
211 1 return (c); // return value received through UART1
212 1
213 1 }
214
215 //-----------------------------------------------------------------------------
216 // Delay
217 //-----------------------------------------------------------------------------
218 //
219 // Return Value : none
220 // Parameters : none
221 //
222 // Used for a small pause of approximately 40 us.
223 //
224 //-----------------------------------------------------------------------------
225
226 void Delay(void)
227 {
228 1 int x;
229 1 for(x = 0;x < 500;x)
230 1 x++;
231 1 }
232
233
234 //-----------------------------------------------------------------------------
235 // MAIN Routine
236 //-----------------------------------------------------------------------------
237
238 void main (void) {
239 1 char input_char;
240 1
241 1 PCA0MD &= ~0x40; // Disable Watchdog timer
C51 COMPILER V8.08 F34X_UART_STDIO 04/13/2008 09:11:04 PAGE 5
242 1
243 1 SYSTEMCLOCK_Init (); // initialize oscillator
244 1 PORT_Init (); // initialize crossbar and GPIO
245 1 UART1_Init (); // initialize UART1
246 1
247 1 CH423_Set_H(0xff);
248 1 CH423_Set_L(0xff);
249 1
250 1 // transmit example UART1
251 1 printf ("Hello, from UART1!\n");
252 1
253 1 while (1)
254 1 {
255 2 input_char = getchar();
256 2 printf (" '%c', 0x%02x\n", (unsigned char) input_char,
257 2 (unsigned) input_char);
258 2 switch (input_char)
259 2 {
260 3 case 0x01:
261 3 Main_LCD_Show_Black(); //
262 3 break;
263 3 case 0x02:
264 3 Main_LCD_Show_White(); //
265 3 break;
266 3 case 0x03:
267 3 Main_LCD_Show_Red(); //
268 3 break;
269 3 case 0x04: //
270 3 Main_LCD_Show_Green();
271 3 break;
272 3 case 0x05:
273 3 Main_LCD_Show_Blue(); //
274 3 break;
275 3 case 0x06:
276 3 Main_LCD_Grey_Scale_Test(); //
277 3 break;
278 3 case 0x07:
279 3 Sub_LCD_Show_Black(); //
280 3 break;
281 3 case 0x08: //
282 3 Sub_LCD_Show_White();
283 3 break;
284 3 case 0x09:
285 3 Sub_LCD_Show_Red(); //
286 3 break;
287 3 case 0x0a: //
288 3 Sub_LCD_Show_Green();
289 3 break;
290 3 case 0x0b:
291 3 Sub_LCD_Show_Blue(); //
292 3 break;
293 3 case 0x0c: //
294 3 Sub_LCD_Grey_Scale_Test();
295 3 break;
296 3 case 0x0d: //
297 3 LCD_Off();
298 3 break;
299 3 case 0x10: //
300 3 CH423_Set_H(0xff);
301 3 break;
302 3 case 0x11: //
303 3 CH423_Set_L(0x7f);
C51 COMPILER V8.08 F34X_UART_STDIO 04/13/2008 09:11:04 PAGE 6
304 3 break;
305 3 case 0x12: //
306 3 CH423_Set_L(0xbf);
307 3 break;
308 3 case 0x13: //
309 3 CH423_Set_L(0xdf);
310 3 break;
311 3 case 0x14: //
312 3 CH423_Set_L(0xef);
313 3 break;
314 3 case 0x15: //
315 3 CH423_Set_L(0xf7);
316 3 break;
317 3 case 0x16: //
318 3 CH423_Set_L(0xfb);
319 3 break;
320 3 case 0x17: //
321 3 CH423_Set_L(0xfd);
322 3 break;
323 3 case 0x18: //
324 3 CH423_Set_L(0xfe);
325 3 break;
326 3 case 0x20: //
327 3 CH423_Set_H(0x00);
328 3 CH423_Set_L(0xff);
329 3 break;
330 3 default:
331 3 break;
332 3 }
333 2 input_char=0x00;
334 2
335 2
336 2 }
337 1
338 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2554 ----
CONSTANT SIZE = 35 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 8 7
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -