Dear forum member,
I have a problem with using uart of pic 16f887 to communicate with PC via VB 6.0.
I can successfully send command from VB to control pic but I try to get text back from pic it doesn't work. but instead read text, I can read back only what I sent out.
Could you please help my problem.
I have write a small code for testing using MikroC pro for pic as bellow:
//*******************************************
char dataRx;
void main() {
ANSEL = 0; // Configure AN pins as digital
ANSELH = 0;
trisd=0;
portd=0xff;
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
while (1) { // Endless loop
if (uart1_data_ready())
{
dataRx=uart1_read();
if (dataRx=='A')
{
uart1_write_text("You type A");
uart1_write(13);
uart1_write(10);
}
else if (dataRx=='B')
{
uart1_write_text("You type B");
uart1_write(13);
uart1_write(10);
}
else
{
uart1_write_text("I don't understand");
uart1_write(13);
uart1_write(10);
}
portd = dataRx;
}
}
//***********************************************
And my VB code as bellow:
'************************************************
Private Sub cmdDataReceive_Click()
Dim DataReceive$
DataReceive = MSComm1.Input
txtDataReceive.Text = DataReceive
End Sub
Private Sub cmdDataSend_Click()
Dim DataSend$
DataSend = txtDataSend.Text
MSComm1.Output = DataSend
End Sub
Private Sub Form_Load()
MSComm1.PortOpen = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub
'*********************************************
I have also attached picture of circuit but instead use 10ufF I used 22pF. I don't know this can effect or not.
Thank for helping.

I have a problem with using uart of pic 16f887 to communicate with PC via VB 6.0.
I can successfully send command from VB to control pic but I try to get text back from pic it doesn't work. but instead read text, I can read back only what I sent out.
Could you please help my problem.
I have write a small code for testing using MikroC pro for pic as bellow:
//*******************************************
char dataRx;
void main() {
ANSEL = 0; // Configure AN pins as digital
ANSELH = 0;
trisd=0;
portd=0xff;
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
while (1) { // Endless loop
if (uart1_data_ready())
{
dataRx=uart1_read();
if (dataRx=='A')
{
uart1_write_text("You type A");
uart1_write(13);
uart1_write(10);
}
else if (dataRx=='B')
{
uart1_write_text("You type B");
uart1_write(13);
uart1_write(10);
}
else
{
uart1_write_text("I don't understand");
uart1_write(13);
uart1_write(10);
}
portd = dataRx;
}
}
//***********************************************
And my VB code as bellow:
'************************************************
Private Sub cmdDataReceive_Click()
Dim DataReceive$
DataReceive = MSComm1.Input
txtDataReceive.Text = DataReceive
End Sub
Private Sub cmdDataSend_Click()
Dim DataSend$
DataSend = txtDataSend.Text
MSComm1.Output = DataSend
End Sub
Private Sub Form_Load()
MSComm1.PortOpen = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub
'*********************************************
I have also attached picture of circuit but instead use 10ufF I used 22pF. I don't know this can effect or not.
Thank for helping.