Click here to Skip to main content
Click here to Skip to main content

A PIC C Code Wizard

, 5 May 2003 CPOL
Rate this:
Please Sign up or sign in to vote.
Creates C code templates for PIC microcontrollers. The default templates are for use with the Hi-Tech (tm) PICC compiler.

Sample Image - piccpc-wiz.jpg

Introduction

I do some C programming for PIC microcontrollers at work. Some time ago, I developed a "PIC" C AppWizard (under MS-Visual Studio v6) to create C PIC applications. Now I've decided to make it a Win32 "regular" executable so the wizard does not depend on Visual Studio IDE.

This PIC-C Wizard creates C code templates to be used for certain Microchip (tm) PIC microcontrollers using the Hi-Tech's PICC compiler (tm). I know these two issues limit the usability of the tool, so I hope someone finds it useful.

The demo files provided are part of a demo PIC C project created using this wizard.

Features

  • GUI interface to assist the user setup PIC's hardware and software.
  • Creates C code templates that can be compiled with PICC (tm) compiler for the embedded version and Visual C/C++ for the PC version of the PIC's application.
  • Handles different users.
  • Creates a basic make batch file for PICC compilation and a project file (.dsp) for MS Visual C/C++ v6.0.
  • User can add or remove PIC micros by editing a text information file (PIC.INF).
  • Users can modify, add and/or remove the default C templates, so the wizard generates C code with the user's programming style.
  • It includes basic source code comments to create documentation using doxygen.

To be honest, all these features are not yet implemented 100% and the wizard may still be "buggy". I'll be posting frequent updates as I'm still working on it.

Install

I have not yet created an installer for this tool. So for now, simply download it and place it under a folder of your choice. I have tested it under Windows XP, 2K and NT SP6.

How This Wizard Works

User's folder and default C template files

The wizard will create a folder under the wizard's root folder. This folder will be named: Templates_<username>. For instance, if the actual logged on user is trinity, the folder created will be: Templates_trinity. This is where the wizard will put the default C templates and configuration files used to create PIC applications for different users. If a user's folder has been removed for some reason, the wizard will create it again with default templates.

The user can modify these C templates and the wizard will just replace the macros contained in them.

This is a list of the files generated by the wizard:

Common to both PIC and PC:

  1. pic.h: this file will be included in the sources and it'll load the PICC's pic.h or picpc.h (for Win32).
  2. main.h: this file will be renamed to the application's name. The user can add all sorts of definitions in this file that are specific to the application.
  3. main.c: this file will also be renamed. It'll contain the C main() entry point and the interrupt vector, as well as a default program structure based on a simple tasks scheduler. The user can add code to this file that is specific to the application.
  4. typedefs.h:this file will contain common definitions to both the embedded and Win32 versions of the application.
  5. picpcproj.inf: this file contains what template files will be part of the application's project. It contains a brief explanation on the keywords to indicate to the wizard, how to create the project files.
  6. confirm.inf: it contains the text information to be displayed just before the creation of the project files.
  7. pic.inf: it contains the list of PIC microcontrollers that are going to be listed for selection. This file can be modified to add or remove micros. The information required to add a new microcontroller can be obtained from a Microchip's Product Line Card.

For PIC compilation:

  1. picc.h: it will contain definitions more specific to the PIC rather than the application.
  2. picc.c: it will contain code implementation of different support functions for PIC programming, depending on which options the user selected to create the application.

For PC compilation:

  1. picpc.h: it will contain definitions more specific to Win32 programming.
  2. picpc.c: it will contain code implementation of different support functions trying to simulate some of the PIC 's peripherals. Mmmh, didn't get much with this.

You may be wondering, why is there a Win32 version of an application that is supposed to go into an 8-bit micro? Because the idea was to debug the application, to some extent, before actually downloading the zeros and ones into the micro. The idea made some sense to me before, as it's easier to debug under VC. But quickly I learned that I lack the time and knowledge to simulate the PIC's peripherals.

Well, at least it helps me to debug certain applications using floating-point based algorithms.

How does the wizard create a PIC application?

Since I've used the Visual C/C++ AppWizard several times, my brain could not think of another good way to implement one, but to imitate the way MS-VC does it. Of course my implementation falls short compared to the real one but I think it does the job. So this wizard basically looks for special words, called macros, in all the template files and replace them with values provided by the user through the GUI interface.

One clear advantage of this wizard is that the C templates are open for the user to modify. It makes sense, I mean, I provided these C default templates, which only reflects my limited experience in C programming; good enough for the novice user though. But for the expert, mmh, let's better have another look at that code.

Now, for someone to start modifying the default templates, it's necessary to know all the available macros and I'll include them in this article in the very near future.

Can the source code be modified to have another wizard?

Short answer is yes. Soon I'll provide more information on what and how to modify the source code provided to have another wizard.

How To Use

A tutorial will be coming soon...

Revision History

  • 06/MAY/2003:
    • Initial revision.

Acknowledgments

What? You really think that the only cool things about the wizard were programmed by me? Of course not, I really must thank these guys for their great code:

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Carlos Buelna
Delphi
United States United States
Carlos Buelna works in the automotive industry.

Comments and Discussions

 
GeneralThis is realy nice! PinsussAnonymous12-May-03 23:13 
GeneralCool PinmemberPavel0077-May-03 14:58 
I planned to make my own for the c compiler and ide I wrote for PIC and this one can save me lot of work (http://www.picant.com/c2c/c.html)
 
Regards,
Pavel

GeneralRe: PIC PinmemberBrian Delahunty7-May-03 9:00 
GeneralRe: PIC PinmemberAmer Gerzic7-May-03 9:10 
GeneralRe: PIC Pinmemberjauming25-Apr-09 21:30 
GeneralRe: PIC PinmemberCarlos Buelna27-Apr-09 8:17 
GeneralPIC PinmemberAmer Gerzic7-May-03 8:09 
GeneralRe: PIC PinmemberCarlos Buelna7-May-03 8:43 
GeneralFree C compiler PinmemberRobert Bielik5-Oct-06 2:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 6 May 2003
Article Copyright 2003 by Carlos Buelna
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid