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

Creating C data lookup for interchip communication

I'm using an AT89S8252 Flash eeprom processor. The question I have is getting my case table to to do a char by char comparison. There are multiple user strings, and what I want to happen is for each letter to be compared and when found in the case table, it outputs the corresponding binary/hex value on port 0. Then move to the next char and repeat until the complete word is sent to the decoder with a an adjustable delay between each char send so the decoder blanking doesn't drop chars. Then move on to the next user string and continue this forever.

I've already got most of the frame work but I'm getting three compiler errors, I'm probably missing something petty, its late.....you know that goes. Can someone offer any recommendation as to what I'm missing ?? If more info is needed, just let me know and I can provide more.......here is framework and error:

VFD_DISPLAY.C(217): error C141: syntax error near 'P0'

#include <reg51.h>

void Userstring1();
void Userstring2();
void Userstring3();
void DigitDelay(unsigned int time);
void ASCII_convert(z);


void main()             //core system functionality
        {
        Userstring1();
        Userstring2();
        Userstring3();
        }

void Userstring1()      // User string as needed
                {
                unsigned char Turbine [] = "Turbine";
                unsigned char z;
                for(z=0;z<7;z++)
                        ASCII_convert(z)
                        P0=ASCII_convert[z];  // <<<<<<<<<<<<<<<  Error
                        DigitDelay(1);
                }

void Userstring2()      // User string as needed
                {
                unsigned char Boost [] = "Boost";
                unsigned char z;
                for(z=0;z<5;z++)
                        ASCII_convert(z)
                        P0=ASCII_convert[z];   // <<<<<<<<<<<<<<<  Error
                        DigitDelay(1);
                }

void Userstring3() // User string as needed
                {
                unsigned char Validate [] = "Validate";
                unsigned char z;
                for(z=0;z<8;z++)
                        ASCII_convert(z)
                        P0=ASCII_convert[z];  // <<<<<<<<<<<<<<<  Error
                        DigitDelay(1);
                }

void DigitDelay(unsigned int time)              //digit shifting delay to allow propogation delay transition between characters
        {
        unsigned int i,j;
        for (i=0;i<time;i++)
                for (j=0;j<1275;j++);
        }

/*=====  Case table to convert hex byte to ASCII char generation ========*/

void ASCII_convert(z)
        {
                z=z&40; //Set the write line
                switch(z)
                        {
                                case('@'):
                                        {
                                        P0=0x00;        //Binary value needed to put this char on display
                                        break;
                                        }
                                case('A'):
                                        {
                                        P0=0x01;        //Binary value needed to put this char on display
                                        break;
                                        }
                                case('B'):
                                        {
                                        P0=0x02;        //Binary value needed to put this char on display
                                        break;
                                        }
                                case('C'):
                                        {
                                        P0=0x03;        //Binary value needed to put this char on display
                                        break;
                                        }
                        }
        }

Parents Reply Children
  • Hi Dan,

    This was the most helpful answer I got and bingo it worked as I wanted it. I didn't think to take the ascii table values and then AND them with the matrix size and it works perfectly. Thank you!

    To everyone else, thanks for offering up advise and guidance.

    Regards,
    Chris

    Here is the end result:

    #include <reg51.h>
    
    
    void main(void)
    {
            while(1)
            {
    
    /// Copy this block and repeat
    
                    {
                            unsigned char string1[]="TURBINE";
                            unsigned char z;
                            for (z=0;z<=7;z++)
                            P0= 0x3F & string1[z];
                    }
    /// End copy block and paste below just bore the "Do Not edit below this line comment, be sure in include the {} braces!!!
    
                    {
                            unsigned char string1[]="BOOST";
                            unsigned char z;
                            for (z=0;z<=5;z++)
                            P0= 0x3F & string1[z];
                    }
                    {
                            unsigned char string1[]="VALIDATE";
                            unsigned char z;
                            for (z=0;z<=8;z++)
                            P0= 0x3F & string1[z];
                    }
                    {
                            unsigned char string1[]="SENSOR";
                            unsigned char z;
                            for (z=0;z<=6;z++)
                            P0= 0x3F & string1[z];
                    }
    
    
    
    // ========Do Not edit below this line =============
    
            }
    }
    
    
    

  • "... it worked as I wanted it."

    Glad to hear it.

    If you will indulge me with one more suggestion that will eliminate the need for your user to hardcode the string lengths into the 'for' loops, I'll point out that C strings are character arrays with a NUL-terminating character ('\0') as the last element. You and your user can take advantage of that to make the loops independent of a hardcoded string length. For example:

    {
        unsigned char string1[]="TURBINE";
        unsigned char z;
        for (z=0;string1[z]!='\0';z++)
            P0= 0x3F & string1[z];
    }