#include<htc.h>
#define xtalfreq 4000000
#define baudrate 9600
void delay(int s)
{
while(s--);
}
void serialint()
{
TRISC6=0;
TRISC7=1;
SPBRG=((xtalfreq/16)*1/baudrate)-1;
BRGH=1;
SYNC=0;
SPEN=1;
CREN=1;
SREN=0;
TXIE=0;
RCIE=1;
TX9=0;
RX9=0;
TXEN=0;
TXEN=1;
}
void serialwrite(char tx)
{
TXREG=tx;
while(TRMT==0);
TRMT=0;
}
char serialread()
{
char rx;
while(RCIF==0);
rx=RCREG;
RCIF=0;
return (rx);
}
void main()
{
serialint();
delay(100);
serialwrite('o');
serialwrite('k');
while(1)
{
char chr;
chr=serialread();
delay(100);
serialwrite(chr);
}
}
#define xtalfreq 4000000
#define baudrate 9600
void delay(int s)
{
while(s--);
}
void serialint()
{
TRISC6=0;
TRISC7=1;
SPBRG=((xtalfreq/16)*1/baudrate)-1;
BRGH=1;
SYNC=0;
SPEN=1;
CREN=1;
SREN=0;
TXIE=0;
RCIE=1;
TX9=0;
RX9=0;
TXEN=0;
TXEN=1;
}
void serialwrite(char tx)
{
TXREG=tx;
while(TRMT==0);
TRMT=0;
}
char serialread()
{
char rx;
while(RCIF==0);
rx=RCREG;
RCIF=0;
return (rx);
}
void main()
{
serialint();
delay(100);
serialwrite('o');
serialwrite('k');
while(1)
{
char chr;
chr=serialread();
delay(100);
serialwrite(chr);
}
}
No comments:
Post a Comment