C Programming (Where to begin?)

I’m trying to program my BRAT in C ( I have an Atom Pro) but I’m getting ridiculous error messages that I shouldn’t be getting. I tried to make a dummy program that just has the main function and returns 0 but I get compiler errors. I must have to configure the compiler to work with C. Are there any good resources out there that will walk you through the process? Thanks!

I don’t have an Atom Pro. But assuming you’re running an IDE to compile/download code to the Atom Pro, then I suggest you look for a “tool path” setting of some sort. You may still be selecting the BASIC compiler.

You probably need to include a header file (.H) or two as well. Didn’t you get a ‘C’ manual of some sort with the Atom Pro and IDE? Assuming you know C, you just need the “embedded” aspects of the IDE and language to get going.

HTH

Alan KM6VV

I am not sure where you are starting from or have tried. But I have been doing some stuff with C (or C++) on the Atom Pro. In another thread I have C code that allows me to ping an SRF08 range finder. At least it now appears to be working.

First off what IDE are you running? I would recommend that you install 8.0.1.7 if you have not done so already.

Then you should create a new project: I created a sub-directory under where I have all of my LynxMotion files for C Projects. This will create a directory of the name you select with several files in it. If you try to build this project, it will compile up to the point where it does not find “main”. At this point you can create a new c file and add it to the project and write your main.

I found working with the different IO registers as defined in regdefs.h not very convienant so I downloaded a zip file from the Renasis site that had IO registers broken down for the different H8 processors. In the case of the PRO28 I included the file 3694s.h. it made it a lot easier to blink lights on the board or the like.

With it my HelloWorld program that blinks lights on the BB2 looks something like:

[code]#include <signal.h>
//#include “regdefs.h”

extern “C” {
#include “3694s.h”
};
#include “i2c.h”

volatile short int ms_count;

/*

  • ms_sleep() - delay for specified number of milliseconds
    */
    void ms_sleep(short int ms)
    {
    ms_count = 0;
    while (ms_count < ms)
    ;
    }

/*

  • millisecond counter interrupt vector
    */
    extern “C” void TIMERAV();

#pragma interrupt(TIMERAV)

void TIMERAV()
{
ms_count++;
//;IO.PDR8.BIT.B6 = 0x0;
IRR1.BIT.IRRTA = 0;

}

//
// initialize timer 0 to generate an interrupt every millisecond.
//
void init_timer(void)
{

TA.TMA.BYTE=4;   			//increments on clock/256 
	
IRR1.BIT.IRRTA = 0;			// Make sure the interrupt happened flag is clear
IENR1.BIT.IENTA = 1; 		// ENABLE TIMERAINT 

}

int main(void)
{
int iError;
init_timer();
unsigned short iVal;
unsigned char abRegs[2];
TW.TIOR1.BIT.IOD = 0; // Make sure P84 is an IO pin…
IO.PCR8 = 0x70; // make sure it is write
IO.PDR8.BIT.B6 = 0x1; // start off in some known state
IO.PDR8.BIT.B5 = 0x1;
IO.PDR8.BIT.B4 = 0x1;

while (1) {
 	ms_sleep(128);    /* wait 0.5 seconds */
	IO.PDR8.BIT.B4 = 0x0;    /* toggle LED */
	ms_sleep(128);
	IO.PDR8.BIT.B4 = 0x1;    /* toggle LED */
}

}[/code]

Please not I cut out my test stuff for I2C so there may be a few problems in what I left. Also if you try this, you will need to modify the vects.c file to point to the timer interrupt handler in this file.

Note: when you try to download your code. It will download, but at the end after the verify you will get a stupid message like: “Error connecting to atom” “Incorrect Function”

I hope this helps.

Kurt

First of all, thank you Kurt! I’ve only been using the ATOM Pro IDE for about a week and I didn’t know that you had to create a new project. I’ve always just created a new file and compiled it individually. That helped a lot! I’m still a little befuddled on what functions are available to me. I have to be honest, I’m new to C (I have a strong scripting language background however, so it won’t be hard for me to get my head around it). I have a book on C programming for a PC, but I realize this may not be relevant to what I can do on the ATOM Pro.

With all the IDE stuff out of the way, my last question is this: Is there a manual for programming the ATOM pro in C, and if not would the book that I already have be relevant?

I’m sorry I’m so empty handed at this! I just really want to be able to do more with the brat w/o switching over to a different microcontroller. All help is greatly appreciated! Thankyou!

You are welcome. We all have been there.

I am not sure if there is a good manual for Atom Pro in C. The C and C++ is the standard GNU GCC set of tools and compilers. I first used them on AVR microprocesers througn WinAVR. My guess is there are probably some manuals around for GNU tools and their standard C functions. For the most part I just stumble through the install directories to find the appropriate header files and the like.

The next important document is the Atom Pro IDE. One of the main pages I reference is the module pin layout (page 187), which shows which internal pins H8) connect to the external pins of the PRO. So for example if You wish to play with the LEDs on the BB2. You look at the “A” led, which is connected to P12 on the PRO, then you see that on the H8 it is connected to IO pin 84.

Now you need to look at the Renesis H8 documentation for the actual microprocessor that is on the Pro. In this case it is an 3694. Again the help manual of the IDE should open up this document. To play with this IO port you look in this manual in the IO ports section for Port 8. In here are a couple of registers that control if the pins are input or output, the value, and if they are to be used as a general purpose IO or for specific purposes…

You can either do your own calculations for the different bits in these registers or you can try to download the files from Renasis that break it up as I mentions in the first post.

Good Luck.

Hi Kurte,

OK, this is probably a better place to pose my questions on running ‘C’ on a BB2. The last post or two suggests that ‘C’ is only available on the Atom Pro, and not on the Atom. Is that true?

I just ordered a replacement Atom and BB2. I wanted to stay with the PIC, but had I known that, I might have relented and ordered an Atom Pro.

The Atom BASIC compiler generates an ASM file as well as a HEX file. Do you know if Basic Micro documents how to link and locate object files for use under their proprietary boot loader somewhere? I may be happy just loading my compiled C programs under the Basic Micro bootloader.

Another thought I had was to make up a 28-pin header to carry 18F4620 family chips, or even the dsPIC33FJ chips complete with a ISP connector. Do you know of anyone offering something like this?

Alan KM6VV

Hi Alan,

I don’t know of any C compiler for the Atom (not pro). I could be wrong, but…

I also have not looked into any other 28 pin BS2 compatible chips and the C compiler. I have used C compilers on other Microcontrollers such as Atmega (atmel) as well as a little with the propeller, but those were on different boards.

Sorry I could not help more.

Kurt

C is not available for the regular Atom. Those modules are based on PICmicro 16F processors and there is no GNU C for the 16F PICmicro processors.

Also the C/C++ for sue with AtomPro is pure GNU. None of the high level functions of the Basic compiler are available in C/C++. Atleast not yet.

Only the basic compiler supports single file programs. C programs require more setup files. The project system creates these inital setup files for you. All you have to add is a main() routine to get a functional program(as Kurte mentioned above).

OK I get it, no GNU for F16 parts. Too bad.

Any plans for an 18F or 33F Atom? That should be hot! Of course, you have the Hitachi (Renisys) part.

Not having a set of functions (LIB) to handle the built-in hardware would be a disadvantage for ‘C’ users. That’s a major advantage for your M BASIC on this PIC (and the Renisys). An M-BASIC compatible C library would be a nice resource.

I see .ASM and .HEX files after compiling a sample AH3.BAS file for a hexapod. Do you supply the compile and link invocations for the Mbasic compiler? Do you run an assembler pass after the compile, and then a link? OK I just answered one question from the MBASIC.PDF file I downloaded. You compile to .ASM and then MASM assembles. And then I take it the boot loader loads the .HEX file results.

Is there a specification published so that I can design a program and compile it to a HEX file for download into your ATOM? Both CCS and Hitech make C compilers for the F16 parts, as you undoubtedly know. This would be a great way to expand your ATOM market.

EDIT: I just noticed that you have an Mbasic as a stand-along compiler on your website. Must be for non-ATOM parts?

Sorry for all the questions!

Alan KM6VV

Yes, the have MBasic for pic microprocessors. I believe they are in beta for an update to handle more of the newer pics. I have not followed carefully, but there is more information on their forum.

Kurt

We are working on 18F for MBasic.

Mbasic is also sold seperately as a standalone compiler specifically for raw PICmicro processors.

I do plan on making an MBasic equivilent C library for AtomPro(which uses GNU C/C++). No timeline on that though.

The .ASM files are produced for debuging purposes primarily so users can see their inline assembly output. The .ASM file generated by MBasic for PICmicros can be used within MPLab but it is a real pain and we do not support it or document it.

We use GPASM not MPasm for PICmicro based products.

The MBasic for PICmicro compiler has a command line option. The Atom and AtomPro compilers do not.

Obviously we can’t include CCS or Hitech C unelss you want to add several hundred dollars cost to the MBasic for PICmicro compiler. We could only support a free C compiler which does not exist for the 16F PICmicro family. The 18F chips have a GNU C version but the LIBC library is not open source(it was produced by Microchip and is not free) which would limit it’s usefullness as well though we are not illiminating the possibility of including it for 18F based products.

18F based Atom modules are unlikely at the moment though not out of the question. They would be in between the Atom and AtomPro as far as performance goes. The 33F processors are much more interesting as a module but at the moment that is far in the future if at all.

Glad to hear an 18F MBasic is on the way!

I will look at the standalone MBasic.

Yes, good to be able to see the code generated!

OK I can see the reasoning behind that.

Not ADD the C compiler to your product, but alternately allow the USE the HEX file generated by Hitech and load it into a BasicAtom chip (I have the compilers). I do seem to recall that Hitech offers a free ‘877 C compiler.

That’s true, the Pro might be faster, but the 18F parts (I’m told) are easier to compile a high level language for and faster (then 16F). But you’ve got that covered. I’m working on a design a board for the 33FJ part; I’m told it’s quite fast. AND it has the dual motor control and dual encoders I want!

Thanks for your comments!

Alan KM6VV