This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Simple Serial Communication between 8051 MCU and LabVIEW

I am trying to use LabVIEW to read the serial output from the simple ISR-Driven Serial I/O V2 Example ( used on a C8051F300 MCU. I know my LabVIEW can acquire string or character data from the serial port. The C code compiles without any errors or warnings and I have included the proper header files.

void main (void)
com_initialize ();              /* initialize interrupt driven serial I/O */
com_baudrate (1200);            /* setup for 1200 baud */

EA = 1;                         /* Enable Interrupts */

printf ("Interrupt-driver Serial I/O Example\r\n\r\n");

while (1)
  unsigned char c;

 		 printf ("Press a key.\r\n");
  		c = getchar ();
 		 printf ("\r\n");
  		printf ("You pressed '%c'.\r\n\r\n", c);

The program seems to get stuck before the first printf line, which makes me think there may be a problem with com_initialize() or com_baudrate. The only change I have made is that I changed XTAL (see code below) to the MCU oscillator frequency (24.5 MHz). XTAL was originally giving me an error. Correct me if I am wrong, but I think it is only used if I have an external crystal.

Original function:

void com_baudrate ( unsigned baudrate)
Clear transmit interrupt and buffer.
TI = 0;             /* clear transmit interrupt */
t_in = 0;           /* empty transmit buffer */
t_out = 0;

Set timer 1 up as a baud rate generator.
TR1 = 0;            /* stop timer 1 */
ET1 = 0;            /* disable timer 1 interrupt */

PCON |= 0x80;       /* 0x80=SMOD: set serial baudrate doubler */

TMOD &= ~0xF0;      /* clear timer 1 mode bits */
TMOD |= 0x20;       /* put timer 1 into MODE 2 */

TH1 = (unsigned char) (256 - (XTAL / (16L * 12L * baudrate)));

TR1 = 1;            /* start timer 1 */

Changed second to last line to:
TH1 = (unsigned char) (256 - (24500000 / (16L * 12L * baudrate)));

I am working on an undergraduate research project and have no prior experience with programming embedded controllers, so any help or advice would be greatly appreciated.
Also, please let me know if you have a recommendation for a simpler example program I can run just to make sure I can establish communication between the MCU and LabVIEW.