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?

Parents
  • 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.

Reply
  • 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.

Children
No data