Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3487214
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:07:20+00:00 2026-05-18T11:07:20+00:00

I’ve got an LCD, connected to an Atmega32, working with single characters using this

  • 0

I’ve got an LCD, connected to an Atmega32, working with single characters using this function:

void send_char(uint8_t c){
    PORTD = c; // set the output pins to the ascii value of the char
    PORTB |= 0x05;
    _delay_us(1);
    PORTB &= 0xfa;
    _delay_us(60);
    PORTD = 0x00;
    update_cursor();
}

I can call this with a character as an argument: send_char('a'); and it works.

Then I tried wrapping a send_string function around it:

void send_string(const char * msg){
    while (*msg != '\0'){
        send_char(*msg++);
    }
}

This just puts gibberish on my LCD indicating that the ASCII value has been far off. And when I try passing an empty string (send_string("")) a minimum of three gibberish characters get displayed on the LCD.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:07:20+00:00Added an answer on May 18, 2026 at 11:07 am

    First, it seems that you are using the avr-gcc compiler. When making questions for embedded devices, you always need to say which compiler you are using.

    I will now try to help you understand what is wrong with your code and why your solution works. The function you have defined:

    void send_string(const char * msg);
    

    expects a string pointer in RAM. It doesn’t matter that you have used the const keyword, the compiler still expects the string to be in RAM. So if you have a string in ROM:

    const char msg[] PROGMEM = "Test";
    

    and you try to pass it in your function:

    send_string(msg);
    

    it just passes an invalid address to it and thus gibberish are displayed. If instead you copy it first to RAM, as you did in your solution, it works fine:

    char buf[strlen(msg)];
    strcpy_P(buf,msg);
    send_string(buf);
    

    If you want to define a function that will directly read a ROM string, you can do it like this:

    void send_string_P(const char *data)
    {
        while (pgm_read_byte(data) != 0x00)
            send_char(pgm_read_byte(data++));
    } 
    

    Notice the _P suffix. This is the general convention used to distinct functions that operate on ROM from the ones that operate on RAM.

    All these and more are nicely explained here. I also suggest that you try the AVR Freaks forum for these kind of questions. People there will be certainly more experienced in these issues than Stack Overflow users and are always happy to help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
i got an object with contents of html markup in it, for example: string
I've got a string that has curly quotes in it. I'd like to replace
I want to count how many characters a certain string has in PHP, but
I have a JSP page retrieving data and when single or double quotes are
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.