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

ADC and LCD interfacing issue

I have written a code for getting input from ADC 0804 and then display the value on 16x2 lcd
I need help in writing a function to convert ADC output into a value which can be displayed in 16x2 lcd. ADC is used to convert temperature output from lm35. 5V supply voltage and Vref=2.5V.
I need code for - convert_display(value)
Also keil compiler gives error - adc_inter.c(16): error C141: syntax error near '='. I am unable to understand what should be done?

#include <reg51.h>
#include <stdio.h>
#include <string.h>
void msdelay(unsigned int time);
void convert_display(unsigned char value);
#define RD P2^5;
#define WR P2^6;
#define INTR P2^7;
unsigned long MYDATA;

void main()
{ unsigned char value; MYDATA = P1; MYDATA = 0xFF; INTR = 1; RD = 1; WR = 1; while(1) { WR=0; WR=1; while(INTR==1) { } RD=0; value=MYDATA; convert_display(value); RD=1; }
}

void msdelay(unsigned int time)
{ unsigned char x,y; for(x=0;x<=time;x++) for(y=0;y<=1275;y++);
}

Parents Reply Children
  • I didn't get what does it mean?
    It means you may have thanked us for the help, but you didn't actually follow it.

  • So post the current failing code, using PRE tags so the formatting is clear.

  • #include <reg51.h>
    #include <stdio.h>
    #include <string.h>
    void msdelay(unsigned int time);
    void convert_display(unsigned char value);

    int INTR;
    #define RD = P2^5
    #define WR = P2^6;
    unsigned long MYDATA;

    void main()
    { unsigned char value; RD = 1; WR = 1; INTR = P2^7; INTR = 1; MYDATA = P1; MYDATA = 0xFF; while(1) { WR=0; WR=1; while(INTR==1) { } RD=0; value=MYDATA; convert_display(value); RD=1; }
    }

    void convert_display(unsigned char value)
    { unsigned char x,d1,d2,d3; x=value/10; d1=value%10; d2=value/10; d3=x/10; P0=d1; msdelay(250); P0=d2; msdelay(250); P0=d3; msdelay(250);
    }

    void msdelay(unsigned int time)
    { unsigned char x,y; for(x=0;x<=time;x++) for(y=0;y<=1275;y++);
    }

    Error is displayed at line 15,16,23,27,30. Error - "syntax error near '=' ".
    At every line I pass some int value to WR,RD, error is displayed.

  • The preprocessor is an _almost_ totally stupid search-and-replace function.

    You have

    #define RD P2^5;
    


    So where you use RD, the preprocesor removes RD and inserts "P2^5;". How fun is that in your expression:

    RD = 1;
    


    where you end up with

    P2^5; = 1;
    


    Does the above look like valid C code? How many ';' does it take for a single C statement?

  • #include <reg51.h>
    #include <stdio.h>
    #include <string.h>
    void msdelay(unsigned int time);
    void convert_display(unsigned char value);

    int INTR;
    #define RD = P2^5
    #define WR = P2^6
    unsigned long MYDATA;

    void main()
    { unsigned char value; RD = 1; WR = 1; INTR = P2^7; INTR = 1; MYDATA = P1; MYDATA = 0xFF; while(1) { WR=0; WR=1; while(INTR==1) { } RD=0; value=MYDATA; convert_display(value); RD=1; }
    }

    void convert_display(unsigned char value)
    { unsigned char x,d1,d2,d3; x=value/10; d1=value%10; d2=value/10; d3=x/10; P0=d1; msdelay(250); P0=d2; msdelay(250); P0=d3; msdelay(250);
    }

    void msdelay(unsigned int time)
    { unsigned char x,y; for(x=0;x<=time;x++) for(y=0;y<=1275;y++);
    }

    Error - syntax error near '='.
    I think I'm making some mistake in passing value to RD,WR

  • Read the posting notes lest it be obvious you didn't bother. Place source code between PRE tags, otherwise the line relationships are lost.
    http://www.keil.com/forum/tips.asp

  • Too late - it is obvious!

    And if you can so totally fail to spot & follow such such obviously-placed, clearly-stated, easy instruction - even having had them pointed-out to you several times - that doesn't bode well for success in any kind of programming.

    www.danlhenry.com/.../keil_code.png

  • P2^5; = 1;
    

    Where it should be blatantly obvious that there is a, "syntax error near '=' " - isn't it?

    Which is almost exactly the same as the example I gave you earlier:

    www.8052.com/.../29152

  • P2^5; = 1;
    


    Can be "translated to"

    P2^5;
    = 1;
    


    First a meaningless pin read without any use of the result.

    Then a very interesting expression where some magic "nothing" should be given the value 1.

    I don't blame the compiler for not liking a statement starting with a '='.

  • Please will you give me c code? I'll study the code. - Take input from ADC 0804 and display it at 16x2 lcd display.

  • I have written a code. At last, no errors and no warnings. Now I need function definition for "convert_display" Please help me. I have to convert temperature from lm35 ->ADC0804(ref voltage 2.28V) ->89s51and display it on 16x2 lcd display.

    
    #include <REGX51.h>
    #include <stdio.h>
    #include <string.h>
    void msdelay(unsigned int time);
    void convert_display(unsigned char value);
    #define SET(reg, bit) reg |=  (1 << bit)  // Sets a bit in reg.
    #define CLR(reg, bit) reg &= ~(1 << bit)  // Clears a bit in reg.
    #define INTR P2^7
    #define RD P2^5
    #define WR P2^6
    #define MYDATA P0
    void main()
    {
            unsigned char value;
            SET(P2,5);
            SET (P2,6);
            SET (P2,7);
            MYDATA =0xFF;
            while(1)
            {
                    CLR(P2,6); SET(P2,6);
                    while(INTR==1)
                    {
                    }
                    CLR(P2,5);
                    value=MYDATA;
                    convert_display(value);
                    SET(P2,5);
            }
    }
    
    void convert_display(unsigned char value)
    {
    
    }
    
    void msdelay(unsigned int time)
    {
            unsigned char x,y;
            for(x=0;x<=time;x++)
            for(y=0;y<=1275;y++);
    }
    
    
    

  • I have written a code. At last, no errors and no warnings. Now I need function definition for "convert_display" Please help me. I have to convert temperature from lm35 ->ADC0804(ref voltage 2.28V) ->89s51and display it on 16x2 lcd display.

    
    #include <REGX51.h>
    #include <stdio.h>
    #include <string.h>
    void msdelay(unsigned int time);
    void convert_display(unsigned char value);
    #define SET(reg, bit) reg |=  (1 << bit)  // Sets a bit in reg.
    #define CLR(reg, bit) reg &= ~(1 << bit)  // Clears a bit in reg.
    #define INTR P2^7
    #define RD P2^5
    #define WR P2^6
    #define MYDATA P0
    void main()
    {
            unsigned char value;
            SET(P2,5);
            SET (P2,6);
            SET (P2,7);
            MYDATA =0xFF;
            while(1)
            {
                    CLR(P2,6); SET(P2,6);
                    while(INTR==1)
                    {
                    }
                    CLR(P2,5);
                    value=MYDATA;
                    convert_display(value);
                    SET(P2,5);
            }
    }
    
    void convert_display(unsigned char value)
    {
    
    }
    
    void msdelay(unsigned int time)
    {
            unsigned char x,y;
            for(x=0;x<=time;x++)
            for(y=0;y<=1275;y++);
    }
    
    
    

  • The number/alphabets must be in ascii format to be dispalyed on lcd.
    Heard about itoa function? perform a web search.

  • There is plenty of code already on this very site - not to mention the rest of the internet - for you to study.

    There are also plenty of resources to help you learn 'C' programming; eg,

    blog.antronics.co.uk/.../

  • So what do you think these lines are for

    #include <stdio.h>
    #include <string.h>
    

    Get out your 'C' textbook, and look at the functions provided by the Standard 'C' Library...

    Again, here are some 'C' learning resources - including a free online textbook:

    blog.antronics.co.uk/.../