serial communication problem

Status
Not open for further replies.

arafatronics

Newbie level 3
Joined
Apr 10, 2013
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,323
hi all
i'm a beginner in pic microcontroller
i'm programming two pic18f4550 one sender and the other is a reciever which connected Rx to Tx to communicate
i wrote the program in mikroc c based on its library and tested on protus and worked
but in the real world nothing work at all
the sender code is :

char uart_rd;

void main() {
ADCON1 |= 0x0F; // Configure all ports with analog function as digital
CMCON |= 7; // Disable comparators

TRISC0_bit = 0;
TRISC2_bit = 0; RC2_bit = 1;

UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
SPEN_bit = 1;
TXEN_bit = 1;



while (1) { // Endless loop

Delay_ms(1000);
UART1_Write(0x01);
RC0_bit^=1;
Delay_ms(1000);
UART1_Write(0x02);
RC0_bit^=1;
}
}
the reciever code is :

char uart_rd;

void main() {
ADCON1 |= 0x0F; // Configure all ports with analog function as digital
CMCON |= 7; // Disable comparators

TRISD=0;
TRISC0_bit = 0;
TRISC2_bit = 0; RC5_bit = 0;

UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
SPEN_bit=1;
CREN_bit=1;



while (1) { // Endless loop
if (UART1_Data_Ready()) { // If data is received,
uart_rd = UART1_Read(); // read the received data,
if(uart_rd==0x01) RD5_bit^=1;
if(uart_rd==0x02) RD7_bit^=1;
if((uart_rd!=0x01) && (uart_rd!=0x02)) RD3_bit^=1;
}

}
}
 

1. For Tx TRISCx = 0; Rx = TRISCx = 1; where x corresponding to corresponding port pin.
Also Try to use Receive interrupt.
2. Check is Ur Individual control Transmit data correct on Hyper Terminal. Don't assume
simulation work means practical circuit also work.
3. Check B.R setting according to ur Crystal.
 

you need to connect 0.1uf(tantalum) capacitor between pin 15 and grount,this will remove timing error in communication.
try it
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…