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.

What is wrong in this code?

Status
Not open for further replies.

swapan

Full Member level 4
Joined
Feb 20, 2009
Messages
199
Helped
27
Reputation
54
Reaction score
24
Trophy points
1,298
Location
Kolkata
Activity points
2,806
Friends,

I tried this simple code compiled in mikroC. When built it shows error as "Invalid expression" against a statement. The statement (red coloured) is shown below. Your help is highly solicited.

swapan

Code:
    int sample();
int sample()  {
int l_volt;
l_volt = ADC_Read (4);
        return (l_volt);
}

   int g_volt;

void main() {

     TRISC    =   0x07;
     TRISA    =   0x00;
     CMCON =      0x07;
     ANSEL =      0x30;
     do {
     g_volt = sample();

     if  (g_volt < 622)
     PORTA.F5 = 0;
     PORTA.F4 = 0;

[COLOR="#FF0000"]else if (g_volt > 622  &&  g_volt < 800)[/COLOR] // Invalid expression.
     PORTA.F5 = 1;
     PORTA.F4 = 0;

     else if (g_volt > 800  &&  g_volt < 1000)
     PORTA.F5 = 0;
     PORTA.F4 = 1;

     else
     PORTA.F5 = 1;
     PORTA.F4 = 1;

     }  while (1);
}
 

you need to enclose multiple statements under an IF in curly brackets
 


Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top