|
|||||||||||
Technical Support Support Resources
Product Information |
µVISION DEBUGGER: Automated Serial Input ScriptInformation in this article applies to:
QUESTIONI have an 8051 application that processes a lot of serial data. I'm simulating the program using the µVision Debugger, but I have to type in a lot of data in the serial window. Is there a way to automate this? ANSWERYes. You can create a simple script that injects your data into the serial input buffer. To demonstrate this, first you will need the following simple test program: /*----------------------------------------------------------------------------- -----------------------------------------------------------------------------*/ #include <reg52.h> #include <stdio.h> /*------------------------------------------------ The following string is the stuff we're gonna send into the serial port. ------------------------------------------------*/ unsigned char xdata serial_input_buffer [] = "This is a test to see if this data gets " "injected into the serial port.\r\n" "Have fun.\r\n" "\r\n\r\n"; void main (void) { /*------------------------------------------------ Setup the serial port for 2400 baud at 12MHz. ------------------------------------------------*/ SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */ TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */ TH1 = 0xF3; /* TH1: reload value for 2400 baud @ 12MHz */ TR1 = 1; /* TR1: timer 1 run */ TI = 1; /* TI: set TI to send first char of UART */ /*------------------------------------------------ Get a key from the serial port and send it right back out the serial port. ------------------------------------------------*/ while (1) { putchar (_getkey ()); } } /*----------------------------------------------------------------------------- -----------------------------------------------------------------------------*/ Note that this test program simply sets up the serial port for 2400 baud and echos characters it receives. The data that you will send into the simulated serial port is stored in the serial_input_buffer string declared at the top of this file. This is a convenient way to get this data into memory. However, you may want to create Intel HEX files (at fixed addresses) that contain your test data. You may load the HEX files and then dump their contents into the serial window using a method similar to this one. Second, you must create a simple debugger script that reads the input data and inputs it into the simulated serial port. The following script does that: define int seri_index; signal void seri_start (float baudrate) { seri_index = 0; for (seri_index = 0; serial_input_buffer[seri_index] != '\0'; seri_index++) { SIN = serial_input_buffer[seri_index]; // Wait for a little longer than 1 character time between each character swatch (1.0 / ((baudrate/10.0) + 20.0)); } } define button "Send Data" , "seri_start(1200)" Additionally, a button is created in the toolbox to start sending in the serial data. There are several things to note about this script.
SEE ALSO
Last Reviewed: Friday, December 11, 2020 | ||||||||||
|
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.