|
#define NINE 0 /* FALSE Use 8bit ELSE USE 9bit*/
#define HIGH_SPEED 1 /* Speed UART */
#if HIGH_SPEED == 1
#define SPEED 0x4
#define DIVIDER ((int)(FOSC/(16UL * BAUD) -1))
#else
#define SPEED 0
#define DIVIDER ((int)(FOSC/(64UL * BAUD) -1))
#endif
#if NINE == 1
#define NINE_BITS 0x40
#else
#define NINE_BITS 0
#endif
void init_comms(void);
void putbyte(unsigned char);
.....
.....
// serial.c
void
init_comms(void)
{
SPBRG = DIVIDER;
TXSTA = (SPEED|NINE_BITS|0x20);
RCSTA = (NINE_BITS|0x90);
TRISC6 = 0; //OUTPUT
TRISC7 = 1; //INPUT
}
/* Send byte to serial port */
void
putbyte(unsigned char byte)
{
/* output one byte */
while(!TXIF); /* set when register is empty */
TXREG = byte;
}
E-mail: info@telesys.ru