You need braces around a multi-statement block, if you want to use it as the body of an if
(or for
or whatever) statement:
else if (PORTA.RA2==1) {
count = count+1;
PORTC = count;
}
otherwise only the first statement is conditional; so your code executes PORTC = count;
every time, whatever the result of the if
tests.
I like to put braces around all such blocks, even there's only a single statement, so I can't forget to add them if I add more statements later.
Also, main
must return int
not void
, and you should take more care formatting your code to match its logical structure.
UPDATE: Also, you never initialise count
, so it has an arbitrary floating-point value. You want a small integer type, since it's only supposed to take integer values from 0 to 16, and you need to initialise it:
char count = 0;