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

8bit reversal of all the bytes in a string

Hello everybody, Wish you all a very happy new year.

I am facing a problem, I know basically it is a C language problem but I am still not able to catch up the language yet.

I have reversed the data pins of LCD. Now while programming I can reverse the data byte by byte, but the speed of the LCD is quite low.

void LCD_sendstring(unsigned char *strLCD){     // e.g. LCD_sendstring("LCD Tutorial");
    while(*strLCD)                              //till string ends
        LCD_senddata(*strLCD++);                //send characters one by one
}


void LCD_senddata(unsigned char var){           // e.g. LCD_senddata('A');
    LCD_data = reverse(var);
    LCD_rs = 1;                 //Selected data register
    LCD_rw = 0;                 //We are writing
    LCD_en = 1;                 //Enable H->
    LCD_en = 0;
    LCD_busy1();                //Wait for LCD to process the command
}

As the above code reverses each character before sending to LCD, the characters appears slowly on LCD. So I am trying to reverse the whole string before sending to the LCD (LCD_senddata). I have tried the following codes but its not working.


void LCD_sendstring(unsigned char *strLCD){     // e.g. LCD_sendstring("LCD Tutorial");
     reverse_string(strLCD);
        *strLCD =  reverse_string1(strLCD);

        while(*strLCD)                          //till string ends
    LCD_senddata(*strLCD++);                    //send characters one by one
}


void LCD_senddata(unsigned char var){           // e.g. LCD_senddata('A');

    LCD_data = var;
    LCD_rs = 1;                 //Selected data register
    LCD_rw = 0;                 //We are writing
    LCD_en = 1;                 //Enable H->
    LCD_en = 0;
    LCD_busy1();                //Wait for LCD to process the command
}


void reverse_string(char *str){ //junk result
        while(*str){
//              *str=reverse3(*str);
                *str='B';

                str++;
        }
        str = &str;
}



char *reverse_string1(char *str){       //blank result
    int len = strlen(str);
        char *newstr = malloc(len+1);

        while(*str){                    //till string ends
//              *newstr++ = reverse(*str++);
//              *newstr++ = *str++;
                *newstr++ = 'B';
        }
        *newstr = '\0';
    return newstr;
}

In reverse_string I get junk result whereas in reverse_string1 I am getting blank display. Please Help!!!

Parents
  • My basic problem is solved!!!

    In LCD_busy function instead of using delay, I used D7 bit to check busy status. Now the LCD operation is quite fast even if the bytes are reversed one by one. Thanks for giving your time.

    One more question please. If I just added two statements in the LCD_sendstring function, boxes appear on the LCD. I declared a string & used strcpy to copy original string to it.

    void LCD_sendstring(unsigned char *strLCD){     // e.g. LCD_sendstring("LCD Tutorial");
            unsigned char *reversed_str;
    //      strcpy(reversed_str, strLCD);
    //      reverse_string(strLCD);
        while(*strLCD)                              //till string ends
        LCD_senddata(*strLCD++);    //send characters one by one
    }
    

    If I comment out the strcpy line it works ok.

Reply
  • My basic problem is solved!!!

    In LCD_busy function instead of using delay, I used D7 bit to check busy status. Now the LCD operation is quite fast even if the bytes are reversed one by one. Thanks for giving your time.

    One more question please. If I just added two statements in the LCD_sendstring function, boxes appear on the LCD. I declared a string & used strcpy to copy original string to it.

    void LCD_sendstring(unsigned char *strLCD){     // e.g. LCD_sendstring("LCD Tutorial");
            unsigned char *reversed_str;
    //      strcpy(reversed_str, strLCD);
    //      reverse_string(strLCD);
        while(*strLCD)                              //till string ends
        LCD_senddata(*strLCD++);    //send characters one by one
    }
    

    If I comment out the strcpy line it works ok.

Children