MicroCode Studio
mecanique

 | Index | ICD | Setup | Models | Serial | Sys. Req. |

| Break Points | Toolbar | Edit | WIN | MPASM |

ICD Serial Communications

ICD Serial Communications

MicroCode Studio allows you to receive and transmit serial data when the ICD process is executing. Serial data can be sent to a PICBasic HSERIN instruction using the ICD Serial In window. Serial data sent by a HSEROUT instruction is received and displayed using the ICD Serial Out window.

It is essential that MicroCode Studio takes complete control of the microcontrollers hardware serial port (USART), to ensure that the ICD functions correctly. A USART that is not configured properly could compromise the ICD process. Certain user defines are therefore disabled during an ICD Compile or ICD Compile and Program and include:

HSER_BAUD 'baud rate
HSER_SPBRG
'spbrg init
HSER_RCSTA
'receive status init
HSER_TXSTA
'transmit status init
HSER_EVEN
'even parity
HSER_ODD
'odd parity

The ICD will only disable hardware serial defines if they are present in your main program. MicroCode Studio will not disable defines if they are present in an include file. Using hardware serial defines in an include file may, in certain circumstances, cause the ICD process to fail. In addition, the MicroCode Studio ICD will only support HSERIN and HSEROUT if they are used from within your main program block.

The MicroCode Studio ICD uses the default PICBasic serial data format of 8 data bits, no parity and one stop bit (8N1) to communicate with your computer. In addition, the following defines are used:

DEFINE HSER_SPBRG Value 'spbrg init
DEVICE HSER_TXSTA Value 'transmit status init

You won't see these values normally, but you can view the actual values used by the MicroCode Studio ICD by right clicking on the ICD Explorer window and then selecting 'ICD Serial Settings...' The ICD also uses the following RCSTA value, which is a default PICBasic define:

DEFINE HSER_RCSTA 90H 'receive status init

This means that when using the ICD, you do not need to configure HSERIN and HSEROUT as you would normally, because the ICD will do this automatically. However, you may need one or more of the above defines in your final code build, if HSERIN and HSEROUT are used.

Example

Here is a simple program, which reads in a value using HSERIN and then echoes it to screen using HSEROUT. It assumes you are using a microcontroller running at 20MHz, programmed with bootloader software.

DEFINE LOADER_USED 1
DEFINE OSC 20

CR CON 13
Char VAR BYTE

HSEROUT ["Program Starting...",CR]
ProgramStart:
HSERIN [Char]
HSEROUT [
"Char = '", Char,"' is ASCII = ",DEC Char,CR]
GOTO ProgramStart

The above program will run within the ICD process, but not if you compile and program your microcontroller normally (that is, you have not used ICD Compile or ICD Compile and Program). You can view the defines MicroCode Studio has used by right clicking on the ICD Explorer window and then selecting 'ICD Serial Settings...'

ICD Serial Settings

If you want to use HSERIN and HSEROUT in your final program, then just add the above defines to your source code. For example,

DEFINE HSER_TXSTA 24H ' add TXSTA value, high speed
DEFINE HSER_SPBRG 0AH ' add SPBRG value

DEFINE LOADER_USED 1
DEFINE OSC 20

CR CON 13
Char VAR BYTE

HSEROUT ["Program Starting...",CR]
ProgramStart:
HSERIN [Char]
HSEROUT [
"Char = '", Char,"' is ASCII = ",DEC Char,CR]
GOTO ProgramStart

See Also

ICD Serial In
ICD Serial Out


Page up-dated at December 13, 2003


GRIFO®
Via dell'Artigiano, 8/6
40016 San Giorgio di Piano
Bologna ITALY

Tel: +39 051 892.052 (4 lines)
FAX: +39 051 893.661


homeHome Index Software Tables Cat. Index