koolguy
Active Member
I am working on wireless based UART serial control using 2.2Ghz module everything is fine but i don't understanding while sending and using if cond at rx it is not working here is the code...
for Rx
for tx
for Rx
Code:
void HSerinit(void);
unsigned char Hserin(void); // transmission functions
void main()
{
HSerinit();
TRISC3=0;
TRISC1=0;
unsigned char ch;
while(1)
{
RC1=0;
RC3=0;
ch=Hserin();
if(ch=='a'){
RC3=1;
__delay_ms(200);
}
if(ch=='b'){
RC1=1;
__delay_ms(200);
}
}
}
unsigned char Hserin(void)
{
while(!RCIF);
return RCREG;
}
void HSerinit()
{
TRISC = 0x80; // TX was an input!
SPBRG = 129; // 20Mhz xtal 9600 BAUD
TXSTA = 0x24; // TXEN and BRGH
RCSTA = 0x90; // SPEN and CREN
}
for tx
Code:
void HSerinit(void), Hserout(unsigned char ch);
void main(void)
{
TRISA = 0xff ;
HSerinit();
__delay_ms(150);
unsigned char ch;
TRISD0=1;
TRISD1=1;
RD0=0;
RD1=0;
while(1)
{
if(RD1==1){ch='a';
Hserout(ch);
}
if(RD0==1){
ch='b';k
Hserout(ch);
}
ch=0; }
}
void Hserout(unsigned char ch)
{
while(!TXIF);
TXREG = ch;
}
void HSerinit()
{
TRISC = 0x80; // TX was an input!
SPBRG = 129; // 20Mhz xtal 9600 BAUD
TXSTA = 0x24; // TXEN and BRGH
RCSTA = 0x90; // SPEN and CREN
}