Tried project 12, it is working in CCSv4 with some changes. But, the warning for
"return 0" still exist.
Thank you Jon for just wonderful practice lessons.
--- In m..., "shskurkra" wrote:
>
> 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
> > >
>
CCSv4 LED blink
Started by ●June 5, 2010
Reply by ●June 6, 20102010-06-06
Reply by ●June 6, 20102010-06-06
On Sun, 06 Jun 2010 10:56:15 -0000, you wrote:
> With error "declaration may not appear after executable
> statement in block...." in console.
This often occurs in c compilers. Take a look at the
following code:
{
unsigned int i;
{
i= 5;
unsigned int j;
j= 6;
}
}
Most c compilers, those anyway that don't also support c++,
will complain that the 'unsigned int j;' declaration takes
place _after_ the executable statement 'i= 5;'
This is because that's the standard for c. If the code were
rewritten this way:
{
unsigned int i;
{
unsigned int j;
i= 5;
j= 6;
}
}
It would be just fine.
Program 11 does, in fact, declare (and define) some local
variables in the middle of executable code blocks. So it
would, with a c compiler, generate such errors.
Again, this is a matter of learning what c++ can do vs what c
can do. For example, in program 11, the statement:
auto unsigned int tac= TACCR1;
occurs in the middle of a block of executable code. This
both declares and defines a new local variable. c won't
allow this, directly. It needs to be broken into these two
pieces:
auto unsigned int tac;
.
.
.
tac= TACCR1;
With the first line above placed at the beginning of main()
and the second line placed just where the old one was at.
Jon
P.S.
I was recently made conscious of the fact that some compilers
may actually consider 'auto' as a compiler hint for placing
the local variable on the stack as opposed to placing it into
a register, even when the compiler would prefer placing it
into a register (no address is taken and it is frequently
accessed, for example.) I've never encountered such a
compiler case before, but I'm assured that at some revision
of gcc it can be taken that way (for ARM7?) Anyway, the use
of 'auto' is generally harmless and I had long since
consistently used the idiom of declaring 'auto' variables
using the auto keyword in source code I write. I'm probably
not going to change that well-worn standard behavior of mine
until I face that circumstance in person.
> With error "declaration may not appear after executable
> statement in block...." in console.
This often occurs in c compilers. Take a look at the
following code:
{
unsigned int i;
{
i= 5;
unsigned int j;
j= 6;
}
}
Most c compilers, those anyway that don't also support c++,
will complain that the 'unsigned int j;' declaration takes
place _after_ the executable statement 'i= 5;'
This is because that's the standard for c. If the code were
rewritten this way:
{
unsigned int i;
{
unsigned int j;
i= 5;
j= 6;
}
}
It would be just fine.
Program 11 does, in fact, declare (and define) some local
variables in the middle of executable code blocks. So it
would, with a c compiler, generate such errors.
Again, this is a matter of learning what c++ can do vs what c
can do. For example, in program 11, the statement:
auto unsigned int tac= TACCR1;
occurs in the middle of a block of executable code. This
both declares and defines a new local variable. c won't
allow this, directly. It needs to be broken into these two
pieces:
auto unsigned int tac;
.
.
.
tac= TACCR1;
With the first line above placed at the beginning of main()
and the second line placed just where the old one was at.
Jon
P.S.
I was recently made conscious of the fact that some compilers
may actually consider 'auto' as a compiler hint for placing
the local variable on the stack as opposed to placing it into
a register, even when the compiler would prefer placing it
into a register (no address is taken and it is frequently
accessed, for example.) I've never encountered such a
compiler case before, but I'm assured that at some revision
of gcc it can be taken that way (for ARM7?) Anyway, the use
of 'auto' is generally harmless and I had long since
consistently used the idiom of declaring 'auto' variables
using the auto keyword in source code I write. I'm probably
not going to change that well-worn standard behavior of mine
until I face that circumstance in person.