Electronic – Setting a pin on PORTA in the PIC18F452 high: Compilation of code failed

cpicport

I am trying to write code that will set bit0 on PORTA in the PIC18F452 high if any of the conditions in the IF statements has been met. I am using the MPLAB ICD2 debugger and the Microchip C18 Toolsuite. The code is as follows:

#include <p18f452.h>

void main (void)
{
    // array containing vital sign values 
    unsigned char pulseR = 0x32;  // syntax error 
    unsigned char sysP = 0x64;
    unsigned char diasP = 0x26;

    // acceptable limits for vital signs according to relavant heath officials
    unsigned char pulseR_ULimit = 0xA0;
    unsigned char pulseR_LLimit = 0x28;

    unsigned char diastolic_ULimit = 0x5A;
    unsigned char diastolic_LLimit = 0x3C;

    unsigned char systolic_ULimit = 0x8C;
    unsigned char systolic_LLimit = 0x5A;

    TRISAbits.TRISA0 = 0;

    //Comparing obtained values with acceptable limits
    if (sysP < systolic_LLimit || sysP > systolic_ULimit)
    {
        PORTAbits.RA0 = 1;
    }
    else if (diasP < diastolic_LLimit || diasP > diastolic_ULimit ) 
    {
        PORTAbits.RA0 = 1 ;    
    }
    else if (pulseR < pulseR_LLimit || pulseR > pulseR_ULimit ) 
    {
        PORTAbits.RA0 = 1;
    }
    else                 
        PORTAbits.RA0 = 0;
}

Added:

The Build output is as follows:

 Debug build of project `C:\Users\Owner\Desktop\School Files\ECNG 3006 2011\Labs\Lab 3\Softare-Hardware Only\Lab3_3.mcp' started.
Preprocessor symbol `__DEBUG' is defined.
Sat Nov 19 13:56:03 2011
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\Users\Owner\Desktop\School Files\ECNG 3006 2011\Labs\Lab 3\Softare-Hardware Only\Lab3_3.mcs".
Clean: Done.
Couldn't locate build tool.  Check tool locations.
----------------------------------------------------------------------
Debug build of project `C:\Users\Owner\Desktop\School Files\ECNG 3006 2011\Labs\Lab 3\Softare-Hardware Only\Lab3_3.mcp' failed.
Preprocessor symbol `__DEBUG' is defined.
Sat Nov 19 13:56:05 2011
----------------------------------------------------------------------
BUILD FAILED

Can somebody please help me troubleshoot this code?

Best Answer

For setting an output you should use LATAbits.RA0 = x instead of PORTAbits.RA0 = x.

Also, try adding some brackets. Try this:

#include <p18f452.h>

void main (void)
{
    // array containing vital sign values 
    unsigned char pulseR = 0x32;  // syntax error 
    unsigned char sysP = 0x64;
    unsigned char diasP = 0x26;

    // acceptable limits for vital signs according to relavant heath officials
    unsigned char pulseR_ULimit = 0xA0;
    unsigned char pulseR_LLimit = 0x28;

    unsigned char diastolic_ULimit = 0x5A;
    unsigned char diastolic_LLimit = 0x3C;

    unsigned char systolic_ULimit = 0x8C;
    unsigned char systolic_LLimit = 0x5A;

    TRISAbits.TRISA0 = 0;

    //Comparing obtained values with acceptable limits
    if ((sysP < systolic_LLimit)||(sysP > systolic_ULimit))
    {
        LATAbits.RA0 = 1;
    }
    else if ((diasP < diastolic_LLimit)||(diasP > diastolic_ULimit)) 
    {
        LATAbits.RA0 = 1 ;    
    }
    else if ((pulseR < pulseR_LLimit)||(pulseR > pulseR_ULimit)) 
    {
        LATAbits.RA0 = 1;
    }
    else 
    {                
        LATAbits.RA0 = 0;
    }
}