Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] "Invalid Expression" problem

Status
Not open for further replies.

shivammun13

Newbie level 4
Joined
Apr 27, 2023
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
42
hello, i have been working on a code for a program which displays the number of counts on an LCD display. When count = 0 it should display Parking Full. When i compiled the code it says invalid expression. I used conversion to string before that but it did not work, so i wrote my code without string conversions.
Can anyone check and suggest why it is not compiling? Here my full code:

Code:
sbit GreenLED at RD6_bit;
sbit RedLED at RD7_bit;
sbit IncrementButton at RB1_bit;
sbit DecrementButton at RB0_bit;
sbit LCD_EN at RD0_bit;
sbit LCD_RS at RD1_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;

sbit GreenLED_Direction at TRISD6_bit;
sbit RedLED_Direction at TRISD7_bit;
sbit IncrementButton_Direction at TRISB1_bit;
sbit DecrementButton_Direction at TRISB0_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;

int count = 10;
const int MAX_COUNT = 10;

void main() {

GreenLED_Direction = 0;
RedLED_Direction = 0;
IncrementButton_Direction = 1;
DecrementButton_Direction = 1;

Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1, 1, "P.SLOT LEFT:");
Lcd_Out(1, 13, "10");

while(1) {

 if (!DecrementButton) {
    count = count-1;

    if(count < 0){
       count = 0;
       }
       if (count == 0) {
        GreenLED = 0;
        RedLED = 1;
        } else {
        GreenLED = 1;
        RedLED = 0;
        }
        while (!DecrementButton);
    }

 if (!IncrementButton) {
     count=count+1;

     if (count > MAX_COUNT) {
        count = MAX_COUNT;
      }
      if (count > 0){
      GreenLED = 1;
      RedLED = 0;
      } else{
      GreenLED = 0;
      RedLED = 1;
      }
      while (!IncrementButton);
    }

    if (count == 10) {
    Lcd_Out(1, 13, "  ");
    Lcd_Out(1, 13, "10");
    }
    if (count == 9) {
    Lcd_Out(1, 13, "  ");
    Lcd_Out(1, 13, "9");
    }
    if (count == 8) {
    Lcd_Out(1, 13, "  ");
    Lcd_Out(1, 13, "8");
    }
    if (count == 7) {
    Lcd_Out(1, 13, "  ");
    Lcd_Out(1, 13, "7");
    }
    if (count == 6) {
    Lcd_Out(1, 13, "  ");
    Lcd_Out(1, 13, "6");
    }
    if (count == 5) {
    Lcd_Out(1, 13, "  ");
    Lcd_Out(1, 13, "5");
    }
    if (count == 4) {
    Lcd_Out(1, 13, "  ");
    Lcd_Out(1, 13, "4");
    }
    if (count == 3) {
    Lcd_Out(1, 13, "  ");
    Lcd_Out(1, 13, "3");
    }
    if (count == 2) {
    Lcd_Out(1, 13, "  ");
    Lcd_Out(1, 13, "2");
    }
    if (count == 1) {
    Lcd_Out(1, 13, "  ");
    Lcd_Out(1, 13, "1");
    }
    if (count == 0) {
    Lcd_Out(1, 13, "  ");
    Lcd_Out(1, 13, "0");
    Lcd_Out(2, 3, "PARKING FULL");
    }
 }
 
Last edited by a moderator:

Solution
You are missing the closing bracket (from main). If you change the formatting so each bracketed expression or function is indented it look like this:
Code:
sbit GreenLED at RD6_bit;
sbit RedLED at RD7_bit;
sbit IncrementButton at RB1_bit;
sbit DecrementButton at RB0_bit;
sbit LCD_EN at RD0_bit;
sbit LCD_RS at RD1_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;

sbit GreenLED_Direction at TRISD6_bit;
sbit RedLED_Direction at TRISD7_bit;
sbit IncrementButton_Direction at TRISB1_bit;
sbit DecrementButton_Direction at TRISB0_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit...
You are missing the closing bracket (from main). If you change the formatting so each bracketed expression or function is indented it look like this:
Code:
sbit GreenLED at RD6_bit;
sbit RedLED at RD7_bit;
sbit IncrementButton at RB1_bit;
sbit DecrementButton at RB0_bit;
sbit LCD_EN at RD0_bit;
sbit LCD_RS at RD1_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;

sbit GreenLED_Direction at TRISD6_bit;
sbit RedLED_Direction at TRISD7_bit;
sbit IncrementButton_Direction at TRISB1_bit;
sbit DecrementButton_Direction at TRISB0_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;

int count = 10;
const int MAX_COUNT = 10;

void main() 
{

  GreenLED_Direction = 0;
  RedLED_Direction = 0;
  IncrementButton_Direction = 1;
  DecrementButton_Direction = 1;

  Lcd_Init();
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Cmd(_LCD_CURSOR_OFF);
  Lcd_Out(1, 1, "P.SLOT LEFT:");
  Lcd_Out(1, 13, "10");

  while(1) 
  {
    if (!DecrementButton) 
    {
      count = count-1;
      if(count < 0)
      {
        count = 0;
      }
      if (count == 0) 
      {
        GreenLED = 0;
        RedLED = 1;
      } 
      else 
      {
        GreenLED = 1;
        RedLED = 0;
      }
      
      while (!DecrementButton);
    }

    if (!IncrementButton) 
    {
      count=count+1;
      if (count > MAX_COUNT) 
      {
          count = MAX_COUNT;
      }
      if (count > 0)
      {
          GreenLED = 1;
          RedLED = 0;
        }
        else
        {
          GreenLED = 0;
          RedLED = 1;
        }
      
        while (!IncrementButton);
      }

      if (count == 10) 
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "10");
      }
      if (count == 9) 
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "9");
      }
      if (count == 8) 
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "8");
      }
      if (count == 7) 
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "7");
      }
      if (count == 6) 
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "6");
      }
      if (count == 5) 
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "5");
      }
      if (count == 4) 
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "4");
      }
      if (count == 3) 
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "3");
      }
      if (count == 2) 
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "2");
      }
      if (count == 1) 
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "1");
      }
      if (count == 0) 
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "0");
        Lcd_Out(2, 3, "PARKING FULL");
      }
  }

and you can see your closing bracket matches the while statement instead of main.
Very messy and over complicated display routine.

Brian.
 

Solution
You are missing the closing bracket (from main). If you change the formatting so each bracketed expression or function is indented it look like this:
Code:
sbit GreenLED at RD6_bit;
sbit RedLED at RD7_bit;
sbit IncrementButton at RB1_bit;
sbit DecrementButton at RB0_bit;
sbit LCD_EN at RD0_bit;
sbit LCD_RS at RD1_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;

sbit GreenLED_Direction at TRISD6_bit;
sbit RedLED_Direction at TRISD7_bit;
sbit IncrementButton_Direction at TRISB1_bit;
sbit DecrementButton_Direction at TRISB0_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;

int count = 10;
const int MAX_COUNT = 10;

void main()
{

  GreenLED_Direction = 0;
  RedLED_Direction = 0;
  IncrementButton_Direction = 1;
  DecrementButton_Direction = 1;

  Lcd_Init();
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Cmd(_LCD_CURSOR_OFF);
  Lcd_Out(1, 1, "P.SLOT LEFT:");
  Lcd_Out(1, 13, "10");

  while(1)
  {
    if (!DecrementButton)
    {
      count = count-1;
      if(count < 0)
      {
        count = 0;
      }
      if (count == 0)
      {
        GreenLED = 0;
        RedLED = 1;
      }
      else
      {
        GreenLED = 1;
        RedLED = 0;
      }
     
      while (!DecrementButton);
    }

    if (!IncrementButton)
    {
      count=count+1;
      if (count > MAX_COUNT)
      {
          count = MAX_COUNT;
      }
      if (count > 0)
      {
          GreenLED = 1;
          RedLED = 0;
        }
        else
        {
          GreenLED = 0;
          RedLED = 1;
        }
     
        while (!IncrementButton);
      }

      if (count == 10)
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "10");
      }
      if (count == 9)
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "9");
      }
      if (count == 8)
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "8");
      }
      if (count == 7)
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "7");
      }
      if (count == 6)
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "6");
      }
      if (count == 5)
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "5");
      }
      if (count == 4)
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "4");
      }
      if (count == 3)
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "3");
      }
      if (count == 2)
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "2");
      }
      if (count == 1)
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "1");
      }
      if (count == 0)
      {
        Lcd_Out(1, 13, "  ");
        Lcd_Out(1, 13, "0");
        Lcd_Out(2, 3, "PARKING FULL");
      }
  }

and you can see your closing bracket matches the while statement instead of main.
Very messy and over complicated display routine.

Brian.
Thanks man! Actually i started using conversions to convert the counts to strings but i was having a lot of problems and the lcd was not displaying the counting. As a result i tried doing it this way. I don't know if this will work. I just hope it displays the counting sequence🙂
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top