This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

is it a correct keil v4 program or not

#include <regx51.h> // standard 8051 defines
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// -=-=-=-=- Include files -=-=-=-=-=-=-=
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include <lcd.h>
#include <utils.h>

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// -=-=-=-=- Hardware Defines -=-=-=-=-=-=-=
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
sfr DATA = P0;
sbit OUT1 = P3^4;
sbit OUT2 = P3^5;
sbit OUT3 = P3^6;
sbit OUT4 = P3^7;

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// -=-=-=-=- Variables -=-=-=-=-=-=-=
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
char buf[20];
char code M1[] ="SPEECH: ONE";
char code M2[] ="SPEECH: TWO";
char code M3[] ="SPEECH: THREE";
char code M4[] ="SPEECH: FOUR";
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// -=-=-=-=- Main Program -=-=-=-=-=-=-=
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void main()
{ unsigned char lastdata, datanow; // -=-=- Intialize variables -=-=-= OUT1 = 0; OUT2 = 0; OUT3 = 0; OUT4 = 0; // -=-=- Intialise -=-=-= lcdInit(); // -=-=- Welcome LCD Message -=-=-= lcdClear(); lcdGotoXY(0,0); // 1st Line of LCD lcdPrint("Speech Test"); lcdGotoXY(0,1); // 2nd Line of LCD lcdPrint("System"); delayms(5000); // 5 sec lcdClear(); lcdGotoXY(0,0); // 1st Line of LCD lcdPrint("Train: 1-4 key >"); lcdGotoXY(0,1); // 2nd Line of LCD lcdPrint("Train>Speak Now"); // -=-=- Program Loop -=-=-= lastdata=0xff; while(1) { datanow=DATA; // read data from speech board

if(lastdata!=datanow) // if there is new data then, { lastdata=datanow; switch(lastdata) { case 0x55: lcdClear(); lcdGotoXY(0,0); // 1st Line of LCD lcdPrint("Speech too Long"); lcdGotoXY(0,1); // 2nd Line of LCD lcdPrint("Try Again!"); break; case 0x66: lcdClear(); lcdGotoXY(0,0); // 1st Line of LCD lcdPrint("Speech too Short"); lcdGotoXY(0,1); // 2nd Line of LCD lcdPrint("Try Again!"); break; case 0x77: lcdClear(); lcdGotoXY(0,0); // 1st Line of LCD lcdPrint("No Match"); lcdGotoXY(0,1); // 2nd Line of LCD lcdPrint("Try Again!"); break; case 0x01: if(OUT1==1) OUT1 = 0; else OUT1 = 1; lcdClear(); lcdGotoXY(0,0); // 1st Line of LCD lcdPrint(M1); break; case 0x02: if(OUT2==1) OUT2 = 0; else OUT2 = 1; lcdClear(); lcdGotoXY(0,0); // 1st Line of LCD lcdPrint(M2); break; case 0x03: if(OUT3==1) OUT3 = 0; else OUT3 = 1; lcdClear(); lcdGotoXY(0,0); // 1st Line of LCD lcdPrint(M3); break; case 0x04: if(OUT4==1) OUT4 = 0; else OUT4 = 1; lcdClear(); lcdGotoXY(0,0); // 1st Line of LCD lcdPrint(M4); break; } } }
}

is it a correct program?
and what is utils.h?

  • If it's a correct Keil program?

    We can't even read it since you didn't add the proper formatting.

    What <lcd.h> and <utils.h> means? That depends entirely on what files you happen to have with these file names, and available in the configured "system" include directories.

    Why are you asking? Do you get compilation errors?

  • #include <REGX51.H>
    // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    // -=-=-=-=- Include files -=-=-=-=-=-=-=
    // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    #include <lcd.h>
    #include <utils.h>
    #include <stdio.h>

    // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    // -=-=-=-=- Hardware Defines -=-=-=-=-=-=-=
    // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    sfr DATA = P0;
    sbit OUT1 = P3^4;
    sbit OUT2 = P3^5;
    sbit OUT3 = P3^6;
    sbit OUT4 = P3^7;

    // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    // -=-=-=-=- Variables -=-=-=-=-=-=-=
    // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    char buf[20];
    char code M1[] ="SPEECH: ONE";
    char code M2[] ="SPEECH: TWO";
    char code M3[] ="SPEECH: THREE";
    char code M4[] ="SPEECH: FOUR";
    // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    // -=-=-=-=- Main Program -=-=-=-=-=-=-=
    // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    void main()
    {

    unsigned char lastdata, datanow; // -=-=- Intialize variables -=-=-=

    OUT1 = 0; OUT2 = 0; OUT3 = 0; OUT4 = 0;

    // -=-=- Intialise -=-=-=

    lcdInit();

    // -=-=- Welcome LCD Message -=-=-= lcdClear();

    lcdGotoXY(0,0); // 1st Line of LCD

    lcdPrint("Speech Test");

    lcdGotoXY(0,1); // 2nd Line of LCD

    lcdPrint("System");

    delayms(5000); // 5 sec

    lcdClear();

    lcdGotoXY(0,0); // 1st Line of LCD

    lcdPrint("Train: 1-4 key >");

    lcdGotoXY(0,1); // 2nd Line of LCD

    lcdPrint("Train>Speak Now");

    // -=-=- Program Loop -=-=-=

    lastdata=0xff; while(1) { datanow=DATA; // read data from speech board

    if(lastdata!=datanow) // if there is new data then, { lastdata=datanow;

    switch(lastdata) { case 0x55:

    lcdClear();

    lcdGotoXY(0,0); // 1st Line of LCD

    lcdPrint("Speech too Long");

    lcdGotoXY(0,1); // 2nd Line of LCD

    lcdPrint("Try Again!");

    break;

    case 0x66:

    lcdClear();

    lcdGotoXY(0,0); // 1st Line of LCD

    lcdPrint("Speech too Short");

    lcdGotoXY(0,1); // 2nd Line of LCD

    lcdPrint("Try Again!");

    break;

    case 0x77:

    lcdClear();

    lcdGotoXY(0,0); // 1st Line of LCD

    lcdPrint("No Match");

    lcdGotoXY(0,1); // 2nd Line of LCD

    lcdPrint("Try Again!");

    break;

    case 0x01:

    if(OUT1==1)

    OUT1 = 0;

    else

    OUT1 = 1;

    lcdClear();

    lcdGotoXY(0,0); // 1st Line of LCD

    lcdPrint(M1);

    break;

    case 0x02:

    if(OUT2==1)

    OUT2 = 0;

    else

    OUT2 = 1;

    lcdClear();

    lcdGotoXY(0,0); // 1st Line of LCD

    lcdPrint(M2);

    break;

    case 0x03:

    if(OUT3==1)

    OUT3 = 0;

    else

    OUT3 = 1;

    lcdClear();

    lcdGotoXY(0,0); // 1st Line of LCD

    lcdPrint(M3);

    break;

    case 0x04:

    if(OUT4==1)

    OUT4 = 0;

    else

    OUT4 = 1;

    lcdClear();

    lcdGotoXY(0,0); // 1st Line of LCD

    lcdPrint(M4);

    break;

    }

    } }
    }

  • So fix them, then!

    Is it really that hard to spot & follow the posting instructions: www.danlhenry.com/.../keil_code.png

  • You get compilation errors. But for some magic reason you don't think it would be to your advantage to post these error messages?

    One of the main goals with compilation error messages is to inform the developer of what is wrong. It is then up to the developer to decide how best to rectify this before trying again.

  • #include <REGX51.H>
    // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    // -=-=-=-=- Include files -=-=-=-=-=-=-=
    // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    #include <lcd.h>
    #include <utils.h>
    #include <stdio.h>
    
    // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    // -=-=-=-=- Hardware Defines -=-=-=-=-=-=-=
    // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    sfr DATA = P0;
    sbit OUT1 = P3^4;
    sbit OUT2 = P3^5;
    sbit OUT3 = P3^6;
    sbit OUT4 = P3^7;
    
    // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    // -=-=-=-=- Variables -=-=-=-=-=-=-=
    // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    char buf[20];
    char code M1[] ="SPEECH: ONE";
    char code M2[] ="SPEECH: TWO";
    char code M3[] ="SPEECH: THREE";
    char code M4[] ="SPEECH: FOUR";
    // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    // -=-=-=-=- Main Program -=-=-=-=-=-=-=
    // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    void main()
    {
        unsigned char lastdata, datanow;
        // -=-=- Intialize variables -=-=-=
        OUT1 = 0;
        OUT2 = 0;
        OUT3 = 0;
        OUT4 = 0;
        // -=-=- Intialise -=-=-=
        lcdInit();
        // -=-=- Welcome LCD Message -=-=-=
        lcdClear();
        lcdGotoXY(0,0); // 1st Line of LCD
        lcdPrint("Speech Test");
        lcdGotoXY(0,1); // 2nd Line of LCD
        lcdPrint("System");
        delayms(5000); // 5 sec
        lcdClear();
        lcdGotoXY(0,0); // 1st Line of LCD
        lcdPrint("Train: 1-4 key >");
        lcdGotoXY(0,1); // 2nd Line of LCD
        lcdPrint("Train>Speak Now");
        // -=-=- Program Loop -=-=-=
        lastdata=0xff;
        while(1)
        {
            datanow=DATA; // read data from speech board
    
            if(lastdata!=datanow) // if there is new data then,
            {
                lastdata=datanow;
                switch(lastdata)
                {
                    case 0x55:
                    lcdClear();
                    lcdGotoXY(0,0); // 1st Line of LCD
                    lcdPrint("Speech too Long");
                    lcdGotoXY(0,1); // 2nd Line of LCD
                    lcdPrint("Try Again!");
                    break;
                    case 0x66:
                    lcdClear();
                    lcdGotoXY(0,0); // 1st Line of LCD
                    lcdPrint("Speech too Short");
                    lcdGotoXY(0,1); // 2nd Line of LCD
                    lcdPrint("Try Again!");
                    break;
                    case 0x77:
                    lcdClear();
                    lcdGotoXY(0,0); // 1st Line of LCD
                    lcdPrint("No Match");
                    lcdGotoXY(0,1); // 2nd Line of LCD
                    lcdPrint("Try Again!");
                    break;
                    case 0x01:
                    if(OUT1==1)
                    OUT1 = 0;
                    else
                    OUT1 = 1;
                    lcdClear();
                    lcdGotoXY(0,0); // 1st Line of LCD
                    lcdPrint(M1);
                    break;
                    case 0x02:
                    if(OUT2==1)
                    OUT2 = 0;
                    else
                    OUT2 = 1;
                    lcdClear();
                    lcdGotoXY(0,0); // 1st Line of LCD
                    lcdPrint(M2);
                    break;
                    case 0x03:
                    if(OUT3==1)
                    OUT3 = 0;
                    else
                    OUT3 = 1;
                    lcdClear();
                    lcdGotoXY(0,0); // 1st Line of LCD
                    lcdPrint(M3);
                    break;
                    case 0x04:
                    if(OUT4==1)
                    OUT4 = 0;
                    else
                    OUT4 = 1;
                    lcdClear();
                    lcdGotoXY(0,0); // 1st Line of LCD
                    lcdPrint(M4);
                    break;
                }
            }
        }
    }
    
    
    
    and I am getting following errors:-
    voice.c(5): warning C318: can't open file 'lcd.h'
    voice.c(6): warning C318: can't open file 'utils.h'
    VOICE.C(12): error C141: syntax error near 'P0', expected 'const'
    voice.c - 1 Error(s), 2 Warning(s).
    
    
    

  • can't open file 'lcd.h'
    

    I think you should know what it means, as it writes.
    The compiler cannot find/open the header file 'lcd.h'.
    You should tell the compiler where it is. Normally you should tell the compiler proper include paths in Options for Target >> C/C++ >> Include Paths

  • thank you.
    what about this error VOICE.C(12): error C141: syntax error near 'P0', expected 'const'

  • Learn your Cx51 User's Guide for proper syntax of 'sfr'.

  • now these errors are coming into picture
    compiling voice.c...
    voice.c(6): warning C318: can't open file 'utils.h'
    VOICE.C(38): warning C206: 'lcdInit': missing function-prototype
    VOICE.C(40): warning C206: 'lcdClear': missing function-prototype
    VOICE.C(41): warning C206: 'lcdGotoXY': missing function-prototype
    VOICE.C(41): error C267: 'lcdGotoXY': requires ANSI-style prototype
    voice.c - 1 Error(s), 4 Warning(s).

  • So - you have picked up some random source code somewhere.

    Most probably you have a school project and figured that the code you found seems to be close enough to your task so you want to hand it in and save lots of time.

    But one thing with code you have found - you need to understand it. Another thing - you need to make sure you get the complete code. the lcd.h and utils.h files aren't part of the C language but are most probably either extensions supplied by a tool vendor or a library vendor or are written by the same person who wrote the main source file.

    Before you have these lcd.h and utils.h files in your configured include path, "your" code will not compile.

  • So provide a suitable function prototype, then!

    You do know what a function prototype is - don't you...?

  • The prototype (in the style defined by the ANSI standard) is not optional - it is required

  • You do not need to learn the Cx51 User's Guide in the sense of memorising it by heart; it is a reference document - so you should refer to it when required.

    But you do need to spend time gaining familiarity with it - so that you can find your way around easily.

    You also need a good understanding of the 'C' Programming language.

  • One interesting thing with this incomplete program.

    Not only are the two header files needed.

    But one step later, the linker will also need access to the object code for the actual implementation of whatever functions that the lcd and utils header files happens to mention.