
DOCUMENT NUMBER :E-M-0001-00
C++ Sample Code Y-Series
7/18 E2
−
5008
−
00
3.1.3 Sample Code
Example 3-1 is a C++ sample code for Fig. 3-2 (Asynchronous Serial Interface). It initializes the module and executes
a demonstration (displaying all Common Font Set characters). The code has been compiled with the CCS C++
Complier only and may need minor editing to work with other compilers. Refer to your specific module specification
“Serial Interface” and “Jumper Setting”.
#include <16F877.h>
//for PIC16F877
#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
#use delay(clock = 20000000)
//for 20MHz clock
//use EUSART module, baud rate = 38,400bps, format: Start (1bit) + Data (8bit) + Stop (1bit)
#use rs232(BAUD = 38400, XMIT = PIN_C6, RCV = PIN_C7)
#use fast_io(D)
//use D port fast I/O
//define output ports
#define SBUSY PIN_D3
//Variable declaration
int n, data;
//Prototype of functions
void executing_demo( );
void asynchro_out(int data);
void main( )
{
//Initialize a PIC and a display.
delay_ms(1000);
//warmup delay
set_tris_d(0x04);
//D3 = input
asynchro_out(0x1B); //display
initialization
asynchro_out(0x40);
//Execute a demonstration.
executing_demo( );
}
void executing_demo( )
{
for(data = 0x20; data <= 0x7F; data++)
asynchro_out(data);
}
void asynchro_out(int data)
{
//if SBUSY == 1, wait until SBUSY == 0
while(input(SBUSY) == 1)
{
}
putc(data);
//send 8-bit Asynchronous Serial data
}
Example 3-1