12F675 and registers

General discussion on mikroC.
Post Reply
Author
Message
ascomm
Posts: 129
Joined: 30 Mar 2005 18:28
Location: Finland

12F675 and registers

#1 Post by ascomm » 26 Jul 2005 13:58

Hi!

Something weird going on with this program:

Code: Select all

void main(void)
{
  //TRISIO = 1;
  //CMCON = 7;
  //ANSEL = 0;

  unsigned short a, b;
  a = 0;
  b = 0;

  while (1)
  {
    a = Button(&GPIO, 0, 1, 5);
    if (a == 255 && b < 3)
    {
      b++;
    }
    else
    {
      b=0;
    }
    switch (b)
    {
      case 0: poweroff();  break;
      case 1: bright(); break;
      case 2: powersaving();  break;
      case 3: blinking(); break;
    }
  }
}
Program compiles without setting registers, but with them
mC complains that unsigned short a, b; is invalid expression.
Any ideas how to overcome this problem?

Storic
Posts: 393
Joined: 01 Oct 2004 00:20
Location: Australia (S.A.)

#2 Post by Storic » 26 Jul 2005 14:17

You assign a ungigned short a, b; within void main(void), I was alway under the impression to declare all vars and const etc at the top of the program and declare the unsigned short a, b value within void main(void)

Andrew

ascomm
Posts: 129
Joined: 30 Mar 2005 18:28
Location: Finland

#3 Post by ascomm » 26 Jul 2005 16:40

Storic wrote:You assign a ungigned short a, b; within void main(void)
Hmmm... Declaring variables in main() has never before been problem. Strange... :?

ascomm
Posts: 129
Joined: 30 Mar 2005 18:28
Location: Finland

#4 Post by ascomm » 26 Jul 2005 16:56

Ok. This must be a somekind of an bug? :!: mE team :!:
If I move unsigned short a, b; before the register initialization then the program compiles without any pain.
But if it's after the register initialization then the problems arise.
So problem has been bypassed :)
char *signature;
signature = "MikroC Pro and EasyPIC 2";

pizon
mikroElektronika team
Posts: 823
Joined: 11 Oct 2004 08:53

#5 Post by pizon » 27 Jul 2005 08:48

The ANSI C Standard requires the declarations (if they exist) to be placed at the beginning of the statement block ({}), so the last thing you've done is the right way to do it.
pizon

Post Reply

Return to “mikroC General”