My Own COM Port GUI

I am going to  write about the GUI that I developed for sending data to my PIC development board. I used Liberty BASIC Gold version to develop this GUI.

You may download the demo version for free at http://www.libertybasic.com/. However, there are certain limits for the software and you have to register for a Gold version to enjoy all the features of the software.  The programming window of the software looks like the one shown in the picture below. There are tutorials available in the software which may be accessed as shown in the picture below. You may learn to open a GUI window, add buttons and consequently handle events upon button click  using the simple tutorials. These are  essential elements for our COM port recipe. When you are done with the tutorials,  you would be capable enough to design a small interface as shown in the picture below: Once you are done adding buttons, you must add a functionality to the buttons. For eg: I have added the close window option to Quit button. I am sending a string of information to my controller when I press either of the Forward, Reverse or Neutral buttons.

The algorithm for the same is as follows:

1) Open COM port

2) Send string

3) Close COM port.

Close button press event handle

Note: You have to close the event handles properly once you are done with handling the event of a button press or your code may end with bugs.

The algorithm at the PIC microcontroller end  to receive ASCII string from your computer is as follows:

1) Initialise ports and Set the Baud rate

2) If data received, read the data.

3) If string x is received, move forward

4)If string y is received, move reverse

5)If string z is received, move to neutral position

6) Go to step 2

Please note that I am trying to control a servo motor through serial port.  If you would like to know the operation of a servo motor, please refer to the following link.

I used the MikroC compiler to write the code for serial port communication and servo motor control.

unsigned short i;
void main()
{
TRISB = 0x00;
USART_init(19200);
while(1)
{ if (USART_Data_Ready())
{
i = USART_Read();
i = i-48;
if( i ==1)
{
PORTB = 1;
delay_us(1500);
PORTB = 0;
delay_ms(18);
delay_us(500);
delay_ms(1000);
}
else if(i==0)
{
PORTB = 1;
delay_us(1250);
PORTB = 0;
delay_ms(18);
delay_us(750);
delay_ms(1000);
}
else if(i==2)
{
PORTB = 1;
delay_us(1750);
PORTB = 0;
delay_ms(18);
delay_us(250);
delay_ms(1000);
}
else
{
}
}
}
}

Please note that the baud rate was 19200 bps, 1 stop bit, no parity, no hardware control and the number of bits transmitted was 8.

When you are done coding your PIC, you may create an exe file for your application as follows: You may download the GUI that I developed from the following location.

You may also have a look at my video of operating my servo motor through serial port.

Advertisements

One Response to My Own COM Port GUI

  1. Srihari says:

    Congratulations! Keep up the good work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: