I am learning to code on a microcontroller from Texas Instruments, MSP430FR6969 (link), using MSP-EXP430FR6969 launch pad (link).
I am also using an IDE CCS 6.1.0 (link).
I am doing a simple odometer, where the program counts from 0 to 99,999 and then resets again.
code below
#include <msp430.h>
#define DEVELOPMENT 0x5A80
#define ENABLE_PINS 0xFFFE
int main(void)
{
WDTCTL = DEVELOPMENT;//disable WDT
PM5CTL0 = ENABLE_PINS;//this is needed in order to enable pins
P1DIR = 0x01;//P1.1 is output
P1OUT = 0x00;//port 1 = 0x00
unsigned int tnth, thou, hund, tens, ones;
unsigned long km = 0;
while(1)
{
for(tnth = 0;tnth < 10;tnth++)
{
for(thou = 0;thou<10;thou++)
{
for(hund = 0;hund<10;hund++)
{
for(tens = 0;tens<10;tens++)
{
for(ones = 0;ones<10;ones++)
{
km = 10000*tnth + 1000*thou + 100*hund +10*tens+
ones;
}
}
}
}
}
P1OUT = ~P1OUT;//I added a breakpoint there.
km = 0;
}
return 0;
}
I added a breakpoint at P1OUT = ~P1OUT;
, build it and debugged it like in the image below.
When the debugger reaches the breakpoint, I see in the variable watch window ones, tens, hunds, thou, and tnth all equal to 10, which is what I expect.
But I also expected km = 99999
, instead I have km = 34463
, which doesn't make sense as km
is an unsigned long
Also.
When I modify the code and change unsigned int tnth, thou, hund, tens, ones
to signed int
, put a breakpoint at P1OUT = ~P1OUT
build it and debug I get km = 4294936223
in the variable watch window.
I asked the question in TI forum (link), and a member said that in my build
"../main.c", line 16: warning #552-D: variable "km" was set but never used
Kindly help me on this matter, and sorry for the long post.