Harshal Dalal
Newbie level 3
- Joined
- Jul 23, 2014
- Messages
- 4
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 23
hello everyone ,
I am interested in communication between to pic18f4550 hardware.
here is my 2 code..
1st is for transmit from 1st board to another,
and here is my 2nd code to receive the data from 1st board
my both code is perfectly working on hyper terminal and proteus simulation when i connect them "SEPARATELY" with PC
but when i try connect two pic with rs232 then its not working...
so plz help me.. yours suggestion are most welcome
I am interested in communication between to pic18f4550 hardware.
here is my 2 code..
1st is for transmit from 1st board to another,
Code:
unsigned char txbuf[]={0x02, 0x31, 0x37, 0x3B, 0x3B, 0x44, 0x45,0x03,};
unsigned char z, i;
void TXbyte(char data)
{
while(TXSTAbits.TRMT==0); //wait tiiltransmit buffer in not empty
TXREG = data; // Transmit Data
}//end TXbyte
-------------------------
------------------------
-----------------------
void main()
{
SPCON1 = 0; // Make sure SPI is disabled //Refer Datasheet
TRISCbits.TRISC7=1; // RX
TRISCbits.TRISC6=0; // TX
SPBRG = 0x9B; //4800 baud XTAL=20MHz, Fosc=48Mhz
TXSTA = 0x20; // TX enable BRGH=0
RCSTA = 0x90;
for(i=0;txbuf[i]!='\0';i++)
{
TXbyte(txbuf[i]);
}
}//main ends
and here is my 2nd code to receive the data from 1st board
Code:
void main()
{
SSPCON1 = 0; // Make sure SPI is disabled //Refer Datasheet
TRISCbits.TRISC7=1; // RX
TRISCbits.TRISC6=0; // TX
SPBRG = 0x9B; //4800 baud XTAL=20MHz, Fosc=48Mhz
TXSTA = 0x20; // TX enable BRGH=0
RCSTA = 0x90; // continuous RX
BAUDCON = 0x00; // BRG16 = 0
for(i=0;i<8;i++) //for loop receive 8 byte to receive and it will store in rxbuf
{
while(PIR1bits.RCIF==0); //Wait util data from PC is received
rxbuf[i]=RCREG;
PIR1bits.RCIF = 0;
}
if (rxbuf[1]==0x31 && rxbuf[2]==0x37 ) // this loop will check 1st and 2nd byte whether it is 1 and 7 or not
{
PORTBbits.RB5=1;
}
}
my both code is perfectly working on hyper terminal and proteus simulation when i connect them "SEPARATELY" with PC
but when i try connect two pic with rs232 then its not working...
so plz help me.. yours suggestion are most welcome