PicStic 1-4 (2K Version)

 Using the Hardware Serial Port with PicBasic Pro

December 13, 2001

This application note will illustrate how to utilize the hardware serial port available on the 2K versions of Micromints PicStic 1-4 line of microcontrollers.

The original versions of Micromints PicStic 1-4 controllers were only capable of serial communication through a user designated pin that becomes a software serial port. The 2K versions of Micromints PicStic 1-4 are equipped with a hardware USART.  The USART is available on pins 8 and 9 on the PicStic 1_2K – PicStic 3_2K and on pins 6 and 7 of the PicStic 4_2K. The USART can only transmit a non-inverted signal, so dual 485 drivers are being used to invert the signals to allow for serial communications with a PC.


How it works:     In the configurations shown in Figures A and B the transmit enable is connected to PortB.0. By using the port pin to control the transmit enable the PicStic is capable of RS232A, RS485 and RS422 communications. Before any serial communication can take place, the transmitter needs to be enabled by setting PortB.0 high. PortB.0 is tied to the transmit enable pin of the 485 driver to allow for the wide communication protocols. There needs to be a brief pause of 1µSec to allow the transmitter time to enable before any serial communication can transpire.

     PicBasic Pro provides serial commands that read from (HSERIN) and write to (HSEROUT) the hardware serial port. These commands have several parameters that can be modified to create the required data format. These parameters default to the following data format; 8N1@2400bps (8 data bits, no parity, and 1 stop bit).  To change the data format simply change the parameter by changing one or more of the following definitions (NOTE: When changing the definitions listed below, note that each definition is fully capitalized. A compiler error will be generated if the definitions are not capitalized.);


DEFINE  HSER_RCSTA     90H              ‘ Set receive status and control register*

DEFINE  HSER_TXSTA     20H              ‘ Set transmit status and control register*

DEFINE  HSER_BAUD       2400             ‘ It is only necessary to set one of these parameters.

DEFINE  HSER_SPBRG      25                 ‘ When one is set the other is automatically set.

DEFINE  HSER_EVEN        1                   ‘ Only odd or even should be defined at a time

DEFINE  HSER_ODD          1                   ‘ Only odd or even should be defined at a time


     For 8N1 communications between 300bps and 2400bps, there is no need to change the RCSTA* or TXSTA* registers. Baud rates from 1200Kbps to 19.2Kbps can be reached by defining the TXSTA* register as 24H.  The HSER_BAUD also needs to be defined as one of the following:


1202  for 1200Kbps

2403  for 2400Kbps

9615  for 9600Kbps

19231 for 19.2Kbps



      PicBasic Pro supports several data modifiers, which may be mixed and matched freely within a single HSERIN OR HSEROUT command to provide for various input/output formatting. For a complete list of the modifiers available with the HSERIN and HSEROUT commands please refer to the PicBasic Pro programmers reference manual.

*For detailed descriptions of the RCSTA and TXSTA registers please refer to the Microchip PIC16F62XÔ Data Sheet or contact Micromint Inc..


Figure A


Figure B



Program Listing:  The following program illustrates how to use the HSERIN command with the hardware serial port. Examples of the HEX, BIN, and DEC modifiers are also shown.


Define HSER_TXSTA   24H                                      ‘ Set TXSTA to allow for higher baud rate

Define  HSER_BAUD       56000                                         ‘ Set baud rate to 56Kbps


INPUT    VAR        WORD                                                       ‘ Define INPUT as a word sized variable



                PAUSE 1

                HSEROUT ["ENTER A DECIMAL NUMBER BETWEEN 0 – 65535" ,10,13]

                HSERIN [DEC5 INPUT]


                HSEROUT ["ENTER A HEX NUMBER BETWEEN 0 – FFFFH" ,10,13]

                HSERIN [HEX4 INPUT]


                PAUSE 1000

                GOTO START