EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

CCSv4 LED blink

Started by shskurkra June 5, 2010
Hi,

Starting from CCSv4 with led blink program, posted in sampleEZlessons on led in files section. I noticed two error's whiles testing lesson two.
One was "expected a expression" error, second was "identifier "i" is undefined" error, third is an warning "statement is unreachable"

The second expression can be solved by defining "int i;" warning can be ignored because it is in-finite for loop. But, the first error is to "for loop defined inside for loop" I was not able to solve. Can anyone help me to solve this simple error.

Thank you in advance.

The original program
-------------------------
#include
int main( ) {
WDTCTL= WDTPW + WDTHOLD; // turn off the watchdog timer.
P1DIR |= 0x01; // set P1.0 for output
for ( ; ; ) {
P1OUT ^= 0x01; // using XOR toggles the pin value.
for ( unsigned int i= 5; i != 0; --i )
;
}

return 0;
}
-------------------------

Beginning Microcontrollers with the MSP430

Hurray, I'm happy I debugged the code posted in "SampleEZlessons". The error one, two is solved by replacing with code:-

------------------
------------------
The original program
-------------------------
#include
unsigned int i = 0;
int main( ) {
WDTCTL= WDTPW + WDTHOLD; // turn off the watchdog timer.
P1DIR |= 0x01; // set P1.0 for output
for ( ; ; ) {
P1OUT ^= 0x01; // using XOR toggles the pin value.
for ( i= 5; i != 0; --i )
;
}

return 0;
}

--------------------
--------------------
--- In m..., "shskurkra" wrote:
>
> Hi,
>
> Starting from CCSv4 with led blink program, posted in sampleEZlessons on led in files section. I noticed two error's whiles testing lesson two.
> One was "expected a expression" error, second was "identifier "i" is undefined" error, third is an warning "statement is unreachable"
>
> The second expression can be solved by defining "int i;" warning can be ignored because it is in-finite for loop. But, the first error is to "for loop defined inside for loop" I was not able to solve. Can anyone help me to solve this simple error.
>
> Thank you in advance.
>
> The original program
> -------------------------
> #include
> int main( ) {
> WDTCTL= WDTPW + WDTHOLD; // turn off the watchdog timer.
> P1DIR |= 0x01; // set P1.0 for output
> for ( ; ; ) {
> P1OUT ^= 0x01; // using XOR toggles the pin value.
> for ( unsigned int i= 5; i != 0; --i )
> ;
> }
>
> return 0;
> }
> -------------------------
>

On Sat, 05 Jun 2010 03:04:38 -0000, you wrote:

> Starting from CCSv4 with led blink program, posted in
> sampleEZlessons on led in files section. I noticed two
> error's whiles testing lesson two.
>
> One was "expected a expression" error, second was
> "identifier "i" is undefined" error, third is an warning
> "statement is unreachable"
>
> The second expression can be solved by defining "int i;"
> warning can be ignored because it is in-finite for loop.

The compiler the code was designed for, IAR, accepts c++
for-loop constructs. That code is fine in that case, but
apparently ccsv4 doesn't accept it (given the compiler
options you are using, if for no other reason.)

For your situation, the variable 'i' does appear to require a
definition/declaration prior to executable code, just as you
noted. :)

> But, the first error is to "for loop defined inside for
> loop" I was not able to solve. Can anyone help me to solve
> this simple error.

That error message doesn't tell me much. Nesting a for-loop
inside another should be legal in both c and c++. If for
some reason you cannot get it to work as it should, you can
certainly try the following (just to be sure, I'll avoid
using do or while loops, as well):

#include
int main( ) {
unsigned int i;
WDTCTL= WDTPW + WDTHOLD;
P1DIR |= 0x01;
aa: P1OUT ^= 0x01;
for ( i= 5; i != 0; --i )
;
goto aa;
return 0;
}

But the outer for loop in the original code should have
worked, I think.

Hopefully, you can see the near-equivalence of the above code
to the original example.

Bear in mind that the "i= 5" is far too small of an
initializer and will need to be changed to make it work as
intended. The comments discuss this fact.

I don't have or use ccsv4. So I can't test the above example
to be sure, nor to answer your question about the nested for
loop error message.

Jon
On Sat, 05 Jun 2010 06:23:20 -0000, you wrote:

> Hurray, I'm happy I debugged the code posted in
> "SampleEZlessons". The error one, two is solved by
> replacing with code:-

Good. There isn't a need to initialize the variable 'i' to
zero at the outset. It gets initialized at the start of each
inner for loop. But it won't hurt, either, and the c
compiler would generate that initialization to zero without
explicitly saying so, anyway. (All instances of basic static
lifetime vars are initialized to a semantic zero prior to
starting main().)

Jon
Thank you Jon for posting a wonderful LED programs.
I have encountered another problem. This time it is in program "prj_06.cpp". After project is Build, if i test the program in Debug stage, the LED on USB does not blink. I'm testing in CCSv4, the program I'm using is posted here. Please help me to resolve this problem. Thank you.
=========Program
=====================================================================#include
volatile unsigned int i;
char timer_event, false, true;
int main( ) {
WDTCTL= WDTPW | WDTHOLD;
P1DIR |= 0x01;
BCSCTL1= CALBC1_16MHZ;
DCOCTL= CALDCO_16MHZ;
TACTL= MC_0 | TASSEL_2 | ID_3 | TACLR; // reset it, first.
TACCTL0= CM_0 | CCIS_2 | SCS | OUTMOD_1 | CCIE;
TACCR0= 19999; // 10ms intervals.
TACTL= MC_1 | TASSEL_2 | ID_3; // turn it on.
__enable_interrupt( );
for ( ; ; ) {
P1OUT ^= 0x01; // using XOR toggles the pin value.
for ( int i= 0; i < 50; ++i )
for ( timer_event= false; !timer_event; )
;
}

return 0;
}

#pragma vector= TIMERA0_VECTOR
__interrupt void timer_A2( void ) {
timer_event= true;

return;
}
=====================================================================--- In m..., Jon Kirwan wrote:
>
> On Sat, 05 Jun 2010 03:04:38 -0000, you wrote:
>
> > Starting from CCSv4 with led blink program, posted in
> > sampleEZlessons on led in files section. I noticed two
> > error's whiles testing lesson two.
> >
> > One was "expected a expression" error, second was
> > "identifier "i" is undefined" error, third is an warning
> > "statement is unreachable"
> >
> > The second expression can be solved by defining "int i;"
> > warning can be ignored because it is in-finite for loop.
>
> The compiler the code was designed for, IAR, accepts c++
> for-loop constructs. That code is fine in that case, but
> apparently ccsv4 doesn't accept it (given the compiler
> options you are using, if for no other reason.)
>
> For your situation, the variable 'i' does appear to require a
> definition/declaration prior to executable code, just as you
> noted. :)
>
> > But, the first error is to "for loop defined inside for
> > loop" I was not able to solve. Can anyone help me to solve
> > this simple error.
>
> That error message doesn't tell me much. Nesting a for-loop
> inside another should be legal in both c and c++. If for
> some reason you cannot get it to work as it should, you can
> certainly try the following (just to be sure, I'll avoid
> using do or while loops, as well):
>
> #include
> int main( ) {
> unsigned int i;
> WDTCTL= WDTPW + WDTHOLD;
> P1DIR |= 0x01;
> aa: P1OUT ^= 0x01;
> for ( i= 5; i != 0; --i )
> ;
> goto aa;
> return 0;
> }
>
> But the outer for loop in the original code should have
> worked, I think.
>
> Hopefully, you can see the near-equivalence of the above code
> to the original example.
>
> Bear in mind that the "i= 5" is far too small of an
> initializer and will need to be changed to make it work as
> intended. The comments discuss this fact.
>
> I don't have or use ccsv4. So I can't test the above example
> to be sure, nor to answer your question about the nested for
> loop error message.
>
> Jon
>

On Sat, 05 Jun 2010 20:14:03 -0000, you wrote:

>Thank you Jon for posting a wonderful LED programs.

No problem. Glad you are trying them out. I think I'd like
to include more documentation regarding the differences
between c++ and c constructs as minor lesson points, now that
you've been discussing your experiences. That's a help to
me.

> I have encountered another problem. This time it is in
> program "prj_06.cpp". After project is Build, if i test the
> program in Debug stage, the LED on USB does not blink. I'm
> testing in CCSv4, the program I'm using is posted here.
> Please help me to resolve this problem. Thank you.

I see you noticed that 'bool' isn't available readily with
your own compiler and have replaced it with 'char.' That is
fine, so far as it goes. But you've made a few mistakes.

>#include
>volatile unsigned int i;
>char timer_event, false, true;

The 'timer_event' really does need to be 'volatile' since the
interrupt routine can modify it due to an interrupting event.
So define it:

volatile char timer_event;

Also, the 'false' and 'true' are constants and need to carry
_different_ values. This is because c++ (and c99) defines
true and false for you, but apparently your compiler doesn't.
So I'd recommend this (to keep the changes simpler):

#define false (0)
#define true (1)

That will cover the need, I think.

Well, except that you posted code that included this:

for ( int i= 0; i < 50; ++i )

I think you've already said the "int i" part of that doesn't
work in your compiler.

The rest might work okay.

Try this:
#include
static volatile unsigned int i;
static volatile char timer_event;
#define false (0)
#define true (1)
int main( ) {
WDTCTL= WDTPW | WDTHOLD;
P1DIR |= 0x01;
BCSCTL1= CALBC1_16MHZ;
DCOCTL= CALDCO_16MHZ;
TACTL= MC_0 | TASSEL_2 | ID_3 | TACLR;
TACCTL0= CM_0 | CCIS_2 | SCS | OUTMOD_1 | CCIE;
TACCR0= 19999;
TACTL= MC_1 | TASSEL_2 | ID_3;
__enable_interrupt( );
for ( ; ; ) {
P1OUT ^= 0x01;
for ( i= 0; i < 50; ++i )
for ( timer_event= false; !timer_event; )
;
}
return 0;
}
#pragma vector= TIMERA0_VECTOR
__interrupt void timer_A2( void ) {
timer_event= true;

return;
}
Hi Jon,

In Project 7, section 5 did not work as specified. Warning was still reported. Apart from the section 5, ll other sections in project 7 worked.

In Project 8, 9, 10 worked without any error. I was not able to test waving USB stick in air (assume should work without any problem).

In Project 11, there was errors like, "icounter" is undefined,TAC is never used, expected a "}", in line 58, 59, 82, and 86.

I tried declaring icounter as integer, but did not minus the error.

Please give some idea to solve the errors.

Thank you.

=================Project 11 Program
=================#include
#define ADJRATE (0.02)
#define LIMIT (0.002)
#define LEDRATE (100) // in Hertz
#define SYSCLK (16000000) // in Hertz
#if SYSCLK == 16000000
# define DCO (CALDCO_16MHZ)
# define BC1 (CALBC1_16MHZ)
#elif SYSCLK == 12000000
# define DCO (CALDCO_12MHZ)
# define BC1 (CALBC1_12MHZ)
#elif SYSCLK == 8000000
# define DCO (CALDCO_8MHZ)
# define BC1 (CALBC1_8MHZ)
#elif SYSCLK == 1000000
# define DCO (CALDCO_1MHZ)
# define BC1 (CALBC1_1MHZ)
#else
# error Uncalibrated SYSCLK requested.
#endif
#define TICKS (SYSCLK/2/LEDRATE)
#define IDVAL (1+(TICKS >> 16))
#if IDVAL > 4
# undef IDVAL
# define IDVAL (8)
# define IDCTL (ID_3)
#elif IDVAL > 2
# undef IDVAL
# define IDVAL (4)
# define IDCTL (ID_2)
#elif IDVAL == 2
# define IDCTL (ID_1)
#elif IDVAL == 1
# define IDCTL (ID_0)
#else
# error LEDRATE is negative; try a positive value.
#endif
#if (TICKS/IDVAL) > 65535
# error LEDRATE is too small for the given SYSCLK; try a lower SYSCLK.
#endif
#define TAC ((unsigned int) (TICKS/IDVAL))
#define PROXIMITY ((unsigned int) (TICKS*LIMIT/IDVAL))
#define TACADJ ((unsigned int) (TICKS*ADJRATE/IDVAL))
int main( ) {
WDTCTL= WDTPW | WDTHOLD;
P1OUT &= ~0x01;
P1DIR |= 0x01;
BCSCTL1= BC1;
DCOCTL= DCO;
TACTL= MC_0 | TASSEL_2 | IDCTL | TACLR; // reset it, first.
TACCTL0= CM_0 | CCIS_2 | SCS | OUTMOD_1; // set the mode.
TACCTL1= CM_0 | CCIS_2 | SCS | OUTMOD_1 | CCIE;
TACCR0= TAC - 1;
TACCR1= TAC - PROXIMITY - 1;
TACTL= MC_3 | TASSEL_2 | IDCTL | TAIE; // turn it on.
__enable_interrupt( );

auto unsigned int tac= TACCR1; // *** FROM HERE ***
for ( ; ; ) {
static enum { brighter, dimmer } mode= dimmer;
for ( icounter= 0; icounter < 4; )
;
switch ( mode ) {

case brighter:
if ( tac < (TACADJ + PROXIMITY) ) {
tac= PROXIMITY;
mode= dimmer;
} else
tac -= TACADJ;
break;

case dimmer:
if ( tac > (TAC - TACADJ - PROXIMITY - 1) ) {
tac= TAC - PROXIMITY - 1;
mode= brighter;
} else
tac += TACADJ;
break;
}
TACCR1= tac;
}
}

#define CCIFG1_EVENT 0x02
#pragma vector= TIMERA1_VECTOR
__interrupt void timer_A2_CCIFG1_TAIFG( void ) {
switch ( TAIV ) {
case CCIFG1_EVENT:
P1OUT ^= 0x01;
// break;
// case TAIFG_EVENT:
++icounter;
break;
}

return;
}
#if 0
__low_power_mode_0( );

return 0;
}

#define TAIFG_EVENT 0x0A
#define CCIFG1_EVENT 0x02
#pragma vector= TIMERA1_VECTOR
__interrupt void timer_A2_CCIFG1_TAIFG( void ) {

static enum { brighter, dimmer } mode= dimmer;
auto unsigned int tac;

switch ( TAIV ) {
case CCIFG1_EVENT:
P1OUT ^= 0x01;
break;
case TAIFG_EVENT:
tac= TACCR1;
switch ( mode ) {
case brighter:
if ( tac < (TACADJ + PROXIMITY) ) {
tac= PROXIMITY;
mode= dimmer;
} else
tac -= TACADJ;
break;
case dimmer:
if ( tac > (TAC - TACADJ - PROXIMITY - 1) ) {
tac= TAC - PROXIMITY - 1;
mode= brighter;
} else
tac += TACADJ;
break;
}
TACCR1= tac;
break;
}

return;
}
#endif

===============
--- In m..., Jon Kirwan wrote:
>
> On Sat, 05 Jun 2010 20:14:03 -0000, you wrote:
>
> >Thank you Jon for posting a wonderful LED programs.
>
> No problem. Glad you are trying them out. I think I'd like
> to include more documentation regarding the differences
> between c++ and c constructs as minor lesson points, now that
> you've been discussing your experiences. That's a help to
> me.
>
> > I have encountered another problem. This time it is in
> > program "prj_06.cpp". After project is Build, if i test the
> > program in Debug stage, the LED on USB does not blink. I'm
> > testing in CCSv4, the program I'm using is posted here.
> > Please help me to resolve this problem. Thank you.
>
> I see you noticed that 'bool' isn't available readily with
> your own compiler and have replaced it with 'char.' That is
> fine, so far as it goes. But you've made a few mistakes.
>
> >#include
> >volatile unsigned int i;
> >char timer_event, false, true;
>
> The 'timer_event' really does need to be 'volatile' since the
> interrupt routine can modify it due to an interrupting event.
> So define it:
>
> volatile char timer_event;
>
> Also, the 'false' and 'true' are constants and need to carry
> _different_ values. This is because c++ (and c99) defines
> true and false for you, but apparently your compiler doesn't.
> So I'd recommend this (to keep the changes simpler):
>
> #define false (0)
> #define true (1)
>
> That will cover the need, I think.
>
> Well, except that you posted code that included this:
>
> for ( int i= 0; i < 50; ++i )
>
> I think you've already said the "int i" part of that doesn't
> work in your compiler.
>
> The rest might work okay.
>
> Try this:
> #include
> static volatile unsigned int i;
> static volatile char timer_event;
> #define false (0)
> #define true (1)
> int main( ) {
> WDTCTL= WDTPW | WDTHOLD;
> P1DIR |= 0x01;
> BCSCTL1= CALBC1_16MHZ;
> DCOCTL= CALDCO_16MHZ;
> TACTL= MC_0 | TASSEL_2 | ID_3 | TACLR;
> TACCTL0= CM_0 | CCIS_2 | SCS | OUTMOD_1 | CCIE;
> TACCR0= 19999;
> TACTL= MC_1 | TASSEL_2 | ID_3;
> __enable_interrupt( );
> for ( ; ; ) {
> P1OUT ^= 0x01;
> for ( i= 0; i < 50; ++i )
> for ( timer_event= false; !timer_event; )
> ;
> }
> return 0;
> }
> #pragma vector= TIMERA0_VECTOR
> __interrupt void timer_A2( void ) {
> timer_event= true;
>
> return;
> }
>

On Sun, 06 Jun 2010 04:34:44 -0000, you wrote:

> In Project 7, section 5 did not work as specified. Warning
> was still reported. Apart from the section 5, ll other
> sections in project 7 worked.

The #pragma given won't work in ccsv4, I believe. It's
normal for different vendors to use somewhat different
#pragma statements for the exact same effect and to support
(or fail to support) different features than other vendors.
It's pretty much not standardized, by definition. You will
need to look up the warning in your documentation on the
compiler and see how they recommend disabling it and try to
get it working. That's part of the homework, here, I
suppose.

> In Project 8, 9, 10 worked without any error. I was not
> able to test waving USB stick in air (assume should work
> without any problem).
>
> In Project 11, there was errors like, "icounter" is
> undefined,

It's defined, as in:

static volatile unsigned int icounter;

look for that, somewhere.

>TAC is never used

It should be defined this way:

#define TAC ((unsigned int) (TICKS/IDVAL))

and that should be in the code, as given. (Also, there is a
variable called 'tac' (lower case) in the code.)

>expected a "}", in line 58,
> 59, 82, and 86.

This is beginning to sound like a problem in the commentary.
It's possible that I included some injudicious characters
there which do not cause problems for the IAR compiler. Best
thing to try is simply removing all the comments from the
code and try again to see how that works out. For these
errors and perhaps those above, as well.

> I tried declaring icounter as integer, but did not minus
> the error.
>
> Please give some idea to solve the errors.

Remove the commentary and strip it down to the basic code
itself. You seem to have done that in the posted code
example, but try to clean it up once again, from scratch. I
don't have any problems when using IAR. Speaking of which,
you might install the IAR kickstart as a comparison tool to
use in trying these things out. None of these examples
exceed the IAR code size limitations and the IAR kickstart is
free from TI's web site and only a "sign up" at the IAR web
site. Might help to have a standard against which you can
try things out.

Jon
I tried once again by inserting the "static volatile unsigned int icounter;" command into CCSv4 for program 11. It solved many errors. I still have a error for "auto unsigned int tac = TACCR1;" in CCSv4.

With error "declaration may not appear after executable statement in block...." in console.

Does any one has faced this error in CCSv4? Is there a solution for this king of error? Please let me know. Thank you.
-------
Program
-------
#include
#define ADJRATE (0.02)
#define LIMIT (0.002)
#define LEDRATE (100) // in Hertz
#define SYSCLK (16000000) // in Hertz
#if SYSCLK == 16000000
# define DCO (CALDCO_16MHZ)
# define BC1 (CALBC1_16MHZ)
#elif SYSCLK == 12000000
# define DCO (CALDCO_12MHZ)
# define BC1 (CALBC1_12MHZ)
#elif SYSCLK == 8000000
# define DCO (CALDCO_8MHZ)
# define BC1 (CALBC1_8MHZ)
#elif SYSCLK == 1000000
# define DCO (CALDCO_1MHZ)
# define BC1 (CALBC1_1MHZ)
#else
# error Uncalibrated SYSCLK requested.
#endif
#define TICKS (SYSCLK/2/LEDRATE)
#define IDVAL (1+(TICKS >> 16))
#if IDVAL > 4
# undef IDVAL
# define IDVAL (8)
# define IDCTL (ID_3)
#elif IDVAL > 2
# undef IDVAL
# define IDVAL (4)
# define IDCTL (ID_2)
#elif IDVAL == 2
# define IDCTL (ID_1)
#elif IDVAL == 1
# define IDCTL (ID_0)
#else
# error LEDRATE is negative; try a positive value.
#endif
#if (TICKS/IDVAL) > 65535
# error LEDRATE is too small for the given SYSCLK; try a lower SYSCLK.
#endif
#define TAC ((unsigned int) (TICKS/IDVAL))
#define PROXIMITY ((unsigned int) (TICKS*LIMIT/IDVAL))
#define TACADJ ((unsigned int) (TICKS*ADJRATE/IDVAL))

static volatile unsigned int icounter;

int main( ) {
WDTCTL= WDTPW | WDTHOLD;
P1OUT &= ~0x01;
P1DIR |= 0x01;

BCSCTL1= BC1;
DCOCTL= DCO;

TACTL= MC_0 | TASSEL_2 | IDCTL | TACLR; // reset it, first.
TACCTL0= CM_0 | CCIS_2 | SCS | OUTMOD_1; // set the mode.
TACCTL1= CM_0 | CCIS_2 | SCS | OUTMOD_1 | CCIE;
TACCR0= TAC - 1;
TACCR1= TAC - PROXIMITY - 1;
TACTL= MC_3 | TASSEL_2 | IDCTL | TAIE; // turn it on.
__enable_interrupt( );

auto unsigned int tac = TACCR1; // *** FROM HERE ***
for ( ; ; ) {
static enum { brighter, dimmer } mode= dimmer;
for ( icounter= 0; icounter < 4; )
;
switch ( mode ) {

case brighter:
if ( tac < (TACADJ + PROXIMITY) ) {
tac= PROXIMITY;
mode= dimmer;
} else
tac -= TACADJ;
break;

case dimmer:
if ( tac > (TAC - TACADJ - PROXIMITY - 1) ) {
tac= TAC - PROXIMITY - 1;
mode= brighter;
} else
tac += TACADJ;
break;
}
TACCR1= tac;
} // *** TO HERE ***

return 0; // once again, this line produces a warning.
}
#define TAIFG_EVENT 0x0A
#define CCIFG1_EVENT 0x02
#pragma vector= TIMERA1_VECTOR
__interrupt void timer_A2_CCIFG1_TAIFG( void ) {
switch ( TAIV ) {
case CCIFG1_EVENT:
P1OUT ^= 0x01;
break;
case TAIFG_EVENT:
++icounter;
break;
}

return;
}
#if 0
__low_power_mode_0( );

return 0;
}

#define TAIFG_EVENT 0x0A
#define CCIFG1_EVENT 0x02
#pragma vector= TIMERA1_VECTOR
__interrupt void timer_A2_CCIFG1_TAIFG( void ) {
static enum { brighter, dimmer } mode= dimmer;
auto unsigned int tac;

switch ( TAIV ) {
case CCIFG1_EVENT:
P1OUT ^= 0x01;
break;
case TAIFG_EVENT:
tac= TACCR1;
switch ( mode ) {
case brighter:
if ( tac < (TACADJ + PROXIMITY) ) {
tac= PROXIMITY;
mode= dimmer;
} else
tac -= TACADJ;
break;
case dimmer:
if ( tac > (TAC - TACADJ - PROXIMITY - 1) ) {
tac= TAC - PROXIMITY - 1;
mode= brighter;
} else
tac += TACADJ;
break;
}
TACCR1= tac;
break;
}

return;
}
#endif
--------------------

--- In m..., Jon Kirwan wrote:
>
> On Sun, 06 Jun 2010 04:34:44 -0000, you wrote:
>
> > In Project 7, section 5 did not work as specified. Warning
> > was still reported. Apart from the section 5, ll other
> > sections in project 7 worked.
>
> The #pragma given won't work in ccsv4, I believe. It's
> normal for different vendors to use somewhat different
> #pragma statements for the exact same effect and to support
> (or fail to support) different features than other vendors.
> It's pretty much not standardized, by definition. You will
> need to look up the warning in your documentation on the
> compiler and see how they recommend disabling it and try to
> get it working. That's part of the homework, here, I
> suppose.
>
> > In Project 8, 9, 10 worked without any error. I was not
> > able to test waving USB stick in air (assume should work
> > without any problem).
> >
> > In Project 11, there was errors like, "icounter" is
> > undefined,
>
> It's defined, as in:
>
> static volatile unsigned int icounter;
>
> look for that, somewhere.
>
> >TAC is never used
>
> It should be defined this way:
>
> #define TAC ((unsigned int) (TICKS/IDVAL))
>
> and that should be in the code, as given. (Also, there is a
> variable called 'tac' (lower case) in the code.)
>
> >expected a "}", in line 58,
> > 59, 82, and 86.
>
> This is beginning to sound like a problem in the commentary.
> It's possible that I included some injudicious characters
> there which do not cause problems for the IAR compiler. Best
> thing to try is simply removing all the comments from the
> code and try again to see how that works out. For these
> errors and perhaps those above, as well.
>
> > I tried declaring icounter as integer, but did not minus
> > the error.
> >
> > Please give some idea to solve the errors.
>
> Remove the commentary and strip it down to the basic code
> itself. You seem to have done that in the posted code
> example, but try to clean it up once again, from scratch. I
> don't have any problems when using IAR. Speaking of which,
> you might install the IAR kickstart as a comparison tool to
> use in trying these things out. None of these examples
> exceed the IAR code size limitations and the IAR kickstart is
> free from TI's web site and only a "sign up" at the IAR web
> site. Might help to have a standard against which you can
> try things out.
>
> Jon
>

Hi,
Project 11 is working with out errors. Was able to obtain the output by CCSv4. I have reposted the program for project 11 (for step 2) and project 11 (for step 3)
-------------------------
project 11 step 2
-------------------------
#include
#define ADJRATE (0.02)
#define LIMIT (0.002)
#define LEDRATE (100) // in Hertz
#define SYSCLK (16000000) // in Hertz
#if SYSCLK == 16000000
# define DCO (CALDCO_16MHZ)
# define BC1 (CALBC1_16MHZ)
#elif SYSCLK == 12000000
# define DCO (CALDCO_12MHZ)
# define BC1 (CALBC1_12MHZ)
#elif SYSCLK == 8000000
# define DCO (CALDCO_8MHZ)
# define BC1 (CALBC1_8MHZ)
#elif SYSCLK == 1000000
# define DCO (CALDCO_1MHZ)
# define BC1 (CALBC1_1MHZ)
#else
# error Uncalibrated SYSCLK requested.
#endif
#define TICKS (SYSCLK/2/LEDRATE)
#define IDVAL (1+(TICKS >> 16))
#if IDVAL > 4
# undef IDVAL
# define IDVAL (8)
# define IDCTL (ID_3)
#elif IDVAL > 2
# undef IDVAL
# define IDVAL (4)
# define IDCTL (ID_2)
#elif IDVAL == 2
# define IDCTL (ID_1)
#elif IDVAL == 1
# define IDCTL (ID_0)
#else
# error LEDRATE is negative; try a positive value.
#endif
#if (TICKS/IDVAL) > 65535
# error LEDRATE is too small for the given SYSCLK; try a lower SYSCLK.
#endif
#define TAC ((unsigned int) (TICKS/IDVAL))
#define PROXIMITY ((unsigned int) (TICKS*LIMIT/IDVAL))
#define TACADJ ((unsigned int) (TICKS*ADJRATE/IDVAL))

static volatile unsigned int icounter;

int main( ) {
WDTCTL= WDTPW | WDTHOLD;
P1OUT &= ~0x01;
P1DIR |= 0x01;

BCSCTL1= BC1;
DCOCTL= DCO;

TACTL= MC_0 | TASSEL_2 | IDCTL | TACLR; // reset it, first.
TACCTL0= CM_0 | CCIS_2 | SCS | OUTMOD_1; // set the mode.
TACCTL1= CM_0 | CCIS_2 | SCS | OUTMOD_1 | CCIE;
TACCR0= TAC - 1;
TACCR1= TAC - PROXIMITY - 1;
TACTL= MC_3 | TASSEL_2 | IDCTL | TAIE; // turn it on.
__enable_interrupt( );

//auto unsigned int tac= TACCR1; // *** FROM HERE ***
for ( ; ; ) {
static enum { brighter, dimmer } mode= dimmer;
auto unsigned int tac= TACCR1;
for ( icounter= 0; icounter < 4; )
;
switch ( mode ) {

case brighter:
if ( tac < (TACADJ + PROXIMITY) ) {
tac= PROXIMITY;
mode= dimmer;
} else
tac -= TACADJ;
break;

case dimmer:
if ( tac > (TAC - TACADJ - PROXIMITY - 1) ) {
tac= TAC - PROXIMITY - 1;
mode= brighter;
} else
tac += TACADJ;
break;
}
TACCR1= tac;
} // *** TO HERE ***

return 0; // once again, this line produces a warning.
}
//#define TAIFG_EVENT 0x0A
#define CCIFG1_EVENT 0x02
#pragma vector= TIMERA1_VECTOR
__interrupt void timer_A2_CCIFG1_TAIFG( void ) {
switch ( TAIV ) {
case CCIFG1_EVENT:
P1OUT ^= 0x01;
//break;
//case TAIFG_EVENT:
++icounter;
break;
}
return;
}
#if 0
__low_power_mode_0( );

return 0;
}

#define TAIFG_EVENT 0x0A
#define CCIFG1_EVENT 0x02
#pragma vector= TIMERA1_VECTOR
__interrupt void timer_A2_CCIFG1_TAIFG( void ) {
static enum { brighter, dimmer } mode= dimmer;
auto unsigned int tac;

switch ( TAIV ) {
case CCIFG1_EVENT:
P1OUT ^= 0x01;
break;
case TAIFG_EVENT:
tac= TACCR1;
switch ( mode ) {
case brighter:
if ( tac < (TACADJ + PROXIMITY) ) {
tac= PROXIMITY;
mode= dimmer;
} else
tac -= TACADJ;
break;
case dimmer:
if ( tac > (TAC - TACADJ - PROXIMITY - 1) ) {
tac= TAC - PROXIMITY - 1;
mode= brighter;
} else
tac += TACADJ;
break;
}
TACCR1= tac;
break;
}

return;
}
#endif
----------------------
project 11 step 2 end
----------------------
project 11 step 3
--------------------
#include
#define ADJRATE (0.02)
#define LIMIT (0.002)
#define LEDRATE (100) // in Hertz
#define SYSCLK (16000000) // in Hertz
#if SYSCLK == 16000000
# define DCO (CALDCO_16MHZ)
# define BC1 (CALBC1_16MHZ)
#elif SYSCLK == 12000000
# define DCO (CALDCO_12MHZ)
# define BC1 (CALBC1_12MHZ)
#elif SYSCLK == 8000000
# define DCO (CALDCO_8MHZ)
# define BC1 (CALBC1_8MHZ)
#elif SYSCLK == 1000000
# define DCO (CALDCO_1MHZ)
# define BC1 (CALBC1_1MHZ)
#else
# error Uncalibrated SYSCLK requested.
#endif
#define TICKS (SYSCLK/2/LEDRATE)
#define IDVAL (1+(TICKS >> 16))
#if IDVAL > 4
# undef IDVAL
# define IDVAL (8)
# define IDCTL (ID_3)
#elif IDVAL > 2
# undef IDVAL
# define IDVAL (4)
# define IDCTL (ID_2)
#elif IDVAL == 2
# define IDCTL (ID_1)
#elif IDVAL == 1
# define IDCTL (ID_0)
#else
# error LEDRATE is negative; try a positive value.
#endif
#if (TICKS/IDVAL) > 65535
# error LEDRATE is too small for the given SYSCLK; try a lower SYSCLK.
#endif
#define TAC ((unsigned int) (TICKS/IDVAL))
#define PROXIMITY ((unsigned int) (TICKS*LIMIT/IDVAL))
#define TACADJ ((unsigned int) (TICKS*ADJRATE/IDVAL))

//static volatile unsigned int icounter;

int main( ) {
WDTCTL= WDTPW | WDTHOLD;
P1OUT &= ~0x01;
P1DIR |= 0x01;

BCSCTL1= BC1;
DCOCTL= DCO;

TACTL= MC_0 | TASSEL_2 | IDCTL | TACLR; // reset it, first.
TACCTL0= CM_0 | CCIS_2 | SCS | OUTMOD_1; // set the mode.
TACCTL1= CM_0 | CCIS_2 | SCS | OUTMOD_1 | CCIE;
TACCR0= TAC - 1;
TACCR1= TAC - PROXIMITY - 1;
TACTL= MC_3 | TASSEL_2 | IDCTL | TAIE; // turn it on.
__enable_interrupt( );
__low_power_mode_0( );

return 0; // once again, this line produces a warning.
}
#define TAIFG_EVENT 0x0A
#define CCIFG1_EVENT 0x02
#pragma vector= TIMERA1_VECTOR
__interrupt void timer_A2_CCIFG1_TAIFG( void ) {
static enum { brighter, dimmer } mode= dimmer;
auto unsigned int tac= TACCR1;
switch ( TAIV ) {
case CCIFG1_EVENT:
P1OUT ^= 0x01;
break;
case TAIFG_EVENT:
tac= TACCR1;
//auto unsigned int tac= TACCR1; // *** FROM HERE ***
//for ( ; ; ) {
//static enum { brighter, dimmer } mode= dimmer;
//auto unsigned int tac= TACCR1;
//for ( icounter= 0; icounter < 4; )
//;
switch ( mode ) {

case brighter:
if ( tac < (TACADJ + PROXIMITY) ) {
tac= PROXIMITY;
mode= dimmer;
} else
tac -= TACADJ;
break;

case dimmer:
if ( tac > (TAC - TACADJ - PROXIMITY - 1) ) {
tac= TAC - PROXIMITY - 1;
mode= brighter;
} else
tac += TACADJ;
break;
}
TACCR1= tac;
//} // *** TO HERE ***
break;
}
return;
}
#if 0
__low_power_mode_0( );

return 0;
}

#define TAIFG_EVENT 0x0A
#define CCIFG1_EVENT 0x02
#pragma vector= TIMERA1_VECTOR
__interrupt void timer_A2_CCIFG1_TAIFG( void ) {
static enum { brighter, dimmer } mode= dimmer;
auto unsigned int tac;

switch ( TAIV ) {
case CCIFG1_EVENT:
P1OUT ^= 0x01;
break;
case TAIFG_EVENT:
tac= TACCR1;
switch ( mode ) {
case brighter:
if ( tac < (TACADJ + PROXIMITY) ) {
tac= PROXIMITY;
mode= dimmer;
} else
tac -= TACADJ;
break;
case dimmer:
if ( tac > (TAC - TACADJ - PROXIMITY - 1) ) {
tac= TAC - PROXIMITY - 1;
mode= brighter;
} else
tac += TACADJ;
break;
}
TACCR1= tac;
break;
}

return;
}
#endif
---------------------
project 11 step 3 end
---------------------
**********************************************************************
--- In m..., "shskurkra" wrote:
>
> I tried once again by inserting the "static volatile unsigned int icounter;" command into CCSv4 for program 11. It solved many errors. I still have a error for "auto unsigned int tac = TACCR1;" in CCSv4.
>
> With error "declaration may not appear after executable statement in block...." in console.
>
> Does any one has faced this error in CCSv4? Is there a solution for this king of error? Please let me know. Thank you.
> -------
> Program
> -------
> #include
> #define ADJRATE (0.02)
> #define LIMIT (0.002)
> #define LEDRATE (100) // in Hertz
> #define SYSCLK (16000000) // in Hertz
> #if SYSCLK == 16000000
> # define DCO (CALDCO_16MHZ)
> # define BC1 (CALBC1_16MHZ)
> #elif SYSCLK == 12000000
> # define DCO (CALDCO_12MHZ)
> # define BC1 (CALBC1_12MHZ)
> #elif SYSCLK == 8000000
> # define DCO (CALDCO_8MHZ)
> # define BC1 (CALBC1_8MHZ)
> #elif SYSCLK == 1000000
> # define DCO (CALDCO_1MHZ)
> # define BC1 (CALBC1_1MHZ)
> #else
> # error Uncalibrated SYSCLK requested.
> #endif
> #define TICKS (SYSCLK/2/LEDRATE)
> #define IDVAL (1+(TICKS >> 16))
> #if IDVAL > 4
> # undef IDVAL
> # define IDVAL (8)
> # define IDCTL (ID_3)
> #elif IDVAL > 2
> # undef IDVAL
> # define IDVAL (4)
> # define IDCTL (ID_2)
> #elif IDVAL == 2
> # define IDCTL (ID_1)
> #elif IDVAL == 1
> # define IDCTL (ID_0)
> #else
> # error LEDRATE is negative; try a positive value.
> #endif
> #if (TICKS/IDVAL) > 65535
> # error LEDRATE is too small for the given SYSCLK; try a lower SYSCLK.
> #endif
> #define TAC ((unsigned int) (TICKS/IDVAL))
> #define PROXIMITY ((unsigned int) (TICKS*LIMIT/IDVAL))
> #define TACADJ ((unsigned int) (TICKS*ADJRATE/IDVAL))
>
> static volatile unsigned int icounter;
>
> int main( ) {
> WDTCTL= WDTPW | WDTHOLD;
> P1OUT &= ~0x01;
> P1DIR |= 0x01;
>
> BCSCTL1= BC1;
> DCOCTL= DCO;
>
> TACTL= MC_0 | TASSEL_2 | IDCTL | TACLR; // reset it, first.
> TACCTL0= CM_0 | CCIS_2 | SCS | OUTMOD_1; // set the mode.
> TACCTL1= CM_0 | CCIS_2 | SCS | OUTMOD_1 | CCIE;
> TACCR0= TAC - 1;
> TACCR1= TAC - PROXIMITY - 1;
> TACTL= MC_3 | TASSEL_2 | IDCTL | TAIE; // turn it on.
> __enable_interrupt( );
>
> auto unsigned int tac = TACCR1; // *** FROM HERE ***
> for ( ; ; ) {
> static enum { brighter, dimmer } mode= dimmer;
> for ( icounter= 0; icounter < 4; )
> ;
> switch ( mode ) {
>
> case brighter:
> if ( tac < (TACADJ + PROXIMITY) ) {
> tac= PROXIMITY;
> mode= dimmer;
> } else
> tac -= TACADJ;
> break;
>
> case dimmer:
> if ( tac > (TAC - TACADJ - PROXIMITY - 1) ) {
> tac= TAC - PROXIMITY - 1;
> mode= brighter;
> } else
> tac += TACADJ;
> break;
> }
> TACCR1= tac;
> } // *** TO HERE ***
>
> return 0; // once again, this line produces a warning.
> }
> #define TAIFG_EVENT 0x0A
> #define CCIFG1_EVENT 0x02
> #pragma vector= TIMERA1_VECTOR
> __interrupt void timer_A2_CCIFG1_TAIFG( void ) {
> switch ( TAIV ) {
> case CCIFG1_EVENT:
> P1OUT ^= 0x01;
> break;
> case TAIFG_EVENT:
> ++icounter;
> break;
> }
>
> return;
> }
> #if 0
> __low_power_mode_0( );
>
> return 0;
> }
>
> #define TAIFG_EVENT 0x0A
> #define CCIFG1_EVENT 0x02
> #pragma vector= TIMERA1_VECTOR
> __interrupt void timer_A2_CCIFG1_TAIFG( void ) {
> static enum { brighter, dimmer } mode= dimmer;
> auto unsigned int tac;
>
> switch ( TAIV ) {
> case CCIFG1_EVENT:
> P1OUT ^= 0x01;
> break;
> case TAIFG_EVENT:
> tac= TACCR1;
> switch ( mode ) {
> case brighter:
> if ( tac < (TACADJ + PROXIMITY) ) {
> tac= PROXIMITY;
> mode= dimmer;
> } else
> tac -= TACADJ;
> break;
> case dimmer:
> if ( tac > (TAC - TACADJ - PROXIMITY - 1) ) {
> tac= TAC - PROXIMITY - 1;
> mode= brighter;
> } else
> tac += TACADJ;
> break;
> }
> TACCR1= tac;
> break;
> }
>
> return;
> }
> #endif
> --------------------
>
>
>
> --- In m..., Jon Kirwan wrote:
> >
> > On Sun, 06 Jun 2010 04:34:44 -0000, you wrote:
> >
> > > In Project 7, section 5 did not work as specified. Warning
> > > was still reported. Apart from the section 5, ll other
> > > sections in project 7 worked.
> >
> > The #pragma given won't work in ccsv4, I believe. It's
> > normal for different vendors to use somewhat different
> > #pragma statements for the exact same effect and to support
> > (or fail to support) different features than other vendors.
> > It's pretty much not standardized, by definition. You will
> > need to look up the warning in your documentation on the
> > compiler and see how they recommend disabling it and try to
> > get it working. That's part of the homework, here, I
> > suppose.
> >
> > > In Project 8, 9, 10 worked without any error. I was not
> > > able to test waving USB stick in air (assume should work
> > > without any problem).
> > >
> > > In Project 11, there was errors like, "icounter" is
> > > undefined,
> >
> > It's defined, as in:
> >
> > static volatile unsigned int icounter;
> >
> > look for that, somewhere.
> >
> > >TAC is never used
> >
> > It should be defined this way:
> >
> > #define TAC ((unsigned int) (TICKS/IDVAL))
> >
> > and that should be in the code, as given. (Also, there is a
> > variable called 'tac' (lower case) in the code.)
> >
> > >expected a "}", in line 58,
> > > 59, 82, and 86.
> >
> > This is beginning to sound like a problem in the commentary.
> > It's possible that I included some injudicious characters
> > there which do not cause problems for the IAR compiler. Best
> > thing to try is simply removing all the comments from the
> > code and try again to see how that works out. For these
> > errors and perhaps those above, as well.
> >
> > > I tried declaring icounter as integer, but did not minus
> > > the error.
> > >
> > > Please give some idea to solve the errors.
> >
> > Remove the commentary and strip it down to the basic code
> > itself. You seem to have done that in the posted code
> > example, but try to clean it up once again, from scratch. I
> > don't have any problems when using IAR. Speaking of which,
> > you might install the IAR kickstart as a comparison tool to
> > use in trying these things out. None of these examples
> > exceed the IAR code size limitations and the IAR kickstart is
> > free from TI's web site and only a "sign up" at the IAR web
> > site. Might help to have a standard against which you can
> > try things out.
> >
> > Jon
>


The 2024 Embedded Online Conference