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

A PIC C Code Wizard

By , 5 May 2003
 

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)

About the Author

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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralThis is realy nice!sussAnonymous12 May '03 - 22:13 
I didn't expect to see such a topic in the code project but it feels great to see some of your personal madness (microcontrollers) inside a pure high-level software site!
 
I hope there to be more interesting articles like this. At last, PIC are computers too.
 
ps Can you imagine MFC for PIC16F87X with objects like CUsart and CTimer0... Xmmm!
GeneralCoolmemberPavel0077 May '03 - 13: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: PICmemberBrian Delahunty7 May '03 - 8:00 
Carlos Buelna wrote:
PIC16F87X
 
I was using the PIC16F877 last yeah a lot. Very good chip with some nice features. Nice wizard too Big Grin | :-D
 
Regards,
Brian Dela Smile | :)
 

GeneralRe: PICmemberAmer Gerzic7 May '03 - 8:10 
Thanks a lot!!
GeneralRe: PICmemberjauming25 Apr '09 - 20:30 
it will not load template in release build,how to fix this?
GeneralRe: PICmemberCarlos Buelna27 Apr '09 - 7:17 
Workaround try: re-run the executable and it should load the template folder.
 
It works, but it's not been tested. -anonymous-

GeneralPICmemberAmer Gerzic7 May '03 - 7:09 
I have been trying to get into PIC programming in C language, but I don't really know where to start. I looked at some PIC programmers, but I am not sure what programming software do I use with them. Do you have any tips on where to start with PIC programming, and is PICC compiler free, and if yes then where can I get it?
 
Thanks in advance
GeneralRe: PICmemberCarlos Buelna7 May '03 - 7:43 
The PICC compiler is not free but there's an evaluation download available w/manual at http://www.htsoft.com/software/updates/pic/updates.html[^]
 
About the programmers, there're many. You may want to take a look at this one as it's very good and low cost.
http://www.microchipc.com/reviews/PICALL/[^]
 
I personally recommend the PIC16F87X series as it has a good set of peripherals and are flash based, which makes re-programming very practical.

 
It works, but it's not been tested. -anonymous-
GeneralFree C compilermemberRobert Bielik5 Oct '06 - 1:22 
The SDCC (Small Device C Compiler) has the PIC14 (PIC16x series) and PIC16 targets (PIC18x series). You can find it at http://sdcc.sourceforge.net/
 
I have not yet gotten around to using SDCC for my PIC projects (using PICC), but I'll definitely try it out some day. Also, if you use Eclipse (http://www.eclipse.org/) you can create a toolchain for SDCC and use Eclipse as a full-fledged IDE for PIC code development!

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

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