I thought it would be fun to at least experiment with C and C++ code on the atom pro. So I thought I would try a simple hello world type application and try to blink the RED led on the ABB board. So I went into the BAP ide and did a create of a C project. I then tried to compile the code and found that it had problems finding the compiler pieces. I went into my Vista system CPL and changed the PATH environment to find the compiler pieces and got everything to compile.
Next was to put the code in to change the IO ports. I first did this with the regdefs.h file that was created in my project, but later found a header file that had all of the registers defined in structures. I first got the blink working with some simple delay loops. Then I wanted to use a timer interrupt to make it work properly. I am basically working with no instructions for the C compiler, but I now have it somewhat working. The timer interupt gets set up properly until the first reset. Still need to figure that part out. Anyone had any better luck? I thought I would post parts of the code as it now sits:
form hwinit.c:
void hw_initialise (void)
{
IO.PMR5.BYTE &= 0x70; // make sure P54 P55 P56 are standard IO pins
IO.PCR5 |= 0x70; //Make sure P54 is output pin
IO.PDR5.BIT.B4 = 0; // start off in some known state
IO.PDR5.BIT.B5 = 1; // start off in some known state
IO.PDR5.BIT.B6 = 0; // start off in some known state
}
from my HelloWorld.cpp:
[code]#include <signal.h>
//#include āregdefs.hā
extern āCā {
#include ā3664s.hā
};
volatile short int ms_count;
/*
-
ms_sleep() - delay for specified number of milliseconds
*/
void ms_sleep(short int ms)
{
#if 1
//TCA = 0;
ms_count = 0;
while (ms_count != ms)
;
#else
int i;
int j;
int k;j = 0;
for (i=0; i < 1000; i++)
{
for (j = 0; j < 32767; j++)
k = k + 1;
}
#endif
}
/*
- millisecond counter interrupt vector
*/
extern āCā void TIMERAV();
#pragma interrupt(TIMERAV)
void TIMERAV()
{
ms_count++;
IO.PDR5.BIT.B6 = 1; // See if this gets called
IRR1.BIT.IRRTA = 0;
}
/*
-
initialize timer 0 to generate an interrupt every millisecond.
/
void init_timer(void)
{
/- Initialize timer0 to generate an output compare interrupt, and
- set the output compare register so that we get that interrupt
- every millisecond.
*/
//ONINTERRUPT TIMERAINT,handle_timeraTA.TMA.BYTE=4; //increments on clock/256
IENR1.BIT.IENTA = 1; // ENABLE TIMERAINT
}
int main(void)
{
init_timer();
// IO.PMR5.BYTE &= 0x10; // make sure P54 is standard IO pin
// IO.PCR5 |= 0x10; //Make sure P54 is output pin
IO.PDR5.BIT.B4 = 0x1; // start off in some known state
while (1) {
ms_sleep(512); /* wait 0.5 seconds */
IO.PDR5.BIT.B6 = 0x1; // start off in some known state
IO.PDR5.BIT.B4 = 0x0; /* toggle LED */
ms_sleep(512);
IO.PDR5.BIT.B4 = 0x1; /* toggle LED */
}
}
[/code]
from vects.c:
[code]void start(void); /* Startup code (in start.s) */
asm (" .section .vects");
asm("jmp @_start"); //_RESET
...
asm("jmp @_TIMERAV"); //_TIMERAV:
...
[/code]
Anyone had any better luck? Any suggestions? Any other examples?
Thanks
Kurt