Functions/Constants to Support A Simulated UART

These functions and constants support UART functionality in the MPLAB SIM simulator.

Examples of Use

Example 1: UART1 I/O

#include <libpic30.h> /* a new header file for these definitions */
#include <stdio.h>
void main() {
  if (__attach_input_file("foo.txt")) {
    while (!feof(stdin)) {
      putchar(getchar());
    }
    __close_input_file();
  }
}

Example 2: Using UART2

/* This program flashes a light and transmits a lot of messages at 
   9600 8n1 through uart 2 using the default stdio provided by the 
   16-bit compiler. This is for a dsPIC33F DSC on an Explorer 16(tm) board 
   (and isn't very pretty) */
#include <libpic30.h> /* a new header file for these definitions */
#include <stdio.h> 

#ifndef __dsPIC33F__ 
#error this is a 33F demo for the explorer 16(tm) board 
#endif 
#inlcude <p33Fxxxx.h>

_FOSCSEL(FNOSC_PRI ); 
_FOSC(FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMD_XT); 
_FWDT(FWDTEN_OFF); 

main() {
  ODCA = 0; 
  TRISAbits.TRISA6 = 0; 
  __C30_UART=2; 
  U2BRG = 38; 
  U2MODEbits.UARTEN = 1; 
  while (1) {
    __builtin_btg(&LATA,6); 
    printf("Hello world %d\n",U2BRG); 
  } 
}

Example 3: Millisecond Delay

#define FCY 1000000UL 
#include <libpic30.h> 
int main() { 
  /* at 1MHz, these are equivalent */ 
  __delay_ms(1); 
  __delay32(1000); 
}

Example 4: Microsecond Delay

#define FCY 1000000UL 
#include <libpic30.h> 
int main() { 
  /* at 1MHz, these are equivalent */ 
  __delay_us(1000); 
  __delay32(1000); 
}