PDA

View Full Version : PC and Micro Communication


Philip
05-01-08, 08:38 AM
Sir

I wrote a visual basic program which i use to communicate with my NMI0016.

The code was intended to send a character or a string to the micro, the micro will then validate the string receive and send the corresponding responds back to the pc.

However after the micros validation it doesn't send the responds but it
sends back the string it received for the respond please help.

Below is the micro side of the code:

#include clib\common51.c
#include clib\syslib51.c
#include clib\stdio.h
#include clib\fputc.c
#include clib\fputs.c
#include clib\fgetc.c
#include clib\fgets.c

main()
{
int i;
char cin;

char cout;
char clear;


while(1)
{


cin =fgets(stdin);

if (cin == 'P')
{
cout= 'PHILIP'
fputs(cout,stdout);
}

if (cin == 'A')
{
cout= 'APPIAH'
fputs(cout,stdout);
}

if (cin == 'K')
{
cout= 'KUNDO'
fputs(cout,stdout);
}
}

}


Thank You

nmitech
05-01-08, 02:01 PM
main()
{
int i;
char cin;

/* char cout; */
char *cout;

char clear;

while(1)
{


/* cin =fgets(stdin); */
cin =fgetc(stdin);

if (cin == 'P')
{
/* cout= 'PHILIP' */
cout= "PHILIP";
fputs(cout,stdout);
}

if (cin == 'A')
{
/* cout= 'APPIAH' */
cout= "APPIAH";
fputs(cout,stdout);
}

if (cin == 'K')
{
/* cout= 'KUNDO' */
cout= "KUNDO";
fputs(cout,stdout);
}
}

}

Philip
05-02-08, 10:43 AM
Sir

Now it works but with some logical error i think.

When you send 'P' the micro responds with 'PPhilip'

When you send 'A' it responds 'AAPPIAH'

When you send 'K' it responds 'KUNDO'

When you send AP instead of displaying nothing
the micro reponds with 'AAPPIAHPPHILIP'

And also when you send any other caharacter apart from
the A,K,P the micro transmit that same character back.