PIC16F877에서 SERIAL 통신 소스



===============================================================

#include <16f874.h>
#device pic16f874 *=8 adc=10

#byte PIR1 = 0x0c
#bit RCIF = PIR1.5
#byte RCSTA = 0x18
#byte TXSTA = 0x98
#bit TRMT = TXSTA.1
#byte SPBRG = 0x99
#byte RCREG = 0x1a
#byte TXREG = 0x19

unsigned char Getch(void)
{
while(!RCIF);
return(RCREG);
}

void Putch(unsigned char TxD)
{
while(!TRMT);
TXREG = TxD;
}

void init(void)
{
SPBRG = 23;
RCSTA = 0b10010000;
TXSTA = 0b00100000;
TXREG = 0;
}

void main(void)
{
unsigned char i;
init();
Putch(0x0c);

do {
i = Getch();
Putch(i);
} while(1);
}

=====================================================================

+ Recent posts