My Own COM Port GUI

June 9, 2010

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.


Make your PIC18F4550 talk to your PC via USB

April 13, 2010

I have always fancied PIC USB communication. I bought a PIC USB development board from Rhydolabz. I am going to write about making your PIC’s USB port communicate to the PC.

You would be requiring the Microchip USB Stack to start.  After having downloaded the USB Stack, execute the exe file to install the USB stack. Once the USB stack is installed, proceed to the directory where your “Microchip Solutions” folder could be found.

You should be able to find a file by name picdemfsusb.hex under Precompiled Demos/Factory Hex Files folder inside your Microchip Solutions Directory. My development board came with a pre-loaded bootloader. If you are going to use a fresh PIC18F4550 chip, you may have to use the downloader that is readily available in the Microchip Solutions directory. I used a hex download software that came along with  my development board and loaded the picdemfsusb.hex into the controller.

As soon as you hit the reset button of your development board, you must be able to see a New Hardware Found Tab appear in your system tray.

In most of the cases, the hardware may not be recognised by the computer and you may have to install the drivers for your development board when your system asks for it as shown in the figure below:

You would be able to locate the driver files for Microchip Hardware in the respective project folders located inside the directory.

Once you locate the drive files and install them, your system would reflect the installed hardware as shown in the figure below:

You would be able to locate the connected device in Device Manager.

Bingo! You have installed a Microchip hardware to your system!

Write to me if you have questions about this post.


PIC12F508 — as small as it is

March 3, 2010

I ordered a PIC12F508 from http://www.kitsnspares.com . I assumed that the package of the microcontroller would be a DIP package. It was a MSOP package when it arrived.

A cute little microcontroller

I am trying to develop a customised board for this controller.


PIC JDM Programmer

March 1, 2010

I must thank my friend Sathish who has developed this cute little JDM PIC programmer. This is the smallest programmer that I have ever used for a PIC.

PIC JDM Programmer

He has used the schematic from Olimex as a reference.

Please find the link below:

http://www.olimex.com/dev/images/pic-pg2c-sch.gif


She(Development Board) is ready

January 24, 2010

Finally the board that I had developed is ready. I tested the function of the board with simple PWM program. I provided the output to capture the output using a LED. Though it may not look like a pulse width modulated output, I am happy that the basic functionality of the board is a great success. I believe that the other functionalities are also successful.  I plan to make it open source when the board is fully functional.

I am also enclosing a few photographs of my development board


PIC16F84A based robot

September 2, 2009

Well, I had been working on a DC Motor control for the past few days using the PIC16F84A Platform. I have uploaded two videos. The first one shows the DC Motor operation in the forward and reverse direction.

I assembled those DC Motors on to a acrylic sheet and clamped them to run them in the forward and reverse directions with a pause. Wow!

I have also shown the LED indicating the time duration for which the DC Motors keep rotating in the either direction. Well, there has been some problems with the balancing. I am trying to add a castor in the back side also!


My experiments with PIC

August 13, 2009

I relocated to Coimbatore recently and since then it has been difficult to get settled with things.  The first thing being setting things right with my interests i.e Microcontroller kit installation and purchase of components. I need to find a shop where I am able to buy electronics stuff. It has been a tough time to solder my own USB PIC  programmer board. Well, things would get straight as the days pass by.

I always wanted to use/write a delay program which listens to my words. I had never been successful in this regard.

I downloaded a header file which was available over the internet. I had problems with my MPLAB software.

#include “delay.h”
#include <pic.h>
void main()
{
 TRISB = 0x00;
 PORTB = 0x00;
 
 while (1)
{
 PORTB = 0x00;
 DelayS(1);
 PORTB = 0XFF;
 DelayS(1);
}
}

Now, the problem with the code was that the hex file was mysteriously wrong.

Hex file Snapshot from winpic

Hex file Snapshot from winpic

Later, I used my age old code which I learnt from an Embedded Systems training centre:

#include “pic.h”
void delay_ms (int n);
void delay_us (int n);
void main()
{
 TRISB = 0x00;
 PORTB = 0x00;
 
 while (1)
{
 PORTB = 0x00;
delay_ms(1000);
 PORTB = 0XFF;
delay_ms(1000);
}
}
void delay_ms(int n)
{
 int i;
 for(i = 0; i<=n; i++)
{
delay_us(n);
}
}
void delay_us(int n)
{
 int j;
 for(j=0; j<=n; j++);
}

The result was the same.

I had a two line hex file. Hence, I concluded that something is wrong with MPLAB. I used MikroC for the same code.

Bingo! My code worked. My hex code was:

Led Blinking Mikro C

Now, I tried testing my code using the PIC16F877A Development board. It worked. My first relocation experiement is done. I don’t have a camera to upload the PIC right now. I shall do so in the near future